1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
|
/*-
* ============LICENSE_START=======================================================
* ONAP - SO
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
*/
package org.onap.so.bpmn;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.camunda.bpm.engine.ExternalTaskService;
import org.camunda.bpm.engine.RepositoryService;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.extension.mockito.mock.FluentJavaDelegateMock;
import org.camunda.bpm.model.bpmn.Bpmn;
import org.camunda.bpm.model.bpmn.BpmnModelInstance;
import org.camunda.bpm.model.bpmn.builder.ServiceTaskBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.onap.so.TestApplication;
import org.onap.so.bpmn.buildingblock.HomingV2;
import org.onap.so.bpmn.common.DelegateExecutionImpl;
import org.onap.so.bpmn.common.validation.BuildingBlockValidatorRunner;
import org.onap.so.bpmn.infrastructure.aai.tasks.AAICommonTasks;
import org.onap.so.bpmn.infrastructure.aai.tasks.AAICreateTasks;
import org.onap.so.bpmn.infrastructure.aai.tasks.AAIDeleteTasks;
import org.onap.so.bpmn.infrastructure.aai.tasks.AAIFlagTasks;
import org.onap.so.bpmn.infrastructure.aai.tasks.AAIQueryTasks;
import org.onap.so.bpmn.infrastructure.aai.tasks.AAIUpdateTasks;
import org.onap.so.bpmn.infrastructure.adapter.network.tasks.NetworkAdapterCreateTasks;
import org.onap.so.bpmn.infrastructure.adapter.network.tasks.NetworkAdapterDeleteTasks;
import org.onap.so.bpmn.infrastructure.adapter.network.tasks.NetworkAdapterUpdateTasks;
import org.onap.so.bpmn.infrastructure.adapter.vnf.tasks.VnfAdapterCreateTasks;
import org.onap.so.bpmn.infrastructure.adapter.vnf.tasks.VnfAdapterDeleteTasks;
import org.onap.so.bpmn.infrastructure.adapter.vnf.tasks.VnfAdapterImpl;
import org.onap.so.bpmn.infrastructure.appc.tasks.AppcRunTasks;
import org.onap.so.bpmn.infrastructure.audit.AuditTasks;
import org.onap.so.bpmn.infrastructure.flowspecific.tasks.ActivateVfModule;
import org.onap.so.bpmn.infrastructure.flowspecific.tasks.AssignNetwork;
import org.onap.so.bpmn.infrastructure.flowspecific.tasks.AssignNetworkBBUtils;
import org.onap.so.bpmn.infrastructure.flowspecific.tasks.AssignVnf;
import org.onap.so.bpmn.infrastructure.flowspecific.tasks.ConfigurationScaleOut;
import org.onap.so.bpmn.infrastructure.flowspecific.tasks.CreateNetwork;
import org.onap.so.bpmn.infrastructure.flowspecific.tasks.CreateNetworkCollection;
import org.onap.so.bpmn.infrastructure.flowspecific.tasks.GenericVnfHealthCheck;
import org.onap.so.bpmn.infrastructure.flowspecific.tasks.UnassignNetworkBB;
import org.onap.so.bpmn.infrastructure.flowspecific.tasks.UnassignVnf;
import org.onap.so.bpmn.infrastructure.namingservice.tasks.NamingServiceCreateTasks;
import org.onap.so.bpmn.infrastructure.namingservice.tasks.NamingServiceDeleteTasks;
import org.onap.so.bpmn.infrastructure.manualhandling.tasks.ManualHandlingTasks;
import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCActivateTasks;
import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCAssignTasks;
import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCChangeAssignTasks;
import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCDeactivateTasks;
import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCQueryTasks;
import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCUnassignTasks;
import org.onap.so.bpmn.infrastructure.workflow.tasks.FlowCompletionTasks;
import org.onap.so.bpmn.infrastructure.workflow.tasks.OrchestrationStatusValidator;
import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowAction;
import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionBBFailure;
import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionBBTasks;
import org.onap.so.bpmn.sdno.tasks.SDNOHealthCheckTasks;
import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup;
import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils;
import org.onap.so.bpmn.servicedecomposition.tasks.ExecuteBuildingBlockRainyDay;
import org.onap.so.client.sdnc.SDNCClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpHeaders;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("test")
public abstract class BaseBPMNTest {
@Autowired
protected RuntimeService runtimeService;
@Autowired
protected ExternalTaskService externalTaskService;
@Autowired
private RepositoryService repositoryService;
protected Map<String, Object> variables = new HashMap<>();
protected List<String> mockedSubprocessList = new ArrayList<>();
protected TestRestTemplate restTemplate = new TestRestTemplate();
protected HttpHeaders headers = new HttpHeaders();
@MockBean
protected AAIUpdateTasks aaiUpdateTasks;
@MockBean
protected AAICreateTasks aaiCreateTasks;
@MockBean
protected AAIQueryTasks aaiQueryTasks;
@MockBean
protected AAIDeleteTasks aaiDeleteTasks;
@MockBean
protected AAIFlagTasks aaiFlagTasks;
@MockBean
protected AppcRunTasks appcRunTasks;
@MockBean
protected SDNCActivateTasks sdncActivateTasks;
@MockBean
protected SDNCAssignTasks sdncAssignTasks;
@MockBean
protected SDNCUnassignTasks sdncUnassignTasks;
@MockBean
protected SDNCDeactivateTasks sdncDeactivateTasks;
@MockBean
protected SDNCQueryTasks sdncQueryTasks;
@MockBean
protected SDNCChangeAssignTasks sdncChangeAssignTasks;
@MockBean
protected NetworkAdapterDeleteTasks networkAdapterDeleteTasks;
@MockBean
protected NetworkAdapterUpdateTasks networkAdapterUpdateTasks;
@MockBean
protected VnfAdapterCreateTasks vnfAdapterCreateTasks;
@MockBean
protected NetworkAdapterCreateTasks networkAdapterCreateTasks;
@MockBean
protected CreateNetwork createNetwork;
@MockBean
protected AssignNetworkBBUtils assignNetworkBBUtils;
@MockBean
protected AssignNetwork assignNetwork;
@MockBean
protected CreateNetworkCollection createNetworkCollection;
@MockBean
protected VnfAdapterDeleteTasks vnfAdapterDeleteTasks;
@MockBean
protected AAICommonTasks aaiCommonTasks;
@MockBean
protected ActivateVfModule activateVfModule;
@MockBean
protected AssignVnf assignVnf;
@MockBean
protected UnassignVnf unassignVnf;
@MockBean
protected VnfAdapterImpl vnfAdapterImpl;
@MockBean
protected UnassignNetworkBB unassignNetworkBB;
@MockBean
protected OrchestrationStatusValidator orchestrationStatusValidator;
@MockBean
protected BBInputSetup bbInputSetup;
@MockBean
protected BBInputSetupUtils bbInputSetupUtils;
@MockBean
protected ExecuteBuildingBlockRainyDay executeBuildingBlockRainyDay;
@MockBean
protected WorkflowAction workflowAction;
@MockBean
protected WorkflowActionBBTasks workflowActionBBTasks;
@MockBean
protected GenericVnfHealthCheck genericVnfHealthCheck;
@MockBean
protected ConfigurationScaleOut configurationScaleOut;
@MockBean
protected FlowCompletionTasks flowCompletionTasks;
@MockBean
protected BuildingBlockValidatorRunner buildingBlockValidatorRunner;
@MockBean
protected SDNOHealthCheckTasks sdnoHealthCheckTasks;
@MockBean
protected SDNCClient sdncClient;
@MockBean
protected HomingV2 homing;
@MockBean
protected NamingServiceDeleteTasks namingServiceDeleteTasks;
@MockBean
protected NamingServiceCreateTasks namingServiceCreateTasks;
@MockBean
protected WorkflowActionBBFailure workflowActionBBFailure;
@MockBean
protected AuditTasks auditTasks;
@MockBean
protected ManualHandlingTasks manualHandlingTasks;
@LocalServerPort
protected int port;
protected String createURLWithPort(String uri) {
return "http://localhost:" + port + uri;
}
@Before
public void baseBefore() {
variables.put("gBuildingBlockExecution", new DelegateExecutionImpl(new HashMap<>()));
}
@After
public void baseAfter() {
for (String deploymentId : mockedSubprocessList) {
repositoryService.deleteDeployment(deploymentId);
}
mockedSubprocessList.clear();
}
/**
* Create and deploy a process model with one logger delegate as service task.
*
* @param origProcessKey key to call
* @param mockProcessName process name
* @param fileName file name without extension
*/
protected void mockSubprocess(String origProcessKey, String mockProcessName, String fileName) {
mockSubprocess(origProcessKey, mockProcessName, fileName, new HashMap<String, String>());
}
/**
* Create and deploy a process model with one logger delegate as service task.
*
* @param origProcessKey key to call
* @param mockProcessName process name
* @param fileName file name without extension
* @param outParam output parameters
*/
protected void mockSubprocess(String origProcessKey, String mockProcessName, String fileName,
Map<String, String> outParam) {
ServiceTaskBuilder builder = Bpmn.createExecutableProcess(origProcessKey).name(mockProcessName).startEvent()
.name("Start_Event").serviceTask().name("Mock_Delegate").camundaClass(FluentJavaDelegateMock.class);
for (String key : outParam.keySet()) {
builder.camundaOutputParameter(key, outParam.get(key));
}
BpmnModelInstance modelInstance = builder.endEvent().name("End_Event").done();
mockedSubprocessList.add(repositoryService.createDeployment()
.addModelInstance(fileName + ".bpmn", modelInstance).deploy().getId());
}
}
|