"e2mgr/clients"
"e2mgr/configuration"
"e2mgr/e2managererrors"
- "e2mgr/e2pdus"
"e2mgr/logger"
"e2mgr/managers"
"e2mgr/mocks"
AssociatedE2TInstanceAddress = "10.0.2.15:38000"
ValidationFailureJson = "{\"errorCode\":402,\"errorMessage\":\"Validation error\"}"
ResourceNotFoundJson = "{\"errorCode\":404,\"errorMessage\":\"Resource not found\"}"
+ NodebExistsJson = "{\"errorCode\":406,\"errorMessage\":\"Nodeb already exists\"}"
RnibErrorJson = "{\"errorCode\":500,\"errorMessage\":\"RNIB error\"}"
InternalErrorJson = "{\"errorCode\":501,\"errorMessage\":\"Internal Server Error. Please try again later\"}"
+ AddEnbUrl = "/nodeb/enb"
)
var (
ServedNrCellInformationRequiredFields = []string{"cellId", "choiceNrMode", "nrMode", "nrPci", "servedPlmns"}
NrNeighbourInformationRequiredFields = []string{"nrCgi", "choiceNrMode", "nrMode", "nrPci"}
+ EnbRequiredFields = []string{"enbType", "servedCells"}
+ ServedCellRequiredFields = []string{"broadcastPlmns", "cellId", "choiceEutraMode", "eutraMode", "pci", "tac"}
)
type controllerGetNodebTestContext struct {
err error
}
+type saveNodebParams struct {
+ nodebInfo *entities.NodebInfo
+ nbIdentity *entities.NbIdentity
+ err error
+}
+
type removeServedNrCellsParams struct {
servedNrCells []*entities.ServedNRCell
- err error
+ err error
}
type controllerUpdateGnbTestContext struct {
- getNodebInfoResult *getNodebInfoResult
+ getNodebInfoResult *getNodebInfoResult
removeServedNrCellsParams *removeServedNrCellsParams
- updateGnbCellsParams *updateGnbCellsParams
+ updateGnbCellsParams *updateGnbCellsParams
+ requestBody map[string]interface{}
+ expectedStatusCode int
+ expectedJsonResponse string
+}
+
+type controllerAddEnbTestContext struct {
+ getNodebInfoResult *getNodebInfoResult
+ saveNodebParams *saveNodebParams
requestBody map[string]interface{}
expectedStatusCode int
expectedJsonResponse string
return ret
}
+func buildServedCell(propToOmit string) map[string]interface{} {
+ ret := map[string]interface{}{
+ "cellId": "whatever",
+ "choiceEutraMode": map[string]interface{}{
+ "fdd": map[string]interface{}{},
+ },
+ "eutraMode": 1,
+ "pci": 1,
+ "tac": "whatever3",
+ "broadcastPlmns": []interface{}{
+ "whatever",
+ },
+ }
+
+ if len(propToOmit) != 0 {
+ delete(ret, propToOmit)
+ }
+
+ return ret
+}
+
func setupControllerTest(t *testing.T) (*NodebController, *mocks.RnibReaderMock, *mocks.RnibWriterMock, *mocks.RmrMessengerMock, *mocks.E2TInstancesManagerMock) {
log := initLog(t)
config := configuration.ParseConfiguration()
e2tInstancesManager := &mocks.E2TInstancesManagerMock{}
httpClientMock := &mocks.HttpClientMock{}
rmClient := clients.NewRoutingManagerClient(log, config, httpClientMock)
- e2tAssociationManager := managers.NewE2TAssociationManager(log, rnibDataService, e2tInstancesManager, rmClient)
- handlerProvider := httpmsghandlerprovider.NewIncomingRequestHandlerProvider(log, rmrSender, config, rnibDataService, ranSetupManager, e2tInstancesManager, e2tAssociationManager, 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, ranConnectStatusChangeManager)
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
- writerMock.On("UpdateNodebInfo", &nbUpdated).Return(nil)
-
- var nbUpdated2 = &entities.NodebInfo{RanName: ranName, ConnectionStatus: entities.ConnectionStatus_CONNECTING, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, 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)
-
- rmrMessengerMock.On("SendMsg", mock.Anything, true).Return(msg, nil)
+func TestSetGeneralConfigurationHandlerRnibError(t *testing.T) {
+ controller, readerMock, _, _, _ := setupControllerTest(t)
- 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
- writerMock.On("UpdateNodebInfo", &nbUpdated).Return(nil)
-
- var nbUpdated2 = &entities.NodebInfo{RanName: ranName, ConnectionStatus: entities.ConnectionStatus_CONNECTING, E2ApplicationProtocol: entities.E2ApplicationProtocol_ENDC_X2_SETUP_REQUEST, 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)
-
- header := http.Header{}
- header.Set("Content-Type", "application/json")
- httpRequest := tests.GetHttpRequest()
- httpRequest.Header = header
+ controller.SetGeneralConfiguration(writer, httpRequest)
- 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) {
assert.Equal(t, context.expectedJsonResponse, string(bodyBytes))
readerMock.AssertExpectations(t)
writerMock.AssertExpectations(t)
+}
- if context.getNodebInfoResult != nil {
- readerMock.AssertNotCalled(t, "GetNodeb")
- }
-
- if context.updateGnbCellsParams != nil {
- writerMock.AssertNotCalled(t, "UpdateGnb")
- }
-
- if context.removeServedNrCellsParams != nil {
- writerMock.AssertNotCalled(t, "RemoveServedNrCells")
- }
+func assertControllerAddEnb(t *testing.T, context *controllerAddEnbTestContext, writer *httptest.ResponseRecorder, readerMock *mocks.RnibReaderMock, writerMock *mocks.RnibWriterMock) {
+ assert.Equal(t, context.expectedStatusCode, writer.Result().StatusCode)
+ bodyBytes, _ := ioutil.ReadAll(writer.Body)
+ assert.Equal(t, context.expectedJsonResponse, string(bodyBytes))
+ readerMock.AssertExpectations(t)
+ writerMock.AssertExpectations(t)
}
func buildUpdateGnbRequest(context *controllerUpdateGnbTestContext) *http.Request {
updateGnbUrl := fmt.Sprintf("/nodeb/%s/update", RanName)
requestBody := getJsonRequestAsBuffer(context.requestBody)
- req, _ := http.NewRequest(http.MethodGet, updateGnbUrl, requestBody)
+ req, _ := http.NewRequest(http.MethodPut, updateGnbUrl, requestBody)
req.Header.Set("Content-Type", "application/json")
req = mux.SetURLVars(req, map[string]string{"ranName": RanName})
return req
}
+func buildAddEnbRequest(context *controllerAddEnbTestContext) *http.Request {
+ requestBody := getJsonRequestAsBuffer(context.requestBody)
+ req, _ := http.NewRequest(http.MethodPost, AddEnbUrl, requestBody)
+ req.Header.Set("Content-Type", "application/json")
+ return req
+}
+
func controllerUpdateGnbTestExecuter(t *testing.T, context *controllerUpdateGnbTestContext) {
controller, readerMock, writerMock, _, _ := setupControllerTest(t)
writer := httptest.NewRecorder()
assertControllerUpdateGnb(t, context, writer, readerMock, writerMock)
}
+func activateControllerAddEnbMocks(context *controllerAddEnbTestContext, readerMock *mocks.RnibReaderMock, writerMock *mocks.RnibWriterMock, addEnbRequest *models.AddEnbRequest) {
+ if context.getNodebInfoResult != nil {
+ readerMock.On("GetNodeb", RanName).Return(context.getNodebInfoResult.nodebInfo, context.getNodebInfoResult.rnibError)
+ }
+
+ if context.saveNodebParams != nil {
+ nodebInfo := entities.NodebInfo{
+ RanName: addEnbRequest.RanName,
+ Ip: addEnbRequest.Ip,
+ Port: addEnbRequest.Port,
+ GlobalNbId: addEnbRequest.GlobalNbId,
+ Configuration: &entities.NodebInfo_Enb{Enb: addEnbRequest.Enb},
+ ConnectionStatus: entities.ConnectionStatus_DISCONNECTED,
+ }
+
+ nbIdentity := entities.NbIdentity{InventoryName: addEnbRequest.RanName, GlobalNbId: addEnbRequest.GlobalNbId}
+
+ writerMock.On("SaveNodeb",&nbIdentity, &nodebInfo).Return(context.saveNodebParams.err)
+ }
+}
+
+func controllerAddEnbTestExecuter(t *testing.T, context *controllerAddEnbTestContext) {
+ controller, readerMock, writerMock, _, _ := setupControllerTest(t)
+ writer := httptest.NewRecorder()
+ r := buildAddEnbRequest(context)
+ defer r.Body.Close()
+ body, _ := ioutil.ReadAll(io.LimitReader(r.Body, LimitRequest))
+
+ addEnbRequest := models.AddEnbRequest{}
+
+ _ = json.Unmarshal(body, &addEnbRequest)
+ activateControllerAddEnbMocks(context, readerMock, writerMock, &addEnbRequest)
+ controller.AddEnb(writer, buildAddEnbRequest(context))
+ assertControllerAddEnb(t, context, writer, readerMock, writerMock)
+}
+
func TestControllerUpdateGnbEmptyServedNrCells(t *testing.T) {
context := controllerUpdateGnbTestContext{
getNodebInfoResult: nil,
}
func TestControllerUpdateGnbGetNodebSuccessRemoveServedNrCellsFailure(t *testing.T) {
- oldServedNrCells := generateServedNrCells("whatever1","whatever2")
+ oldServedNrCells := generateServedNrCells("whatever1", "whatever2")
context := controllerUpdateGnbTestContext{
removeServedNrCellsParams: &removeServedNrCellsParams{
- err: common.NewInternalError(errors.New("#writer.UpdateGnbCells - Internal Error")),
+ err: common.NewInternalError(errors.New("#writer.UpdateGnbCells - Internal Error")),
servedNrCells: oldServedNrCells,
},
getNodebInfoResult: &getNodebInfoResult{
}
func TestControllerUpdateGnbGetNodebSuccessUpdateGnbCellsFailure(t *testing.T) {
- oldServedNrCells := generateServedNrCells("whatever1","whatever2")
+ oldServedNrCells := generateServedNrCells("whatever1", "whatever2")
context := controllerUpdateGnbTestContext{
removeServedNrCellsParams: &removeServedNrCellsParams{
- err: nil,
+ err: nil,
servedNrCells: oldServedNrCells,
},
updateGnbCellsParams: &updateGnbCellsParams{
controllerUpdateGnbTestExecuter(t, &context)
}
+func TestControllerAddEnbSuccess(t *testing.T) {
+ context := controllerAddEnbTestContext{
+ saveNodebParams: &saveNodebParams{
+ err: nil,
+ },
+ getNodebInfoResult: &getNodebInfoResult{
+ nodebInfo: nil,
+ rnibError: common.NewResourceNotFoundError("#reader.GetNodeb - Not found Error"),
+ },
+ requestBody: map[string]interface{}{
+ "ranName": RanName,
+ "globalNbId": map[string]interface{}{
+ "plmnId": "whatever",
+ "nbId": "whatever2",
+ },
+ "enb": map[string]interface{}{
+ "enbType": 1,
+ "servedCells": []interface{}{
+ buildServedCell(""),
+ },
+ },
+ },
+ expectedStatusCode: http.StatusCreated,
+ expectedJsonResponse: "{\"ranName\":\"test\",\"connectionStatus\":\"DISCONNECTED\",\"globalNbId\":{\"plmnId\":\"whatever\",\"nbId\":\"whatever2\"},\"enb\":{\"enbType\":\"MACRO_ENB\",\"servedCells\":[{\"pci\":1,\"cellId\":\"whatever\",\"tac\":\"whatever3\",\"broadcastPlmns\":[\"whatever\"],\"choiceEutraMode\":{\"fdd\":{}},\"eutraMode\":\"FDD\"}]}}",
+ }
+
+ controllerAddEnbTestExecuter(t, &context)
+}
+
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) {
header := &http.Header{}
- controller.handleRequest(writer, header, httpmsghandlerprovider.ShutdownRequest, nil, true)
+ controller.handleRequest(writer, header, httpmsghandlerprovider.ShutdownRequest, nil, true, 0)
var errorResponse = parseJsonRequest(t, writer.Body)
err := e2managererrors.NewHeaderValidationError()
if err != nil {
t.Errorf("Error cannot deserialize json request")
}
- _ =json.Unmarshal(body, &errorResponse)
+ _ = json.Unmarshal(body, &errorResponse)
return errorResponse
}
// no body
b := new(bytes.Buffer)
+ data4Req := map[string]interface{}{}
+ _ = json.NewEncoder(b).Encode(data4Req)
req, _ := http.NewRequest("PUT", "https://localhost:3800/nodeb-reset", b)
req = mux.SetURLVars(req, map[string]string{"ranName": ranName})
controller.X2Reset(writer, req)
assert.Equal(t, http.StatusNoContent, writer.Result().StatusCode)
-
}
func TestX2ResetHandleFailureInvalidBody(t *testing.T) {