Addition of Dockerfile/logback for SO-Monitoring
[so.git] / bpmn / so-bpmn-building-blocks / src / test / java / org / onap / so / bpmn / BaseBPMNTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20 package org.onap.so.bpmn;
21
22 import java.util.ArrayList;
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Map;
26
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;
78
79 @RunWith(SpringRunner.class)
80 @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
81 @ActiveProfiles("test")
82 public abstract class BaseBPMNTest {
83         @Autowired
84         protected RuntimeService runtimeService;
85
86         @Autowired
87         private RepositoryService repositoryService;
88         
89         protected Map<String, Object> variables = new HashMap<>();
90         
91         protected List<String> mockedSubprocessList = new ArrayList<>();
92
93         protected TestRestTemplate restTemplate = new TestRestTemplate();
94
95         protected HttpHeaders headers = new HttpHeaders();
96
97         @MockBean
98         protected AAIUpdateTasks aaiUpdateTasks;
99
100         @MockBean
101         protected AAICreateTasks aaiCreateTasks;
102
103         @MockBean
104         protected AAIQueryTasks aaiQueryTasks;
105
106         @MockBean
107         protected AAIDeleteTasks aaiDeleteTasks;
108
109         @MockBean
110         protected SDNCActivateTasks sdncActivateTasks;
111
112         @MockBean
113         protected SDNCAssignTasks sdncAssignTasks;
114
115         @MockBean
116         protected SDNCUnassignTasks sdncUnassignTasks;
117
118         @MockBean
119         protected SDNCDeactivateTasks sdncDeactivateTasks;
120
121         @MockBean
122         protected SDNCQueryTasks sdncQueryTasks;
123
124         @MockBean
125         protected SDNCChangeAssignTasks sdncChangeAssignTasks;
126
127         @MockBean
128         protected NetworkAdapterDeleteTasks networkAdapterDeleteTasks;
129
130         @MockBean
131         protected NetworkAdapterUpdateTasks networkAdapterUpdateTasks;
132
133         @MockBean
134         protected VnfAdapterCreateTasks vnfAdapterCreateTasks;
135
136         @MockBean
137         protected NetworkAdapterCreateTasks networkAdapterCreateTasks;
138
139         @MockBean
140         protected CreateNetwork createNetwork;
141
142         @MockBean
143         protected AssignNetworkBBUtils assignNetworkBBUtils;
144         
145         @MockBean
146         protected AssignNetwork assignNetwork;
147
148         @MockBean
149         protected CreateNetworkCollection createNetworkCollection;
150
151         @MockBean
152         protected VnfAdapterDeleteTasks vnfAdapterDeleteTasks;
153
154         @MockBean
155         protected AAICommonTasks aaiCommonTasks;
156
157         @MockBean
158         protected AssignVnf assignVnf;
159
160         @MockBean
161         protected UnassignVnf unassignVnf;
162
163         @MockBean
164         protected VnfAdapterImpl vnfAdapterImpl;
165
166         @MockBean
167         protected UnassignNetworkBB unassignNetworkBB;
168
169         @MockBean
170         protected OrchestrationStatusValidator orchestrationStatusValidator;
171         
172         @MockBean
173         protected BBInputSetup bbInputSetup;
174         
175         @MockBean
176         protected BBInputSetupUtils bbInputSetupUtils;
177         
178         @MockBean
179         protected ExecuteBuildingBlockRainyDay executeBuildingBlockRainyDay;
180         
181         @MockBean
182         protected WorkflowAction workflowAction;
183
184         @MockBean
185         protected WorkflowActionBBTasks workflowActionBBTasks;
186         
187         @MockBean
188         protected GenericVnfHealthCheck genericVnfHealthCheck;
189         
190         @MockBean
191         protected ConfigurationScaleOut configurationScaleOut;
192         
193         @LocalServerPort
194         private int port;
195
196         protected String createURLWithPort(String uri) {
197                 return "http://localhost:" + port + uri;
198         }
199
200         @Before
201         public void baseBefore() {
202                 variables.put("gBuildingBlockExecution", new DelegateExecutionImpl(new HashMap<>()));
203         }
204         
205         @After
206         public void baseAfter() {
207                 for (String deploymentId : mockedSubprocessList) {
208                         repositoryService.deleteDeployment(deploymentId);
209                 }
210                 mockedSubprocessList.clear();
211         }
212         
213         /**
214          * Create and deploy a process model with one logger delegate as service task.
215          *
216          * @param origProcessKey
217          *            key to call
218          * @param mockProcessName
219          *            process name
220          * @param fileName
221          *            file name without extension
222          */
223         protected void mockSubprocess(String origProcessKey, String mockProcessName, String fileName) {
224                 mockSubprocess(origProcessKey, mockProcessName, fileName, new HashMap<String, String>());
225         }
226
227         /**
228          * Create and deploy a process model with one logger delegate as service task.
229          *
230          * @param origProcessKey
231          *            key to call
232          * @param mockProcessName
233          *            process name
234          * @param fileName
235          *            file name without extension
236          * @param outParam
237          *            output parameters
238          */
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);
245
246                 for (String key : outParam.keySet()) {
247                         builder.camundaOutputParameter(key, outParam.get(key));
248                 }
249                 
250                 BpmnModelInstance modelInstance = builder.endEvent().name("End_Event").done();
251                 mockedSubprocessList.add(repositoryService.createDeployment().addModelInstance(fileName + ".bpmn", modelInstance).deploy().getId());
252         }
253 }