2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 // This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 // platform project (RICP).
29 "github.com/pkg/errors"
30 "github.com/stretchr/testify/assert"
36 const E2TAddress = "10.0.2.15:38000"
38 // TODO: add response Body and dont check for nil in prod code. itll always be populated
40 func initRoutingManagerClientTest(t *testing.T) (*RoutingManagerClient, *mocks.HttpClientMock, *configuration.Configuration) {
42 config := &configuration.Configuration{}
43 config.RoutingManager.BaseUrl = "http://iltlv740.intl.att.com:8080/ric/v1/handles/"
44 httpClientMock := &mocks.HttpClientMock{}
45 rmClient := NewRoutingManagerClient(logger, config, httpClientMock)
46 return rmClient, httpClientMock, config
49 func TestAddE2TInstanceSuccess(t *testing.T) {
50 rmClient, httpClientMock, config := initRoutingManagerClientTest(t)
52 data := models.NewRoutingManagerE2TData(E2TAddress)
53 marshaled, _ := json.Marshal(data)
54 body := bytes.NewBuffer(marshaled)
55 url := config.RoutingManager.BaseUrl + "e2t"
56 respBody := ioutil.NopCloser(bytes.NewBufferString(""))
57 httpClientMock.On("Post", url, "application/json", body).Return(&http.Response{StatusCode: http.StatusCreated, Body: respBody}, nil)
58 err := rmClient.AddE2TInstance(E2TAddress)
62 func TestAddE2TInstanceHttpPostFailure(t *testing.T) {
63 rmClient, httpClientMock, config := initRoutingManagerClientTest(t)
65 data := models.NewRoutingManagerE2TData(E2TAddress)
66 marshaled, _ := json.Marshal(data)
67 body := bytes.NewBuffer(marshaled)
68 url := config.RoutingManager.BaseUrl + "e2t"
69 httpClientMock.On("Post", url, "application/json", body).Return(&http.Response{}, errors.New("error"))
70 err := rmClient.AddE2TInstance(E2TAddress)
74 func TestAddE2TInstanceFailure(t *testing.T) {
75 rmClient, httpClientMock, config := initRoutingManagerClientTest(t)
77 data := models.NewRoutingManagerE2TData(E2TAddress)
78 marshaled, _ := json.Marshal(data)
79 body := bytes.NewBuffer(marshaled)
80 url := config.RoutingManager.BaseUrl + "e2t"
81 respBody := ioutil.NopCloser(bytes.NewBufferString(""))
82 httpClientMock.On("Post", url, "application/json", body).Return(&http.Response{StatusCode: http.StatusBadRequest, Body:respBody}, nil)
83 err := rmClient.AddE2TInstance(E2TAddress)
87 // TODO: extract to test_utils
88 func initLog(t *testing.T) *logger.Logger {
89 log, err := logger.InitLogger(logger.InfoLevel)
91 t.Errorf("#delete_all_request_handler_test.TestHandleSuccessFlow - failed to initialize logger, error: %s", err)
96 //func TestAddE2TInstanceInteg(t *testing.T) {
97 // logger := initLog(t)
98 // config := configuration.ParseConfiguration()
99 // httpClient := &http.Client{}
100 // rmClient := NewRoutingManagerClient(logger, config, httpClient)
101 // err := rmClient.AddE2TInstance(E2TAddress)
102 // assert.Nil(t, err)