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.AAIQueryTasks;
42 import org.onap.so.bpmn.infrastructure.aai.tasks.AAIUpdateTasks;
43 import org.onap.so.bpmn.infrastructure.adapter.network.tasks.NetworkAdapterCreateTasks;
44 import org.onap.so.bpmn.infrastructure.adapter.network.tasks.NetworkAdapterDeleteTasks;
45 import org.onap.so.bpmn.infrastructure.adapter.network.tasks.NetworkAdapterUpdateTasks;
46 import org.onap.so.bpmn.infrastructure.adapter.vnf.tasks.VnfAdapterCreateTasks;
47 import org.onap.so.bpmn.infrastructure.adapter.vnf.tasks.VnfAdapterDeleteTasks;
48 import org.onap.so.bpmn.infrastructure.adapter.vnf.tasks.VnfAdapterImpl;
49 import org.onap.so.bpmn.infrastructure.flowspecific.tasks.AssignNetwork;
50 import org.onap.so.bpmn.infrastructure.flowspecific.tasks.AssignNetworkBBUtils;
51 import org.onap.so.bpmn.infrastructure.flowspecific.tasks.AssignVnf;
52 import org.onap.so.bpmn.infrastructure.flowspecific.tasks.ConfigurationScaleOut;
53 import org.onap.so.bpmn.infrastructure.flowspecific.tasks.CreateNetwork;
54 import org.onap.so.bpmn.infrastructure.flowspecific.tasks.CreateNetworkCollection;
55 import org.onap.so.bpmn.infrastructure.flowspecific.tasks.GenericVnfHealthCheck;
56 import org.onap.so.bpmn.infrastructure.flowspecific.tasks.UnassignNetworkBB;
57 import org.onap.so.bpmn.infrastructure.flowspecific.tasks.UnassignVnf;
58 import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCActivateTasks;
59 import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCAssignTasks;
60 import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCChangeAssignTasks;
61 import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCDeactivateTasks;
62 import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCQueryTasks;
63 import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCUnassignTasks;
64 import org.onap.so.bpmn.infrastructure.workflow.tasks.OrchestrationStatusValidator;
65 import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowAction;
66 import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionBBTasks;
67 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup;
68 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils;
69 import org.onap.so.bpmn.servicedecomposition.tasks.ExecuteBuildingBlockRainyDay;
70 import org.springframework.beans.factory.annotation.Autowired;
71 import org.springframework.boot.context.embedded.LocalServerPort;
72 import org.springframework.boot.test.context.SpringBootTest;
73 import org.springframework.boot.test.mock.mockito.MockBean;
74 import org.springframework.boot.test.web.client.TestRestTemplate;
75 import org.springframework.http.HttpHeaders;
76 import org.springframework.test.context.ActiveProfiles;
77 import org.springframework.test.context.junit4.SpringRunner;
79 @RunWith(SpringRunner.class)
80 @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
81 @ActiveProfiles("test")
82 public abstract class BaseBPMNTest {
84 protected RuntimeService runtimeService;
87 private RepositoryService repositoryService;
89 protected Map<String, Object> variables = new HashMap<>();
91 protected List<String> mockedSubprocessList = new ArrayList<>();
93 protected TestRestTemplate restTemplate = new TestRestTemplate();
95 protected HttpHeaders headers = new HttpHeaders();
98 protected AAIUpdateTasks aaiUpdateTasks;
101 protected AAICreateTasks aaiCreateTasks;
104 protected AAIQueryTasks aaiQueryTasks;
107 protected AAIDeleteTasks aaiDeleteTasks;
110 protected SDNCActivateTasks sdncActivateTasks;
113 protected SDNCAssignTasks sdncAssignTasks;
116 protected SDNCUnassignTasks sdncUnassignTasks;
119 protected SDNCDeactivateTasks sdncDeactivateTasks;
122 protected SDNCQueryTasks sdncQueryTasks;
125 protected SDNCChangeAssignTasks sdncChangeAssignTasks;
128 protected NetworkAdapterDeleteTasks networkAdapterDeleteTasks;
131 protected NetworkAdapterUpdateTasks networkAdapterUpdateTasks;
134 protected VnfAdapterCreateTasks vnfAdapterCreateTasks;
137 protected NetworkAdapterCreateTasks networkAdapterCreateTasks;
140 protected CreateNetwork createNetwork;
143 protected AssignNetworkBBUtils assignNetworkBBUtils;
146 protected AssignNetwork assignNetwork;
149 protected CreateNetworkCollection createNetworkCollection;
152 protected VnfAdapterDeleteTasks vnfAdapterDeleteTasks;
155 protected AAICommonTasks aaiCommonTasks;
158 protected AssignVnf assignVnf;
161 protected UnassignVnf unassignVnf;
164 protected VnfAdapterImpl vnfAdapterImpl;
167 protected UnassignNetworkBB unassignNetworkBB;
170 protected OrchestrationStatusValidator orchestrationStatusValidator;
173 protected BBInputSetup bbInputSetup;
176 protected BBInputSetupUtils bbInputSetupUtils;
179 protected ExecuteBuildingBlockRainyDay executeBuildingBlockRainyDay;
182 protected WorkflowAction workflowAction;
185 protected WorkflowActionBBTasks workflowActionBBTasks;
188 protected GenericVnfHealthCheck genericVnfHealthCheck;
191 protected ConfigurationScaleOut configurationScaleOut;
196 protected String createURLWithPort(String uri) {
197 return "http://localhost:" + port + uri;
201 public void baseBefore() {
202 variables.put("gBuildingBlockExecution", new DelegateExecutionImpl(new HashMap<>()));
206 public void baseAfter() {
207 for (String deploymentId : mockedSubprocessList) {
208 repositoryService.deleteDeployment(deploymentId);
210 mockedSubprocessList.clear();
214 * Create and deploy a process model with one logger delegate as service task.
216 * @param origProcessKey
218 * @param mockProcessName
221 * file name without extension
223 protected void mockSubprocess(String origProcessKey, String mockProcessName, String fileName) {
224 mockSubprocess(origProcessKey, mockProcessName, fileName, new HashMap<String, String>());
228 * Create and deploy a process model with one logger delegate as service task.
230 * @param origProcessKey
232 * @param mockProcessName
235 * file name without extension
239 protected void mockSubprocess(String origProcessKey, String mockProcessName, String fileName, Map<String, String> outParam) {
240 ServiceTaskBuilder builder = Bpmn
241 .createExecutableProcess(origProcessKey).name(mockProcessName)
242 .startEvent().name("Start_Event")
243 .serviceTask().name("Mock_Delegate")
244 .camundaClass(FluentJavaDelegateMock.class);
246 for (String key : outParam.keySet()) {
247 builder.camundaOutputParameter(key, outParam.get(key));
250 BpmnModelInstance modelInstance = builder.endEvent().name("End_Event").done();
251 mockedSubprocessList.add(repositoryService.createDeployment().addModelInstance(fileName + ".bpmn", modelInstance).deploy().getId());