X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=E2Manager%2Fcontrollers%2Fnodeb_controller_test.go;h=bfdf2703d555e82295a06b52aa75aabf824d4fca;hb=0fb24ff00209041b316352327e2c73b699943131;hp=97303204fd91954b4a7cf945cbf8f30e7bd7c1f8;hpb=1bf79dda6f002618a7e00fa95b54914d5a273fa1;p=ric-plt%2Fe2mgr.git diff --git a/E2Manager/controllers/nodeb_controller_test.go b/E2Manager/controllers/nodeb_controller_test.go index 9730320..bfdf270 100644 --- a/E2Manager/controllers/nodeb_controller_test.go +++ b/E2Manager/controllers/nodeb_controller_test.go @@ -1,6 +1,7 @@ // // Copyright 2019 AT&T Intellectual Property // Copyright 2019 Nokia +// Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -101,7 +102,7 @@ type updateEnbCellsParams struct { err error } -type saveNodebParams struct { +type addEnbParams struct { err error } @@ -139,7 +140,7 @@ type controllerUpdateGnbTestContext struct { type controllerAddEnbTestContext struct { getNodebInfoResult *getNodebInfoResult - saveNodebParams *saveNodebParams + addEnbParams *addEnbParams addNbIdentityParams *addNbIdentityParams requestBody map[string]interface{} expectedStatusCode int @@ -160,9 +161,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, @@ -321,8 +320,8 @@ func setupControllerTest(t *testing.T) (*NodebController, *mocks.RnibReaderMock, ranConnectStatusChangeManager := managers.NewRanConnectStatusChangeManager(log, rnibDataService, ranListManager, ranAlarmService) nodebValidator := managers.NewNodebValidator() updateEnbManager := managers.NewUpdateEnbManager(log, rnibDataService, nodebValidator) - - handlerProvider := httpmsghandlerprovider.NewIncomingRequestHandlerProvider(log, rmrSender, config, rnibDataService, e2tInstancesManager, rmClient, ranConnectStatusChangeManager, nodebValidator, updateEnbManager, ranListManager) + updateGnbManager := managers.NewUpdateGnbManager(log, rnibDataService, nodebValidator) + handlerProvider := httpmsghandlerprovider.NewIncomingRequestHandlerProvider(log, rmrSender, config, rnibDataService, e2tInstancesManager, rmClient, ranConnectStatusChangeManager, nodebValidator, updateEnbManager, updateGnbManager, ranListManager) controller := NewNodebController(log, handlerProvider) return controller, readerMock, writerMock, rmrMessengerMock, e2tInstancesManager, ranListManager } @@ -352,8 +351,9 @@ func setupDeleteEnbControllerTest(t *testing.T, preAddNbIdentity bool) (*NodebCo ranConnectStatusChangeManager := managers.NewRanConnectStatusChangeManager(log, rnibDataService, ranListManager, ranAlarmService) nodebValidator := managers.NewNodebValidator() updateEnbManager := managers.NewUpdateEnbManager(log, rnibDataService, nodebValidator) + updateGnbManager := managers.NewUpdateGnbManager(log, rnibDataService, nodebValidator) - handlerProvider := httpmsghandlerprovider.NewIncomingRequestHandlerProvider(log, rmrSender, config, rnibDataService, e2tInstancesManager, rmClient, ranConnectStatusChangeManager, nodebValidator, updateEnbManager, ranListManager) + handlerProvider := httpmsghandlerprovider.NewIncomingRequestHandlerProvider(log, rmrSender, config, rnibDataService, e2tInstancesManager, rmClient, ranConnectStatusChangeManager, nodebValidator, updateEnbManager, updateGnbManager, ranListManager) controller := NewNodebController(log, handlerProvider) return controller, readerMock, writerMock, nbIdentity } @@ -373,7 +373,7 @@ func TestShutdownHandlerRnibError(t *testing.T) { } func TestSetGeneralConfigurationHandlerRnibError(t *testing.T) { - controller, readerMock, _, _, _ , _:= setupControllerTest(t) + controller, readerMock, _, _, _, _ := setupControllerTest(t) configuration := &entities.GeneralConfiguration{} readerMock.On("GetGeneralConfiguration").Return(configuration, e2managererrors.NewRnibDbError()) @@ -431,7 +431,7 @@ func controllerGetNodebIdListTestExecuter(t *testing.T, context *controllerGetNo controller.GetNodebIdList(writer, req) assert.Equal(t, context.expectedStatusCode, writer.Result().StatusCode) bodyBytes, _ := ioutil.ReadAll(writer.Body) - assert.Equal(t, context.expectedJsonResponse, string(bodyBytes)) + assert.Contains(t, context.expectedJsonResponse, string(bodyBytes)) } func activateControllerUpdateEnbMocks(context *controllerUpdateEnbTestContext, readerMock *mocks.RnibReaderMock, writerMock *mocks.RnibWriterMock, updateEnbRequest *models.UpdateEnbRequest) { @@ -445,6 +445,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) @@ -512,7 +517,7 @@ func buildUpdateEnbRequest(context *controllerUpdateEnbTestContext) *http.Reques } func buildUpdateGnbRequest(context *controllerUpdateGnbTestContext) *http.Request { - updateGnbUrl := fmt.Sprintf("/nodeb/%s/update", RanName) + updateGnbUrl := fmt.Sprintf("/nodeb/gnb/%s", RanName) requestBody := getJsonRequestAsBuffer(context.requestBody) req, _ := http.NewRequest(http.MethodPut, updateGnbUrl, requestBody) req.Header.Set("Content-Type", "application/json") @@ -561,7 +566,7 @@ func activateControllerAddEnbMocks(context *controllerAddEnbTestContext, readerM readerMock.On("GetNodeb", RanName).Return(context.getNodebInfoResult.nodebInfo, context.getNodebInfoResult.rnibError) } - if context.saveNodebParams != nil { + if context.addEnbParams != nil { nodebInfo := entities.NodebInfo{ RanName: addEnbRequest.RanName, Ip: addEnbRequest.Ip, @@ -572,7 +577,7 @@ func activateControllerAddEnbMocks(context *controllerAddEnbTestContext, readerM ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, } - writerMock.On("SaveNodeb", &nodebInfo).Return(context.saveNodebParams.err) + writerMock.On("AddEnb", &nodebInfo).Return(context.addEnbParams.err) } if context.addNbIdentityParams != nil { @@ -600,10 +605,11 @@ 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) + writerMock.On("RemoveNbIdentity", entities.Node_ENB, nbIdentity).Return(nil) } } writer := httptest.NewRecorder() @@ -614,12 +620,17 @@ func controllerDeleteEnbTestExecuter(t *testing.T, context *controllerDeleteEnbT assertControllerDeleteEnb(t, context, writer, readerMock, writerMock) } +/* +UpdateGnb UTs +*/ + +// BEGIN - UpdateGnb Validation Failure UTs + func TestControllerUpdateGnbEmptyServedNrCells(t *testing.T) { context := controllerUpdateGnbTestContext{ getNodebInfoResult: nil, requestBody: map[string]interface{}{ - "servedNrCells": []interface{}{ - }, + "servedNrCells": []interface{}{}, }, expectedStatusCode: http.StatusBadRequest, expectedJsonResponse: ValidationFailureJson, @@ -733,6 +744,8 @@ func TestControllerUpdateGnbMissingNrNeighbourInformationRequiredProp(t *testing } } +// END - UpdateGnb Validation Failure UTs + func TestControllerUpdateGnbValidServedNrCellInformationGetNodebNotFound(t *testing.T) { context := controllerUpdateGnbTestContext{ getNodebInfoResult: &getNodebInfoResult{ @@ -780,6 +793,7 @@ func TestControllerUpdateGnbGetNodebSuccessInvalidGnbConfiguration(t *testing.T) RanName: RanName, ConnectionStatus: entities.ConnectionStatus_CONNECTED, AssociatedE2TInstanceAddress: AssociatedE2TInstanceAddress, + NodeType: entities.Node_ENB, }, rnibError: nil, }, @@ -793,8 +807,8 @@ func TestControllerUpdateGnbGetNodebSuccessInvalidGnbConfiguration(t *testing.T) }, }, }, - expectedStatusCode: http.StatusInternalServerError, - expectedJsonResponse: InternalErrorJson, + expectedStatusCode: http.StatusBadRequest, + expectedJsonResponse: ValidationFailureJson, } controllerUpdateGnbTestExecuter(t, &context) @@ -813,6 +827,7 @@ func TestControllerUpdateGnbGetNodebSuccessRemoveServedNrCellsFailure(t *testing ConnectionStatus: entities.ConnectionStatus_CONNECTED, AssociatedE2TInstanceAddress: AssociatedE2TInstanceAddress, Configuration: &entities.NodebInfo_Gnb{Gnb: &entities.Gnb{ServedNrCells: oldServedNrCells}}, + NodeType: entities.Node_GNB, }, rnibError: nil, }, @@ -849,6 +864,7 @@ func TestControllerUpdateGnbGetNodebSuccessUpdateGnbCellsFailure(t *testing.T) { ConnectionStatus: entities.ConnectionStatus_CONNECTED, AssociatedE2TInstanceAddress: AssociatedE2TInstanceAddress, Configuration: &entities.NodebInfo_Gnb{Gnb: &entities.Gnb{ServedNrCells: oldServedNrCells}}, + NodeType: entities.Node_GNB, }, rnibError: nil, }, @@ -869,8 +885,48 @@ func TestControllerUpdateGnbGetNodebSuccessUpdateGnbCellsFailure(t *testing.T) { controllerUpdateGnbTestExecuter(t, &context) } +func TestControllerUpdateGnbExistingEmptyCellsSuccess(t *testing.T) { + oldServedNrCells := []*entities.ServedNRCell{} + + context := controllerUpdateGnbTestContext{ + updateGnbCellsParams: &updateGnbCellsParams{ + err: nil, + }, + getNodebInfoResult: &getNodebInfoResult{ + nodebInfo: &entities.NodebInfo{ + RanName: RanName, + ConnectionStatus: entities.ConnectionStatus_CONNECTED, + AssociatedE2TInstanceAddress: AssociatedE2TInstanceAddress, + Configuration: &entities.NodebInfo_Gnb{Gnb: &entities.Gnb{ServedNrCells: oldServedNrCells}}, + NodeType: entities.Node_GNB, + }, + rnibError: nil, + }, + requestBody: map[string]interface{}{ + "servedNrCells": []interface{}{ + map[string]interface{}{ + "servedNrCellInformation": buildServedNrCellInformation(""), + "nrNeighbourInfos": []interface{}{ + buildNrNeighbourInformation(""), + }, + }, + }, + }, + expectedStatusCode: http.StatusOK, + expectedJsonResponse: "{\"ranName\":\"test\",\"connectionStatus\":\"CONNECTED\",\"nodeType\":\"GNB\",\"gnb\":{\"servedNrCells\":[{\"servedNrCellInformation\":{\"nrPci\":1,\"cellId\":\"whatever\",\"servedPlmns\":[\"whatever\"],\"nrMode\":\"FDD\",\"choiceNrMode\":{\"fdd\":{}}},\"nrNeighbourInfos\":[{\"nrPci\":1,\"nrCgi\":\"whatever\",\"nrMode\":\"FDD\",\"choiceNrMode\":{\"tdd\":{}}}]}]},\"associatedE2tInstanceAddress\":\"10.0.2.15:38000\"}", + } + + controllerUpdateGnbTestExecuter(t, &context) +} + func TestControllerUpdateGnbSuccess(t *testing.T) { + oldServedNrCells := generateServedNrCells("whatever1", "whatever2") + context := controllerUpdateGnbTestContext{ + removeServedNrCellsParams: &removeServedNrCellsParams{ + err: nil, + servedNrCells: oldServedNrCells, + }, updateGnbCellsParams: &updateGnbCellsParams{ err: nil, }, @@ -879,7 +935,8 @@ func TestControllerUpdateGnbSuccess(t *testing.T) { RanName: RanName, ConnectionStatus: entities.ConnectionStatus_CONNECTED, AssociatedE2TInstanceAddress: AssociatedE2TInstanceAddress, - Configuration: &entities.NodebInfo_Gnb{Gnb: &entities.Gnb{}}, + Configuration: &entities.NodebInfo_Gnb{Gnb: &entities.Gnb{ServedNrCells: oldServedNrCells}}, + NodeType: entities.Node_GNB, }, rnibError: nil, }, @@ -894,12 +951,16 @@ func TestControllerUpdateGnbSuccess(t *testing.T) { }, }, expectedStatusCode: http.StatusOK, - expectedJsonResponse: "{\"ranName\":\"test\",\"connectionStatus\":\"CONNECTED\",\"gnb\":{\"servedNrCells\":[{\"servedNrCellInformation\":{\"nrPci\":1,\"cellId\":\"whatever\",\"servedPlmns\":[\"whatever\"],\"nrMode\":\"FDD\",\"choiceNrMode\":{\"fdd\":{}}},\"nrNeighbourInfos\":[{\"nrPci\":1,\"nrCgi\":\"whatever\",\"nrMode\":\"FDD\",\"choiceNrMode\":{\"tdd\":{}}}]}]},\"associatedE2tInstanceAddress\":\"10.0.2.15:38000\"}", + expectedJsonResponse: "{\"ranName\":\"test\",\"connectionStatus\":\"CONNECTED\",\"nodeType\":\"GNB\",\"gnb\":{\"servedNrCells\":[{\"servedNrCellInformation\":{\"nrPci\":1,\"cellId\":\"whatever\",\"servedPlmns\":[\"whatever\"],\"nrMode\":\"FDD\",\"choiceNrMode\":{\"fdd\":{}}},\"nrNeighbourInfos\":[{\"nrPci\":1,\"nrCgi\":\"whatever\",\"nrMode\":\"FDD\",\"choiceNrMode\":{\"tdd\":{}}}]}]},\"associatedE2tInstanceAddress\":\"10.0.2.15:38000\"}", } controllerUpdateGnbTestExecuter(t, &context) } +/* +UpdateEnb UTs +*/ + func TestControllerUpdateEnbInvalidRequest(t *testing.T) { controller, _, _, _, _, _ := setupControllerTest(t) @@ -951,6 +1012,29 @@ func TestControllerUpdateEnbMissingEnb(t *testing.T) { controllerUpdateEnbTestExecuter(t, &context) } +func TestControllerUpdateEnbMissingRequiredServedCellProps(t *testing.T) { + + r := getUpdateEnbRequest("") + + for _, v := range ServedCellRequiredFields { + enb := r["enb"] + + enbMap, _ := enb.(map[string]interface{}) + + enbMap["servedCells"] = []interface{}{ + buildServedCell(v), + } + + context := controllerUpdateEnbTestContext{ + requestBody: r, + expectedStatusCode: http.StatusBadRequest, + expectedJsonResponse: ValidationFailureJson, + } + + controllerUpdateEnbTestExecuter(t, &context) + } +} + func TestControllerUpdateEnbValidServedCellsGetNodebNotFound(t *testing.T) { context := controllerUpdateEnbTestContext{ getNodebInfoResult: &getNodebInfoResult{ @@ -1053,7 +1137,62 @@ func TestControllerUpdateEnbGetNodebSuccessUpdateEnbFailure(t *testing.T) { controllerUpdateEnbTestExecuter(t, &context) } -func TestControllerUpdateEnbSuccess(t *testing.T) { +func TestControllerUpdateEnbExistingEmptyCellsSuccess(t *testing.T) { + oldServedCells := []*entities.ServedCellInfo{} + context := controllerUpdateEnbTestContext{ + 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_MACRO_ENB}}, + }, + rnibError: nil, + }, + requestBody: getUpdateEnbRequest(""), + expectedStatusCode: http.StatusOK, + expectedJsonResponse: "{\"ranName\":\"test\",\"connectionStatus\":\"CONNECTED\",\"nodeType\":\"ENB\",\"enb\":{\"enbType\":\"MACRO_ENB\",\"servedCells\":[{\"pci\":1,\"cellId\":\"whatever\",\"tac\":\"whatever3\",\"broadcastPlmns\":[\"whatever\"],\"choiceEutraMode\":{\"fdd\":{}},\"eutraMode\":\"FDD\"}]},\"associatedE2tInstanceAddress\":\"10.0.2.15:38000\"}", + } + + controllerUpdateEnbTestExecuter(t, &context) +} + +func TestControllerUpdateEnbNgEnbFailure(t *testing.T) { + + requestBody := map[string]interface{}{ + "enb": map[string]interface{}{ + "enbType": 3, + "servedCells": []interface{}{ + buildServedCell(""), + }}, + } + + 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{ @@ -1069,7 +1208,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, }, @@ -1081,6 +1220,39 @@ 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 +*/ + func TestControllerAddEnbGetNodebInternalError(t *testing.T) { context := controllerAddEnbTestContext{ getNodebInfoResult: &getNodebInfoResult{ @@ -1111,8 +1283,8 @@ func TestControllerAddEnbNodebExistsFailure(t *testing.T) { func TestControllerAddEnbSaveNodebFailure(t *testing.T) { context := controllerAddEnbTestContext{ - saveNodebParams: &saveNodebParams{ - err: common.NewInternalError(errors.New("#reader.SaveeNodeb - Internal Error")), + addEnbParams: &addEnbParams{ + err: common.NewInternalError(errors.New("#reader.AddEnb - Internal Error")), }, getNodebInfoResult: &getNodebInfoResult{ nodebInfo: nil, @@ -1128,7 +1300,7 @@ func TestControllerAddEnbSaveNodebFailure(t *testing.T) { func TestControllerAddEnbAddNbIdentityFailure(t *testing.T) { context := controllerAddEnbTestContext{ - saveNodebParams: &saveNodebParams{ + addEnbParams: &addEnbParams{ err: nil, }, addNbIdentityParams: &addNbIdentityParams{ @@ -1208,9 +1380,9 @@ func TestControllerAddEnbMissingRequiredEnbProps(t *testing.T) { } } -func TestControllerUpdateEnbMissingRequiredServedCellProps(t *testing.T) { +func TestControllerAddEnbMissingRequiredServedCellProps(t *testing.T) { - r := getUpdateEnbRequest("") + r := getAddEnbRequest("") for _, v := range ServedCellRequiredFields { enb := r["enb"] @@ -1221,42 +1393,41 @@ func TestControllerUpdateEnbMissingRequiredServedCellProps(t *testing.T) { buildServedCell(v), } - context := controllerUpdateEnbTestContext{ + context := controllerAddEnbTestContext{ requestBody: r, expectedStatusCode: http.StatusBadRequest, expectedJsonResponse: ValidationFailureJson, } - controllerUpdateEnbTestExecuter(t, &context) + controllerAddEnbTestExecuter(t, &context) } } -func TestControllerAddEnbMissingRequiredServedCellProps(t *testing.T) { - - r := getAddEnbRequest("") - - for _, v := range ServedCellRequiredFields { - enb := r["enb"] - - enbMap, _ := enb.(map[string]interface{}) - - enbMap["servedCells"] = []interface{}{ - buildServedCell(v), - } +func TestControllerAddEnbNgEnbFailure(t *testing.T) { - context := controllerAddEnbTestContext{ - requestBody: r, - expectedStatusCode: http.StatusBadRequest, - expectedJsonResponse: ValidationFailureJson, - } + requestBody := map[string]interface{}{ + "ranName": RanName, + "globalNbId": buildGlobalNbId(""), + "enb": map[string]interface{}{ + "enbType": 5, + "servedCells": []interface{}{ + buildServedCell(""), + }, + }, + } - controllerAddEnbTestExecuter(t, &context) + context := controllerAddEnbTestContext{ + requestBody: requestBody, + expectedStatusCode: http.StatusBadRequest, + expectedJsonResponse: ValidationFailureJson, } + + controllerAddEnbTestExecuter(t, &context) } func TestControllerAddEnbSuccess(t *testing.T) { context := controllerAddEnbTestContext{ - saveNodebParams: &saveNodebParams{ + addEnbParams: &addEnbParams{ err: nil, }, addNbIdentityParams: &addNbIdentityParams{ @@ -1287,6 +1458,10 @@ func TestControllerDeleteEnbGetNodebInternalError(t *testing.T) { controllerDeleteEnbTestExecuter(t, &context, false) } +/* +DeleteEnb UTs +*/ + func TestControllerDeleteEnbNodebNotExistsFailure(t *testing.T) { context := controllerDeleteEnbTestContext{ getNodebInfoResult: &getNodebInfoResult{ @@ -1313,6 +1488,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{ @@ -1331,6 +1518,10 @@ func getJsonRequestAsBuffer(requestJson map[string]interface{}) *bytes.Buffer { return b } +/* +GetNodeb UTs +*/ + func TestControllerGetNodebSuccess(t *testing.T) { ranName := "test" var rnibError error @@ -1385,7 +1576,7 @@ func TestControllerGetNodebIdListSuccess(t *testing.T) { nodebIdList: nodebIdList, rnibError: rnibError, expectedStatusCode: http.StatusOK, - expectedJsonResponse: "[{\"inventoryName\":\"test1\",\"globalNbId\":{\"plmnId\":\"plmnId1\",\"nbId\":\"nbId1\"}},{\"inventoryName\":\"test2\",\"globalNbId\":{\"plmnId\":\"plmnId2\",\"nbId\":\"nbId2\"}}]", + expectedJsonResponse: "[{\"inventoryName\":\"test1\",\"globalNbId\":{\"plmnId\":\"plmnId1\",\"nbId\":\"nbId1\"}},{\"inventoryName\":\"test2\",\"globalNbId\":{\"plmnId\":\"plmnId2\",\"nbId\":\"nbId2\"}}][{\"inventoryName\":\"test2\",\"globalNbId\":{\"plmnId\":\"plmnId2\",\"nbId\":\"nbId2\"}},{\"inventoryName\":\"test1\",\"globalNbId\":{\"plmnId\":\"plmnId1\",\"nbId\":\"nbId1\"}}]", } controllerGetNodebIdListTestExecuter(t, &context) @@ -1614,6 +1805,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)