[RIC-395] - E2M new REST API - E2M Set Parameters - Automation + Decoder
[ric-plt/e2mgr.git] / E2Manager / controllers / nodeb_controller_test.go
index c61249e..8209228 100644 (file)
@@ -92,16 +92,16 @@ type updateGnbCellsParams struct {
 
 type removeServedNrCellsParams struct {
        servedNrCells []*entities.ServedNRCell
-       err error
+       err           error
 }
 
 type controllerUpdateGnbTestContext struct {
-       getNodebInfoResult   *getNodebInfoResult
+       getNodebInfoResult        *getNodebInfoResult
        removeServedNrCellsParams *removeServedNrCellsParams
-       updateGnbCellsParams *updateGnbCellsParams
-       requestBody          map[string]interface{}
-       expectedStatusCode   int
-       expectedJsonResponse string
+       updateGnbCellsParams      *updateGnbCellsParams
+       requestBody               map[string]interface{}
+       expectedStatusCode        int
+       expectedJsonResponse      string
 }
 
 func generateServedNrCells(cellIds ...string) []*entities.ServedNRCell {
@@ -277,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("{\"enableRic\":false, \"someValue\":false}"))
+
+       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()
@@ -545,10 +578,10 @@ func TestControllerUpdateGnbGetNodebSuccessInvalidGnbConfiguration(t *testing.T)
 }
 
 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{
@@ -578,10 +611,10 @@ func TestControllerUpdateGnbGetNodebSuccessRemoveServedNrCellsFailure(t *testing
 }
 
 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{
@@ -647,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) {
@@ -835,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
 }