"e2mgr/clients"
"e2mgr/configuration"
"e2mgr/e2managererrors"
- "e2mgr/e2pdus"
"e2mgr/logger"
"e2mgr/managers"
"e2mgr/mocks"
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{} {
e2tInstancesManager := &mocks.E2TInstancesManagerMock{}
httpClientMock := &mocks.HttpClientMock{}
rmClient := clients.NewRoutingManagerClient(log, config, httpClientMock)
- e2tAssociationManager := managers.NewE2TAssociationManager(log, rnibDataService, e2tInstancesManager, rmClient)
+ ranListManager := &mocks.RanListManagerMock{}
+ ranAlarmService := &mocks.RanAlarmServiceMock{}
+ ranConnectStatusChangeManager := managers.NewRanConnectStatusChangeManager(log, rnibDataService, ranListManager, ranAlarmService)
+
+ e2tAssociationManager := managers.NewE2TAssociationManager(log, rnibDataService, e2tInstancesManager, rmClient, ranConnectStatusChangeManager)
handlerProvider := httpmsghandlerprovider.NewIncomingRequestHandlerProvider(log, rmrSender, config, rnibDataService, ranSetupManager, e2tInstancesManager, e2tAssociationManager, rmClient)
controller := NewNodebController(log, handlerProvider)
return controller, readerMock, writerMock, rmrMessengerMock, e2tInstancesManager
}
-func TestX2SetupInvalidBody(t *testing.T) {
-
- controller, _, _, _, _ := setupControllerTest(t)
-
- header := http.Header{}
- header.Set("Content-Type", "application/json")
- httpRequest, _ := http.NewRequest("POST", "http://localhost:3800/v1/nodeb/x2-setup", strings.NewReader("{}{}"))
- httpRequest.Header = header
+func TestShutdownHandlerRnibError(t *testing.T) {
+ controller, _, _, _, e2tInstancesManagerMock := setupControllerTest(t)
+ e2tInstancesManagerMock.On("GetE2TAddresses").Return([]string{}, e2managererrors.NewRnibDbError())
writer := httptest.NewRecorder()
- controller.X2Setup(writer, httpRequest)
+
+ controller.Shutdown(writer, tests.GetHttpRequest())
var errorResponse = parseJsonRequest(t, writer.Body)
- assert.Equal(t, http.StatusBadRequest, writer.Result().StatusCode)
- assert.Equal(t, e2managererrors.NewInvalidJsonError().Code, errorResponse.Code)
+ assert.Equal(t, http.StatusInternalServerError, writer.Result().StatusCode)
+ assert.Equal(t, errorResponse.Code, e2managererrors.NewRnibDbError().Code)
}
-func TestX2SetupSuccess(t *testing.T) {
-
- controller, readerMock, writerMock, rmrMessengerMock, _ := setupControllerTest(t)
-
- ranName := "test"
- nb := &entities.NodebInfo{RanName: ranName, ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, AssociatedE2TInstanceAddress: "10.0.2.15:8989"}
- readerMock.On("GetNodeb", ranName).Return(nb, nil)
- var nbUpdated = *nb
- nbUpdated.ConnectionAttempts = 0
- writerMock.On("UpdateNodebInfo", &nbUpdated).Return(nil)
-
- var nbUpdated2 = &entities.NodebInfo{RanName: ranName, ConnectionStatus: entities.ConnectionStatus_CONNECTING, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 1, AssociatedE2TInstanceAddress: "10.0.2.15:8989"}
- writerMock.On("UpdateNodebInfo", nbUpdated2).Return(nil)
-
- payload := e2pdus.PackedX2setupRequest
- var xAction []byte
- var msgSrc unsafe.Pointer
- msg := rmrCgo.NewMBuf(rmrCgo.RIC_X2_SETUP_REQ, len(payload), ranName, &payload, &xAction, msgSrc)
+func TestSetGeneralConfigurationHandlerRnibError(t *testing.T) {
+ controller, readerMock, _, _, _ := setupControllerTest(t)
- rmrMessengerMock.On("SendMsg", mock.Anything, true).Return(msg, nil)
-
- header := http.Header{}
- header.Set("Content-Type", "application/json")
- httpRequest := tests.GetHttpRequest()
- httpRequest.Header = header
+ configuration := &entities.GeneralConfiguration{}
+ readerMock.On("GetGeneralConfiguration").Return(configuration, e2managererrors.NewRnibDbError())
writer := httptest.NewRecorder()
- controller.X2Setup(writer, httpRequest)
-
- assert.Equal(t, http.StatusNoContent, writer.Result().StatusCode)
-}
-
-func TestEndcSetupSuccess(t *testing.T) {
-
- controller, readerMock, writerMock, rmrMessengerMock, _ := setupControllerTest(t)
- ranName := "test"
- nb := &entities.NodebInfo{RanName: ranName, ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, E2ApplicationProtocol: entities.E2ApplicationProtocol_ENDC_X2_SETUP_REQUEST, AssociatedE2TInstanceAddress: "10.0.2.15:8989"}
- readerMock.On("GetNodeb", ranName).Return(nb, nil)
- var nbUpdated = *nb
- nbUpdated.ConnectionAttempts = 0
- writerMock.On("UpdateNodebInfo", &nbUpdated).Return(nil)
-
- var nbUpdated2 = &entities.NodebInfo{RanName: ranName, ConnectionStatus: entities.ConnectionStatus_CONNECTING, E2ApplicationProtocol: entities.E2ApplicationProtocol_ENDC_X2_SETUP_REQUEST, ConnectionAttempts: 1, AssociatedE2TInstanceAddress: "10.0.2.15:8989"}
- writerMock.On("UpdateNodebInfo", nbUpdated2).Return(nil)
-
- payload := e2pdus.PackedEndcX2setupRequest
- var xAction []byte
- var msgSrc unsafe.Pointer
- msg := rmrCgo.NewMBuf(rmrCgo.RIC_ENDC_X2_SETUP_REQ, len(payload), ranName, &payload, &xAction, msgSrc)
+ httpRequest, _ := http.NewRequest("PUT", "https://localhost:3800/v1/nodeb/parameters", strings.NewReader("{\"enableRic\":false}"))
- rmrMessengerMock.On("SendMsg", mock.Anything, true).Return(msg, nil)
+ controller.SetGeneralConfiguration(writer, httpRequest)
- header := http.Header{}
- header.Set("Content-Type", "application/json")
- httpRequest := tests.GetHttpRequest()
- httpRequest.Header = header
-
- writer := httptest.NewRecorder()
- controller.EndcSetup(writer, httpRequest)
+ var errorResponse = parseJsonRequest(t, writer.Body)
- assert.Equal(t, http.StatusNoContent, writer.Result().StatusCode)
+ assert.Equal(t, http.StatusInternalServerError, writer.Result().StatusCode)
+ assert.Equal(t, e2managererrors.NewRnibDbError().Code, errorResponse.Code)
}
-func TestShutdownHandlerRnibError(t *testing.T) {
- controller, _, _, _, e2tInstancesManagerMock := setupControllerTest(t)
- e2tInstancesManagerMock.On("GetE2TAddresses").Return([]string{}, e2managererrors.NewRnibDbError())
+func TestSetGeneralConfigurationInvalidJson(t *testing.T) {
+ controller, _, _, _, _ := setupControllerTest(t)
writer := httptest.NewRecorder()
- controller.Shutdown(writer, tests.GetHttpRequest())
+ httpRequest, _ := http.NewRequest("PUT", "https://localhost:3800/v1/nodeb/parameters", strings.NewReader("{\"enableRic\":false, \"someValue\":false}"))
+
+ controller.SetGeneralConfiguration(writer, httpRequest)
var errorResponse = parseJsonRequest(t, writer.Body)
- assert.Equal(t, http.StatusInternalServerError, writer.Result().StatusCode)
- assert.Equal(t, errorResponse.Code, e2managererrors.NewRnibDbError().Code)
+ assert.Equal(t, http.StatusBadRequest, writer.Result().StatusCode)
+ assert.Equal(t, e2managererrors.NewInvalidJsonError().Code, errorResponse.Code)
}
func controllerGetNodebTestExecuter(t *testing.T, context *controllerGetNodebTestContext) {
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)
}
}
if context.updateGnbCellsParams != nil {
writerMock.AssertNotCalled(t, "UpdateGnb")
}
+
+ if context.removeServedNrCellsParams != nil {
+ writerMock.AssertNotCalled(t, "RemoveServedNrCells")
+ }
}
func buildUpdateGnbRequest(context *controllerUpdateGnbTestContext) *http.Request {
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")),
},
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,
},
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) {
if err != nil {
t.Errorf("Error cannot deserialize json request")
}
- _ =json.Unmarshal(body, &errorResponse)
+ _ = json.Unmarshal(body, &errorResponse)
return errorResponse
}