Containerization feature of SO
[so.git] / bpmn / so-bpmn-building-blocks / src / test / java / org / onap / so / bpmn / infrastructure / bpmn / subprocess / CreateVfModuleBBTest.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
23 import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareAssertions.assertThat;
24 import static org.mockito.Matchers.any;
25 import static org.mockito.Mockito.doThrow;
26
27 import org.camunda.bpm.engine.delegate.BpmnError;
28 import org.camunda.bpm.engine.runtime.ProcessInstance;
29 import org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareTests;
30 import org.junit.Test;
31 import org.onap.so.bpmn.BaseBPMNTest;
32 import org.onap.so.bpmn.common.BuildingBlockExecution;
33
34 public class CreateVfModuleBBTest extends BaseBPMNTest{
35         @Test
36         public void sunnyDayCreateVfModule_Test() throws InterruptedException {
37                 mockSubprocess("VnfAdapter", "Mocked VnfAdapter", "GenericStub");
38                 ProcessInstance pi = runtimeService.startProcessInstanceByKey("CreateVfModuleBB", variables);
39                 assertThat(pi).isNotNull();
40                 assertThat(pi).isStarted().hasPassedInOrder("CreateVfModuleBB_Start",
41                                 "QueryVnf",
42                                 "QueryVfModule",
43                                 "CreateVfModule",
44                                 "VnfAdapter",
45                                 "UpdateVfModuleStatus",
46                                 "CreateVfModuleBB_End");
47                 assertThat(pi).isEnded();
48         }
49         
50         @Test
51         public void rainyDayCreateVfModuleSDNCQueryVnfError_Test() throws Exception {
52                 doThrow(new BpmnError("7000", "TESTING ERRORS")).when(sdncQueryTasks).queryVnf(any(BuildingBlockExecution.class));
53                 ProcessInstance pi = runtimeService.startProcessInstanceByKey("CreateVfModuleBB", variables);
54                 assertThat(pi).isNotNull();
55                 assertThat(pi).isStarted()
56                                 .hasPassedInOrder("CreateVfModuleBB_Start", "QueryVnf")
57                                 .hasNotPassed("QueryVfModule", "CreateVfModule", "VnfAdapter", "UpdateVfModuleStatus", "CreateVfModuleBB_End");
58                 assertThat(pi).isEnded();
59         }
60
61         @Test
62         public void rainyDayCreateVfModuleSDNCQueryVnfModuleError_Test() throws Exception {
63                 doThrow(new BpmnError("7000", "TESTING ERRORS")).when(sdncQueryTasks).queryVfModule(any(BuildingBlockExecution.class));
64                 ProcessInstance pi = runtimeService.startProcessInstanceByKey("CreateVfModuleBB", variables);
65                 assertThat(pi).isNotNull();
66                 assertThat(pi).isStarted()
67                                 .hasPassedInOrder("CreateVfModuleBB_Start", "QueryVnf", "QueryVfModule")
68                                 .hasNotPassed("CreateVfModule", "VnfAdapter", "UpdateVfModuleStatus", "CreateVfModuleBB_End");
69                 assertThat(pi).isEnded();
70         }
71         
72         @Test
73         public void rainyDayCreateVfModuleVnfAdapterCreateError_Test() throws Exception {
74                 doThrow(new BpmnError("7000", "TESTING ERRORS")).when(vnfAdapterCreateTasks).createVfModule(any(BuildingBlockExecution.class));
75                 ProcessInstance pi = runtimeService.startProcessInstanceByKey("CreateVfModuleBB", variables);
76                 assertThat(pi).isNotNull();
77                 assertThat(pi).isStarted()
78                                 .hasPassedInOrder("CreateVfModuleBB_Start", "QueryVnf", "QueryVfModule", "CreateVfModule")
79                                 .hasNotPassed("VnfAdapter", "UpdateVfModuleStatus", "CreateVfModuleBB_End");
80                 assertThat(pi).isEnded();
81         }
82         
83         @Test
84         public void rainyDayCreateVfModuleUpdateVfModuleStatusError_Test() throws Exception {
85                 mockSubprocess("VnfAdapter", "Mocked VnfAdapter", "GenericStub");
86                 doThrow(new BpmnError("7000", "TESTING ERRORS")).when(aaiUpdateTasks).updateOrchestrationStatusCreatedVfModule(any(BuildingBlockExecution.class));
87                 ProcessInstance pi = runtimeService.startProcessInstanceByKey("CreateVfModuleBB", variables);
88                 assertThat(pi).isNotNull();
89                 assertThat(pi).isStarted()
90                                 .hasPassedInOrder("CreateVfModuleBB_Start", "QueryVnf", "QueryVfModule", "CreateVfModule", "VnfAdapter", "UpdateVfModuleStatus")
91                                 .hasNotPassed("CreateVfModuleBB_End");
92                 assertThat(pi).isEnded();
93         }
94 }