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;
22 import java.util.ArrayList;
23 import java.util.HashMap;
24 import java.util.List;
27 import org.camunda.bpm.engine.RepositoryService;
28 import org.camunda.bpm.engine.RuntimeService;
29 import org.camunda.bpm.extension.mockito.mock.FluentJavaDelegateMock;
30 import org.camunda.bpm.model.bpmn.Bpmn;
31 import org.camunda.bpm.model.bpmn.BpmnModelInstance;
32 import org.camunda.bpm.model.bpmn.builder.ServiceTaskBuilder;
33 import org.junit.After;
34 import org.junit.Before;
35 import org.junit.runner.RunWith;
36 import org.onap.so.TestApplication;
37 import org.onap.so.bpmn.common.DelegateExecutionImpl;
38 import org.onap.so.bpmn.infrastructure.aai.tasks.AAICommonTasks;
39 import org.onap.so.bpmn.infrastructure.aai.tasks.AAICreateTasks;
40 import org.onap.so.bpmn.infrastructure.aai.tasks.AAIDeleteTasks;
41 import org.onap.so.bpmn.infrastructure.aai.tasks.AAIFlagTasks;
42 import org.onap.so.bpmn.infrastructure.aai.tasks.AAIQueryTasks;
43 import org.onap.so.bpmn.infrastructure.aai.tasks.AAIUpdateTasks;
44 import org.onap.so.bpmn.infrastructure.adapter.network.tasks.NetworkAdapterCreateTasks;
45 import org.onap.so.bpmn.infrastructure.adapter.network.tasks.NetworkAdapterDeleteTasks;
46 import org.onap.so.bpmn.infrastructure.adapter.network.tasks.NetworkAdapterUpdateTasks;
47 import org.onap.so.bpmn.infrastructure.adapter.vnf.tasks.VnfAdapterCreateTasks;
48 import org.onap.so.bpmn.infrastructure.adapter.vnf.tasks.VnfAdapterDeleteTasks;
49 import org.onap.so.bpmn.infrastructure.adapter.vnf.tasks.VnfAdapterImpl;
50 import org.onap.so.bpmn.infrastructure.appc.tasks.AppcRunTasks;
51 import org.onap.so.bpmn.infrastructure.flowspecific.tasks.AssignNetwork;
52 import org.onap.so.bpmn.infrastructure.flowspecific.tasks.AssignNetworkBBUtils;
53 import org.onap.so.bpmn.infrastructure.flowspecific.tasks.AssignVnf;
54 import org.onap.so.bpmn.infrastructure.flowspecific.tasks.ConfigurationScaleOut;
55 import org.onap.so.bpmn.infrastructure.flowspecific.tasks.CreateNetwork;
56 import org.onap.so.bpmn.infrastructure.flowspecific.tasks.CreateNetworkCollection;
57 import org.onap.so.bpmn.infrastructure.flowspecific.tasks.GenericVnfHealthCheck;
58 import org.onap.so.bpmn.infrastructure.flowspecific.tasks.UnassignNetworkBB;
59 import org.onap.so.bpmn.infrastructure.flowspecific.tasks.UnassignVnf;
60 import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCActivateTasks;
61 import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCAssignTasks;
62 import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCChangeAssignTasks;
63 import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCDeactivateTasks;
64 import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCQueryTasks;
65 import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCUnassignTasks;
66 import org.onap.so.bpmn.infrastructure.workflow.tasks.FlowCompletionTasks;
67 import org.onap.so.bpmn.infrastructure.workflow.tasks.OrchestrationStatusValidator;
68 import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowAction;
69 import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionBBTasks;
70 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup;
71 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils;
72 import org.onap.so.bpmn.servicedecomposition.tasks.ExecuteBuildingBlockRainyDay;
73 import org.springframework.beans.factory.annotation.Autowired;
74 import org.springframework.boot.context.embedded.LocalServerPort;
75 import org.springframework.boot.test.context.SpringBootTest;
76 import org.springframework.boot.test.mock.mockito.MockBean;
77 import org.springframework.boot.test.web.client.TestRestTemplate;
78 import org.springframework.http.HttpHeaders;
79 import org.springframework.test.context.ActiveProfiles;
80 import org.springframework.test.context.junit4.SpringRunner;
82 @RunWith(SpringRunner.class)
83 @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
84 @ActiveProfiles("test")
85 public abstract class BaseBPMNTest {
87 protected RuntimeService runtimeService;
90 private RepositoryService repositoryService;
92 protected Map<String, Object> variables = new HashMap<>();
94 protected List<String> mockedSubprocessList = new ArrayList<>();
96 protected TestRestTemplate restTemplate = new TestRestTemplate();
98 protected HttpHeaders headers = new HttpHeaders();
101 protected AAIUpdateTasks aaiUpdateTasks;
104 protected AAICreateTasks aaiCreateTasks;
107 protected AAIQueryTasks aaiQueryTasks;
110 protected AAIDeleteTasks aaiDeleteTasks;
113 protected AAIFlagTasks aaiFlagTasks;
117 protected AppcRunTasks appcRunTasks;
120 protected SDNCActivateTasks sdncActivateTasks;
123 protected SDNCAssignTasks sdncAssignTasks;
126 protected SDNCUnassignTasks sdncUnassignTasks;
129 protected SDNCDeactivateTasks sdncDeactivateTasks;
132 protected SDNCQueryTasks sdncQueryTasks;
135 protected SDNCChangeAssignTasks sdncChangeAssignTasks;
138 protected NetworkAdapterDeleteTasks networkAdapterDeleteTasks;
141 protected NetworkAdapterUpdateTasks networkAdapterUpdateTasks;
144 protected VnfAdapterCreateTasks vnfAdapterCreateTasks;
147 protected NetworkAdapterCreateTasks networkAdapterCreateTasks;
150 protected CreateNetwork createNetwork;
153 protected AssignNetworkBBUtils assignNetworkBBUtils;
156 protected AssignNetwork assignNetwork;
159 protected CreateNetworkCollection createNetworkCollection;
162 protected VnfAdapterDeleteTasks vnfAdapterDeleteTasks;
165 protected AAICommonTasks aaiCommonTasks;
168 protected AssignVnf assignVnf;
171 protected UnassignVnf unassignVnf;
174 protected VnfAdapterImpl vnfAdapterImpl;
177 protected UnassignNetworkBB unassignNetworkBB;
180 protected OrchestrationStatusValidator orchestrationStatusValidator;
183 protected BBInputSetup bbInputSetup;
186 protected BBInputSetupUtils bbInputSetupUtils;
189 protected ExecuteBuildingBlockRainyDay executeBuildingBlockRainyDay;
192 protected WorkflowAction workflowAction;
195 protected WorkflowActionBBTasks workflowActionBBTasks;
198 protected GenericVnfHealthCheck genericVnfHealthCheck;
201 protected ConfigurationScaleOut configurationScaleOut;
204 protected FlowCompletionTasks flowCompletionTasks;
209 protected String createURLWithPort(String uri) {
210 return "http://localhost:" + port + uri;
214 public void baseBefore() {
215 variables.put("gBuildingBlockExecution", new DelegateExecutionImpl(new HashMap<>()));
219 public void baseAfter() {
220 for (String deploymentId : mockedSubprocessList) {
221 repositoryService.deleteDeployment(deploymentId);
223 mockedSubprocessList.clear();
227 * Create and deploy a process model with one logger delegate as service task.
229 * @param origProcessKey
231 * @param mockProcessName
234 * file name without extension
236 protected void mockSubprocess(String origProcessKey, String mockProcessName, String fileName) {
237 mockSubprocess(origProcessKey, mockProcessName, fileName, new HashMap<String, String>());
241 * Create and deploy a process model with one logger delegate as service task.
243 * @param origProcessKey
245 * @param mockProcessName
248 * file name without extension
252 protected void mockSubprocess(String origProcessKey, String mockProcessName, String fileName, Map<String, String> outParam) {
253 ServiceTaskBuilder builder = Bpmn
254 .createExecutableProcess(origProcessKey).name(mockProcessName)
255 .startEvent().name("Start_Event")
256 .serviceTask().name("Mock_Delegate")
257 .camundaClass(FluentJavaDelegateMock.class);
259 for (String key : outParam.keySet()) {
260 builder.camundaOutputParameter(key, outParam.get(key));
263 BpmnModelInstance modelInstance = builder.endEvent().name("End_Event").done();
264 mockedSubprocessList.add(repositoryService.createDeployment().addModelInstance(fileName + ".bpmn", modelInstance).deploy().getId());