2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.so.bpmn.infrastructure.bpmn.subprocess;
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;
35 public class DeleteVfModuleBBTest extends BaseBPMNTest {
38 public void before() {
39 variables.put("auditInventoryNeeded", true);
43 public void sunnyDay() throws InterruptedException, IOException {
44 mockSubprocess("SDNCHandler", "My Mock Process Name", "GenericStub");
45 mockSubprocess("VnfAdapter", "Mocked VnfAdapter", "GenericStub");
46 ProcessInstance pi = runtimeService.startProcessInstanceByKey("DeleteVfModuleBB", variables);
47 List<LockedExternalTask> tasks = externalTaskService.fetchAndLock(100, "externalWorkerId")
48 .topic("InventoryDeleteAudit", 60L * 1000L).execute();
49 while (!tasks.isEmpty()) {
50 for (LockedExternalTask task : tasks) {
51 externalTaskService.complete(task.getId(), "externalWorkerId");
53 tasks = externalTaskService.fetchAndLock(100, "externalWorkerId").topic("InventoryDeleteAudit", 60L * 1000L)
56 assertThat(pi).isNotNull();
57 assertThat(pi).isStarted().hasPassed("DeleteVfModuleBB_Start", "ExclusiveGateway_0xrgzm7",
58 "ExclusiveGateway_1yvh16a", "Check_Audit", "Setup_Audit_Variable", "Audit_Inventory",
59 "DeleteVfModuleVnfAdapter", "VnfAdapter", "DeleteNetworkPolicies", "UpdateVnfIpv4OamAddress",
60 "UpdateVnfManagementV6Address", "UpdateVfModuleContrailServiceInstanceFqdn",
61 "UpdateVfModuleHeatStackId", "UpdateVfModuleDeleteStatus", "DeleteVfModuleBB_End");
62 assertThat(pi).isEnded();
66 public void rainyDay() throws Exception {
67 doThrow(BpmnError.class).when(vnfAdapterDeleteTasks).deleteVfModule(any(BuildingBlockExecution.class));
68 ProcessInstance pi = runtimeService.startProcessInstanceByKey("DeleteVfModuleBB", variables);
69 List<LockedExternalTask> tasks = externalTaskService.fetchAndLock(100, "externalWorkerId")
70 .topic("InventoryDeleteAudit", 60L * 1000L).execute();
71 while (!tasks.isEmpty()) {
72 for (LockedExternalTask task : tasks) {
73 externalTaskService.complete(task.getId(), "externalWorkerId");
75 tasks = externalTaskService.fetchAndLock(100, "externalWorkerId").topic("InventoryDeleteAudit", 60L * 1000L)
78 assertThat(pi).isNotNull();
79 assertThat(pi).isStarted().hasPassed("DeleteVfModuleBB_Start", "DeleteVfModuleVnfAdapter").hasNotPassed(
80 "VnfAdapter", "DeleteNetworkPolicies", "UpdateVnfIpv4OamAddress", "UpdateVnfManagementV6Address",
81 "UpdateVfModuleContrailServiceInstanceFqdn", "UpdateVfModuleHeatStackId", "UpdateVfModuleDeleteStatus",
82 "DeleteVfModuleBB_End");
83 assertThat(pi).isEnded();