if audit fails write sub interface data to a ai
[so.git] / bpmn / so-bpmn-building-blocks / src / test / java / org / onap / so / bpmn / infrastructure / bpmn / subprocess / ActivateVfModuleBBTest.java
index dcf9d7f..deac50c 100644 (file)
  */
 
 package org.onap.so.bpmn.infrastructure.bpmn.subprocess;
-
 import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareAssertions.assertThat;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.doThrow;
-
 import java.io.IOException;
+import java.util.List;
 
 import org.camunda.bpm.engine.delegate.BpmnError;
+import org.camunda.bpm.engine.externaltask.LockedExternalTask;
 import org.camunda.bpm.engine.runtime.ProcessInstance;
+import org.junit.Before;
 import org.junit.Test;
 import org.onap.so.bpmn.BaseBPMNTest;
 import org.onap.so.bpmn.common.BuildingBlockExecution;
 
 public class ActivateVfModuleBBTest extends BaseBPMNTest{
+       
+       @Before
+       public void before() {
+               variables.put("vfModuleActivateTimerDuration", "PT2S");
+               variables.put("auditInventoryNeeded", "true");
+               variables.put("auditIsSuccessful", "true");     
+       }
+
        @Test
        public void sunnyDay() throws InterruptedException, IOException {
+               mockSubprocess("SDNCHandler", "My Mock Process Name", "GenericStub");
                ProcessInstance pi = runtimeService.startProcessInstanceByKey("ActivateVfModuleBB", variables);
+               List<LockedExternalTask> tasks = externalTaskService.fetchAndLock(100, "externalWorkerId")
+                .topic("InventoryAddAudit", 60L * 1000L).execute();
+        while (!tasks.isEmpty()) {
+            for (LockedExternalTask task : tasks) {
+                externalTaskService.complete(task.getId(), "externalWorkerId");
+            }
+            tasks = externalTaskService.fetchAndLock(100, "externalWorkerId")
+                    .topic("InventoryAddAudit", 60L * 1000L).execute();
+        }
+               
                assertThat(pi).isNotNull();
-               assertThat(pi).isStarted().hasPassedInOrder("ActivateVfModuleBB_Start", "ActivateVfModule",
+               assertThat(pi).isStarted().hasPassedInOrder("ActivateVfModuleBB_Start","ExclusiveGateway_1v8bmbu","Setup_AAI_Inventory_Audit", "Audit_AAI_Inventory", "ActivateVfModule", "CallActivity_sdncHandler",
                                "UpdateVfModuleActiveStatus", "ActivateVfModuleBB_End");
                assertThat(pi).isEnded();
        }
        
        @Test
        public void rainyDay() throws Exception {
+               mockSubprocess("SDNCHandler", "My Mock Process Name", "GenericStub");
                doThrow(BpmnError.class).when(aaiUpdateTasks).updateOrchestrationStatusActivateVfModule(any(BuildingBlockExecution.class));
                ProcessInstance pi = runtimeService.startProcessInstanceByKey("ActivateVfModuleBB", variables);
-               assertThat(pi).isNotNull();
-               assertThat(pi).isStarted()
-                               .hasPassedInOrder("ActivateVfModuleBB_Start", "ActivateVfModule", "UpdateVfModuleActiveStatus")
+               List<LockedExternalTask> tasks = externalTaskService.fetchAndLock(100, "externalWorkerId")
+                .topic("InventoryAddAudit", 60L * 1000L).execute();
+        while (!tasks.isEmpty()) {
+            for (LockedExternalTask task : tasks) {
+                externalTaskService.complete(task.getId(), "externalWorkerId");
+            }
+            tasks = externalTaskService.fetchAndLock(100, "externalWorkerId")
+                    .topic("InventoryAddAudit", 60L * 1000L).execute();
+        }
+
+               assertThat(pi).isNotNull().isStarted()
+                               .hasPassedInOrder("ActivateVfModuleBB_Start","ExclusiveGateway_1v8bmbu","Setup_AAI_Inventory_Audit", "Audit_AAI_Inventory", "ActivateVfModule", "UpdateVfModuleActiveStatus")
                                .hasNotPassed("ActivateVfModuleBB_End");
-               assertThat(pi).isEnded().hasVariables("gBuildingBlockExecution");
-       
        }
 }