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.buildingblock.SniroHomingV2;
38 import org.onap.so.bpmn.common.DelegateExecutionImpl;
39 import org.onap.so.bpmn.common.validation.BuildingBlockValidatorRunner;
40 import org.onap.so.bpmn.infrastructure.aai.tasks.AAICommonTasks;
41 import org.onap.so.bpmn.infrastructure.aai.tasks.AAICreateTasks;
42 import org.onap.so.bpmn.infrastructure.aai.tasks.AAIDeleteTasks;
43 import org.onap.so.bpmn.infrastructure.aai.tasks.AAIFlagTasks;
44 import org.onap.so.bpmn.infrastructure.aai.tasks.AAIQueryTasks;
45 import org.onap.so.bpmn.infrastructure.aai.tasks.AAIUpdateTasks;
46 import org.onap.so.bpmn.infrastructure.adapter.network.tasks.NetworkAdapterCreateTasks;
47 import org.onap.so.bpmn.infrastructure.adapter.network.tasks.NetworkAdapterDeleteTasks;
48 import org.onap.so.bpmn.infrastructure.adapter.network.tasks.NetworkAdapterUpdateTasks;
49 import org.onap.so.bpmn.infrastructure.adapter.vnf.tasks.VnfAdapterCreateTasks;
50 import org.onap.so.bpmn.infrastructure.adapter.vnf.tasks.VnfAdapterDeleteTasks;
51 import org.onap.so.bpmn.infrastructure.adapter.vnf.tasks.VnfAdapterImpl;
52 import org.onap.so.bpmn.infrastructure.appc.tasks.AppcRunTasks;
53 import org.onap.so.bpmn.infrastructure.flowspecific.tasks.AssignNetwork;
54 import org.onap.so.bpmn.infrastructure.flowspecific.tasks.AssignNetworkBBUtils;
55 import org.onap.so.bpmn.infrastructure.flowspecific.tasks.AssignVnf;
56 import org.onap.so.bpmn.infrastructure.flowspecific.tasks.ConfigurationScaleOut;
57 import org.onap.so.bpmn.infrastructure.flowspecific.tasks.CreateNetwork;
58 import org.onap.so.bpmn.infrastructure.flowspecific.tasks.CreateNetworkCollection;
59 import org.onap.so.bpmn.infrastructure.flowspecific.tasks.GenericVnfHealthCheck;
60 import org.onap.so.bpmn.infrastructure.flowspecific.tasks.UnassignNetworkBB;
61 import org.onap.so.bpmn.infrastructure.flowspecific.tasks.UnassignVnf;
62 import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCActivateTasks;
63 import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCAssignTasks;
64 import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCChangeAssignTasks;
65 import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCDeactivateTasks;
66 import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCQueryTasks;
67 import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCUnassignTasks;
68 import org.onap.so.bpmn.infrastructure.workflow.tasks.FlowCompletionTasks;
69 import org.onap.so.bpmn.infrastructure.workflow.tasks.OrchestrationStatusValidator;
70 import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowAction;
71 import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionBBTasks;
72 import org.onap.so.bpmn.sdno.tasks.SDNOHealthCheckTasks;
73 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup;
74 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils;
75 import org.onap.so.bpmn.servicedecomposition.tasks.ExecuteBuildingBlockRainyDay;
76 import org.onap.so.client.sdnc.SDNCClient;
77 import org.springframework.beans.factory.annotation.Autowired;
78 import org.springframework.beans.factory.annotation.Qualifier;
79 import org.springframework.boot.web.server.LocalServerPort;
80 import org.springframework.boot.test.context.SpringBootTest;
81 import org.springframework.boot.test.mock.mockito.MockBean;
82 import org.springframework.boot.test.web.client.TestRestTemplate;
83 import org.springframework.http.HttpHeaders;
84 import org.springframework.test.context.ActiveProfiles;
85 import org.springframework.test.context.junit4.SpringRunner;
87 @RunWith(SpringRunner.class)
88 @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
89 @ActiveProfiles("test")
90 public abstract class BaseBPMNTest {
92 protected RuntimeService runtimeService;
95 private RepositoryService repositoryService;
97 protected Map<String, Object> variables = new HashMap<>();
99 protected List<String> mockedSubprocessList = new ArrayList<>();
101 protected TestRestTemplate restTemplate = new TestRestTemplate();
103 protected HttpHeaders headers = new HttpHeaders();
106 protected AAIUpdateTasks aaiUpdateTasks;
109 protected AAICreateTasks aaiCreateTasks;
112 protected AAIQueryTasks aaiQueryTasks;
115 protected AAIDeleteTasks aaiDeleteTasks;
118 protected AAIFlagTasks aaiFlagTasks;
122 protected AppcRunTasks appcRunTasks;
125 protected SDNCActivateTasks sdncActivateTasks;
128 protected SDNCAssignTasks sdncAssignTasks;
131 protected SDNCUnassignTasks sdncUnassignTasks;
134 protected SDNCDeactivateTasks sdncDeactivateTasks;
137 protected SDNCQueryTasks sdncQueryTasks;
140 protected SDNCChangeAssignTasks sdncChangeAssignTasks;
143 protected NetworkAdapterDeleteTasks networkAdapterDeleteTasks;
146 protected NetworkAdapterUpdateTasks networkAdapterUpdateTasks;
149 protected VnfAdapterCreateTasks vnfAdapterCreateTasks;
152 protected NetworkAdapterCreateTasks networkAdapterCreateTasks;
155 protected CreateNetwork createNetwork;
158 protected AssignNetworkBBUtils assignNetworkBBUtils;
161 protected AssignNetwork assignNetwork;
164 protected CreateNetworkCollection createNetworkCollection;
167 protected VnfAdapterDeleteTasks vnfAdapterDeleteTasks;
170 protected AAICommonTasks aaiCommonTasks;
173 protected AssignVnf assignVnf;
176 protected UnassignVnf unassignVnf;
179 protected VnfAdapterImpl vnfAdapterImpl;
182 protected UnassignNetworkBB unassignNetworkBB;
185 protected OrchestrationStatusValidator orchestrationStatusValidator;
188 protected BBInputSetup bbInputSetup;
191 protected BBInputSetupUtils bbInputSetupUtils;
194 protected ExecuteBuildingBlockRainyDay executeBuildingBlockRainyDay;
197 protected WorkflowAction workflowAction;
200 protected WorkflowActionBBTasks workflowActionBBTasks;
203 protected GenericVnfHealthCheck genericVnfHealthCheck;
206 protected ConfigurationScaleOut configurationScaleOut;
209 protected FlowCompletionTasks flowCompletionTasks;
212 protected BuildingBlockValidatorRunner buildingBlockValidatorRunner;
215 protected SDNOHealthCheckTasks sdnoHealthCheckTasks;
218 protected SDNCClient sdncClient;
221 protected SniroHomingV2 sniroHoming;
226 protected String createURLWithPort(String uri) {
227 return "http://localhost:" + port + uri;
231 public void baseBefore() {
232 variables.put("gBuildingBlockExecution", new DelegateExecutionImpl(new HashMap<>()));
236 public void baseAfter() {
237 for (String deploymentId : mockedSubprocessList) {
238 repositoryService.deleteDeployment(deploymentId);
240 mockedSubprocessList.clear();
244 * Create and deploy a process model with one logger delegate as service task.
246 * @param origProcessKey
248 * @param mockProcessName
251 * file name without extension
253 protected void mockSubprocess(String origProcessKey, String mockProcessName, String fileName) {
254 mockSubprocess(origProcessKey, mockProcessName, fileName, new HashMap<String, String>());
258 * Create and deploy a process model with one logger delegate as service task.
260 * @param origProcessKey
262 * @param mockProcessName
265 * file name without extension
269 protected void mockSubprocess(String origProcessKey, String mockProcessName, String fileName, Map<String, String> outParam) {
270 ServiceTaskBuilder builder = Bpmn
271 .createExecutableProcess(origProcessKey).name(mockProcessName)
272 .startEvent().name("Start_Event")
273 .serviceTask().name("Mock_Delegate")
274 .camundaClass(FluentJavaDelegateMock.class);
276 for (String key : outParam.keySet()) {
277 builder.camundaOutputParameter(key, outParam.get(key));
280 BpmnModelInstance modelInstance = builder.endEvent().name("End_Event").done();
281 mockedSubprocessList.add(repositoryService.createDeployment().addModelInstance(fileName + ".bpmn", modelInstance).deploy().getId());