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;
22 import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareAssertions.assertThat;
23 import static org.mockito.ArgumentMatchers.any;
24 import static org.mockito.Mockito.doReturn;
25 import static org.mockito.Mockito.doThrow;
26 import java.io.IOException;
27 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");
46 public void sunnyDay() throws InterruptedException, IOException {
47 mockSubprocess("SDNCHandler", "My Mock Process Name", "GenericStub");
48 ProcessInstance pi = runtimeService.startProcessInstanceByKey("ActivateVfModuleBB", variables);
49 List<LockedExternalTask> tasks = externalTaskService.fetchAndLock(100, "externalWorkerId")
50 .topic("InventoryAddAudit", 60L * 1000L).execute();
51 while (!tasks.isEmpty()) {
52 for (LockedExternalTask task : tasks) {
53 externalTaskService.complete(task.getId(), "externalWorkerId");
55 tasks = externalTaskService.fetchAndLock(100, "externalWorkerId")
56 .topic("InventoryAddAudit", 60L * 1000L).execute();
59 assertThat(pi).isNotNull();
60 assertThat(pi).isStarted().hasPassedInOrder("ActivateVfModuleBB_Start","ExclusiveGateway_1v8bmbu","Setup_AAI_Inventory_Audit", "Audit_AAI_Inventory", "ActivateVfModule", "CallActivity_sdncHandler",
61 "UpdateVfModuleActiveStatus", "ActivateVfModuleBB_End");
62 assertThat(pi).isEnded();
66 public void rainyDay() throws Exception {
67 mockSubprocess("SDNCHandler", "My Mock Process Name", "GenericStub");
68 doThrow(BpmnError.class).when(aaiUpdateTasks).updateOrchestrationStatusActivateVfModule(any(BuildingBlockExecution.class));
69 ProcessInstance pi = runtimeService.startProcessInstanceByKey("ActivateVfModuleBB", variables);
70 List<LockedExternalTask> tasks = externalTaskService.fetchAndLock(100, "externalWorkerId")
71 .topic("InventoryAddAudit", 60L * 1000L).execute();
72 while (!tasks.isEmpty()) {
73 for (LockedExternalTask task : tasks) {
74 externalTaskService.complete(task.getId(), "externalWorkerId");
76 tasks = externalTaskService.fetchAndLock(100, "externalWorkerId")
77 .topic("InventoryAddAudit", 60L * 1000L).execute();
80 assertThat(pi).isNotNull().isStarted()
81 .hasPassedInOrder("ActivateVfModuleBB_Start","ExclusiveGateway_1v8bmbu","Setup_AAI_Inventory_Audit", "Audit_AAI_Inventory", "ActivateVfModule", "UpdateVfModuleActiveStatus")
82 .hasNotPassed("ActivateVfModuleBB_End");