1 package org.openecomp.mso.bpmn.infrastructure.scripts
\r
3 import static org.mockito.Mockito.*
\r
5 import org.camunda.bpm.engine.ProcessEngineServices
\r
6 import org.camunda.bpm.engine.RepositoryService
\r
7 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
\r
8 import org.camunda.bpm.engine.repository.ProcessDefinition
\r
9 import org.camunda.bpm.engine.delegate.DelegateExecution
\r
10 import org.junit.Before
\r
11 import org.junit.Ignore
\r
12 import org.junit.Rule
\r
13 import org.junit.Test
\r
14 import org.junit.runner.RunWith
\r
15 import org.mockito.MockitoAnnotations
\r
16 import org.mockito.runners.MockitoJUnitRunner
\r
17 import org.openecomp.mso.bpmn.common.scripts.MsoUtils
\r
18 import org.openecomp.mso.bpmn.core.WorkflowException
\r
20 import com.github.tomakehurst.wiremock.junit.WireMockRule
\r
21 import org.apache.commons.lang3.*
\r
24 @RunWith(MockitoJUnitRunner.class)
\r
25 class UpdateNetworkInstanceTest {
\r
28 public WireMockRule wireMockRule = new WireMockRule(8090);
\r
30 String Prefix="UPDNI_"
\r
31 def utils = new MsoUtils()
\r
33 String createDBRequestError =
\r
34 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
\r
37 <ns:updateInfraRequest xmlns:ns="http://org.openecomp.mso/requestsdb">
\r
38 <requestId>88f65519-9a38-4c4b-8445-9eb4a5a5af56</requestId>
\r
39 <lastModifiedBy>BPMN</lastModifiedBy>
\r
40 <statusMessage>Received error from SDN-C: No availability zone available</statusMessage>
\r
41 <responseBody></responseBody>
\r
42 <requestStatus>FAILED</requestStatus>
\r
43 <vnfOutputs><network-id></network-id><network-name></network-names></vnfOutputs>
\r
44 </ns:updateInfraRequest>
\r
46 </soapenv:Envelope>"""
\r
48 String falloutHandlerRequest =
\r
49 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
50 xmlns:ns="http://org.openecomp/mso/request/types/v1"
\r
51 xmlns:wfsch="http://org.openecomp/mso/workflow/schema/v1">
\r
52 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
53 <request-id>b69c9054-da09-4a2c-adf5-51042b62bfac</request-id>
\r
54 <action>UPDATE</action>
\r
55 <source>VID</source>
\r
57 <aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
58 <aetgt:ErrorMessage>Received error from SDN-C: No availability zone available.</aetgt:ErrorMessage>
\r
59 <aetgt:ErrorCode>5300</aetgt:ErrorCode>
\r
60 </aetgt:WorkflowException>
\r
61 </aetgt:FalloutHandlerRequest>"""
\r
63 String completeMsoProcessRequest =
\r
64 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
65 xmlns:ns="http://org.openecomp/mso/request/types/v1"
\r
66 xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
68 <request-id>88f65519-9a38-4c4b-8445-9eb4a5a5af56</request-id>
\r
69 <action>UPDATE</action>
\r
70 <source>VID</source>
\r
72 <aetgt:status-message>Network has been updated successfully.</aetgt:status-message>
\r
73 <aetgt:mso-bpel-name>BPMN Network action: UPDATE</aetgt:mso-bpel-name>
\r
74 </aetgt:MsoCompletionRequest>"""
\r
77 String jsonIncomingRequest =
\r
78 """{ "requestDetails": {
\r
80 "modelType": "networkTyp",
\r
81 "modelId": "modelId",
\r
82 "modelNameVersionId": "modelNameVersionId",
\r
83 "modelName": "CONTRAIL_EXTERNAL",
\r
86 "cloudConfiguration": {
\r
87 "lcpCloudRegionId": "RDM2WAGPLCP",
\r
88 "tenantId": "7dd5365547234ee8937416c65507d266"
\r
91 "instanceName": "MNS-25180-L-01-dmz_direct_net_1",
\r
94 "suppressRollback": true,
\r
95 "productFamilyId": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb"
\r
97 "relatedInstanceList": [
\r
99 "relatedInstance": {
\r
100 "instanceId": "f70e927b-6087-4974-9ef8-c5e4d5847ca4",
\r
102 "modelType": "serviceT",
\r
103 "modelId": "modelI",
\r
104 "modelNameVersionId": "modelNameVersionI",
\r
105 "modelName": "modleNam",
\r
106 "modelVersion": "1"
\r
111 "requestParameters": {
\r
114 "name": "someUserParam1",
\r
115 "value": "someValue1"
\r
124 MockitoAnnotations.initMocks(this)
\r
128 public void initializeVariables(DelegateExecution mockExecution) {
\r
130 verify(mockExecution).setVariable(Prefix + "source", "")
\r
131 verify(mockExecution).setVariable(Prefix + "Success", false)
\r
133 verify(mockExecution).setVariable(Prefix + "CompleteMsoProcessRequest", "")
\r
134 verify(mockExecution).setVariable(Prefix + "FalloutHandlerRequest", "")
\r
140 public void preProcessRequest() {
\r
142 println "************ preProcessRequest() ************* "
\r
143 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
\r
144 // Initialize prerequisite variables
\r
145 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
\r
146 when(mockExecution.getVariable("bpmnRequest")).thenReturn(jsonIncomingRequest)
\r
148 when(mockExecution.getVariable("URN_mso_adapters_db_auth")).thenReturn("757A94191D685FD2092AC1490730A4FC")
\r
149 when(mockExecution.getVariable("URN_mso_msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7")
\r
151 // preProcessRequest(DelegateExecution execution)
\r
152 UpdateNetworkInstance UpdateNetworkInstance = new UpdateNetworkInstance()
\r
153 UpdateNetworkInstance.preProcessRequest(mockExecution)
\r
155 verify(mockExecution).getVariable("isDebugLogEnabled")
\r
156 verify(mockExecution).setVariable("prefix", Prefix)
\r
158 initializeVariables(mockExecution)
\r
159 //verify(mockExecution).setVariable(Prefix + "Success", false)
\r
166 public void getNetworkModelInfo() {
\r
168 println "************ getNetworkModelInfo() ************* "
\r
170 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
\r
171 // Initialize prerequisite variables
\r
172 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
\r
174 // preProcessRequest(DelegateExecution execution)
\r
175 UpdateNetworkInstance UpdateNetworkInstance = new UpdateNetworkInstance()
\r
176 UpdateNetworkInstance.getNetworkModelInfo(mockExecution)
\r
178 verify(mockExecution).getVariable("isDebugLogEnabled")
\r
179 verify(mockExecution).setVariable("prefix", Prefix)
\r
185 public void sendSyncResponse() {
\r
187 println "************ sendSyncResponse ************* "
\r
189 ExecutionEntity mockExecution = setupMock()
\r
190 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
\r
191 when(mockExecution.getVariable("isAsyncProcess")).thenReturn(true)
\r
192 when(mockExecution.getVariable("mso-request-id")).thenReturn("e8ebf6a0-f8ea-4dc0-8b99-fe98a87722d6")
\r
193 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4")
\r
195 // preProcessRequest(DelegateExecution execution)
\r
196 UpdateNetworkInstance UpdateNetworkInstance = new UpdateNetworkInstance()
\r
197 UpdateNetworkInstance.sendSyncResponse(mockExecution)
\r
199 verify(mockExecution).setVariable("prefix", Prefix)
\r
200 verify(mockExecution).setVariable("UpdateNetworkInstanceResponseCode", "202")
\r
206 public void sendSyncError() {
\r
208 println "************ sendSyncError ************* "
\r
210 ExecutionEntity mockExecution = setupMock()
\r
211 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
\r
212 when(mockExecution.getVariable("isAsyncProcess")).thenReturn(true)
\r
213 when(mockExecution.getVariable("mso-request-id")).thenReturn("e8ebf6a0-f8ea-4dc0-8b99-fe98a87722d6")
\r
214 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4")
\r
216 UpdateNetworkInstance UpdateNetworkInstance = new UpdateNetworkInstance()
\r
217 UpdateNetworkInstance.sendSyncError(mockExecution)
\r
219 verify(mockExecution).setVariable("prefix", Prefix)
\r
220 verify(mockExecution).setVariable("UpdateNetworkInstanceResponseCode", "500")
\r
226 public void prepareDBRequestError() {
\r
228 println "************ prepareDBRequestError ************* "
\r
230 WorkflowException sndcWorkflowException = new WorkflowException("UpdateNetworkInstance", 500, "Received error from SDN-C: No availability zone available")
\r
232 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
\r
233 // Initialize prerequisite variables
\r
234 when(mockExecution.getVariable("WorkflowException")).thenReturn(sndcWorkflowException)
\r
235 //when(mockExecution.getVariable("msoRequestId")).thenReturn("88f65519-9a38-4c4b-8445-9eb4a5a5af56")
\r
236 when(mockExecution.getVariable(Prefix + "requestId")).thenReturn("88f65519-9a38-4c4b-8445-9eb4a5a5af56")
\r
237 when(mockExecution.getVariable("networkId")).thenReturn("")
\r
238 when(mockExecution.getVariable("networkName")).thenReturn("")
\r
239 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
\r
241 when(mockExecution.getVariable("URN_mso_adapters_db_auth")).thenReturn("757A94191D685FD2092AC1490730A4FC")
\r
242 when(mockExecution.getVariable("URN_mso_msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7")
\r
244 // preProcessRequest(DelegateExecution execution)
\r
245 UpdateNetworkInstance UpdateNetworkInstance = new UpdateNetworkInstance()
\r
246 UpdateNetworkInstance.prepareDBRequestError(mockExecution)
\r
248 verify(mockExecution).setVariable("prefix", Prefix)
\r
249 verify(mockExecution).setVariable(Prefix + "createDBRequest", createDBRequestError)
\r
256 public void prepareCompletion() {
\r
258 println "************ postProcessResponse ************* "
\r
259 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
\r
260 // Initialize prerequisite variables
\r
261 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
\r
262 when(mockExecution.getVariable("mso-request-id")).thenReturn("88f65519-9a38-4c4b-8445-9eb4a5a5af56")
\r
263 when(mockExecution.getVariable(Prefix + "dbReturnCode")).thenReturn("200")
\r
265 // postProcessResponse(DelegateExecution execution)
\r
266 UpdateNetworkInstance UpdateNetworkInstance = new UpdateNetworkInstance()
\r
267 UpdateNetworkInstance.prepareCompletion(mockExecution)
\r
269 // check the sequence of variable invocation
\r
270 //MockitoDebuggerImpl preDebugger = new MockitoDebuggerImpl()
\r
271 //preDebugger.printInvocations(mockExecution)
\r
273 verify(mockExecution).setVariable("prefix", Prefix)
\r
274 verify(mockExecution).setVariable(Prefix + "Success", true)
\r
275 verify(mockExecution).setVariable(Prefix + "CompleteMsoProcessRequest", completeMsoProcessRequest)
\r
281 public void buildErrorResponse() {
\r
283 println "************ buildErrorResponse ************* "
\r
286 WorkflowException sndcWorkflowException = new WorkflowException("UpdateNetworkInstance", 5300, "Received error from SDN-C: No availability zone available.")
\r
288 ExecutionEntity mockExecution = setupMock()
\r
289 // Initialize prerequisite variables
\r
290 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
\r
291 when(mockExecution.getVariable("mso-request-id")).thenReturn("b69c9054-da09-4a2c-adf5-51042b62bfac")
\r
292 //when(mockExecution.getVariable("WorkflowException")).thenReturn(sndcWorkflowException)
\r
293 when(mockExecution.getVariable("WorkflowException")).thenReturn(sndcWorkflowException)
\r
295 // buildErrorResponse(DelegateExecution execution)
\r
296 UpdateNetworkInstance UpdateNetworkInstance = new UpdateNetworkInstance()
\r
297 UpdateNetworkInstance.buildErrorResponse(mockExecution)
\r
299 verify(mockExecution, atLeast(1)).setVariable("prefix", Prefix)
\r
300 verify(mockExecution).setVariable(Prefix + "FalloutHandlerRequest", falloutHandlerRequest)
\r
302 //MockitoDebuggerImpl debugger = new MockitoDebuggerImpl()
\r
303 //debugger.printInvocations(mockExecution)
\r
309 public void postProcessResponse() {
\r
311 println "************ postProcessResponse() ************* "
\r
312 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
\r
313 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
\r
314 when(mockExecution.getVariable("CMSO_ResponseCode")).thenReturn("200")
\r
316 // postProcessResponse(DelegateExecution execution)
\r
317 UpdateNetworkInstance UpdateNetworkInstance = new UpdateNetworkInstance()
\r
318 UpdateNetworkInstance.postProcessResponse(mockExecution)
\r
320 //verify(mockExecution).getVariable("isDebugLogEnabled")
\r
321 //verify(mockExecution).setVariable("prefix", Prefix)
\r
323 verify(mockExecution).setVariable(Prefix + "Success", true)
\r
329 public void processRollbackData() {
\r
331 println "************ callDBCatalog() ************* "
\r
332 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
\r
333 // Initialize prerequisite variables
\r
334 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
\r
336 // preProcessRequest(DelegateExecution execution)
\r
337 UpdateNetworkInstance UpdateNetworkInstance = new UpdateNetworkInstance()
\r
338 UpdateNetworkInstance.processRollbackData(mockExecution)
\r
340 verify(mockExecution).getVariable("isDebugLogEnabled")
\r
341 verify(mockExecution).setVariable("prefix", Prefix)
\r
345 private ExecutionEntity setupMock() {
\r
347 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
\r
348 when(mockProcessDefinition.getKey()).thenReturn("UpdateNetworkInstance")
\r
349 RepositoryService mockRepositoryService = mock(RepositoryService.class)
\r
350 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
\r
351 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("UpdateNetworkInstance")
\r
352 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
\r
353 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
\r
354 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
\r
356 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
\r
357 // Initialize prerequisite variables
\r
359 when(mockExecution.getId()).thenReturn("100")
\r
360 when(mockExecution.getProcessDefinitionId()).thenReturn("UpdateNetworkInstance")
\r
361 when(mockExecution.getProcessInstanceId()).thenReturn("UpdateNetworkInstance")
\r
362 when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
\r
363 when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)
\r
365 return mockExecution
\r