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=========================================================
21 package org.onap.so.bpmn.infrastructure.scripts
23 import org.camunda.bpm.engine.ProcessEngineServices
24 import org.camunda.bpm.engine.RepositoryService
25 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
26 import org.camunda.bpm.engine.repository.ProcessDefinition
27 import org.camunda.bpm.engine.delegate.DelegateExecution
28 import org.junit.Before
31 import org.mockito.MockitoAnnotations
32 import org.onap.so.bpmn.common.scripts.MsoUtils
33 import org.onap.so.bpmn.core.WorkflowException
35 import static org.junit.Assert.*;
36 import static org.mockito.Mockito.*
38 import com.github.tomakehurst.wiremock.junit.WireMockRule
40 class CreateNetworkInstanceTest {
43 public WireMockRule wireMockRule = new WireMockRule(8090);
45 String Prefix="CRENI_"
46 def utils = new MsoUtils()
48 String createDBRequestError =
49 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
52 <ns:updateInfraRequest xmlns:ns="http://org.onap.so/requestsdb">
53 <requestId>88f65519-9a38-4c4b-8445-9eb4a5a5af56</requestId>
54 <lastModifiedBy>BPMN</lastModifiedBy>
55 <statusMessage>Received error from SDN-C: No availability zone available</statusMessage>
56 <responseBody></responseBody>
57 <requestStatus>FAILED</requestStatus>
58 <vnfOutputs><network-id></network-id><network-name></network-names></vnfOutputs>
59 </ns:updateInfraRequest>
61 </soapenv:Envelope>"""
63 String falloutHandlerRequest =
64 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
65 xmlns:ns="http://org.onap/so/request/types/v1"
66 xmlns:wfsch="http://org.onap/so/workflow/schema/v1">
67 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
68 <request-id>b69c9054-da09-4a2c-adf5-51042b62bfac</request-id>
69 <action>CREATE</action>
72 <aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
73 <aetgt:ErrorMessage>Received error from SDN-C: No availability zone available.</aetgt:ErrorMessage>
74 <aetgt:ErrorCode>5300</aetgt:ErrorCode>
75 </aetgt:WorkflowException>
76 </aetgt:FalloutHandlerRequest>"""
78 String completeMsoProcessRequest =
79 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
80 xmlns:ns="http://org.onap/so/request/types/v1"
81 xmlns="http://org.onap/so/infra/vnf-request/v1">
83 <request-id>88f65519-9a38-4c4b-8445-9eb4a5a5af56</request-id>
84 <action>CREATE</action>
87 <aetgt:status-message>Network has been created successfully.</aetgt:status-message>
88 <aetgt:mso-bpel-name>BPMN Network action: CREATE</aetgt:mso-bpel-name>
89 </aetgt:MsoCompletionRequest>"""
92 String jsonIncomingRequest =
93 """{ "requestDetails": {
95 "modelType": "networkTyp",
97 "modelNameVersionId": "modelNameVersionId",
98 "modelName": "CONTRAIL_EXTERNAL",
101 "cloudConfiguration": {
102 "lcpCloudRegionId": "RDM2WAGPLCP",
103 "tenantId": "7dd5365547234ee8937416c65507d266"
106 "instanceName": "MNS-25180-L-01-dmz_direct_net_1",
109 "suppressRollback": true,
110 "productFamilyId": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb"
112 "relatedInstanceList": [
115 "instanceId": "f70e927b-6087-4974-9ef8-c5e4d5847ca4",
117 "modelType": "serviceT",
119 "modelNameVersionId": "modelNameVersionI",
120 "modelName": "modleNam",
126 "requestParameters": {
129 "name": "someUserParam1",
130 "value": "someValue1"
139 MockitoAnnotations.initMocks(this)
142 public void initializeVariables(DelegateExecution mockExecution) {
144 verify(mockExecution).setVariable(Prefix + "Success", false)
146 verify(mockExecution).setVariable(Prefix + "CompleteMsoProcessRequest", "")
147 verify(mockExecution).setVariable(Prefix + "FalloutHandlerRequest", "")
148 verify(mockExecution).setVariable(Prefix + "isSilentSuccess", false)
154 public void preProcessRequest() {
156 println "************ preProcessRequest() ************* "
157 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
158 // Initialize prerequisite variables
159 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
160 when(mockExecution.getVariable("bpmnRequest")).thenReturn(jsonIncomingRequest)
163 // preProcessRequest(DelegateExecution execution)
164 CreateNetworkInstance CreateNetworkInstance = new CreateNetworkInstance()
165 CreateNetworkInstance.preProcessRequest(mockExecution)
167 //verify(mockExecution).getVariable("isDebugLogEnabled")
168 verify(mockExecution).setVariable("prefix", Prefix)
170 initializeVariables(mockExecution)
171 //verify(mockExecution).setVariable(Prefix + "Success", false)
178 public void getNetworkModelInfo() {
180 println "************ getNetworkModelInfo() ************* "
182 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
183 // Initialize prerequisite variables
184 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
186 // preProcessRequest(DelegateExecution execution)
187 CreateNetworkInstance CreateNetworkInstance = new CreateNetworkInstance()
188 CreateNetworkInstance.getNetworkModelInfo(mockExecution)
190 //verify(mockExecution).getVariable("isDebugLogEnabled")
191 verify(mockExecution).setVariable("prefix", Prefix)
197 public void sendSyncResponse() {
199 println "************ sendSyncResponse ************* "
201 ExecutionEntity mockExecution = setupMock()
202 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
203 when(mockExecution.getVariable("isAsyncProcess")).thenReturn(true)
204 when(mockExecution.getVariable("mso-request-id")).thenReturn("e8ebf6a0-f8ea-4dc0-8b99-fe98a87722d6")
205 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4")
207 // preProcessRequest(DelegateExecution execution)
208 CreateNetworkInstance CreateNetworkInstance = new CreateNetworkInstance()
209 CreateNetworkInstance.sendSyncResponse(mockExecution)
211 verify(mockExecution).setVariable("prefix", Prefix)
212 verify(mockExecution).setVariable("CreateNetworkInstanceResponseCode", "202")
218 public void sendSyncError() {
220 println "************ sendSyncError ************* "
222 ExecutionEntity mockExecution = setupMock()
223 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
224 when(mockExecution.getVariable("isAsyncProcess")).thenReturn(true)
225 when(mockExecution.getVariable("mso-request-id")).thenReturn("e8ebf6a0-f8ea-4dc0-8b99-fe98a87722d6")
226 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4")
228 CreateNetworkInstance CreateNetworkInstance = new CreateNetworkInstance()
229 CreateNetworkInstance.sendSyncError(mockExecution)
231 verify(mockExecution).setVariable("prefix", Prefix)
232 verify(mockExecution).setVariable("CreateNetworkInstanceResponseCode", "500")
238 public void prepareDBRequestError() {
240 println "************ prepareDBRequestError ************* "
242 WorkflowException sndcWorkflowException = new WorkflowException("CreateNetworkInstance", 500, "Received error from SDN-C: No availability zone available")
244 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
245 // Initialize prerequisite variables
246 when(mockExecution.getVariable("WorkflowException")).thenReturn(sndcWorkflowException)
247 //when(mockExecution.getVariable("msoRequestId")).thenReturn("88f65519-9a38-4c4b-8445-9eb4a5a5af56")
248 when(mockExecution.getVariable(Prefix + "requestId")).thenReturn("88f65519-9a38-4c4b-8445-9eb4a5a5af56")
249 when(mockExecution.getVariable("networkId")).thenReturn("")
250 when(mockExecution.getVariable("networkName")).thenReturn("")
251 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
252 when(mockExecution.getVariable("mso.adapters.db.auth")).thenReturn("757A94191D685FD2092AC1490730A4FC")
253 when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7")
255 // preProcessRequest(DelegateExecution execution)
256 CreateNetworkInstance CreateNetworkInstance = new CreateNetworkInstance()
257 CreateNetworkInstance.prepareDBRequestError(mockExecution)
259 verify(mockExecution).setVariable("prefix", Prefix)
260 verify(mockExecution).setVariable(Prefix + "createDBRequest", createDBRequestError)
267 public void prepareCompletion() {
269 println "************ postProcessResponse ************* "
270 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
271 // Initialize prerequisite variables
272 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
273 when(mockExecution.getVariable("mso-request-id")).thenReturn("88f65519-9a38-4c4b-8445-9eb4a5a5af56")
274 when(mockExecution.getVariable(Prefix + "dbReturnCode")).thenReturn("200")
276 // postProcessResponse(DelegateExecution execution)
277 CreateNetworkInstance CreateNetworkInstance = new CreateNetworkInstance()
278 CreateNetworkInstance.prepareCompletion(mockExecution)
280 // check the sequence of variable invocation
281 //MockitoDebuggerImpl preDebugger = new MockitoDebuggerImpl()
282 //preDebugger.printInvocations(mockExecution)
284 verify(mockExecution).setVariable("prefix", Prefix)
285 verify(mockExecution).setVariable(Prefix + "Success", true)
286 verify(mockExecution).setVariable(Prefix + "CompleteMsoProcessRequest", completeMsoProcessRequest)
292 public void buildErrorResponse() {
294 println "************ buildErrorResponse ************* "
297 WorkflowException sndcWorkflowException = new WorkflowException("CreateNetworkInstance", 5300, "Received error from SDN-C: No availability zone available.")
299 ExecutionEntity mockExecution = setupMock()
300 // Initialize prerequisite variables
301 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
302 when(mockExecution.getVariable("mso-request-id")).thenReturn("b69c9054-da09-4a2c-adf5-51042b62bfac")
303 //when(mockExecution.getVariable("WorkflowException")).thenReturn(sndcWorkflowException)
304 when(mockExecution.getVariable("WorkflowException")).thenReturn(sndcWorkflowException)
306 // buildErrorResponse(DelegateExecution execution)
307 CreateNetworkInstance CreateNetworkInstance = new CreateNetworkInstance()
308 CreateNetworkInstance.buildErrorResponse(mockExecution)
310 verify(mockExecution, atLeast(1)).setVariable("prefix", "CRENI_")
311 verify(mockExecution).setVariable(Prefix + "FalloutHandlerRequest", falloutHandlerRequest)
313 //MockitoDebuggerImpl debugger = new MockitoDebuggerImpl()
314 //debugger.printInvocations(mockExecution)
320 public void postProcessResponse() {
322 println "************ postProcessResponse() ************* "
323 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
324 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
325 when(mockExecution.getVariable("CMSO_ResponseCode")).thenReturn("200")
327 // postProcessResponse(DelegateExecution execution)
328 CreateNetworkInstance CreateNetworkInstance = new CreateNetworkInstance()
329 CreateNetworkInstance.postProcessResponse(mockExecution)
331 //verify(mockExecution).getVariable("isDebugLogEnabled")
332 //verify(mockExecution).setVariable("prefix", Prefix)
334 verify(mockExecution).setVariable(Prefix + "Success", true)
340 public void processRollbackData() {
342 println "************ callDBCatalog() ************* "
343 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
344 // Initialize prerequisite variables
345 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
347 // preProcessRequest(DelegateExecution execution)
348 CreateNetworkInstance CreateNetworkInstance = new CreateNetworkInstance()
349 CreateNetworkInstance.processRollbackData(mockExecution)
351 // verify(mockExecution).getVariable("isDebugLogEnabled")
352 verify(mockExecution).setVariable("prefix", Prefix)
356 private ExecutionEntity setupMock() {
358 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
359 when(mockProcessDefinition.getKey()).thenReturn("CreateNetworkInstance")
360 RepositoryService mockRepositoryService = mock(RepositoryService.class)
361 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
362 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("CreateNetworkInstance")
363 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
364 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
365 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
367 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
368 // Initialize prerequisite variables
370 when(mockExecution.getId()).thenReturn("100")
371 when(mockExecution.getProcessDefinitionId()).thenReturn("CreateNetworkInstance")
372 when(mockExecution.getProcessInstanceId()).thenReturn("CreateNetworkInstance")
373 when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
374 when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)