1 package org.openecomp.mso.bpmn.infrastructure.scripts
\r
3 import org.camunda.bpm.engine.ProcessEngineServices
\r
4 import org.camunda.bpm.engine.RepositoryService
\r
5 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
\r
6 import org.camunda.bpm.engine.repository.ProcessDefinition
\r
7 import org.camunda.bpm.engine.delegate.DelegateExecution
\r
8 import org.junit.Before
\r
9 import org.junit.Rule
\r
10 import org.junit.Test
\r
11 import org.mockito.MockitoAnnotations
\r
12 import org.openecomp.mso.bpmn.common.scripts.MsoUtils
\r
13 import org.openecomp.mso.bpmn.core.WorkflowException
\r
15 import static org.junit.Assert.*;
\r
16 import static org.mockito.Mockito.*
\r
18 import com.github.tomakehurst.wiremock.junit.WireMockRule
\r
20 class CreateNetworkInstanceTest {
\r
23 public WireMockRule wireMockRule = new WireMockRule(8090);
\r
25 String Prefix="CRENI_"
\r
26 def utils = new MsoUtils()
\r
28 String createDBRequestError =
\r
29 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
\r
32 <ns:updateInfraRequest xmlns:ns="http://org.openecomp.mso/requestsdb">
\r
33 <requestId>88f65519-9a38-4c4b-8445-9eb4a5a5af56</requestId>
\r
34 <lastModifiedBy>BPMN</lastModifiedBy>
\r
35 <statusMessage>Received error from SDN-C: No availability zone available</statusMessage>
\r
36 <responseBody></responseBody>
\r
37 <requestStatus>FAILED</requestStatus>
\r
38 <vnfOutputs><network-id></network-id><network-name></network-names></vnfOutputs>
\r
39 </ns:updateInfraRequest>
\r
41 </soapenv:Envelope>"""
\r
43 String falloutHandlerRequest =
\r
44 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
45 xmlns:ns="http://org.openecomp/mso/request/types/v1"
\r
46 xmlns:wfsch="http://org.openecomp/mso/workflow/schema/v1">
\r
47 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
48 <request-id>b69c9054-da09-4a2c-adf5-51042b62bfac</request-id>
\r
49 <action>CREATE</action>
\r
50 <source>VID</source>
\r
52 <aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
53 <aetgt:ErrorMessage>Received error from SDN-C: No availability zone available.</aetgt:ErrorMessage>
\r
54 <aetgt:ErrorCode>5300</aetgt:ErrorCode>
\r
55 </aetgt:WorkflowException>
\r
56 </aetgt:FalloutHandlerRequest>"""
\r
58 String completeMsoProcessRequest =
\r
59 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
60 xmlns:ns="http://org.openecomp/mso/request/types/v1"
\r
61 xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
63 <request-id>88f65519-9a38-4c4b-8445-9eb4a5a5af56</request-id>
\r
64 <action>CREATE</action>
\r
65 <source>VID</source>
\r
67 <aetgt:status-message>Network has been created successfully.</aetgt:status-message>
\r
68 <aetgt:mso-bpel-name>BPMN Network action: CREATE</aetgt:mso-bpel-name>
\r
69 </aetgt:MsoCompletionRequest>"""
\r
72 String jsonIncomingRequest =
\r
73 """{ "requestDetails": {
\r
75 "modelType": "networkTyp",
\r
76 "modelId": "modelId",
\r
77 "modelNameVersionId": "modelNameVersionId",
\r
78 "modelName": "CONTRAIL_EXTERNAL",
\r
81 "cloudConfiguration": {
\r
82 "lcpCloudRegionId": "RDM2WAGPLCP",
\r
83 "tenantId": "7dd5365547234ee8937416c65507d266"
\r
86 "instanceName": "MNS-25180-L-01-dmz_direct_net_1",
\r
89 "suppressRollback": true,
\r
90 "productFamilyId": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb"
\r
92 "relatedInstanceList": [
\r
94 "relatedInstance": {
\r
95 "instanceId": "f70e927b-6087-4974-9ef8-c5e4d5847ca4",
\r
97 "modelType": "serviceT",
\r
98 "modelId": "modelI",
\r
99 "modelNameVersionId": "modelNameVersionI",
\r
100 "modelName": "modleNam",
\r
101 "modelVersion": "1"
\r
106 "requestParameters": {
\r
109 "name": "someUserParam1",
\r
110 "value": "someValue1"
\r
119 MockitoAnnotations.initMocks(this)
\r
123 public void initializeVariables(DelegateExecution mockExecution) {
\r
125 verify(mockExecution).setVariable(Prefix + "Success", false)
\r
127 verify(mockExecution).setVariable(Prefix + "CompleteMsoProcessRequest", "")
\r
128 verify(mockExecution).setVariable(Prefix + "FalloutHandlerRequest", "")
\r
129 verify(mockExecution).setVariable(Prefix + "isSilentSuccess", false)
\r
135 public void preProcessRequest() {
\r
137 println "************ preProcessRequest() ************* "
\r
138 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
\r
139 // Initialize prerequisite variables
\r
140 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
\r
141 when(mockExecution.getVariable("bpmnRequest")).thenReturn(jsonIncomingRequest)
\r
144 // preProcessRequest(DelegateExecution execution)
\r
145 CreateNetworkInstance CreateNetworkInstance = new CreateNetworkInstance()
\r
146 CreateNetworkInstance.preProcessRequest(mockExecution)
\r
148 verify(mockExecution).getVariable("isDebugLogEnabled")
\r
149 verify(mockExecution).setVariable("prefix", Prefix)
\r
151 initializeVariables(mockExecution)
\r
152 //verify(mockExecution).setVariable(Prefix + "Success", false)
\r
159 public void getNetworkModelInfo() {
\r
161 println "************ getNetworkModelInfo() ************* "
\r
163 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
\r
164 // Initialize prerequisite variables
\r
165 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
\r
167 // preProcessRequest(DelegateExecution execution)
\r
168 CreateNetworkInstance CreateNetworkInstance = new CreateNetworkInstance()
\r
169 CreateNetworkInstance.getNetworkModelInfo(mockExecution)
\r
171 verify(mockExecution).getVariable("isDebugLogEnabled")
\r
172 verify(mockExecution).setVariable("prefix", Prefix)
\r
178 public void sendSyncResponse() {
\r
180 println "************ sendSyncResponse ************* "
\r
182 ExecutionEntity mockExecution = setupMock()
\r
183 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
\r
184 when(mockExecution.getVariable("isAsyncProcess")).thenReturn(true)
\r
185 when(mockExecution.getVariable("mso-request-id")).thenReturn("e8ebf6a0-f8ea-4dc0-8b99-fe98a87722d6")
\r
186 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4")
\r
188 // preProcessRequest(DelegateExecution execution)
\r
189 CreateNetworkInstance CreateNetworkInstance = new CreateNetworkInstance()
\r
190 CreateNetworkInstance.sendSyncResponse(mockExecution)
\r
192 verify(mockExecution).setVariable("prefix", Prefix)
\r
193 verify(mockExecution).setVariable("CreateNetworkInstanceResponseCode", "202")
\r
199 public void sendSyncError() {
\r
201 println "************ sendSyncError ************* "
\r
203 ExecutionEntity mockExecution = setupMock()
\r
204 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
\r
205 when(mockExecution.getVariable("isAsyncProcess")).thenReturn(true)
\r
206 when(mockExecution.getVariable("mso-request-id")).thenReturn("e8ebf6a0-f8ea-4dc0-8b99-fe98a87722d6")
\r
207 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4")
\r
209 CreateNetworkInstance CreateNetworkInstance = new CreateNetworkInstance()
\r
210 CreateNetworkInstance.sendSyncError(mockExecution)
\r
212 verify(mockExecution).setVariable("prefix", Prefix)
\r
213 verify(mockExecution).setVariable("CreateNetworkInstanceResponseCode", "500")
\r
219 public void prepareDBRequestError() {
\r
221 println "************ prepareDBRequestError ************* "
\r
223 WorkflowException sndcWorkflowException = new WorkflowException("CreateNetworkInstance", 500, "Received error from SDN-C: No availability zone available")
\r
225 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
\r
226 // Initialize prerequisite variables
\r
227 when(mockExecution.getVariable("WorkflowException")).thenReturn(sndcWorkflowException)
\r
228 //when(mockExecution.getVariable("msoRequestId")).thenReturn("88f65519-9a38-4c4b-8445-9eb4a5a5af56")
\r
229 when(mockExecution.getVariable(Prefix + "requestId")).thenReturn("88f65519-9a38-4c4b-8445-9eb4a5a5af56")
\r
230 when(mockExecution.getVariable("networkId")).thenReturn("")
\r
231 when(mockExecution.getVariable("networkName")).thenReturn("")
\r
232 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
\r
233 when(mockExecution.getVariable("URN_mso_adapters_db_auth")).thenReturn("757A94191D685FD2092AC1490730A4FC")
\r
234 when(mockExecution.getVariable("URN_mso_msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7")
\r
236 // preProcessRequest(DelegateExecution execution)
\r
237 CreateNetworkInstance CreateNetworkInstance = new CreateNetworkInstance()
\r
238 CreateNetworkInstance.prepareDBRequestError(mockExecution)
\r
240 verify(mockExecution).setVariable("prefix", Prefix)
\r
241 verify(mockExecution).setVariable(Prefix + "createDBRequest", createDBRequestError)
\r
248 public void prepareCompletion() {
\r
250 println "************ postProcessResponse ************* "
\r
251 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
\r
252 // Initialize prerequisite variables
\r
253 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
\r
254 when(mockExecution.getVariable("mso-request-id")).thenReturn("88f65519-9a38-4c4b-8445-9eb4a5a5af56")
\r
255 when(mockExecution.getVariable(Prefix + "dbReturnCode")).thenReturn("200")
\r
257 // postProcessResponse(DelegateExecution execution)
\r
258 CreateNetworkInstance CreateNetworkInstance = new CreateNetworkInstance()
\r
259 CreateNetworkInstance.prepareCompletion(mockExecution)
\r
261 // check the sequence of variable invocation
\r
262 //MockitoDebuggerImpl preDebugger = new MockitoDebuggerImpl()
\r
263 //preDebugger.printInvocations(mockExecution)
\r
265 verify(mockExecution).setVariable("prefix", Prefix)
\r
266 verify(mockExecution).setVariable(Prefix + "Success", true)
\r
267 verify(mockExecution).setVariable(Prefix + "CompleteMsoProcessRequest", completeMsoProcessRequest)
\r
273 public void buildErrorResponse() {
\r
275 println "************ buildErrorResponse ************* "
\r
278 WorkflowException sndcWorkflowException = new WorkflowException("CreateNetworkInstance", 5300, "Received error from SDN-C: No availability zone available.")
\r
280 ExecutionEntity mockExecution = setupMock()
\r
281 // Initialize prerequisite variables
\r
282 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
\r
283 when(mockExecution.getVariable("mso-request-id")).thenReturn("b69c9054-da09-4a2c-adf5-51042b62bfac")
\r
284 //when(mockExecution.getVariable("WorkflowException")).thenReturn(sndcWorkflowException)
\r
285 when(mockExecution.getVariable("WorkflowException")).thenReturn(sndcWorkflowException)
\r
287 // buildErrorResponse(DelegateExecution execution)
\r
288 CreateNetworkInstance CreateNetworkInstance = new CreateNetworkInstance()
\r
289 CreateNetworkInstance.buildErrorResponse(mockExecution)
\r
291 verify(mockExecution, atLeast(1)).setVariable("prefix", "CRENI_")
\r
292 verify(mockExecution).setVariable(Prefix + "FalloutHandlerRequest", falloutHandlerRequest)
\r
294 //MockitoDebuggerImpl debugger = new MockitoDebuggerImpl()
\r
295 //debugger.printInvocations(mockExecution)
\r
301 public void postProcessResponse() {
\r
303 println "************ postProcessResponse() ************* "
\r
304 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
\r
305 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
\r
306 when(mockExecution.getVariable("CMSO_ResponseCode")).thenReturn("200")
\r
308 // postProcessResponse(DelegateExecution execution)
\r
309 CreateNetworkInstance CreateNetworkInstance = new CreateNetworkInstance()
\r
310 CreateNetworkInstance.postProcessResponse(mockExecution)
\r
312 //verify(mockExecution).getVariable("isDebugLogEnabled")
\r
313 //verify(mockExecution).setVariable("prefix", Prefix)
\r
315 verify(mockExecution).setVariable(Prefix + "Success", true)
\r
321 public void processRollbackData() {
\r
323 println "************ callDBCatalog() ************* "
\r
324 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
\r
325 // Initialize prerequisite variables
\r
326 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
\r
328 // preProcessRequest(DelegateExecution execution)
\r
329 CreateNetworkInstance CreateNetworkInstance = new CreateNetworkInstance()
\r
330 CreateNetworkInstance.processRollbackData(mockExecution)
\r
332 verify(mockExecution).getVariable("isDebugLogEnabled")
\r
333 verify(mockExecution).setVariable("prefix", Prefix)
\r
337 private ExecutionEntity setupMock() {
\r
339 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
\r
340 when(mockProcessDefinition.getKey()).thenReturn("CreateNetworkInstance")
\r
341 RepositoryService mockRepositoryService = mock(RepositoryService.class)
\r
342 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
\r
343 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("CreateNetworkInstance")
\r
344 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
\r
345 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
\r
346 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
\r
348 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
\r
349 // Initialize prerequisite variables
\r
351 when(mockExecution.getId()).thenReturn("100")
\r
352 when(mockExecution.getProcessDefinitionId()).thenReturn("CreateNetworkInstance")
\r
353 when(mockExecution.getProcessInstanceId()).thenReturn("CreateNetworkInstance")
\r
354 when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
\r
355 when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)
\r
357 return mockExecution
\r