Ingest SO Task fields: 'timeout' and 'description' 21/83121/1
authorIttay Stern <ittay.stern@att.com>
Sun, 24 Mar 2019 17:16:51 +0000 (19:16 +0200)
committerIttay Stern <ittay.stern@att.com>
Sun, 24 Mar 2019 17:18:24 +0000 (19:18 +0200)
Follows discussion in SO-1594

Issue-ID: VID-403
Change-Id: I04b793d730c9a26d140f52197c103b14d1babd72
Signed-off-by: Ittay Stern <ittay.stern@att.com>
vid-app-common/src/main/java/org/onap/vid/mso/rest/Task.kt
vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.controller.js
vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.controller.test.js
vid-app-common/src/test/java/org/onap/vid/mso/rest/TaskTest.java

index 311b0fb..7d2a41a 100644 (file)
@@ -32,12 +32,15 @@ data class Task(
         var errorMessage: String?,
         var buildingBlockName: String?,
         var buildingBlockStep: String?,
+        var description: String?,
+        var timeout: String?,
         var validResponses: List<String>?
 ) {
     // i.e. "default constructor", no params
     constructor() : this(
             null, null, null, null,
             null, null, null, null,
-            null, null, null, null
+            null, null, null,
+            null, null, null
     )
 }
index bfe7330..c4f8f14 100644 (file)
         };
 
         function loadAvailableTasks(requestId) {
-            MsoService.getManualTasks(requestId)
+            return MsoService.getManualTasks(requestId)
                 .then(function(response) {
                     vm.task = response.data[0];
                     vm.manualTasks = vm.task && vm.task.validResponses;
+                    vm.description = vm.task && vm.task.description || null;
+                    vm.timeout = vm.task && vm.task.timeout || null;
                 })
                 .catch(function(error) {
                     $log.error(error);
             return vm.manualTasks.includes(task);
         };
 
+        vm.__test_only__ = {
+            loadAvailableTasks: loadAvailableTasks,
+        };
+
         init();
     }
 })();
index f5821f7..93bc1c2 100644 (file)
@@ -32,9 +32,10 @@ describe('changeManagementManualTasksController testing', () => {
     );
 
     beforeEach(inject(function (_$controller_) {
-        $MsoService.getManualTasks = jestMock.fn().mockResolvedValue(
-            {data: [manualTaskResponse]});
         $log.error = jestMock.fn();
+        $uibModalInstance.close = jestMock.fn();
+
+        mockManualTaskResponse(manualTaskResponse);
 
         $controller = _$controller_('changeManagementManualTasksController', {
             "MsoService": $MsoService,
@@ -51,6 +52,12 @@ describe('changeManagementManualTasksController testing', () => {
         });
     }));
 
+    function mockManualTaskResponse(manualTaskResponse) {
+        $MsoService.getManualTasks = jestMock.fn().mockResolvedValue(
+            {data: [manualTaskResponse]}
+        );
+    }
+
     const job = {
         "requestId": "db775fac-d9b5-480e-8b3e-4f0d0ae67890",
         "requestScope": "vnf",
@@ -69,16 +76,34 @@ describe('changeManagementManualTasksController testing', () => {
         }
     };
 
-    const manualTaskResponse = {
+    const manualTaskResponseWithoutValidResponses = {
         "taskId": "db775fac-d9b5-480e-8b3e-4f0d0ae67890",
-        "validResponses": ["rollback", "abort", "skip", "resume", "retry"]
     };
 
+    const manualTaskResponse = Object.assign({
+        "validResponses": ["rollback", "abort", "skip", "resume", "retry"],
+    }, manualTaskResponseWithoutValidResponses);
+
+    const manualTaskResponseWithTimeout = Object.assign({
+        description: 'description',
+        timeout: 'timeout',
+    }, manualTaskResponse);
+
     test('should populate vm.manualTasks (while init)', () => {
         expect($controller.manualTasks).toEqual(
             manualTaskResponse.validResponses);
     });
 
+    test('should undefine vm.manualTasks when ValidResponses not given', () => {
+        // given
+        mockManualTaskResponse(manualTaskResponseWithoutValidResponses);
+        // when
+        return $controller.__test_only__.loadAvailableTasks('anything')
+        .then(() => {
+            expect($controller.manualTasks).toBeUndefined()
+        });
+    });
+
     test('should populate vm.MANUAL_TASKS from COMPONENT (while init)', () => {
         expect($controller.MANUAL_TASKS).toEqual(
             ["manualTaskName1", "manualTaskName2"]);
@@ -88,6 +113,34 @@ describe('changeManagementManualTasksController testing', () => {
         expect($controller.task).toEqual(manualTaskResponse);
     });
 
+    test('should nullify vm.description (while init)', () => {
+        expect($controller.description).toBeNull();
+    });
+
+    test('should nullify vm.timeout (while init)', () => {
+        expect($controller.timeout).toBeNull();
+    });
+
+    test('should populate vm.description', () => {
+        // given
+        mockManualTaskResponse(manualTaskResponseWithTimeout);
+        // when
+        return $controller.__test_only__.loadAvailableTasks('anything')
+        .then(() => {
+            expect($controller.description).toEqual('description');
+        });
+    });
+
+    test('should populate vm.timeout', () => {
+        // given
+        mockManualTaskResponse(manualTaskResponseWithTimeout);
+        // when
+        return $controller.__test_only__.loadAvailableTasks('anything')
+        .then(() => {
+            expect($controller.timeout).toEqual('timeout');
+        });
+    });
+
     test('should find manual task using isTaskAvailable', () => {
         expect($controller.isTaskAvailable('abort')).toBeTruthy();
         expect($controller.isTaskAvailable('resume')).toBeTruthy();
index f6d0c76..d786275 100644 (file)
@@ -34,25 +34,36 @@ import org.testng.annotations.Test;
 public class TaskTest {
 
     private final ObjectMapper mapper = new ObjectMapper();
-    private final String TASK_JSON = ""
-        + "{ "
-        + "  \"taskId\": \"taskId\", "
-        + "  \"type\": \"type\", "
-        + "  \"nfRole\": \"nfRole\", "
-        + "  \"subscriptionServiceType\": \"subscriptionServiceType\", "
-        + "  \"originalRequestId\": \"originalRequestId\", "
-        + "  \"originalRequestorId\": \"originalRequestorId\", "
-        + "  \"buildingBlockName\": \"buildingBlockName\", "
-        + "  \"buildingBlockStep\": \"buildingBlockStep\", "
-        + "  \"errorSource\": \"errorSource\", "
-        + "  \"errorCode\": \"errorCode\", "
-        + "  \"errorMessage\": \"errorMessage\", "
-        + "  \"validResponses\": [ "
-        + "    \"a\", "
-        + "    \"b\", "
-        + "    \"c\" "
-        + "  ] "
-        + "} ";
+
+    private String templateTaskJson(String insertion) {
+        return ""
+            + "{ "
+            + "  \"taskId\": \"taskId\", "
+            + "  \"type\": \"type\", "
+            + "  \"nfRole\": \"nfRole\", "
+            + "  \"subscriptionServiceType\": \"subscriptionServiceType\", "
+            + "  \"originalRequestId\": \"originalRequestId\", "
+            + "  \"originalRequestorId\": \"originalRequestorId\", "
+            + "  \"buildingBlockName\": \"buildingBlockName\", "
+            + "  \"buildingBlockStep\": \"buildingBlockStep\", "
+            + "  \"errorSource\": \"errorSource\", "
+            + "  \"errorCode\": \"errorCode\", "
+            + "  \"errorMessage\": \"errorMessage\", "
+            + insertion
+            + "  \"validResponses\": [ "
+            + "    \"a\", "
+            + "    \"b\", "
+            + "    \"c\" "
+            + "  ] "
+            + "} ";
+    }
+
+    private final String TASK_JSON = templateTaskJson(""
+        + "  \"description\": \"description\", "
+        + "  \"timeout\": \"timeout\", "
+    );
+
+    private final String TASK_JSON_WITHOUT_TIMEOUT = templateTaskJson("");
 
     private Task newTaskWithPopulatedFields() {
         Task task = TestUtils.setStringsInStringProperties(new Task());
@@ -80,4 +91,19 @@ public class TaskTest {
             is(newTaskWithPopulatedFields())
         );
     }
+
+    @Test
+    public void deserializeTaskWithoutTimeout() throws IOException {
+        /*
+        SO may return no timeout, and therefore no description as well
+         */
+        final Task taskWithoutTimeout = newTaskWithPopulatedFields();
+        taskWithoutTimeout.setDescription(null);
+        taskWithoutTimeout.setTimeout(null);
+
+        assertThat(
+            mapper.readValue(TASK_JSON_WITHOUT_TIMEOUT, Task.class),
+            is(taskWithoutTimeout)
+        );
+    }
 }