47d0ad9b7fab4493a93558b9304a65a82fe05274
[so.git] /
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).topic("InventoryQueryAudit", 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                     .topic("InventoryQueryAudit", 60L * 1000L).execute();
56         }
57         assertThat(pi).isNotNull();
58         assertThat(pi).isStarted().hasPassed("DeleteVfModuleBB_Start", "Check_Audit", "auditEnabledCheck",
59                 "Setup_Audit_Variable", "Setup_Audit_Variable", "aicQueryStack", "ExclusiveGateway_1t9q2jl",
60                 "ExclusiveGateway_1naduhl", "ExclusiveGateway_13fhmpf", "DeleteVfModuleVnfAdapter", "VnfAdapter",
61                 "Audit_Inventory", "ExclusiveGateway_1yvh16a", "auditSuccessfulCheck", "ExclusiveGateway_01wvywu",
62                 "ExclusiveGateway_1yvh16a", "DeleteNetworkPolicies", "UpdateVnfIpv4OamAddress",
63                 "UpdateVnfManagementV6Address", "UpdateVfModuleContrailServiceInstanceFqdn",
64                 "UpdateVfModuleHeatStackId", "UpdateVfModuleDeleteStatus", "DeleteVfModuleBB_End");
65         assertThat(pi).isEnded();
66     }
67
68     @Test
69     public void rainyDay() throws Exception {
70         doThrow(BpmnError.class).when(vnfAdapterDeleteTasks).deleteVfModule(any(BuildingBlockExecution.class));
71         ProcessInstance pi = runtimeService.startProcessInstanceByKey("DeleteVfModuleBB", variables);
72         List<LockedExternalTask> tasks = externalTaskService.fetchAndLock(100, "externalWorkerId")
73                 .topic("InventoryDeleteAudit", 60L * 1000L).topic("InventoryQueryAudit", 60L * 1000L).execute();
74         while (!tasks.isEmpty()) {
75             for (LockedExternalTask task : tasks) {
76                 externalTaskService.complete(task.getId(), "externalWorkerId");
77             }
78             tasks = externalTaskService.fetchAndLock(100, "externalWorkerId").topic("InventoryDeleteAudit", 60L * 1000L)
79                     .topic("InventoryQueryAudit", 60L * 1000L).execute();
80         }
81         assertThat(pi).isNotNull();
82         assertThat(pi).isStarted()
83                 .hasPassed("DeleteVfModuleBB_Start", "Check_Audit", "auditEnabledCheck", "Setup_Audit_Variable",
84                         "Setup_Audit_Variable", "aicQueryStack", "ExclusiveGateway_1t9q2jl", "ExclusiveGateway_1naduhl",
85                         "ExclusiveGateway_13fhmpf")
86                 .hasNotPassed("VnfAdapter", "DeleteNetworkPolicies", "UpdateVnfIpv4OamAddress",
87                         "UpdateVnfManagementV6Address", "UpdateVfModuleContrailServiceInstanceFqdn",
88                         "UpdateVfModuleHeatStackId", "UpdateVfModuleDeleteStatus", "DeleteVfModuleBB_End");
89         assertThat(pi).isEnded();
90     }
91 }