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).
20 package rmrmsghandlers
23 "github.com/stretchr/testify/assert"
24 "github.com/stretchr/testify/mock"
34 func initRanConnectedNotificationHandlerTest(t *testing.T, requestName string) (ResourceStatusInitiateNotificationHandler, *mocks.ResourceStatusInitiateManagerMock, *configuration.Configuration) {
35 log, err := logger.InitLogger(logger.DebugLevel)
37 t.Errorf("#... - failed to initialize logger, error: %s", err)
39 config, err := configuration.ParseConfiguration()
41 t.Errorf("#... - failed to parse configuration error: %s", err)
43 managerMock := &mocks.ResourceStatusInitiateManagerMock{}
44 h := NewResourceStatusInitiateNotificationHandler(log, config, managerMock, requestName)
45 return h, managerMock, config
48 func TestHandlerInit(t *testing.T) {
49 h, _, _ := initRanConnectedNotificationHandlerTest(t, "RanConnected")
53 func TestHandleSuccess(t *testing.T) {
54 h, managerMock, config := initRanConnectedNotificationHandlerTest(t, "RanConnected")
56 payloadStr := "{\"nodeType\":1, \"messageDirection\":1}"
57 payload := []byte(payloadStr)
58 rmrReq := &models.RmrRequest{RanName:"RAN1", Payload:payload, Len:len(payload), StartTime:time.Now()}
59 managerMock.On("Execute", rmrReq.RanName, mock.AnythingOfType("*e2pdus.ResourceStatusRequestData")).Return(nil)
61 resourceStatusInitiateRequestParams := &e2pdus.ResourceStatusRequestData{}
62 populateResourceStatusInitiateRequestParams(resourceStatusInitiateRequestParams, config)
65 managerMock.AssertCalled(t, "Execute", rmrReq.RanName, resourceStatusInitiateRequestParams)
68 func TestHandleResourceStatusNotEnabled(t *testing.T) {
69 h, managerMock, config := initRanConnectedNotificationHandlerTest(t, "RanConnected")
70 config.ResourceStatusParams.EnableResourceStatus = false
72 payloadStr := "{\"nodeType\":1, \"messageDirection\":1}"
73 payload := []byte(payloadStr)
74 rmrReq := &models.RmrRequest{RanName:"RAN1", Payload:payload, Len:len(payload), StartTime:time.Now()}
75 managerMock.On("Execute", rmrReq.RanName, mock.AnythingOfType("*e2pdus.ResourceStatusRequestData")).Return(nil)
78 managerMock.AssertNumberOfCalls(t, "Execute", 0)
81 func TestHandleUnknownJson(t *testing.T) {
82 h, managerMock, _ := initRanConnectedNotificationHandlerTest(t, "RanConnected")
84 payloadStr := "blablabla"
85 payload := []byte(payloadStr)
86 rmrReq := &models.RmrRequest{RanName:"RAN1", Payload:payload, Len:len(payload), StartTime:time.Now()}
87 managerMock.On("Execute", rmrReq.RanName, mock.AnythingOfType("*e2pdus.ResourceStatusRequestData")).Return(nil)
90 managerMock.AssertNumberOfCalls(t, "Execute", 0)
93 func TestHandleGnbNode(t *testing.T) {
94 h, managerMock, _ := initRanConnectedNotificationHandlerTest(t, "RanConnected")
96 payloadStr := "{\"nodeType\":2, \"messageDirection\":1}"
97 payload := []byte(payloadStr)
98 rmrReq := &models.RmrRequest{RanName:"RAN1", Payload:payload, Len:len(payload), StartTime:time.Now()}
99 managerMock.On("Execute", rmrReq.RanName, mock.AnythingOfType("*e2pdus.ResourceStatusRequestData")).Return(nil)
102 managerMock.AssertNumberOfCalls(t, "Execute", 0)