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=========================================================
21 package org.onap.so.bpmn.infrastructure.bpmn.subprocess;
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;
37 public class ActivateVfModuleBBTest extends BaseBPMNTest {
40 public void before() {
41 variables.put("vfModuleActivateTimerDuration", "PT2S");
42 variables.put("auditInventoryNeeded", "true");
43 variables.put("auditIsSuccessful", "true");
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");
56 tasks = externalTaskService.fetchAndLock(100, "externalWorkerId").topic("InventoryAddAudit", 60L * 1000L)
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();
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");
79 tasks = externalTaskService.fetchAndLock(100, "externalWorkerId").topic("InventoryAddAudit", 60L * 1000L)
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");