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:networkId>fb03f6f0-9012-41c4-87d8-1dbf3c22b889</aetgt:networkId>
89 <aetgt:mso-bpel-name>BPMN Network action: CREATE</aetgt:mso-bpel-name>
90 </aetgt:MsoCompletionRequest>"""
93 String jsonIncomingRequest =
94 """{ "requestDetails": {
96 "modelType": "networkTyp",
98 "modelNameVersionId": "modelNameVersionId",
99 "modelName": "CONTRAIL_EXTERNAL",
102 "cloudConfiguration": {
103 "lcpCloudRegionId": "RDM2WAGPLCP",
104 "tenantId": "7dd5365547234ee8937416c65507d266"
107 "instanceName": "MNS-25180-L-01-dmz_direct_net_1",
110 "suppressRollback": true,
111 "productFamilyId": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb"
113 "relatedInstanceList": [
116 "instanceId": "f70e927b-6087-4974-9ef8-c5e4d5847ca4",
118 "modelType": "serviceT",
120 "modelNameVersionId": "modelNameVersionI",
121 "modelName": "modleNam",
127 "requestParameters": {
130 "name": "someUserParam1",
131 "value": "someValue1"
140 MockitoAnnotations.initMocks(this)
143 public void initializeVariables(DelegateExecution mockExecution) {
145 verify(mockExecution).setVariable(Prefix + "Success", false)
147 verify(mockExecution).setVariable(Prefix + "CompleteMsoProcessRequest", "")
148 verify(mockExecution).setVariable(Prefix + "FalloutHandlerRequest", "")
149 verify(mockExecution).setVariable(Prefix + "isSilentSuccess", false)
155 public void preProcessRequest() {
157 println "************ preProcessRequest() ************* "
158 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
159 // Initialize prerequisite variables
160 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
161 when(mockExecution.getVariable("bpmnRequest")).thenReturn(jsonIncomingRequest)
164 // preProcessRequest(DelegateExecution execution)
165 CreateNetworkInstance CreateNetworkInstance = new CreateNetworkInstance()
166 CreateNetworkInstance.preProcessRequest(mockExecution)
168 //verify(mockExecution).getVariable("isDebugLogEnabled")
169 verify(mockExecution).setVariable("prefix", Prefix)
171 initializeVariables(mockExecution)
172 //verify(mockExecution).setVariable(Prefix + "Success", false)
179 public void getNetworkModelInfo() {
181 println "************ getNetworkModelInfo() ************* "
183 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
184 // Initialize prerequisite variables
185 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
187 // preProcessRequest(DelegateExecution execution)
188 CreateNetworkInstance CreateNetworkInstance = new CreateNetworkInstance()
189 CreateNetworkInstance.getNetworkModelInfo(mockExecution)
191 //verify(mockExecution).getVariable("isDebugLogEnabled")
192 verify(mockExecution).setVariable("prefix", Prefix)
198 public void sendSyncResponse() {
200 println "************ sendSyncResponse ************* "
202 ExecutionEntity mockExecution = setupMock()
203 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
204 when(mockExecution.getVariable("isAsyncProcess")).thenReturn(true)
205 when(mockExecution.getVariable("mso-request-id")).thenReturn("e8ebf6a0-f8ea-4dc0-8b99-fe98a87722d6")
206 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4")
208 // preProcessRequest(DelegateExecution execution)
209 CreateNetworkInstance CreateNetworkInstance = new CreateNetworkInstance()
210 CreateNetworkInstance.sendSyncResponse(mockExecution)
212 verify(mockExecution).setVariable("prefix", Prefix)
213 verify(mockExecution).setVariable("CreateNetworkInstanceResponseCode", "202")
219 public void sendSyncError() {
221 println "************ sendSyncError ************* "
223 ExecutionEntity mockExecution = setupMock()
224 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
225 when(mockExecution.getVariable("isAsyncProcess")).thenReturn(true)
226 when(mockExecution.getVariable("mso-request-id")).thenReturn("e8ebf6a0-f8ea-4dc0-8b99-fe98a87722d6")
227 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4")
229 CreateNetworkInstance CreateNetworkInstance = new CreateNetworkInstance()
230 CreateNetworkInstance.sendSyncError(mockExecution)
232 verify(mockExecution).setVariable("prefix", Prefix)
233 verify(mockExecution).setVariable("CreateNetworkInstanceResponseCode", "500")
239 public void prepareDBRequestError() {
241 println "************ prepareDBRequestError ************* "
243 WorkflowException sndcWorkflowException = new WorkflowException("CreateNetworkInstance", 500, "Received error from SDN-C: No availability zone available")
245 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
246 // Initialize prerequisite variables
247 when(mockExecution.getVariable("WorkflowException")).thenReturn(sndcWorkflowException)
248 //when(mockExecution.getVariable("msoRequestId")).thenReturn("88f65519-9a38-4c4b-8445-9eb4a5a5af56")
249 when(mockExecution.getVariable(Prefix + "requestId")).thenReturn("88f65519-9a38-4c4b-8445-9eb4a5a5af56")
250 when(mockExecution.getVariable("networkId")).thenReturn("")
251 when(mockExecution.getVariable("networkName")).thenReturn("")
252 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
253 when(mockExecution.getVariable("mso.adapters.db.auth")).thenReturn("757A94191D685FD2092AC1490730A4FC")
254 when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7")
256 // preProcessRequest(DelegateExecution execution)
257 CreateNetworkInstance CreateNetworkInstance = new CreateNetworkInstance()
258 CreateNetworkInstance.prepareDBRequestError(mockExecution)
260 verify(mockExecution).setVariable("prefix", Prefix)
261 verify(mockExecution).setVariable(Prefix + "createDBRequest", createDBRequestError)
268 public void prepareCompletion() {
270 println "************ postProcessResponse ************* "
271 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
272 // Initialize prerequisite variables
273 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
274 when(mockExecution.getVariable("mso-request-id")).thenReturn("88f65519-9a38-4c4b-8445-9eb4a5a5af56")
275 when(mockExecution.getVariable(Prefix + "dbReturnCode")).thenReturn("200")
276 when(mockExecution.getVariable("networkId")).thenReturn("fb03f6f0-9012-41c4-87d8-1dbf3c22b889")
278 // postProcessResponse(DelegateExecution execution)
279 CreateNetworkInstance CreateNetworkInstance = new CreateNetworkInstance()
280 CreateNetworkInstance.prepareCompletion(mockExecution)
282 // check the sequence of variable invocation
283 //MockitoDebuggerImpl preDebugger = new MockitoDebuggerImpl()
284 //preDebugger.printInvocations(mockExecution)
286 verify(mockExecution).setVariable("prefix", Prefix)
287 verify(mockExecution).setVariable(Prefix + "Success", true)
288 verify(mockExecution).setVariable(Prefix + "CompleteMsoProcessRequest", completeMsoProcessRequest)
294 public void buildErrorResponse() {
296 println "************ buildErrorResponse ************* "
299 WorkflowException sndcWorkflowException = new WorkflowException("CreateNetworkInstance", 5300, "Received error from SDN-C: No availability zone available.")
301 ExecutionEntity mockExecution = setupMock()
302 // Initialize prerequisite variables
303 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
304 when(mockExecution.getVariable("mso-request-id")).thenReturn("b69c9054-da09-4a2c-adf5-51042b62bfac")
305 //when(mockExecution.getVariable("WorkflowException")).thenReturn(sndcWorkflowException)
306 when(mockExecution.getVariable("WorkflowException")).thenReturn(sndcWorkflowException)
308 // buildErrorResponse(DelegateExecution execution)
309 CreateNetworkInstance CreateNetworkInstance = new CreateNetworkInstance()
310 CreateNetworkInstance.buildErrorResponse(mockExecution)
312 verify(mockExecution, atLeast(1)).setVariable("prefix", "CRENI_")
313 verify(mockExecution).setVariable(Prefix + "FalloutHandlerRequest", falloutHandlerRequest)
315 //MockitoDebuggerImpl debugger = new MockitoDebuggerImpl()
316 //debugger.printInvocations(mockExecution)
322 public void postProcessResponse() {
324 println "************ postProcessResponse() ************* "
325 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
326 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
327 when(mockExecution.getVariable("CMSO_ResponseCode")).thenReturn("200")
329 // postProcessResponse(DelegateExecution execution)
330 CreateNetworkInstance CreateNetworkInstance = new CreateNetworkInstance()
331 CreateNetworkInstance.postProcessResponse(mockExecution)
333 //verify(mockExecution).getVariable("isDebugLogEnabled")
334 //verify(mockExecution).setVariable("prefix", Prefix)
336 verify(mockExecution).setVariable(Prefix + "Success", true)
342 public void processRollbackData() {
344 println "************ callDBCatalog() ************* "
345 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
346 // Initialize prerequisite variables
347 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
349 // preProcessRequest(DelegateExecution execution)
350 CreateNetworkInstance CreateNetworkInstance = new CreateNetworkInstance()
351 CreateNetworkInstance.processRollbackData(mockExecution)
353 // verify(mockExecution).getVariable("isDebugLogEnabled")
354 verify(mockExecution).setVariable("prefix", Prefix)
358 private ExecutionEntity setupMock() {
360 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
361 when(mockProcessDefinition.getKey()).thenReturn("CreateNetworkInstance")
362 RepositoryService mockRepositoryService = mock(RepositoryService.class)
363 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
364 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("CreateNetworkInstance")
365 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
366 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
367 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
369 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
370 // Initialize prerequisite variables
372 when(mockExecution.getId()).thenReturn("100")
373 when(mockExecution.getProcessDefinitionId()).thenReturn("CreateNetworkInstance")
374 when(mockExecution.getProcessInstanceId()).thenReturn("CreateNetworkInstance")
375 when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
376 when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)