[RIC-431] Add UTs | Update AddEnbRequest | Update Swagger
[ric-plt/e2mgr.git] / E2Manager / handlers / rmrmsghandlers / e2_setup_request_notification_handler_test.go
index 9cddbe2..c8b49eb 100644 (file)
@@ -159,9 +159,10 @@ func TestE2SetupRequestNotificationHandler_EnableRicFalse(t *testing.T) {
        writerMock.AssertNotCalled(t, "SaveNodeb")
 }
 
-func testE2SetupRequestNotificationHandler_HandleNewRanSuccess(t *testing.T, xmlPath string) {
-       xml := readXmlFile(t, xmlPath)
-       handler, readerMock, writerMock, rmrMessengerMock, e2tInstancesManagerMock, routingManagerClientMock := initMocks(t)
+
+func TestE2SetupRequestNotificationHandler_HandleNewRanError(t *testing.T) {
+       xml := readXmlFile(t, GnbSetupRequestXmlPath)
+       handler, readerMock, writerMock, _, e2tInstancesManagerMock, _ := initMocks(t)
        readerMock.On("GetGeneralConfiguration").Return(&entities.GeneralConfiguration{EnableRic: true}, nil)
        e2tInstancesManagerMock.On("GetE2TInstance", e2tInstanceFullAddress).Return(&entities.E2TInstance{}, nil)
        var gnb *entities.NodebInfo
@@ -169,26 +170,18 @@ func testE2SetupRequestNotificationHandler_HandleNewRanSuccess(t *testing.T, xml
        notificationRequest := &models.NotificationRequest{RanName: nodebRanName, Payload: append([]byte(e2SetupMsgPrefix), xml...)}
        nodebInfo := getExpectedNodebForNewRan(notificationRequest.Payload)
        nbIdentity := &entities.NbIdentity{InventoryName: nodebRanName, GlobalNbId: nodebInfo.GlobalNbId}
-       writerMock.On("SaveNodeb", nbIdentity, nodebInfo).Return(nil)
-       updatedNodebInfo := *nodebInfo
-       updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_CONNECTED
-       writerMock.On("UpdateNodebInfoOnConnectionStatusInversion", &updatedNodebInfo, StateChangeMessageChannel, nodebRanName+"_CONNECTED").Return(nil)
-       routingManagerClientMock.On("AssociateRanToE2TInstance", e2tInstanceFullAddress, mock.Anything).Return(nil)
-       updatedNodebInfo2 := *nodebInfo
-       updatedNodebInfo2.ConnectionStatus = entities.ConnectionStatus_CONNECTED
-       updatedNodebInfo2.AssociatedE2TInstanceAddress = e2tInstanceFullAddress
-       writerMock.On("UpdateNodebInfo", &updatedNodebInfo2).Return(nil)
-       e2tInstancesManagerMock.On("AddRansToInstance", e2tInstanceFullAddress, []string{nodebRanName}).Return(nil)
-       rmrMessengerMock.On("SendMsg", mock.Anything, mock.Anything).Return(&rmrCgo.MBuf{}, nil)
+       writerMock.On("SaveNodeb", nbIdentity, nodebInfo).Return(common.NewInternalError(errors.New("error")))
+
        handler.Handle(notificationRequest)
+
        readerMock.AssertExpectations(t)
        writerMock.AssertExpectations(t)
        e2tInstancesManagerMock.AssertExpectations(t)
 }
 
-func TestE2SetupRequestNotificationHandler_HandleUpdateNodebInfoOnConnectionStatusInversionFailureForNewGnb(t *testing.T) {
-       xml := readXmlFile(t, GnbSetupRequestXmlPath)
-       handler, readerMock, writerMock, _, e2tInstancesManagerMock, routingManagerClientMock := initMocks(t)
+func testE2SetupRequestNotificationHandler_HandleNewRanSuccess(t *testing.T, xmlPath string) {
+       xml := readXmlFile(t, xmlPath)
+       handler, readerMock, writerMock, rmrMessengerMock, e2tInstancesManagerMock, routingManagerClientMock := initMocks(t)
        readerMock.On("GetGeneralConfiguration").Return(&entities.GeneralConfiguration{EnableRic: true}, nil)
        e2tInstancesManagerMock.On("GetE2TInstance", e2tInstanceFullAddress).Return(&entities.E2TInstance{}, nil)
        var gnb *entities.NodebInfo
@@ -199,14 +192,24 @@ func TestE2SetupRequestNotificationHandler_HandleUpdateNodebInfoOnConnectionStat
        writerMock.On("SaveNodeb", nbIdentity, nodebInfo).Return(nil)
        updatedNodebInfo := *nodebInfo
        updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_CONNECTED
-       writerMock.On("UpdateNodebInfoOnConnectionStatusInversion", &updatedNodebInfo, StateChangeMessageChannel, nodebRanName+"_CONNECTED").Return(common.NewInternalError(errors.New("some error")))
+       writerMock.On("UpdateNodebInfoOnConnectionStatusInversion", &updatedNodebInfo, StateChangeMessageChannel, nodebRanName+"_CONNECTED").Return(nil)
+       routingManagerClientMock.On("AssociateRanToE2TInstance", e2tInstanceFullAddress, mock.Anything).Return(nil)
+       updatedNodebInfo2 := *nodebInfo
+       updatedNodebInfo2.ConnectionStatus = entities.ConnectionStatus_CONNECTED
+       updatedNodebInfo2.AssociatedE2TInstanceAddress = e2tInstanceFullAddress
+       writerMock.On("UpdateNodebInfo", &updatedNodebInfo2).Return(nil)
+       e2tInstancesManagerMock.On("AddRansToInstance", e2tInstanceFullAddress, []string{nodebRanName}).Return(nil)
+       rmrMessengerMock.On("SendMsg", mock.Anything, mock.Anything).Return(&rmrCgo.MBuf{}, nil)
+
        handler.Handle(notificationRequest)
+
        readerMock.AssertExpectations(t)
        writerMock.AssertExpectations(t)
-       routingManagerClientMock.AssertExpectations(t)
        e2tInstancesManagerMock.AssertExpectations(t)
 }
 
+
+
 func TestE2SetupRequestNotificationHandler_HandleNewGnbSuccess(t *testing.T) {
        testE2SetupRequestNotificationHandler_HandleNewRanSuccess(t, GnbSetupRequestXmlPath)
 }
@@ -433,7 +436,9 @@ func TestE2SetupRequestNotificationHandler_ConvertTo20BitStringError(t *testing.
        config := &configuration.Configuration{
                RnibRetryIntervalMs:       10,
                MaxRnibConnectionAttempts: 3,
-               StateChangeMessageChannel: StateChangeMessageChannel,
+               RnibWriter: configuration.RnibWriterConfig{
+                       StateChangeMessageChannel: StateChangeMessageChannel,
+               },
                GlobalRicId: struct {
                        RicId string
                        Mcc   string
@@ -500,7 +505,9 @@ func initMocks(t *testing.T) (*E2SetupRequestNotificationHandler, *mocks.RnibRea
        config := &configuration.Configuration{
                RnibRetryIntervalMs:       10,
                MaxRnibConnectionAttempts: 3,
-               StateChangeMessageChannel: StateChangeMessageChannel,
+               RnibWriter: configuration.RnibWriterConfig{
+                       StateChangeMessageChannel: StateChangeMessageChannel,
+               },
                GlobalRicId: struct {
                        RicId string
                        Mcc   string