Enhanced List Level flow with backward support
[so.git] / bpmn / so-bpmn-building-blocks / src / test / java / org / onap / so / bpmn / infrastructure / bpmn / subprocess / DeleteVfModuleBBTest.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 package org.onap.so.bpmn.infrastructure.bpmn.subprocess;
21
22 import static org.camunda.bpm.engine.test.assertions.ProcessEngineTests.assertThat;
23 import static org.mockito.ArgumentMatchers.any;
24 import static org.mockito.Mockito.doThrow;
25 import java.io.IOException;
26 import java.util.List;
27 import org.camunda.bpm.engine.delegate.BpmnError;
28 import org.camunda.bpm.engine.externaltask.LockedExternalTask;
29 import org.camunda.bpm.engine.runtime.ProcessInstance;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.onap.so.bpmn.BaseBPMNTest;
33 import org.onap.so.bpmn.common.BuildingBlockExecution;
34
35 public class DeleteVfModuleBBTest extends BaseBPMNTest {
36
37     @Before
38     public void before() {
39         variables.put("auditInventoryNeeded", true);
40         variables.put("auditIsSuccessful", true);
41     }
42
43     @Test
44     public void sunnyDay() throws InterruptedException, IOException {
45         mockSubprocess("SDNCHandler", "My Mock Process Name", "GenericStub");
46         mockSubprocess("VnfAdapter", "Mocked VnfAdapter", "GenericStub");
47         ProcessInstance pi = runtimeService.startProcessInstanceByKey("DeleteVfModuleBB", variables);
48         List<LockedExternalTask> tasks = externalTaskService.fetchAndLock(100, "externalWorkerId")
49                 .topic("InventoryDeleteAudit", 60L * 1000L).execute();
50         while (!tasks.isEmpty()) {
51             for (LockedExternalTask task : tasks) {
52                 externalTaskService.complete(task.getId(), "externalWorkerId");
53             }
54             tasks = externalTaskService.fetchAndLock(100, "externalWorkerId").topic("InventoryDeleteAudit", 60L * 1000L)
55                     .execute();
56         }
57         assertThat(pi).isNotNull();
58         assertThat(pi).isStarted().hasPassed("DeleteVfModuleBB_Start", "ExclusiveGateway_0xrgzm7",
59                 "ExclusiveGateway_1yvh16a", "Check_Audit", "Setup_Audit_Variable", "Audit_Inventory",
60                 "DeleteVfModuleVnfAdapter", "VnfAdapter", "DeleteNetworkPolicies", "UpdateVnfIpv4OamAddress",
61                 "UpdateVnfManagementV6Address", "UpdateVfModuleContrailServiceInstanceFqdn",
62                 "UpdateVfModuleHeatStackId", "UpdateVfModuleDeleteStatus", "DeleteVfModuleBB_End");
63         assertThat(pi).isEnded();
64     }
65
66     @Test
67     public void rainyDay() throws Exception {
68         doThrow(BpmnError.class).when(vnfAdapterDeleteTasks).deleteVfModule(any(BuildingBlockExecution.class));
69         ProcessInstance pi = runtimeService.startProcessInstanceByKey("DeleteVfModuleBB", variables);
70         List<LockedExternalTask> tasks = externalTaskService.fetchAndLock(100, "externalWorkerId")
71                 .topic("InventoryDeleteAudit", 60L * 1000L).execute();
72         while (!tasks.isEmpty()) {
73             for (LockedExternalTask task : tasks) {
74                 externalTaskService.complete(task.getId(), "externalWorkerId");
75             }
76             tasks = externalTaskService.fetchAndLock(100, "externalWorkerId").topic("InventoryDeleteAudit", 60L * 1000L)
77                     .execute();
78         }
79         assertThat(pi).isNotNull();
80         assertThat(pi).isStarted().hasPassed("DeleteVfModuleBB_Start", "DeleteVfModuleVnfAdapter").hasNotPassed(
81                 "VnfAdapter", "DeleteNetworkPolicies", "UpdateVnfIpv4OamAddress", "UpdateVnfManagementV6Address",
82                 "UpdateVfModuleContrailServiceInstanceFqdn", "UpdateVfModuleHeatStackId", "UpdateVfModuleDeleteStatus",
83                 "DeleteVfModuleBB_End");
84         assertThat(pi).isEnded();
85     }
86 }