+ 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 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\"},\"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)
+}
+
+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)
+}
+
+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)
+}
+
+func TestControllerDeleteEnbSuccess(t *testing.T) {
+ context := controllerDeleteEnbTestContext{
+ getNodebInfoResult: &getNodebInfoResult{
+ nodebInfo: &entities.NodebInfo{RanName: "ran1", NodeType: entities.Node_ENB, ConnectionStatus: entities.ConnectionStatus_DISCONNECTED},
+ rnibError: nil,
+ },
+ expectedStatusCode: http.StatusNoContent,
+ expectedJsonResponse: "",
+ }
+ controllerDeleteEnbTestExecuter(t, &context)
+}
+
+func getJsonRequestAsBuffer(requestJson map[string]interface{}) *bytes.Buffer {
+ b := new(bytes.Buffer)
+ _ = json.NewEncoder(b).Encode(requestJson)
+ return b
+}
+
+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\"}}]",
+ }
+
+ 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: "[]",
+ }
+
+ controllerGetNodebIdListTestExecuter(t, &context)
+}
+
+func TestControllerGetNodebIdListInternal(t *testing.T) {
+ var nodebIdList []*entities.NbIdentity
+ context := controllerGetNodebIdListTestContext{
+ nodebIdList: nodebIdList,
+ rnibError: common.NewInternalError(errors.New("#reader.GetNodeb - Internal Error")),
+ expectedStatusCode: http.StatusInternalServerError,
+ expectedJsonResponse: RnibErrorJson,