+ r := getAddEnbRequest("")
+
+ for _, v := range ServedCellRequiredFields {
+ enb := r["enb"]
+
+ enbMap, _ := enb.(map[string]interface{})
+
+ enbMap["servedCells"] = []interface{}{
+ buildServedCell(v),
+ }
+
+ context := controllerAddEnbTestContext{
+ requestBody: r,
+ expectedStatusCode: http.StatusBadRequest,
+ expectedJsonResponse: ValidationFailureJson,
+ }
+
+ controllerAddEnbTestExecuter(t, &context)
+ }
+}
+
+func TestControllerAddEnbNgEnbFailure(t *testing.T) {
+
+ requestBody := map[string]interface{}{
+ "ranName": RanName,
+ "globalNbId": buildGlobalNbId(""),
+ "enb": map[string]interface{}{
+ "enbType": 5,
+ "servedCells": []interface{}{
+ buildServedCell(""),
+ },
+ },
+ }
+
+ context := controllerAddEnbTestContext{
+ requestBody: requestBody,
+ expectedStatusCode: http.StatusBadRequest,
+ expectedJsonResponse: ValidationFailureJson,
+ }
+
+ controllerAddEnbTestExecuter(t, &context)
+}
+
+func TestControllerAddEnbSuccess(t *testing.T) {
+ context := controllerAddEnbTestContext{
+ addEnbParams: &addEnbParams{
+ err: nil,
+ },
+ addNbIdentityParams: &addNbIdentityParams{
+ err: nil,
+ },
+ getNodebInfoResult: &getNodebInfoResult{
+ nodebInfo: nil,
+ rnibError: common.NewResourceNotFoundError("#reader.GetNodeb - Not found Error"),
+ },
+ requestBody: getAddEnbRequest(""),
+ expectedStatusCode: http.StatusCreated,
+ expectedJsonResponse: "{\"ranName\":\"test\",\"connectionStatus\":\"DISCONNECTED\",\"globalNbId\":{\"plmnId\":\"whatever\",\"nbId\":\"whatever2\"},\"nodeType\":\"ENB\",\"enb\":{\"enbType\":\"MACRO_ENB\",\"servedCells\":[{\"pci\":1,\"cellId\":\"whatever\",\"tac\":\"whatever3\",\"broadcastPlmns\":[\"whatever\"],\"choiceEutraMode\":{\"fdd\":{}},\"eutraMode\":\"FDD\"}]}}",
+ }
+
+ controllerAddEnbTestExecuter(t, &context)
+}
+
+func TestControllerDeleteEnbGetNodebInternalError(t *testing.T) {
+ context := controllerDeleteEnbTestContext{
+ getNodebInfoResult: &getNodebInfoResult{
+ nodebInfo: nil,
+ rnibError: common.NewInternalError(errors.New("#reader.GetNodeb - Internal Error")),
+ },
+ expectedStatusCode: http.StatusInternalServerError,
+ expectedJsonResponse: RnibErrorJson,
+ }
+
+ controllerDeleteEnbTestExecuter(t, &context, false)
+}
+
+/*
+DeleteEnb UTs
+*/
+
+func TestControllerDeleteEnbNodebNotExistsFailure(t *testing.T) {
+ context := controllerDeleteEnbTestContext{
+ getNodebInfoResult: &getNodebInfoResult{
+ nodebInfo: nil,
+ rnibError: common.NewResourceNotFoundError("#reader.GetNodeb - Not found"),
+ },
+ expectedStatusCode: http.StatusNotFound,
+ expectedJsonResponse: ResourceNotFoundJson,
+ }
+
+ controllerDeleteEnbTestExecuter(t, &context, false)
+}
+
+func TestControllerDeleteEnbNodebNotEnb(t *testing.T) {
+ context := controllerDeleteEnbTestContext{
+ getNodebInfoResult: &getNodebInfoResult{
+ nodebInfo: &entities.NodebInfo{RanName: "ran1", NodeType: entities.Node_GNB, ConnectionStatus: entities.ConnectionStatus_DISCONNECTED},
+ rnibError: nil,
+ },
+ expectedStatusCode: http.StatusBadRequest,
+ expectedJsonResponse: ValidationFailureJson,
+ }
+
+ controllerDeleteEnbTestExecuter(t, &context, false)
+}
+
+func TestControllerDeleteEnbSetupFromNetworkTrueFailure(t *testing.T) {
+ context := controllerDeleteEnbTestContext{
+ getNodebInfoResult: &getNodebInfoResult{
+ nodebInfo: &entities.NodebInfo{RanName: RanName, NodeType: entities.Node_ENB, ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, SetupFromNetwork: true},
+ rnibError: nil,
+ },
+ expectedStatusCode: http.StatusBadRequest,
+ expectedJsonResponse: ValidationFailureJson,
+ }
+ controllerDeleteEnbTestExecuter(t, &context, true)
+}
+
+func TestControllerDeleteEnbSuccess(t *testing.T) {
+ context := controllerDeleteEnbTestContext{
+ getNodebInfoResult: &getNodebInfoResult{
+ nodebInfo: &entities.NodebInfo{RanName: RanName, NodeType: entities.Node_ENB, ConnectionStatus: entities.ConnectionStatus_DISCONNECTED},
+ rnibError: nil,
+ },
+ expectedStatusCode: http.StatusNoContent,
+ expectedJsonResponse: "",
+ }
+ controllerDeleteEnbTestExecuter(t, &context, true)
+}
+
+func getJsonRequestAsBuffer(requestJson map[string]interface{}) *bytes.Buffer {
+ b := new(bytes.Buffer)
+ _ = json.NewEncoder(b).Encode(requestJson)
+ return b
+}
+
+/*
+GetNodeb UTs
+*/
+
+func TestControllerGetNodebSuccess(t *testing.T) {
+ ranName := "test"
+ var rnibError error
+ context := controllerGetNodebTestContext{
+ ranName: ranName,
+ nodebInfo: &entities.NodebInfo{RanName: ranName, Ip: "10.0.2.15", Port: 1234},
+ rnibError: rnibError,
+ expectedStatusCode: http.StatusOK,
+ expectedJsonResponse: fmt.Sprintf("{\"ranName\":\"%s\",\"ip\":\"10.0.2.15\",\"port\":1234}", ranName),
+ }
+
+ controllerGetNodebTestExecuter(t, &context)
+}
+
+func TestControllerGetNodebNotFound(t *testing.T) {
+
+ ranName := "test"
+ var nodebInfo *entities.NodebInfo
+ context := controllerGetNodebTestContext{
+ ranName: ranName,
+ nodebInfo: nodebInfo,
+ rnibError: common.NewResourceNotFoundError("#reader.GetNodeb - Not found Error"),
+ expectedStatusCode: http.StatusNotFound,
+ expectedJsonResponse: ResourceNotFoundJson,
+ }
+
+ controllerGetNodebTestExecuter(t, &context)
+}
+
+func TestControllerGetNodebInternal(t *testing.T) {
+ ranName := "test"
+ var nodebInfo *entities.NodebInfo
+ context := controllerGetNodebTestContext{
+ ranName: ranName,
+ nodebInfo: nodebInfo,
+ rnibError: common.NewInternalError(errors.New("#reader.GetNodeb - Internal Error")),
+ expectedStatusCode: http.StatusInternalServerError,
+ expectedJsonResponse: RnibErrorJson,
+ }
+
+ controllerGetNodebTestExecuter(t, &context)
+}
+
+func TestControllerGetNodebIdListSuccess(t *testing.T) {
+ var rnibError error
+ nodebIdList := []*entities.NbIdentity{
+ {InventoryName: "test1", GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}},
+ {InventoryName: "test2", GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId2", NbId: "nbId2"}},
+ }
+
+ context := controllerGetNodebIdListTestContext{
+ nodebIdList: nodebIdList,
+ rnibError: rnibError,
+ expectedStatusCode: http.StatusOK,
+ expectedJsonResponse: "[{\"inventoryName\":\"test1\",\"globalNbId\":{\"plmnId\":\"plmnId1\",\"nbId\":\"nbId1\"}},{\"inventoryName\":\"test2\",\"globalNbId\":{\"plmnId\":\"plmnId2\",\"nbId\":\"nbId2\"}}][{\"inventoryName\":\"test2\",\"globalNbId\":{\"plmnId\":\"plmnId2\",\"nbId\":\"nbId2\"}},{\"inventoryName\":\"test1\",\"globalNbId\":{\"plmnId\":\"plmnId1\",\"nbId\":\"nbId1\"}}]",
+ }
+
+ controllerGetNodebIdListTestExecuter(t, &context)
+}
+
+func TestControllerGetNodebIdListEmptySuccess(t *testing.T) {
+ var rnibError error
+ var nodebIdList []*entities.NbIdentity
+
+ context := controllerGetNodebIdListTestContext{
+ nodebIdList: nodebIdList,
+ rnibError: rnibError,
+ expectedStatusCode: http.StatusOK,
+ expectedJsonResponse: "[]",