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.CreateNetwork;
53 import org.onap.so.bpmn.infrastructure.flowspecific.tasks.CreateNetworkCollection;
54 import org.onap.so.bpmn.infrastructure.flowspecific.tasks.UnassignNetworkBB;
55 import org.onap.so.bpmn.infrastructure.flowspecific.tasks.UnassignVnf;
56 import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCActivateTasks;
57 import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCAssignTasks;
58 import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCChangeAssignTasks;
59 import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCDeactivateTasks;
60 import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCQueryTasks;
61 import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCUnassignTasks;
62 import org.onap.so.bpmn.infrastructure.workflow.tasks.OrchestrationStatusValidator;
63 import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowAction;
64 import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionBBTasks;
65 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup;
66 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils;
67 import org.onap.so.bpmn.servicedecomposition.tasks.ExecuteBuildingBlockRainyDay;
68 import org.springframework.beans.factory.annotation.Autowired;
69 import org.springframework.boot.context.embedded.LocalServerPort;
70 import org.springframework.boot.test.context.SpringBootTest;
71 import org.springframework.boot.test.mock.mockito.MockBean;
72 import org.springframework.boot.test.web.client.TestRestTemplate;
73 import org.springframework.http.HttpHeaders;
74 import org.springframework.test.context.ActiveProfiles;
75 import org.springframework.test.context.junit4.SpringRunner;
77 @RunWith(SpringRunner.class)
78 @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
79 @ActiveProfiles("test")
80 public abstract class BaseBPMNTest {
82 protected RuntimeService runtimeService;
85 private RepositoryService repositoryService;
87 protected Map<String, Object> variables = new HashMap<>();
89 protected List<String> mockedSubprocessList = new ArrayList<>();
91 protected TestRestTemplate restTemplate = new TestRestTemplate();
93 protected HttpHeaders headers = new HttpHeaders();
96 protected AAIUpdateTasks aaiUpdateTasks;
99 protected AAICreateTasks aaiCreateTasks;
102 protected AAIQueryTasks aaiQueryTasks;
105 protected AAIDeleteTasks aaiDeleteTasks;
108 protected SDNCActivateTasks sdncActivateTasks;
111 protected SDNCAssignTasks sdncAssignTasks;
114 protected SDNCUnassignTasks sdncUnassignTasks;
117 protected SDNCDeactivateTasks sdncDeactivateTasks;
120 protected SDNCQueryTasks sdncQueryTasks;
123 protected SDNCChangeAssignTasks sdncChangeAssignTasks;
126 protected NetworkAdapterDeleteTasks networkAdapterDeleteTasks;
129 protected NetworkAdapterUpdateTasks networkAdapterUpdateTasks;
132 protected VnfAdapterCreateTasks vnfAdapterCreateTasks;
135 protected NetworkAdapterCreateTasks networkAdapterCreateTasks;
138 protected CreateNetwork createNetwork;
141 protected AssignNetworkBBUtils assignNetworkBBUtils;
144 protected AssignNetwork assignNetwork;
147 protected CreateNetworkCollection createNetworkCollection;
150 protected VnfAdapterDeleteTasks vnfAdapterDeleteTasks;
153 protected AAICommonTasks aaiCommonTasks;
156 protected AssignVnf assignVnf;
159 protected UnassignVnf unassignVnf;
162 protected VnfAdapterImpl vnfAdapterImpl;
165 protected UnassignNetworkBB unassignNetworkBB;
168 protected OrchestrationStatusValidator orchestrationStatusValidator;
171 protected BBInputSetup bbInputSetup;
174 protected BBInputSetupUtils bbInputSetupUtils;
177 protected ExecuteBuildingBlockRainyDay executeBuildingBlockRainyDay;
180 protected WorkflowAction workflowAction;
183 protected WorkflowActionBBTasks workflowActionBBTasks;
188 protected String createURLWithPort(String uri) {
189 return "http://localhost:" + port + uri;
193 public void baseBefore() {
194 variables.put("gBuildingBlockExecution", new DelegateExecutionImpl(new HashMap<>()));
198 public void baseAfter() {
199 for (String deploymentId : mockedSubprocessList) {
200 repositoryService.deleteDeployment(deploymentId);
202 mockedSubprocessList.clear();
206 * Create and deploy a process model with one logger delegate as service task.
208 * @param origProcessKey
210 * @param mockProcessName
213 * file name without extension
215 protected void mockSubprocess(String origProcessKey, String mockProcessName, String fileName) {
216 mockSubprocess(origProcessKey, mockProcessName, fileName, new HashMap<String, String>());
220 * Create and deploy a process model with one logger delegate as service task.
222 * @param origProcessKey
224 * @param mockProcessName
227 * file name without extension
231 protected void mockSubprocess(String origProcessKey, String mockProcessName, String fileName, Map<String, String> outParam) {
232 ServiceTaskBuilder builder = Bpmn
233 .createExecutableProcess(origProcessKey).name(mockProcessName)
234 .startEvent().name("Start_Event")
235 .serviceTask().name("Mock_Delegate")
236 .camundaClass(FluentJavaDelegateMock.class);
238 for (String key : outParam.keySet()) {
239 builder.camundaOutputParameter(key, outParam.get(key));
242 BpmnModelInstance modelInstance = builder.endEvent().name("End_Event").done();
243 mockedSubprocessList.add(repositoryService.createDeployment().addModelInstance(fileName + ".bpmn", modelInstance).deploy().getId());