48ae22cb1a5651353474b62016a3421e2e19eb16
[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 import static org.camunda.bpm.engine.test.assertions.ProcessEngineTests.assertThat;
22 import static org.mockito.ArgumentMatchers.any;
23 import static org.mockito.Mockito.doThrow;
24
25 import java.io.IOException;
26 import java.util.List;
27
28 import org.camunda.bpm.engine.delegate.BpmnError;
29 import org.camunda.bpm.engine.externaltask.LockedExternalTask;
30 import org.camunda.bpm.engine.runtime.ProcessInstance;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.onap.so.bpmn.BaseBPMNTest;
34 import org.onap.so.bpmn.common.BuildingBlockExecution;
35
36 public class DeleteVfModuleBBTest extends BaseBPMNTest{
37
38         @Before
39         public void before() {
40                 variables.put("auditInventoryNeeded", 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")
55                     .topic("InventoryDeleteAudit", 60L * 1000L).execute();
56         }
57                 assertThat(pi).isNotNull();
58                 assertThat(pi).isStarted().hasPassed("DeleteVfModuleBB_Start","ExclusiveGateway_0xrgzm7","ExclusiveGateway_1yvh16a","Check_Audit",
59                                 "Setup_Audit_Variable","Audit_Inventory","DeleteVfModuleVnfAdapter", "VnfAdapter",
60                                 "DeleteNetworkPolicies", "UpdateVnfIpv4OamAddress", "UpdateVnfManagementV6Address",
61                                 "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")
77                     .topic("InventoryDeleteAudit", 60L * 1000L).execute();
78         }
79                 assertThat(pi).isNotNull();
80                 assertThat(pi).isStarted()
81                                 .hasPassed("DeleteVfModuleBB_Start", "DeleteVfModuleVnfAdapter")
82                                 .hasNotPassed("VnfAdapter", "DeleteNetworkPolicies", "UpdateVnfIpv4OamAddress", "UpdateVnfManagementV6Address",
83                                                 "UpdateVfModuleContrailServiceInstanceFqdn","UpdateVfModuleHeatStackId", "UpdateVfModuleDeleteStatus",
84                                                 "DeleteVfModuleBB_End");
85                 assertThat(pi).isEnded();
86         }
87 }