deac50ca307529a0509de96f50442f960fcaf8eb
[so.git] / bpmn / so-bpmn-building-blocks / src / test / java / org / onap / so / bpmn / infrastructure / bpmn / subprocess / ActivateVfModuleBBTest.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
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;
28
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;
36
37 public class ActivateVfModuleBBTest extends BaseBPMNTest{
38         
39         @Before
40         public void before() {
41                 variables.put("vfModuleActivateTimerDuration", "PT2S");
42                 variables.put("auditInventoryNeeded", "true");
43                 variables.put("auditIsSuccessful", "true");     
44         }
45
46         @Test
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");
55             }
56             tasks = externalTaskService.fetchAndLock(100, "externalWorkerId")
57                     .topic("InventoryAddAudit", 60L * 1000L).execute();
58         }
59                 
60                 assertThat(pi).isNotNull();
61                 assertThat(pi).isStarted().hasPassedInOrder("ActivateVfModuleBB_Start","ExclusiveGateway_1v8bmbu","Setup_AAI_Inventory_Audit", "Audit_AAI_Inventory", "ActivateVfModule", "CallActivity_sdncHandler",
62                                 "UpdateVfModuleActiveStatus", "ActivateVfModuleBB_End");
63                 assertThat(pi).isEnded();
64         }
65         
66         @Test
67         public void rainyDay() throws Exception {
68                 mockSubprocess("SDNCHandler", "My Mock Process Name", "GenericStub");
69                 doThrow(BpmnError.class).when(aaiUpdateTasks).updateOrchestrationStatusActivateVfModule(any(BuildingBlockExecution.class));
70                 ProcessInstance pi = runtimeService.startProcessInstanceByKey("ActivateVfModuleBB", variables);
71                 List<LockedExternalTask> tasks = externalTaskService.fetchAndLock(100, "externalWorkerId")
72                 .topic("InventoryAddAudit", 60L * 1000L).execute();
73         while (!tasks.isEmpty()) {
74             for (LockedExternalTask task : tasks) {
75                 externalTaskService.complete(task.getId(), "externalWorkerId");
76             }
77             tasks = externalTaskService.fetchAndLock(100, "externalWorkerId")
78                     .topic("InventoryAddAudit", 60L * 1000L).execute();
79         }
80
81                 assertThat(pi).isNotNull().isStarted()
82                                 .hasPassedInOrder("ActivateVfModuleBB_Start","ExclusiveGateway_1v8bmbu","Setup_AAI_Inventory_Audit", "Audit_AAI_Inventory", "ActivateVfModule", "UpdateVfModuleActiveStatus")
83                                 .hasNotPassed("ActivateVfModuleBB_End");
84         }
85 }