Replaced all tabs with spaces in java and pom.xml
[so.git] / bpmn / so-bpmn-building-blocks / src / test / java / org / onap / so / bpmn / infrastructure / bpmn / subprocess / ActivateVfModuleBBTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.bpmn.subprocess;
22
23 import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareAssertions.assertThat;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.Mockito.doReturn;
26 import static org.mockito.Mockito.doThrow;
27 import java.io.IOException;
28 import java.util.List;
29 import org.camunda.bpm.engine.delegate.BpmnError;
30 import org.camunda.bpm.engine.externaltask.LockedExternalTask;
31 import org.camunda.bpm.engine.runtime.ProcessInstance;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.onap.so.bpmn.BaseBPMNTest;
35 import org.onap.so.bpmn.common.BuildingBlockExecution;
36
37 public class ActivateVfModuleBBTest extends BaseBPMNTest {
38
39     @Before
40     public void before() {
41         variables.put("vfModuleActivateTimerDuration", "PT2S");
42         variables.put("auditInventoryNeeded", "true");
43         variables.put("auditIsSuccessful", "true");
44     }
45
46     @Test
47     public void sunnyDay() throws InterruptedException, IOException {
48         mockSubprocess("SDNCHandler", "My Mock Process Name", "GenericStub");
49         ProcessInstance pi = runtimeService.startProcessInstanceByKey("ActivateVfModuleBB", variables);
50         List<LockedExternalTask> tasks = externalTaskService.fetchAndLock(100, "externalWorkerId")
51                 .topic("InventoryAddAudit", 60L * 1000L).execute();
52         while (!tasks.isEmpty()) {
53             for (LockedExternalTask task : tasks) {
54                 externalTaskService.complete(task.getId(), "externalWorkerId");
55             }
56             tasks = externalTaskService.fetchAndLock(100, "externalWorkerId").topic("InventoryAddAudit", 60L * 1000L)
57                     .execute();
58         }
59
60         assertThat(pi).isNotNull();
61         assertThat(pi).isStarted().hasPassedInOrder("ActivateVfModuleBB_Start", "ExclusiveGateway_1v8bmbu",
62                 "Setup_AAI_Inventory_Audit", "Audit_AAI_Inventory", "ActivateVfModule", "CallActivity_sdncHandler",
63                 "UpdateVfModuleActiveStatus", "ActivateVfModuleBB_End");
64         assertThat(pi).isEnded();
65     }
66
67     @Test
68     public void rainyDay() throws Exception {
69         mockSubprocess("SDNCHandler", "My Mock Process Name", "GenericStub");
70         doThrow(BpmnError.class).when(aaiUpdateTasks)
71                 .updateOrchestrationStatusActivateVfModule(any(BuildingBlockExecution.class));
72         ProcessInstance pi = runtimeService.startProcessInstanceByKey("ActivateVfModuleBB", variables);
73         List<LockedExternalTask> tasks = externalTaskService.fetchAndLock(100, "externalWorkerId")
74                 .topic("InventoryAddAudit", 60L * 1000L).execute();
75         while (!tasks.isEmpty()) {
76             for (LockedExternalTask task : tasks) {
77                 externalTaskService.complete(task.getId(), "externalWorkerId");
78             }
79             tasks = externalTaskService.fetchAndLock(100, "externalWorkerId").topic("InventoryAddAudit", 60L * 1000L)
80                     .execute();
81         }
82
83         assertThat(pi).isNotNull().isStarted()
84                 .hasPassedInOrder("ActivateVfModuleBB_Start", "ExclusiveGateway_1v8bmbu", "Setup_AAI_Inventory_Audit",
85                         "Audit_AAI_Inventory", "ActivateVfModule", "UpdateVfModuleActiveStatus")
86                 .hasNotPassed("ActivateVfModuleBB_End");
87     }
88 }