X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=RSM%2Fhandlers%2Frmrmsghandlers%2Fresource_status_initiate_notification_handler_test.go;fp=RSM%2Fhandlers%2Frmrmsghandlers%2Fresource_status_initiate_notification_handler_test.go;h=8474306035856c3babb6b7e100dec9927d67f8e2;hb=7b80668df78103cebafdfb7caa0070dc92ed3779;hp=0000000000000000000000000000000000000000;hpb=66db8f159a8034a65cc02f3ff4701cdfb908b496;p=ric-plt%2Fresource-status-manager.git diff --git a/RSM/handlers/rmrmsghandlers/resource_status_initiate_notification_handler_test.go b/RSM/handlers/rmrmsghandlers/resource_status_initiate_notification_handler_test.go new file mode 100644 index 0000000..8474306 --- /dev/null +++ b/RSM/handlers/rmrmsghandlers/resource_status_initiate_notification_handler_test.go @@ -0,0 +1,100 @@ +// +// Copyright 2019 AT&T Intellectual Property +// Copyright 2019 Nokia +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package rmrmsghandlers + +import ( + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + "rsm/configuration" + "rsm/e2pdus" + "rsm/logger" + "rsm/mocks" + "rsm/models" + "testing" + "time" +) + +func initRanConnectedNotificationHandlerTest(t *testing.T, requestName string) (ResourceStatusInitiateNotificationHandler, *mocks.ResourceStatusInitiateManagerMock, *configuration.Configuration) { + log, err := logger.InitLogger(logger.DebugLevel) + if err != nil { + t.Errorf("#... - failed to initialize logger, error: %s", err) + } + config, err := configuration.ParseConfiguration() + if err != nil { + t.Errorf("#... - failed to parse configuration error: %s", err) + } + managerMock := &mocks.ResourceStatusInitiateManagerMock{} + h := NewResourceStatusInitiateNotificationHandler(log, config, managerMock, requestName) + return h, managerMock, config +} + +func TestHandlerInit(t *testing.T) { + h, _, _ := initRanConnectedNotificationHandlerTest(t, "RanConnected") + assert.NotNil(t, h) +} + +func TestHandleSuccess(t *testing.T) { + h, managerMock, config := initRanConnectedNotificationHandlerTest(t, "RanConnected") + + payloadStr := "{\"nodeType\":1, \"messageDirection\":1}" + payload := []byte(payloadStr) + rmrReq := &models.RmrRequest{RanName:"RAN1", Payload:payload, Len:len(payload), StartTime:time.Now()} + managerMock.On("Execute", rmrReq.RanName, mock.AnythingOfType("*e2pdus.ResourceStatusRequestData")).Return(nil) + + resourceStatusInitiateRequestParams := &e2pdus.ResourceStatusRequestData{} + populateResourceStatusInitiateRequestParams(resourceStatusInitiateRequestParams, config) + + h.Handle(rmrReq) + managerMock.AssertCalled(t, "Execute", rmrReq.RanName, resourceStatusInitiateRequestParams) +} + +func TestHandleResourceStatusNotEnabled(t *testing.T) { + h, managerMock, config := initRanConnectedNotificationHandlerTest(t, "RanConnected") + config.ResourceStatusParams.EnableResourceStatus = false + + payloadStr := "{\"nodeType\":1, \"messageDirection\":1}" + payload := []byte(payloadStr) + rmrReq := &models.RmrRequest{RanName:"RAN1", Payload:payload, Len:len(payload), StartTime:time.Now()} + managerMock.On("Execute", rmrReq.RanName, mock.AnythingOfType("*e2pdus.ResourceStatusRequestData")).Return(nil) + + h.Handle(rmrReq) + managerMock.AssertNumberOfCalls(t, "Execute", 0) +} + +func TestHandleUnknownJson(t *testing.T) { + h, managerMock, _ := initRanConnectedNotificationHandlerTest(t, "RanConnected") + + payloadStr := "blablabla" + payload := []byte(payloadStr) + rmrReq := &models.RmrRequest{RanName:"RAN1", Payload:payload, Len:len(payload), StartTime:time.Now()} + managerMock.On("Execute", rmrReq.RanName, mock.AnythingOfType("*e2pdus.ResourceStatusRequestData")).Return(nil) + + h.Handle(rmrReq) + managerMock.AssertNumberOfCalls(t, "Execute", 0) +} + +func TestHandleGnbNode(t *testing.T) { + h, managerMock, _ := initRanConnectedNotificationHandlerTest(t, "RanConnected") + + payloadStr := "{\"nodeType\":2, \"messageDirection\":1}" + payload := []byte(payloadStr) + rmrReq := &models.RmrRequest{RanName:"RAN1", Payload:payload, Len:len(payload), StartTime:time.Now()} + managerMock.On("Execute", rmrReq.RanName, mock.AnythingOfType("*e2pdus.ResourceStatusRequestData")).Return(nil) + + h.Handle(rmrReq) + managerMock.AssertNumberOfCalls(t, "Execute", 0) +}