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
24 import static org.mockito.Mockito.*
26 import org.camunda.bpm.engine.ProcessEngineServices
27 import org.camunda.bpm.engine.RepositoryService
28 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
29 import org.camunda.bpm.engine.repository.ProcessDefinition
30 import org.camunda.bpm.engine.delegate.DelegateExecution
31 import org.junit.Before
32 import org.junit.Ignore
35 import org.junit.runner.RunWith
36 import org.mockito.MockitoAnnotations
37 import org.mockito.runners.MockitoJUnitRunner
38 import org.onap.so.bpmn.common.scripts.MsoUtils
39 import org.onap.so.bpmn.core.WorkflowException
41 import com.github.tomakehurst.wiremock.junit.WireMockRule
42 import org.apache.commons.lang3.*
45 @RunWith(MockitoJUnitRunner.class)
46 class UpdateNetworkInstanceTest {
49 public WireMockRule wireMockRule = new WireMockRule(8090);
51 String Prefix="UPDNI_"
52 def utils = new MsoUtils()
54 String createDBRequestError =
55 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
58 <ns:updateInfraRequest xmlns:ns="http://org.onap.so/requestsdb">
59 <requestId>88f65519-9a38-4c4b-8445-9eb4a5a5af56</requestId>
60 <lastModifiedBy>BPMN</lastModifiedBy>
61 <statusMessage>Received error from SDN-C: No availability zone available</statusMessage>
62 <responseBody></responseBody>
63 <requestStatus>FAILED</requestStatus>
64 <vnfOutputs><network-id></network-id><network-name></network-names></vnfOutputs>
65 </ns:updateInfraRequest>
67 </soapenv:Envelope>"""
69 String falloutHandlerRequest =
70 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
71 xmlns:ns="http://org.onap/so/request/types/v1"
72 xmlns:wfsch="http://org.onap/so/workflow/schema/v1">
73 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
74 <request-id>b69c9054-da09-4a2c-adf5-51042b62bfac</request-id>
75 <action>UPDATE</action>
78 <aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
79 <aetgt:ErrorMessage>Received error from SDN-C: No availability zone available.</aetgt:ErrorMessage>
80 <aetgt:ErrorCode>5300</aetgt:ErrorCode>
81 </aetgt:WorkflowException>
82 </aetgt:FalloutHandlerRequest>"""
84 String completeMsoProcessRequest =
85 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
86 xmlns:ns="http://org.onap/so/request/types/v1"
87 xmlns="http://org.onap/so/infra/vnf-request/v1">
89 <request-id>88f65519-9a38-4c4b-8445-9eb4a5a5af56</request-id>
90 <action>UPDATE</action>
93 <aetgt:status-message>Network has been updated successfully.</aetgt:status-message>
94 <aetgt:mso-bpel-name>BPMN Network action: UPDATE</aetgt:mso-bpel-name>
95 </aetgt:MsoCompletionRequest>"""
98 String jsonIncomingRequest =
99 """{ "requestDetails": {
101 "modelType": "networkTyp",
102 "modelId": "modelId",
103 "modelNameVersionId": "modelNameVersionId",
104 "modelName": "CONTRAIL_EXTERNAL",
107 "cloudConfiguration": {
108 "lcpCloudRegionId": "RDM2WAGPLCP",
109 "tenantId": "7dd5365547234ee8937416c65507d266"
112 "instanceName": "MNS-25180-L-01-dmz_direct_net_1",
115 "suppressRollback": true,
116 "productFamilyId": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb"
118 "relatedInstanceList": [
121 "instanceId": "f70e927b-6087-4974-9ef8-c5e4d5847ca4",
123 "modelType": "serviceT",
125 "modelNameVersionId": "modelNameVersionI",
126 "modelName": "modleNam",
132 "requestParameters": {
135 "name": "someUserParam1",
136 "value": "someValue1"
145 MockitoAnnotations.initMocks(this)
148 public void initializeVariables(DelegateExecution mockExecution) {
150 verify(mockExecution).setVariable(Prefix + "source", "")
151 verify(mockExecution).setVariable(Prefix + "Success", false)
153 verify(mockExecution).setVariable(Prefix + "CompleteMsoProcessRequest", "")
154 verify(mockExecution).setVariable(Prefix + "FalloutHandlerRequest", "")
160 public void preProcessRequest() {
162 println "************ preProcessRequest() ************* "
163 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
164 // Initialize prerequisite variables
165 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
166 when(mockExecution.getVariable("bpmnRequest")).thenReturn(jsonIncomingRequest)
168 when(mockExecution.getVariable("mso.adapters.db.auth")).thenReturn("757A94191D685FD2092AC1490730A4FC")
169 when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7")
171 // preProcessRequest(DelegateExecution execution)
172 UpdateNetworkInstance UpdateNetworkInstance = new UpdateNetworkInstance()
173 UpdateNetworkInstance.preProcessRequest(mockExecution)
175 // verify(mockExecution).getVariable("isDebugLogEnabled")
176 verify(mockExecution).setVariable("prefix", Prefix)
178 initializeVariables(mockExecution)
179 //verify(mockExecution).setVariable(Prefix + "Success", false)
186 public void getNetworkModelInfo() {
188 println "************ getNetworkModelInfo() ************* "
190 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
191 // Initialize prerequisite variables
192 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
194 // preProcessRequest(DelegateExecution execution)
195 UpdateNetworkInstance UpdateNetworkInstance = new UpdateNetworkInstance()
196 UpdateNetworkInstance.getNetworkModelInfo(mockExecution)
198 // verify(mockExecution).getVariable("isDebugLogEnabled")
199 verify(mockExecution).setVariable("prefix", Prefix)
205 public void sendSyncResponse() {
207 println "************ sendSyncResponse ************* "
209 ExecutionEntity mockExecution = setupMock()
210 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
211 when(mockExecution.getVariable("isAsyncProcess")).thenReturn(true)
212 when(mockExecution.getVariable("mso-request-id")).thenReturn("e8ebf6a0-f8ea-4dc0-8b99-fe98a87722d6")
213 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4")
215 // preProcessRequest(DelegateExecution execution)
216 UpdateNetworkInstance UpdateNetworkInstance = new UpdateNetworkInstance()
217 UpdateNetworkInstance.sendSyncResponse(mockExecution)
219 verify(mockExecution).setVariable("prefix", Prefix)
220 verify(mockExecution).setVariable("UpdateNetworkInstanceResponseCode", "202")
226 public void sendSyncError() {
228 println "************ sendSyncError ************* "
230 ExecutionEntity mockExecution = setupMock()
231 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
232 when(mockExecution.getVariable("isAsyncProcess")).thenReturn(true)
233 when(mockExecution.getVariable("mso-request-id")).thenReturn("e8ebf6a0-f8ea-4dc0-8b99-fe98a87722d6")
234 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4")
236 UpdateNetworkInstance UpdateNetworkInstance = new UpdateNetworkInstance()
237 UpdateNetworkInstance.sendSyncError(mockExecution)
239 verify(mockExecution).setVariable("prefix", Prefix)
240 verify(mockExecution).setVariable("UpdateNetworkInstanceResponseCode", "500")
246 public void prepareCompletion() {
248 println "************ postProcessResponse ************* "
249 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
250 // Initialize prerequisite variables
251 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
252 when(mockExecution.getVariable("mso-request-id")).thenReturn("88f65519-9a38-4c4b-8445-9eb4a5a5af56")
253 when(mockExecution.getVariable(Prefix + "dbReturnCode")).thenReturn("200")
255 // postProcessResponse(DelegateExecution execution)
256 UpdateNetworkInstance UpdateNetworkInstance = new UpdateNetworkInstance()
257 UpdateNetworkInstance.prepareCompletion(mockExecution)
259 // check the sequence of variable invocation
260 //MockitoDebuggerImpl preDebugger = new MockitoDebuggerImpl()
261 //preDebugger.printInvocations(mockExecution)
263 verify(mockExecution).setVariable("prefix", Prefix)
264 verify(mockExecution).setVariable(Prefix + "Success", true)
265 verify(mockExecution).setVariable(Prefix + "CompleteMsoProcessRequest", completeMsoProcessRequest)
271 public void buildErrorResponse() {
273 println "************ buildErrorResponse ************* "
276 WorkflowException sndcWorkflowException = new WorkflowException("UpdateNetworkInstance", 5300, "Received error from SDN-C: No availability zone available.")
278 ExecutionEntity mockExecution = setupMock()
279 // Initialize prerequisite variables
280 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
281 when(mockExecution.getVariable("mso-request-id")).thenReturn("b69c9054-da09-4a2c-adf5-51042b62bfac")
282 //when(mockExecution.getVariable("WorkflowException")).thenReturn(sndcWorkflowException)
283 when(mockExecution.getVariable("WorkflowException")).thenReturn(sndcWorkflowException)
285 // buildErrorResponse(DelegateExecution execution)
286 UpdateNetworkInstance UpdateNetworkInstance = new UpdateNetworkInstance()
287 UpdateNetworkInstance.buildErrorResponse(mockExecution)
289 verify(mockExecution, atLeast(1)).setVariable("prefix", Prefix)
290 verify(mockExecution).setVariable(Prefix + "FalloutHandlerRequest", falloutHandlerRequest)
292 //MockitoDebuggerImpl debugger = new MockitoDebuggerImpl()
293 //debugger.printInvocations(mockExecution)
299 public void postProcessResponse() {
301 println "************ postProcessResponse() ************* "
302 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
303 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
304 when(mockExecution.getVariable("CMSO_ResponseCode")).thenReturn("200")
306 // postProcessResponse(DelegateExecution execution)
307 UpdateNetworkInstance UpdateNetworkInstance = new UpdateNetworkInstance()
308 UpdateNetworkInstance.postProcessResponse(mockExecution)
310 //verify(mockExecution).getVariable("isDebugLogEnabled")
311 //verify(mockExecution).setVariable("prefix", Prefix)
313 verify(mockExecution).setVariable(Prefix + "Success", true)
319 public void processRollbackData() {
321 println "************ callDBCatalog() ************* "
322 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
323 // Initialize prerequisite variables
324 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
326 // preProcessRequest(DelegateExecution execution)
327 UpdateNetworkInstance UpdateNetworkInstance = new UpdateNetworkInstance()
328 UpdateNetworkInstance.processRollbackData(mockExecution)
330 // verify(mockExecution).getVariable("isDebugLogEnabled")
331 verify(mockExecution).setVariable("prefix", Prefix)
335 private ExecutionEntity setupMock() {
337 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
338 when(mockProcessDefinition.getKey()).thenReturn("UpdateNetworkInstance")
339 RepositoryService mockRepositoryService = mock(RepositoryService.class)
340 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
341 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("UpdateNetworkInstance")
342 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
343 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
344 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
346 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
347 // Initialize prerequisite variables
349 when(mockExecution.getId()).thenReturn("100")
350 when(mockExecution.getProcessDefinitionId()).thenReturn("UpdateNetworkInstance")
351 when(mockExecution.getProcessInstanceId()).thenReturn("UpdateNetworkInstance")
352 when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
353 when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)