+func controllerUpdateGnbTestExecuter(t *testing.T, context *controllerUpdateGnbTestContext) {
+ controller, readerMock, _, _, _ := setupControllerTest(t)
+ writer := httptest.NewRecorder()
+
+ if context.getNodebInfoResult != nil {
+ readerMock.On("GetNodeb", RanName).Return(context.getNodebInfoResult.nodebInfo, context.getNodebInfoResult.rnibError)
+ }
+
+ updateGnbUrl := fmt.Sprintf("/nodeb/%s/update", RanName)
+ requestBody := getJsonRequestAsBuffer(context.requestBody)
+ req, _ := http.NewRequest(http.MethodGet, updateGnbUrl, requestBody)
+ req.Header.Set("Content-Type", "application/json")
+ req = mux.SetURLVars(req, map[string]string{"ranName": RanName})
+ controller.UpdateGnb(writer, req)
+ assert.Equal(t, context.expectedStatusCode, writer.Result().StatusCode)
+ bodyBytes, _ := ioutil.ReadAll(writer.Body)
+ assert.Equal(t, context.expectedJsonResponse, string(bodyBytes))
+}
+
+func TestControllerUpdateGnbEmptyServedNrCells(t *testing.T) {
+ context := controllerUpdateGnbTestContext{
+ getNodebInfoResult: nil,
+ requestBody: map[string]interface{}{
+ "servedNrCells": []interface{}{
+ },
+ },
+ expectedStatusCode: http.StatusBadRequest,
+ expectedJsonResponse: ValidationFailureJson,
+ }
+
+ controllerUpdateGnbTestExecuter(t, &context)
+}
+
+func TestControllerUpdateGnbMissingServedNrCellInformation(t *testing.T) {
+ context := controllerUpdateGnbTestContext{
+ getNodebInfoResult: nil,
+ requestBody: map[string]interface{}{
+ "servedNrCells": []interface{}{
+ map[string]interface{}{
+ "servedNrCellInformation": nil,
+ },
+ },
+ },
+ expectedStatusCode: http.StatusBadRequest,
+ expectedJsonResponse: ValidationFailureJson,
+ }
+
+ controllerUpdateGnbTestExecuter(t, &context)
+}
+
+func TestControllerUpdateGnbMissingServedNrCellRequiredProp(t *testing.T) {
+
+ for _, v := range ServedNrCellInformationRequiredFields {
+ context := controllerUpdateGnbTestContext{
+ getNodebInfoResult: nil,
+ requestBody: map[string]interface{}{
+ "servedNrCells": []interface{}{
+ map[string]interface{}{
+ "servedNrCellInformation": buildServedNrCellInformation(v),
+ },
+ },
+ },
+ expectedStatusCode: http.StatusBadRequest,
+ expectedJsonResponse: ValidationFailureJson,
+ }
+
+ controllerUpdateGnbTestExecuter(t, &context)
+ }
+}
+
+func TestControllerUpdateGnbMissingServedNrCellFddOrTdd(t *testing.T) {
+
+ servedNrCellInformation := buildServedNrCellInformation("")
+ servedNrCellInformation["choiceNrMode"] = map[string]interface{}{}
+
+ context := controllerUpdateGnbTestContext{
+ getNodebInfoResult: nil,
+ requestBody: map[string]interface{}{
+ "servedNrCells": []interface{}{
+ map[string]interface{}{
+ "servedNrCellInformation": servedNrCellInformation,
+ },
+ },
+ },
+ expectedStatusCode: http.StatusBadRequest,
+ expectedJsonResponse: ValidationFailureJson,
+ }
+
+ controllerUpdateGnbTestExecuter(t, &context)
+}
+
+func TestControllerUpdateGnbMissingNeighbourInfoFddOrTdd(t *testing.T) {
+
+ nrNeighbourInfo := buildNrNeighbourInformation("")
+ nrNeighbourInfo["choiceNrMode"] = map[string]interface{}{}
+
+ context := controllerUpdateGnbTestContext{
+ getNodebInfoResult: nil,
+ requestBody: map[string]interface{}{
+ "servedNrCells": []interface{}{
+ map[string]interface{}{
+ "servedNrCellInformation": buildServedNrCellInformation(""),
+ "nrNeighbourInfos": []interface{}{
+ nrNeighbourInfo,
+ },
+ },
+ },
+ },
+ expectedStatusCode: http.StatusBadRequest,
+ expectedJsonResponse: ValidationFailureJson,
+ }
+
+ controllerUpdateGnbTestExecuter(t, &context)
+}
+
+func TestControllerUpdateGnbMissingNrNeighbourInformationRequiredProp(t *testing.T) {
+
+ for _, v := range NrNeighbourInformationRequiredFields {
+ context := controllerUpdateGnbTestContext{
+ getNodebInfoResult: nil,
+ requestBody: map[string]interface{}{
+ "servedNrCells": []interface{}{
+ map[string]interface{}{
+ "servedNrCellInformation": buildServedNrCellInformation(""),
+ "nrNeighbourInfos": []interface{}{
+ buildNrNeighbourInformation(v),
+ },
+ },
+ },
+ },
+ expectedStatusCode: http.StatusBadRequest,
+ expectedJsonResponse: ValidationFailureJson,
+ }
+
+ controllerUpdateGnbTestExecuter(t, &context)
+ }
+}
+
+func TestControllerUpdateGnbValidServedNrCellInformationAndNrNeighbourInfoGetNodebSuccess(t *testing.T) {
+ context := controllerUpdateGnbTestContext{
+ getNodebInfoResult: &getNodebInfoResult{
+ nodebInfo: &entities.NodebInfo{RanName: RanName, ConnectionStatus: entities.ConnectionStatus_CONNECTED, AssociatedE2TInstanceAddress: AssociatedE2TInstanceAddress},
+ rnibError: nil,
+ },
+ requestBody: map[string]interface{}{
+ "servedNrCells": []interface{}{
+ map[string]interface{}{
+ "servedNrCellInformation": buildServedNrCellInformation(""),
+ "nrNeighbourInfos": []interface{}{
+ buildNrNeighbourInformation(""),
+ },
+ },
+ },
+ },
+ expectedStatusCode: http.StatusOK,
+ expectedJsonResponse: "{\"ranName\":\"test\",\"connectionStatus\":\"CONNECTED\",\"associatedE2tInstanceAddress\":\"10.0.2.15:38000\"}",
+ }
+
+ controllerUpdateGnbTestExecuter(t, &context)
+}
+
+func TestControllerUpdateGnbValidServedNrCellInformationGetNodebNotFound(t *testing.T) {
+ context := controllerUpdateGnbTestContext{
+ getNodebInfoResult: &getNodebInfoResult{
+ nodebInfo: nil,
+ rnibError: common.NewResourceNotFoundError("#reader.GetNodeb - Not found Error"),
+ },
+ requestBody: map[string]interface{}{
+ "servedNrCells": []interface{}{
+ map[string]interface{}{
+ "servedNrCellInformation": buildServedNrCellInformation(""),
+ },
+ },
+ },
+ expectedStatusCode: http.StatusNotFound,
+ expectedJsonResponse: ResourceNotFoundJson,
+ }
+
+ controllerUpdateGnbTestExecuter(t, &context)
+}
+
+func TestControllerUpdateGnbValidServedNrCellInformationGetNodebInternalError(t *testing.T) {
+ context := controllerUpdateGnbTestContext{
+ getNodebInfoResult: &getNodebInfoResult{
+ nodebInfo: nil,
+ rnibError: common.NewInternalError(errors.New("#reader.GetNodeb - Internal Error")),
+ },
+ requestBody: map[string]interface{}{
+ "servedNrCells": []interface{}{
+ map[string]interface{}{
+ "servedNrCellInformation": buildServedNrCellInformation(""),
+ },
+ },
+ },
+ expectedStatusCode: http.StatusInternalServerError,
+ expectedJsonResponse: RnibErrorJson,
+ }
+
+ controllerUpdateGnbTestExecuter(t, &context)
+}
+
+func getJsonRequestAsBuffer(requestJson map[string]interface{}) *bytes.Buffer {
+ b := new(bytes.Buffer)
+ _ = json.NewEncoder(b).Encode(requestJson)
+ return b;
+}
+