5efc75337db00f7e8ecc12a5f86fc1dcd5bdcaaf
[ric-plt/e2mgr.git] / E2Manager / clients / routing_manager_client_test.go
1 //
2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //      http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16
17 //  This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 //  platform project (RICP).
19
20
21 package clients
22
23 import (
24         "e2mgr/configuration"
25         "e2mgr/logger"
26         "e2mgr/mocks"
27         "testing"
28 )
29
30 const E2TAddress = "10.0.2.15:38000"
31
32 // TODO: add response Body and dont check for nil in prod code. itll always be populated
33
34 func initRoutingManagerClientTest(t *testing.T) (*RoutingManagerClient, *mocks.HttpClientMock, *configuration.Configuration) {
35         logger := initLog(t)
36         config := &configuration.Configuration{
37                 RoutingManagerBaseUrl: "http://iltlv740.intl.att.com:8080/ric/v1/handles/v1/",
38         }
39         httpClientMock := &mocks.HttpClientMock{}
40         rmClient := NewRoutingManagerClient(logger, config, httpClientMock)
41         return rmClient, httpClientMock, config
42 }
43
44 //func TestAddE2TInstanceSuccess(t *testing.T) {
45 //      rmClient, httpClientMock, config := initRoutingManagerClientTest(t)
46 //
47 //      data := models.NewRoutingManagerE2TData(E2TAddress)
48 //      marshaled, _ := json.Marshal(data)
49 //      body := bytes.NewBuffer(marshaled)
50 //      url := config.RoutingManagerBaseUrl + "e2t"
51 //      httpClientMock.On("Post", url, "application/json", body).Return(&http.Response{StatusCode: 200}, nil)
52 //      err := rmClient.AddE2TInstance(E2TAddress)
53 //      assert.Nil(t, err)
54 //}
55 //
56 //func TestAddE2TInstanceFailure(t *testing.T) {
57 //      rmClient, httpClientMock, config := initRoutingManagerClientTest(t)
58 //
59 //      data := models.NewRoutingManagerE2TData(E2TAddress)
60 //      marshaled, _ := json.Marshal(data)
61 //      body := bytes.NewBuffer(marshaled)
62 //      url := config.RoutingManagerBaseUrl + "e2t"
63 //      httpClientMock.On("Post", url, "application/json", body).Return(&http.Response{StatusCode: 400}, nil)
64 //      err := rmClient.AddE2TInstance(E2TAddress)
65 //      assert.NotNil(t, err)
66 //}
67
68 // TODO: extract to test_utils
69 func initLog(t *testing.T) *logger.Logger {
70         log, err := logger.InitLogger(logger.InfoLevel)
71         if err != nil {
72                 t.Errorf("#delete_all_request_handler_test.TestHandleSuccessFlow - failed to initialize logger, error: %s", err)
73         }
74         return log
75 }
76
77 //func TestAddE2TInstanceInteg(t *testing.T) {
78 //      logger := initLog(t)
79 //      config := configuration.ParseConfiguration()
80 //      httpClient := &http.Client{}
81 //      rmClient := NewRoutingManagerClient(logger, config, httpClient)
82 //      err := rmClient.AddE2TInstance(E2TAddress)
83 //      assert.Nil(t, err)
84 //}