X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=E2Manager%2Fcontrollers%2Fnodeb_controller_test.go;h=1543674b6917bd3e2a53f46ba84294e41c65d1b2;hb=refs%2Fheads%2FPI5;hp=4bdfd2c4fc5b29b5031bf58cffecddfaac2670b1;hpb=3ae760f4378ea43575eca6e83ccc01084566e7cf;p=ric-plt%2Fe2mgr.git diff --git a/E2Manager/controllers/nodeb_controller_test.go b/E2Manager/controllers/nodeb_controller_test.go index 4bdfd2c..1543674 100644 --- a/E2Manager/controllers/nodeb_controller_test.go +++ b/E2Manager/controllers/nodeb_controller_test.go @@ -90,12 +90,39 @@ type updateGnbCellsParams struct { err error } +type removeServedNrCellsParams struct { + servedNrCells []*entities.ServedNRCell + err error +} + type controllerUpdateGnbTestContext struct { - getNodebInfoResult *getNodebInfoResult - updateGnbCellsParams *updateGnbCellsParams - requestBody map[string]interface{} - expectedStatusCode int - expectedJsonResponse string + getNodebInfoResult *getNodebInfoResult + removeServedNrCellsParams *removeServedNrCellsParams + updateGnbCellsParams *updateGnbCellsParams + requestBody map[string]interface{} + expectedStatusCode int + expectedJsonResponse string +} + +func generateServedNrCells(cellIds ...string) []*entities.ServedNRCell { + + servedNrCells := []*entities.ServedNRCell{} + + for _, v := range cellIds { + servedNrCells = append(servedNrCells, &entities.ServedNRCell{ServedNrCellInformation: &entities.ServedNRCellInformation{ + CellId: v, + ChoiceNrMode: &entities.ServedNRCellInformation_ChoiceNRMode{ + Fdd: &entities.ServedNRCellInformation_ChoiceNRMode_FddInfo{ + + }, + }, + NrMode: entities.Nr_FDD, + NrPci: 5, + ServedPlmns: []string{"whatever"}, + }}) + } + + return servedNrCells } func buildNrNeighbourInformation(propToOmit string) map[string]interface{} { @@ -250,6 +277,39 @@ func TestShutdownHandlerRnibError(t *testing.T) { assert.Equal(t, errorResponse.Code, e2managererrors.NewRnibDbError().Code) } +func TestSetGeneralConfigurationHandlerRnibError(t *testing.T) { + controller, readerMock, _, _, _ := setupControllerTest(t) + + configuration := &entities.GeneralConfiguration{} + readerMock.On("GetGeneralConfiguration").Return(configuration, e2managererrors.NewRnibDbError()) + + writer := httptest.NewRecorder() + + httpRequest, _ := http.NewRequest("PUT", "https://localhost:3800/v1/nodeb/parameters", strings.NewReader("{\"enableRic\":false}")) + + controller.SetGeneralConfiguration(writer, httpRequest) + + var errorResponse = parseJsonRequest(t, writer.Body) + + assert.Equal(t, http.StatusInternalServerError, writer.Result().StatusCode) + assert.Equal(t, e2managererrors.NewRnibDbError().Code, errorResponse.Code) +} + +func TestSetGeneralConfigurationInvalidJson(t *testing.T) { + controller, _, _, _, _ := setupControllerTest(t) + + writer := httptest.NewRecorder() + + httpRequest, _ := http.NewRequest("PUT", "https://localhost:3800/v1/nodeb/parameters", strings.NewReader("{}{}")) + + controller.SetGeneralConfiguration(writer, httpRequest) + + var errorResponse = parseJsonRequest(t, writer.Body) + + assert.Equal(t, http.StatusBadRequest, writer.Result().StatusCode) + assert.Equal(t, e2managererrors.NewInvalidJsonError().Code, errorResponse.Code) +} + func controllerGetNodebTestExecuter(t *testing.T, context *controllerGetNodebTestContext) { controller, readerMock, _, _, _ := setupControllerTest(t) writer := httptest.NewRecorder() @@ -278,11 +338,16 @@ func activateControllerUpdateGnbMocks(context *controllerUpdateGnbTestContext, r readerMock.On("GetNodeb", RanName).Return(context.getNodebInfoResult.nodebInfo, context.getNodebInfoResult.rnibError) } + if context.removeServedNrCellsParams != nil { + writerMock.On("RemoveServedNrCells", RanName, context.removeServedNrCellsParams.servedNrCells).Return(context.removeServedNrCellsParams.err) + } + if context.updateGnbCellsParams != nil { updatedNodebInfo := *context.getNodebInfoResult.nodebInfo gnb := entities.Gnb{} _ = jsonpb.Unmarshal(getJsonRequestAsBuffer(context.requestBody), &gnb) - updatedNodebInfo.GetGnb().ServedNrCells = gnb.ServedNrCells + updatedGnb := *updatedNodebInfo.GetGnb() + updatedGnb.ServedNrCells = gnb.ServedNrCells writerMock.On("UpdateGnbCells", &updatedNodebInfo, gnb.ServedNrCells).Return(context.updateGnbCellsParams.err) } } @@ -301,6 +366,10 @@ func assertControllerUpdateGnb(t *testing.T, context *controllerUpdateGnbTestCon if context.updateGnbCellsParams != nil { writerMock.AssertNotCalled(t, "UpdateGnb") } + + if context.removeServedNrCellsParams != nil { + writerMock.AssertNotCalled(t, "RemoveServedNrCells") + } } func buildUpdateGnbRequest(context *controllerUpdateGnbTestContext) *http.Request { @@ -508,8 +577,46 @@ func TestControllerUpdateGnbGetNodebSuccessInvalidGnbConfiguration(t *testing.T) controllerUpdateGnbTestExecuter(t, &context) } +func TestControllerUpdateGnbGetNodebSuccessRemoveServedNrCellsFailure(t *testing.T) { + oldServedNrCells := generateServedNrCells("whatever1", "whatever2") + context := controllerUpdateGnbTestContext{ + removeServedNrCellsParams: &removeServedNrCellsParams{ + err: common.NewInternalError(errors.New("#writer.UpdateGnbCells - Internal Error")), + servedNrCells: oldServedNrCells, + }, + getNodebInfoResult: &getNodebInfoResult{ + nodebInfo: &entities.NodebInfo{ + RanName: RanName, + ConnectionStatus: entities.ConnectionStatus_CONNECTED, + AssociatedE2TInstanceAddress: AssociatedE2TInstanceAddress, + Configuration: &entities.NodebInfo_Gnb{Gnb: &entities.Gnb{ServedNrCells: oldServedNrCells}}, + }, + rnibError: nil, + }, + requestBody: map[string]interface{}{ + "servedNrCells": []interface{}{ + map[string]interface{}{ + "servedNrCellInformation": buildServedNrCellInformation(""), + "nrNeighbourInfos": []interface{}{ + buildNrNeighbourInformation(""), + }, + }, + }, + }, + expectedStatusCode: http.StatusInternalServerError, + expectedJsonResponse: RnibErrorJson, + } + + controllerUpdateGnbTestExecuter(t, &context) +} + func TestControllerUpdateGnbGetNodebSuccessUpdateGnbCellsFailure(t *testing.T) { + oldServedNrCells := generateServedNrCells("whatever1", "whatever2") context := controllerUpdateGnbTestContext{ + removeServedNrCellsParams: &removeServedNrCellsParams{ + err: nil, + servedNrCells: oldServedNrCells, + }, updateGnbCellsParams: &updateGnbCellsParams{ err: common.NewInternalError(errors.New("#writer.UpdateGnbCells - Internal Error")), }, @@ -518,7 +625,7 @@ func TestControllerUpdateGnbGetNodebSuccessUpdateGnbCellsFailure(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}}, }, rnibError: nil, }, @@ -573,7 +680,7 @@ func TestControllerUpdateGnbSuccess(t *testing.T) { func getJsonRequestAsBuffer(requestJson map[string]interface{}) *bytes.Buffer { b := new(bytes.Buffer) _ = json.NewEncoder(b).Encode(requestJson) - return b; + return b } func TestControllerGetNodebSuccess(t *testing.T) { @@ -761,7 +868,7 @@ func parseJsonRequest(t *testing.T, r io.Reader) models.ErrorResponse { if err != nil { t.Errorf("Error cannot deserialize json request") } - _ =json.Unmarshal(body, &errorResponse) + _ = json.Unmarshal(body, &errorResponse) return errorResponse }