[RIC-247] RAN Health Check Request API - Validation
[ric-plt/e2mgr.git] / E2Manager / controllers / nodeb_controller_test.go
index 1b3a7db..c01d7c9 100644 (file)
@@ -160,9 +160,7 @@ func generateServedNrCells(cellIds ...string) []*entities.ServedNRCell {
                servedNrCells = append(servedNrCells, &entities.ServedNRCell{ServedNrCellInformation: &entities.ServedNRCellInformation{
                        CellId: v,
                        ChoiceNrMode: &entities.ServedNRCellInformation_ChoiceNRMode{
-                               Fdd: &entities.ServedNRCellInformation_ChoiceNRMode_FddInfo{
-
-                               },
+                               Fdd: &entities.ServedNRCellInformation_ChoiceNRMode_FddInfo{},
                        },
                        NrMode:      entities.Nr_FDD,
                        NrPci:       5,
@@ -446,6 +444,11 @@ func activateControllerUpdateEnbMocks(context *controllerUpdateEnbTestContext, r
 
        if context.updateEnbCellsParams != nil {
                updatedNodebInfo := *context.getNodebInfoResult.nodebInfo
+
+               if context.getNodebInfoResult.nodebInfo.SetupFromNetwork {
+                       updateEnbRequest.Enb.EnbType = context.getNodebInfoResult.nodebInfo.GetEnb().EnbType
+               }
+
                updatedNodebInfo.Configuration = &entities.NodebInfo_Enb{Enb: updateEnbRequest.Enb}
 
                writerMock.On("UpdateEnb", &updatedNodebInfo, updateEnbRequest.Enb.ServedCells).Return(context.updateEnbCellsParams.err)
@@ -601,7 +604,8 @@ func controllerAddEnbTestExecuter(t *testing.T, context *controllerAddEnbTestCon
 func controllerDeleteEnbTestExecuter(t *testing.T, context *controllerDeleteEnbTestContext, preAddNbIdentity bool) {
        controller, readerMock, writerMock, nbIdentity := setupDeleteEnbControllerTest(t, preAddNbIdentity)
        readerMock.On("GetNodeb", RanName).Return(context.getNodebInfoResult.nodebInfo, context.getNodebInfoResult.rnibError)
-       if context.getNodebInfoResult.rnibError == nil && context.getNodebInfoResult.nodebInfo.GetNodeType() == entities.Node_ENB {
+       if context.getNodebInfoResult.rnibError == nil && context.getNodebInfoResult.nodebInfo.GetNodeType() == entities.Node_ENB &&
+               !context.getNodebInfoResult.nodebInfo.SetupFromNetwork {
                writerMock.On("RemoveEnb", context.getNodebInfoResult.nodebInfo).Return(nil)
                if preAddNbIdentity {
                        writerMock.On("RemoveNbIdentity", entities.Node_ENB, nbIdentity).Return(nil)
@@ -625,8 +629,7 @@ func TestControllerUpdateGnbEmptyServedNrCells(t *testing.T) {
        context := controllerUpdateGnbTestContext{
                getNodebInfoResult: nil,
                requestBody: map[string]interface{}{
-                       "servedNrCells": []interface{}{
-                       },
+                       "servedNrCells": []interface{}{},
                },
                expectedStatusCode:   http.StatusBadRequest,
                expectedJsonResponse: ValidationFailureJson,
@@ -1157,8 +1160,38 @@ func TestControllerUpdateEnbExistingEmptyCellsSuccess(t *testing.T) {
        controllerUpdateEnbTestExecuter(t, &context)
 }
 
+func TestControllerUpdateEnbNgEnbFailure(t *testing.T) {
+
+       requestBody := map[string]interface{}{
+               "enb": map[string]interface{}{
+                       "enbType": 3,
+                       "servedCells": []interface{}{
+                               buildServedCell(""),
+                       }},
+       }
 
-func TestControllerUpdateEnbSuccess(t *testing.T) {
+       oldServedCells := generateServedCells("whatever1", "whatever2")
+
+       context := controllerUpdateEnbTestContext{
+               getNodebInfoResult: &getNodebInfoResult{
+                       nodebInfo: &entities.NodebInfo{
+                               RanName:                      RanName,
+                               ConnectionStatus:             entities.ConnectionStatus_CONNECTED,
+                               AssociatedE2TInstanceAddress: AssociatedE2TInstanceAddress,
+                               NodeType:                     entities.Node_ENB,
+                               Configuration:                &entities.NodebInfo_Enb{Enb: &entities.Enb{ServedCells: oldServedCells, EnbType: entities.EnbType_MACRO_NG_ENB}},
+                       },
+                       rnibError: nil,
+               },
+               requestBody:          requestBody,
+               expectedStatusCode:   http.StatusBadRequest,
+               expectedJsonResponse: ValidationFailureJson,
+       }
+
+       controllerUpdateEnbTestExecuter(t, &context)
+}
+
+func TestControllerUpdateEnbSuccessSetupFromNwFalse(t *testing.T) {
        oldServedCells := generateServedCells("whatever1", "whatever2")
        context := controllerUpdateEnbTestContext{
                removeServedCellsParams: &removeServedCellsParams{
@@ -1174,7 +1207,7 @@ func TestControllerUpdateEnbSuccess(t *testing.T) {
                                ConnectionStatus:             entities.ConnectionStatus_CONNECTED,
                                AssociatedE2TInstanceAddress: AssociatedE2TInstanceAddress,
                                NodeType:                     entities.Node_ENB,
-                               Configuration:                &entities.NodebInfo_Enb{Enb: &entities.Enb{ServedCells: oldServedCells, EnbType: entities.EnbType_MACRO_ENB}},
+                               Configuration:                &entities.NodebInfo_Enb{Enb: &entities.Enb{ServedCells: oldServedCells, EnbType: entities.EnbType_LONG_MACRO_ENB}},
                        },
                        rnibError: nil,
                },
@@ -1186,6 +1219,35 @@ func TestControllerUpdateEnbSuccess(t *testing.T) {
        controllerUpdateEnbTestExecuter(t, &context)
 }
 
+func TestControllerUpdateEnbSuccessSetupFromNwTrue(t *testing.T) {
+       oldServedCells := generateServedCells("whatever1", "whatever2")
+       context := controllerUpdateEnbTestContext{
+               removeServedCellsParams: &removeServedCellsParams{
+                       err:            nil,
+                       servedCellInfo: oldServedCells,
+               },
+               updateEnbCellsParams: &updateEnbCellsParams{
+                       err: nil,
+               },
+               getNodebInfoResult: &getNodebInfoResult{
+                       nodebInfo: &entities.NodebInfo{
+                               RanName:                      RanName,
+                               ConnectionStatus:             entities.ConnectionStatus_CONNECTED,
+                               AssociatedE2TInstanceAddress: AssociatedE2TInstanceAddress,
+                               NodeType:                     entities.Node_ENB,
+                               Configuration:                &entities.NodebInfo_Enb{Enb: &entities.Enb{ServedCells: oldServedCells, EnbType: entities.EnbType_LONG_MACRO_ENB}},
+                               SetupFromNetwork:             true,
+                       },
+                       rnibError: nil,
+               },
+               requestBody:          getUpdateEnbRequest(""),
+               expectedStatusCode:   http.StatusOK,
+               expectedJsonResponse: "{\"ranName\":\"test\",\"connectionStatus\":\"CONNECTED\",\"nodeType\":\"ENB\",\"enb\":{\"enbType\":\"LONG_MACRO_ENB\",\"servedCells\":[{\"pci\":1,\"cellId\":\"whatever\",\"tac\":\"whatever3\",\"broadcastPlmns\":[\"whatever\"],\"choiceEutraMode\":{\"fdd\":{}},\"eutraMode\":\"FDD\"}]},\"associatedE2tInstanceAddress\":\"10.0.2.15:38000\",\"setupFromNetwork\":true}",
+       }
+
+       controllerUpdateEnbTestExecuter(t, &context)
+}
+
 /*
 AddEnb UTs
 */
@@ -1340,6 +1402,28 @@ func TestControllerAddEnbMissingRequiredServedCellProps(t *testing.T) {
        }
 }
 
+func TestControllerAddEnbNgEnbFailure(t *testing.T) {
+
+       requestBody := map[string]interface{}{
+               "ranName":    RanName,
+               "globalNbId": buildGlobalNbId(""),
+               "enb": map[string]interface{}{
+                       "enbType": 5,
+                       "servedCells": []interface{}{
+                               buildServedCell(""),
+                       },
+               },
+       }
+
+       context := controllerAddEnbTestContext{
+               requestBody:          requestBody,
+               expectedStatusCode:   http.StatusBadRequest,
+               expectedJsonResponse: ValidationFailureJson,
+       }
+
+       controllerAddEnbTestExecuter(t, &context)
+}
+
 func TestControllerAddEnbSuccess(t *testing.T) {
        context := controllerAddEnbTestContext{
                addEnbParams: &addEnbParams{
@@ -1403,6 +1487,18 @@ func TestControllerDeleteEnbNodebNotEnb(t *testing.T) {
        controllerDeleteEnbTestExecuter(t, &context, false)
 }
 
+func TestControllerDeleteEnbSetupFromNetworkTrueFailure(t *testing.T) {
+       context := controllerDeleteEnbTestContext{
+               getNodebInfoResult: &getNodebInfoResult{
+                       nodebInfo: &entities.NodebInfo{RanName: RanName, NodeType: entities.Node_ENB, ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, SetupFromNetwork: true},
+                       rnibError: nil,
+               },
+               expectedStatusCode:   http.StatusBadRequest,
+               expectedJsonResponse: ValidationFailureJson,
+       }
+       controllerDeleteEnbTestExecuter(t, &context, true)
+}
+
 func TestControllerDeleteEnbSuccess(t *testing.T) {
        context := controllerDeleteEnbTestContext{
                getNodebInfoResult: &getNodebInfoResult{
@@ -1708,6 +1804,10 @@ func TestHandleErrorResponse(t *testing.T) {
        controller.handleErrorResponse(e2managererrors.NewRmrError(), writer)
        assert.Equal(t, http.StatusInternalServerError, writer.Result().StatusCode)
 
+       writer = httptest.NewRecorder()
+       controller.handleErrorResponse(e2managererrors.NewNoConnectedRanError(), writer)
+       assert.Equal(t, http.StatusNotFound, writer.Result().StatusCode)
+
        writer = httptest.NewRecorder()
        controller.handleErrorResponse(e2managererrors.NewResourceNotFoundError(), writer)
        assert.Equal(t, http.StatusNotFound, writer.Result().StatusCode)