1 package org.openecomp.mso.bpmn.infrastructure.scripts
3 import static org.mockito.Mockito.*
5 import org.camunda.bpm.engine.delegate.BpmnError
6 import org.camunda.bpm.engine.ProcessEngineServices
7 import org.camunda.bpm.engine.RepositoryService
8 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
9 import org.camunda.bpm.engine.impl.pvm.process.ProcessDefinitionImpl
10 import org.camunda.bpm.engine.repository.ProcessDefinition
11 import org.camunda.bpm.engine.delegate.DelegateExecution;
\r
12 import org.mockito.MockitoAnnotations
13 import org.mockito.runners.MockitoJUnitRunner
14 import org.mockito.internal.debugging.MockitoDebuggerImpl
15 import org.openecomp.mso.bpmn.common.scripts.MsoUtils
16 import org.openecomp.mso.bpmn.core.WorkflowException
17 import org.junit.Before
18 import org.junit.Rule;
20 import org.junit.Ignore
21 import org.junit.runner.RunWith
23 import static org.junit.Assert.*;
25 import com.github.tomakehurst.wiremock.client.WireMock;
26 import com.github.tomakehurst.wiremock.junit.WireMockRule;
28 import java.util.HashMap;
30 import java.util.UUID;
31 import org.apache.commons.lang3.*
34 @RunWith(MockitoJUnitRunner.class)
35 class DoUpdateNetworkInstanceRollbackTest {
38 public WireMockRule wireMockRule = new WireMockRule(28090);
40 def utils = new MsoUtils()
41 String Prefix="UPDNETIR_"
44 String rollbackNetworkRequest =
45 """<NetworkAdapter:rollbackNetwork xmlns:NetworkAdapter="http://org.openecomp.mso/network">
47 <networkId>MNS-25180-L-01-dmz_direct_net_1/2c88a3a9-69b9-43a7-ada6-1aca577c3641</networkId>
48 <neutronNetworkId>c4f4e878-cde0-4b15-ae9a-bda857759cea</neutronNetworkId>
50 <networkType>CONTRAIL_EXTERNAL</networkType>
51 <networkCreated>true</networkCreated>
52 <tenantId>7dd5365547234ee8937416c65507d266</tenantId>
53 <cloudSiteId>RDM2WAGPLCP</cloudSiteId>
55 <requestId>1ef47428-cade-45bd-a103-0751e8b2deb0</requestId>
59 </NetworkAdapter:rollbackNetwork>"""
61 String rollbackActivateSDNCRequest =
62 """<aetgt:SDNCAdapterWorkflowRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
63 xmlns:ns5="http://org.openecomp/mso/request/types/v1"
64 xmlns:sdncadapter="http://org.openecomp.mso/workflow/sdnc/adapter/schema/v1">
65 <sdncadapter:RequestHeader>
66 <sdncadapter:RequestId>88f65519-9a38-4c4b-8445-9eb4a5a5af56</sdncadapter:RequestId>
67 <sdncadapter:SvcInstanceId>f70e927b-6087-4974-9ef8-c5e4d5847ca4</sdncadapter:SvcInstanceId>
68 <sdncadapter:SvcAction>rollback</sdncadapter:SvcAction>
69 <sdncadapter:SvcOperation>network-topology-operation</sdncadapter:SvcOperation>
70 <sdncadapter:CallbackUrl>sdncCallback</sdncadapter:CallbackUrl>
71 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
72 </sdncadapter:RequestHeader>
73 <aetgt:SDNCRequestData>
75 <request-id>88f65519-9a38-4c4b-8445-9eb4a5a5af56</request-id>
76 <request-action>CreateNetworkInstance</request-action>
81 </request-information>
83 <service-id>a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb</service-id>
84 <service-type>MSO-dev-service-type</service-type>
85 <service-instance-id>f70e927b-6087-4974-9ef8-c5e4d5847ca4</service-instance-id>
86 <subscriber-name>MSO_1610_dev</subscriber-name>
87 </service-information>
89 <network-id>8abc633a-810b-4ca5-8b3a-09511d13a2ce</network-id>
90 <network-type>CONTRAIL_EXTERNAL</network-type>
91 <onap-model-information>
92 <model-invariant-uuid>invariant-uuid</model-invariant-uuid>
93 <model-customization-uuid>customization-uuid</model-customization-uuid>
94 <model-uuid>uuid</model-uuid>
95 <model-version>version</model-version>
96 <model-name>CONTRAIL_EXTERNAL</model-name>
97 </onap-model-information>
98 </network-information>
99 <network-request-information>
100 <network-id>8abc633a-810b-4ca5-8b3a-09511d13a2ce</network-id>
101 <network-type>CONTRAIL_EXTERNAL</network-type>
102 <network-name>MNS-25180-L-01-dmz_direct_net_1</network-name>
103 <tenant>7dd5365547234ee8937416c65507d266</tenant>
104 <aic-cloud-region>RDM2WAGPLCP</aic-cloud-region>
105 </network-request-information>
106 </aetgt:SDNCRequestData>
107 </aetgt:SDNCAdapterWorkflowRequest>"""
109 String rollbackSDNCRequest =
110 """<aetgt:SDNCAdapterWorkflowRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
111 xmlns:ns5="http://org.openecomp/mso/request/types/v1"
112 xmlns:sdncadapter="http://org.openecomp.mso/workflow/sdnc/adapter/schema/v1">
113 <sdncadapter:RequestHeader>
114 <sdncadapter:RequestId>88f65519-9a38-4c4b-8445-9eb4a5a5af56</sdncadapter:RequestId>
115 <sdncadapter:SvcInstanceId>f70e927b-6087-4974-9ef8-c5e4d5847ca4</sdncadapter:SvcInstanceId>
116 <sdncadapter:SvcAction>rollback</sdncadapter:SvcAction>
117 <sdncadapter:SvcOperation>network-topology-operation</sdncadapter:SvcOperation>
118 <sdncadapter:CallbackUrl>sdncCallback</sdncadapter:CallbackUrl>
119 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
120 </sdncadapter:RequestHeader>
121 <aetgt:SDNCRequestData>
122 <request-information>
123 <request-id>88f65519-9a38-4c4b-8445-9eb4a5a5af56</request-id>
124 <request-action>CreateNetworkInstance</request-action>
129 </request-information>
130 <service-information>
131 <service-id>a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb</service-id>
132 <service-type>MSO-dev-service-type</service-type>
133 <service-instance-id>f70e927b-6087-4974-9ef8-c5e4d5847ca4</service-instance-id>
134 <subscriber-name>MSO_1610_dev</subscriber-name>
135 </service-information>
136 <network-information>
137 <network-id>8abc633a-810b-4ca5-8b3a-09511d13a2ce</network-id>
138 <network-type>CONTRAIL_EXTERNAL</network-type>
139 <onap-model-information>
140 <model-invariant-uuid>invariant-uuid</model-invariant-uuid>
141 <model-customization-uuid>customization-uuid</model-customization-uuid>
142 <model-uuid>uuid</model-uuid>
143 <model-version>version</model-version>
144 <model-name>CONTRAIL_EXTERNAL</model-name>
145 </onap-model-information>
146 </network-information>
147 <network-request-information>
148 <network-id>8abc633a-810b-4ca5-8b3a-09511d13a2ce</network-id>
149 <network-type>CONTRAIL_EXTERNAL</network-type>
150 <network-name>MNS-25180-L-01-dmz_direct_net_1</network-name>
151 <tenant>7dd5365547234ee8937416c65507d266</tenant>
152 <aic-cloud-region>RDM2WAGPLCP</aic-cloud-region>
153 </network-request-information>
154 </aetgt:SDNCRequestData>
155 </aetgt:SDNCAdapterWorkflowRequest>"""
163 MockitoAnnotations.initMocks(this)
167 public void initializeVariables (DelegateExecution mockExecution) {
\r
169 verify(mockExecution).setVariable(Prefix + "rollbackNetworkRequest", null)
170 verify(mockExecution).setVariable(Prefix + "rollbackSDNCRequest", null)
171 verify(mockExecution).setVariable(Prefix + "WorkflowException", null)
173 verify(mockExecution).setVariable(Prefix + "rollbackNetworkRequest", "")
174 verify(mockExecution).setVariable(Prefix + "rollbackNetworkResponse", "")
175 verify(mockExecution).setVariable(Prefix + "rollbackNetworkReturnCode", "")
177 verify(mockExecution).setVariable(Prefix + "rollbackSDNCRequest", "")
178 verify(mockExecution).setVariable(Prefix + "rollbackSDNCResponse", "")
179 verify(mockExecution).setVariable(Prefix + "rollbackSDNCReturnCode", "")
181 verify(mockExecution).setVariable(Prefix + "Success", false)
182 verify(mockExecution).setVariable(Prefix + "fullRollback", false)
189 public void preProcessRequest() {
191 println "************ preProcessRequest ************* "
193 WorkflowException workflowException = new WorkflowException("DoUpdateNetworkInstanceRollback", 2500, "Received error from Network Adapter: JBWEB000065: HTTP Status 500.")
194 Map<String, String> rollbackData = new HashMap<String, String>();
195 rollbackData.put("rollbackSDNCRequest", rollbackSDNCRequest)
196 rollbackData.put("rollbackNetworkRequest", rollbackNetworkRequest)
198 ExecutionEntity mockExecution = setupMock()
199 // Initialize prerequisite variables
200 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
201 when(mockExecution.getVariable("prefix")).thenReturn(Prefix + "")
202 when(mockExecution.getVariable("WorkflowException")).thenReturn(workflowException)
203 when(mockExecution.getVariable("rollbackData")).thenReturn(rollbackData)
204 when(mockExecution.getVariable("sdncVersion")).thenReturn("1610")
205 when(mockExecution.getVariable("URN_mso_adapters_po_auth")).thenReturn("3141634BF7E070AA289CF2892C986C0B")
206 when(mockExecution.getVariable("URN_mso_msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7")
208 when(mockExecution.getVariable("URN_mso_adapters_sdnc_endpoint")).thenReturn("http://localhost:28090/SDNCAdapter")
209 when(mockExecution.getVariable("URN_mso_adapters_network_rest_endpoint")).thenReturn("http://localhost:28090/networks/NetworkAdapter")
210 when(mockExecution.getVariable("URN_mso_adapters_sdnc_resource_endpoint")).thenReturn("http://localhost:28090/SDNCAdapterRpc")
213 // preProcessRequest(DelegateExecution execution)
\r
214 DoUpdateNetworkInstanceRollback DoUpdateNetworkInstanceRollback = new DoUpdateNetworkInstanceRollback()
215 DoUpdateNetworkInstanceRollback.preProcessRequest(mockExecution)
217 verify(mockExecution).getVariable("isDebugLogEnabled")
218 verify(mockExecution).setVariable("prefix", Prefix)
220 //verify variable initialization
221 initializeVariables(mockExecution)
228 public void validateRollbackResponses_Good() {
230 WorkflowException workflowException = new WorkflowException("DoUpdateNetworkInstanceRollback", 2500, "AAI Update Contrail Failed. Error 404.")
231 WorkflowException expectedWorkflowException = new WorkflowException("DoUpdateNetworkInstanceRollback", 2500, "AAI Update Contrail Failed. Error 404. + SNDC activate rollback completed. + PO Network rollback completed. + SNDC assign rollback completed.")
233 println "************ validateRollbackResponses_Good() ************* "
234 ExecutionEntity mockExecution = setupMock()
235 // Initialize prerequisite variables
236 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
237 when(mockExecution.getVariable("prefix")).thenReturn(Prefix + "")
238 when(mockExecution.getVariable(Prefix + "rollbackNetworkRequest")).thenReturn("Good")
239 when(mockExecution.getVariable(Prefix + "rollbackSDNCRequest")).thenReturn("Good")
240 when(mockExecution.getVariable(Prefix + "rollbackNetworkReturnCode")).thenReturn("200")
241 when(mockExecution.getVariable(Prefix + "rollbackNetworkResponse")).thenReturn("GoodResponse")
242 when(mockExecution.getVariable(Prefix + "rollbackSDNCReturnCode")).thenReturn("200")
243 when(mockExecution.getVariable(Prefix + "rollbackSDNCResponse")).thenReturn("GoodResponse")
244 when(mockExecution.getVariable(Prefix + "WorkflowException")).thenReturn(workflowException)
245 when(mockExecution.getVariable(Prefix + "fullRollback")).thenReturn(false)
247 DoUpdateNetworkInstanceRollback DoUpdateNetworkInstanceRollback = new DoUpdateNetworkInstanceRollback()
248 DoUpdateNetworkInstanceRollback.validateRollbackResponses(mockExecution)
250 // verify set prefix = Prefix + ""
251 verify(mockExecution, atLeast(1)).setVariable("prefix", Prefix)
252 verify(mockExecution, atLeast(1)).setVariable("rolledBack", true)
253 verify(mockExecution, atLeast(1)).setVariable("wasDeleted", true)
254 verify(mockExecution).setVariable("WorkflowException", refEq(expectedWorkflowException, any(WorkflowException.class)))
255 //verify(mockExecution).setVariable("WorkflowException", expectedWorkflowException)
260 public void validateRollbackResponses_FullRollback() {
262 Map<String, String> rollbackData = new HashMap<String, String>();
263 rollbackData.put("rollbackSDNCRequest", rollbackSDNCRequest)
264 rollbackData.put("rollbackNetworkRequest", rollbackNetworkRequest)
266 println "************ validateRollbackResponses_FullRollback() ************* "
267 ExecutionEntity mockExecution = setupMock()
268 // Initialize prerequisite variables
269 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
270 when(mockExecution.getVariable("prefix")).thenReturn(Prefix)
271 when(mockExecution.getVariable(Prefix + "rollbackNetworkRequest")).thenReturn("Good")
272 when(mockExecution.getVariable(Prefix + "rollbackSDNCRequest")).thenReturn("Good")
273 when(mockExecution.getVariable(Prefix + "rollbackNetworkReturnCode")).thenReturn("200")
274 when(mockExecution.getVariable(Prefix + "rollbackNetworkResponse")).thenReturn("GoodResponse")
275 when(mockExecution.getVariable(Prefix + "rollbackSDNCReturnCode")).thenReturn("200")
276 when(mockExecution.getVariable(Prefix + "rollbackSDNCResponse")).thenReturn("GoodResponse")
277 when(mockExecution.getVariable(Prefix + "WorkflowException")).thenReturn(null)
278 when(mockExecution.getVariable(Prefix + "fullRollback")).thenReturn(true)
279 when(mockExecution.getVariable("rollbackData")).thenReturn(rollbackData)
281 DoUpdateNetworkInstanceRollback DoUpdateNetworkInstanceRollback = new DoUpdateNetworkInstanceRollback()
282 DoUpdateNetworkInstanceRollback.validateRollbackResponses(mockExecution)
284 // verify set prefix = Prefix + ""
285 verify(mockExecution, atLeast(1)).setVariable("prefix", Prefix)
286 verify(mockExecution, atLeast(1)).setVariable("rollbackSuccessful", true)
287 verify(mockExecution, atLeast(1)).setVariable("rollbackError", false)
292 private ExecutionEntity setupMock() {
294 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
295 when(mockProcessDefinition.getKey()).thenReturn("DoUpdateNetworkInstanceRollback")
296 RepositoryService mockRepositoryService = mock(RepositoryService.class)
297 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
298 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("DoUpdateNetworkInstanceRollback")
299 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
300 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
301 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
303 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
304 // Initialize prerequisite variables
306 when(mockExecution.getId()).thenReturn("100")
307 when(mockExecution.getProcessDefinitionId()).thenReturn("DoUpdateNetworkInstanceRollback")
308 when(mockExecution.getProcessInstanceId()).thenReturn("DoUpdateNetworkInstanceRollback")
309 when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
310 when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)