replace all fixed wiremock ports
[so.git] / bpmn / so-bpmn-infrastructure-common / src / test / groovy / org / onap / so / bpmn / vcpe / scripts / DoCreateAllottedResourceBRGRollbackTest.groovy
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.bpmn.vcpe.scripts
24
25 import com.github.tomakehurst.wiremock.junit.WireMockRule
26 import org.camunda.bpm.engine.delegate.BpmnError
27 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
28 import org.junit.*
29 import org.mockito.MockitoAnnotations
30 import org.onap.so.bpmn.core.RollbackData
31
32 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse
33 import static com.github.tomakehurst.wiremock.client.WireMock.get
34 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching
35 import static org.junit.Assert.assertTrue
36 import static org.mockito.Mockito.*
37 import static org.onap.so.bpmn.mock.StubResponseAAI.*
38
39 class DoCreateAllottedResourceBRGRollbackTest extends GroovyTestBase {
40
41     @Rule
42     public WireMockRule wireMockRule = new WireMockRule(PORT)
43
44     String Prefix = "DCARBRGRB_"
45     String RbType = "DCARBRG_"
46
47     @BeforeClass
48     public static void setUpBeforeClass() {
49         GroovyTestBase.setUpBeforeClass()
50     }
51
52     @Before
53     public void init() {
54         MockitoAnnotations.initMocks(this)
55     }
56
57     public DoCreateAllottedResourceBRGRollbackTest() {
58         super("DoCreateAllottedResourceBRGRollback")
59     }
60
61     // ***** preProcessRequest *****
62
63     @Test
64     public void preProcessRequest() {
65         ExecutionEntity mex = setupMock()
66         initPreProcess(mex)
67
68         DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback()
69         DoCreateAllottedResourceBRGRollback.preProcessRequest(mex)
70
71         verify(mex).setVariable("prefix", Prefix)
72         verify(mex).setVariable("serviceInstanceId", "sii")
73         verify(mex).setVariable("parentServiceInstanceId", "psii")
74         verify(mex).setVariable("allottedResourceId", "myid")
75         verify(mex).setVariable("rollbackAAI", true)
76         verify(mex).setVariable("aaiARPath", "mypath")
77         verify(mex).setVariable("rollbackSDNC", true)
78         verify(mex).setVariable("deactivateSdnc", "myactivate")
79         verify(mex).setVariable("deleteSdnc", "mycreate")
80         verify(mex).setVariable("unassignSdnc", "true")
81         verify(mex).setVariable("sdncDeactivateRequest", "activatereq")
82         verify(mex).setVariable("sdncDeleteRequest", "createreq")
83         verify(mex).setVariable("sdncUnassignRequest", "assignreq")
84
85         verify(mex, never()).setVariable("skipRollback", true)
86     }
87
88     @Test
89     public void preProcessRequest_RollbackDisabled() {
90         ExecutionEntity mex = setupMock()
91         initPreProcess(mex)
92
93         when(mex.getVariable("disableRollback")).thenReturn("true")
94
95         DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback()
96         DoCreateAllottedResourceBRGRollback.preProcessRequest(mex)
97
98         verify(mex).setVariable("prefix", Prefix)
99         verify(mex).setVariable("serviceInstanceId", "sii")
100         verify(mex).setVariable("parentServiceInstanceId", "psii")
101         verify(mex).setVariable("allottedResourceId", "myid")
102         verify(mex).setVariable("rollbackAAI", true)
103         verify(mex).setVariable("aaiARPath", "mypath")
104         verify(mex).setVariable("rollbackSDNC", true)
105         verify(mex).setVariable("deactivateSdnc", "myactivate")
106         verify(mex).setVariable("deleteSdnc", "mycreate")
107         verify(mex).setVariable("unassignSdnc", "true")
108         verify(mex).setVariable("sdncDeactivateRequest", "activatereq")
109         verify(mex).setVariable("sdncDeleteRequest", "createreq")
110         verify(mex).setVariable("sdncUnassignRequest", "assignreq")
111
112         verify(mex).setVariable("skipRollback", true)
113     }
114
115     @Test
116     public void preProcessRequest_NoAAI() {
117         ExecutionEntity mex = setupMock()
118         def data = initPreProcess(mex)
119
120         when(mex.getVariable("rollbackAAI")).thenReturn(false)
121         data.put(RbType, "rollbackAAI", "false")
122
123         DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback()
124         DoCreateAllottedResourceBRGRollback.preProcessRequest(mex)
125
126         verify(mex).setVariable("prefix", Prefix)
127         verify(mex).setVariable("serviceInstanceId", "sii")
128         verify(mex).setVariable("parentServiceInstanceId", "psii")
129         verify(mex).setVariable("allottedResourceId", "myid")
130         verify(mex, never()).setVariable("rollbackAAI", true)
131         verify(mex, never()).setVariable("aaiARPath", "mypath")
132         verify(mex).setVariable("rollbackSDNC", true)
133         verify(mex).setVariable("deactivateSdnc", "myactivate")
134         verify(mex).setVariable("deleteSdnc", "mycreate")
135         verify(mex).setVariable("unassignSdnc", "true")
136         verify(mex).setVariable("sdncDeactivateRequest", "activatereq")
137         verify(mex).setVariable("sdncDeleteRequest", "createreq")
138         verify(mex).setVariable("sdncUnassignRequest", "assignreq")
139
140         verify(mex, never()).setVariable("skipRollback", true)
141     }
142
143     @Test
144     public void preProcessRequest_NoAssign() {
145         ExecutionEntity mex = setupMock()
146         def data = initPreProcess(mex)
147
148         when(mex.getVariable("rollbackSDNC")).thenReturn(false)
149         data.put(RbType, "rollbackSDNCassign", "false")
150
151         DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback()
152         DoCreateAllottedResourceBRGRollback.preProcessRequest(mex)
153
154         verify(mex).setVariable("prefix", Prefix)
155         verify(mex).setVariable("serviceInstanceId", "sii")
156         verify(mex).setVariable("parentServiceInstanceId", "psii")
157         verify(mex).setVariable("allottedResourceId", "myid")
158         verify(mex).setVariable("rollbackAAI", true)
159         verify(mex).setVariable("aaiARPath", "mypath")
160         verify(mex, never()).setVariable("rollbackSDNC", true)
161         verify(mex, never()).setVariable("deactivateSdnc", "myactivate")
162         verify(mex, never()).setVariable("deleteSdnc", "mycreate")
163         verify(mex, never()).setVariable("unassignSdnc", "true")
164         verify(mex, never()).setVariable("sdncDeactivateRequest", "activatereq")
165         verify(mex, never()).setVariable("sdncDeleteRequest", "createreq")
166         verify(mex, never()).setVariable("sdncUnassignRequest", "assignreq")
167
168         verify(mex, never()).setVariable("skipRollback", true)
169     }
170
171     @Test
172     public void preProcessRequest_NoAAI_NoAssign() {
173         ExecutionEntity mex = setupMock()
174         initPreProcess(mex)
175
176         when(mex.getVariable("rollbackAAI")).thenReturn(false)
177         when(mex.getVariable("rollbackSDNC")).thenReturn(false)
178
179         DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback()
180         DoCreateAllottedResourceBRGRollback.preProcessRequest(mex)
181
182         verify(mex).setVariable("skipRollback", true)
183     }
184
185     @Test
186     public void preProcessRequest_NoRbStructure() {
187         ExecutionEntity mex = setupMock()
188         initPreProcess(mex)
189
190         when(mex.getVariable("rollbackData")).thenReturn(new RollbackData())
191
192         DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback()
193         DoCreateAllottedResourceBRGRollback.preProcessRequest(mex)
194
195         verify(mex).setVariable("skipRollback", true)
196     }
197
198     @Test
199     public void preProcessRequest_NullRb() {
200         ExecutionEntity mex = setupMock()
201         initPreProcess(mex)
202
203         when(mex.getVariable("rollbackData")).thenReturn(null)
204
205         DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback()
206         DoCreateAllottedResourceBRGRollback.preProcessRequest(mex)
207
208         verify(mex).setVariable("skipRollback", true)
209     }
210
211     @Test
212     public void preProcessRequest_BpmnError() {
213         ExecutionEntity mex = setupMock()
214         initPreProcess(mex)
215
216         when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception"))
217
218         DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback()
219
220         assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRGRollback.preProcessRequest(mex) }))
221     }
222
223     @Test
224     public void preProcessRequest_Ex() {
225         ExecutionEntity mex = setupMock()
226         initPreProcess(mex)
227
228         when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception"))
229
230         DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback()
231
232         assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRGRollback.preProcessRequest(mex) }))
233     }
234
235     @Test
236     @Ignore
237     public void updateAaiAROrchStatus() {
238         ExecutionEntity mex = setupMock()
239         initUpdateAaiAROrchStatus(mex)
240
241         MockGetAllottedResource(wireMockRule, CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRGRollback/arGetById.xml")
242         MockPatchAllottedResource(wireMockRule, CUST, SVC, INST, ARID)
243
244         DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback()
245         DoCreateAllottedResourceBRGRollback.updateAaiAROrchStatus(mex, "success")
246     }
247
248     @Test
249     public void updateAaiAROrchStatus_EmptyResponse() {
250         ExecutionEntity mex = setupMock()
251         initUpdateAaiAROrchStatus(mex)
252
253         wireMockRule
254                 .stubFor(get(urlMatching("/aai/v[0-9]+/.*"))
255                 .willReturn(aResponse()
256                 .withStatus(200)))
257
258         DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback()
259
260         assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRGRollback.updateAaiAROrchStatus(mex, "success") }))
261     }
262
263     @Test
264     public void updateAaiAROrchStatus_NoArPath() {
265         ExecutionEntity mex = setupMock()
266         initUpdateAaiAROrchStatus(mex)
267
268         MockGetAllottedResource(wireMockRule, CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRGRollback/arGetById.xml")
269         MockPatchAllottedResource(wireMockRule, CUST, SVC, INST, ARID)
270
271         when(mex.getVariable("aaiARPath")).thenReturn(null)
272
273         DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback()
274
275         assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRGRollback.updateAaiAROrchStatus(mex, "success") }))
276     }
277
278     // ***** validateSDNCResp *****
279
280     @Test
281     public void validateSDNCResp() {
282         ExecutionEntity mex = setupMock()
283         initValidateSDNCResp(mex)
284         def resp = initValidateSDNCResp_Resp()
285
286         when(mex.getVariable(Prefix + "sdncResponseSuccess")).thenReturn(true)
287
288         DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback()
289
290         DoCreateAllottedResourceBRGRollback.validateSDNCResp(mex, resp, "create")
291
292         verify(mex).getVariable("WorkflowException")
293         verify(mex).getVariable("SDNCA_SuccessIndicator")
294     }
295
296     @Test
297     public void validateSDNCResp_Unsuccessful() {
298         ExecutionEntity mex = setupMock()
299         initValidateSDNCResp(mex)
300         def resp = initValidateSDNCResp_Resp()
301
302         when(mex.getVariable(Prefix + "sdncResponseSuccess")).thenReturn(false)
303
304         DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback()
305
306         assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRGRollback.validateSDNCResp(mex, resp, "create") }))
307     }
308
309     @Test
310     public void validateSDNCResp_BpmnError404() {
311         ExecutionEntity mex = setupMock()
312         initValidateSDNCResp(mex)
313         def resp = initValidateSDNCResp_Resp()
314         when(mex.getVariable(Prefix + "sdncResponseSuccess")).thenReturn(true)
315
316         when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("404", "expected exception"))
317
318         DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback()
319
320         DoCreateAllottedResourceBRGRollback.validateSDNCResp(mex, resp, "create")
321     }
322
323     @Test
324     public void validateSDNCResp_BpmnError() {
325         ExecutionEntity mex = setupMock()
326         initValidateSDNCResp(mex)
327         def resp = initValidateSDNCResp_Resp()
328         when(mex.getVariable(Prefix + "sdncResponseSuccess")).thenReturn(true)
329
330         when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception"))
331
332         DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback()
333
334         assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRGRollback.validateSDNCResp(mex, resp, "create") }))
335     }
336
337     @Test
338     public void validateSDNCResp_Ex() {
339         ExecutionEntity mex = setupMock()
340         initValidateSDNCResp(mex)
341         def resp = initValidateSDNCResp_Resp()
342         when(mex.getVariable(Prefix + "sdncResponseSuccess")).thenReturn(true)
343
344         when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
345
346         DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback()
347
348         assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRGRollback.validateSDNCResp(mex, resp, "create") }))
349     }
350
351     @Test
352     @Ignore
353     public void deleteAaiAR() {
354         ExecutionEntity mex = setupMock()
355         initDeleteAaiAR(mex)
356
357         MockGetAllottedResource(wireMockRule, CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRGRollback/arGetById.xml")
358         MockDeleteAllottedResource(wireMockRule, CUST, SVC, INST, ARID, VERS)
359
360         DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback()
361         DoCreateAllottedResourceBRGRollback.deleteAaiAR(mex)
362     }
363
364     @Test
365     public void deleteAaiAR_NoArPath() {
366         ExecutionEntity mex = setupMock()
367         initDeleteAaiAR(mex)
368
369         MockGetAllottedResource(wireMockRule, CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRGRollback/arGetById.xml")
370         MockDeleteAllottedResource(wireMockRule, CUST, SVC, INST, ARID, VERS)
371
372         when(mex.getVariable("aaiARPath")).thenReturn("")
373
374         DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback()
375
376         assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRGRollback.deleteAaiAR(mex) }))
377     }
378
379     @Test
380     public void deleteAaiAR_BpmnError() {
381         ExecutionEntity mex = setupMock()
382         initDeleteAaiAR(mex)
383
384         MockGetAllottedResource(wireMockRule, CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRGRollback/arGetById.xml")
385         MockDeleteAllottedResource(wireMockRule, CUST, SVC, INST, ARID, VERS)
386
387         when(mex.getVariable("aaiARPath")).thenThrow(new BpmnError("expected exception"))
388
389         DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback()
390
391         assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRGRollback.deleteAaiAR(mex) }))
392     }
393
394     @Test
395     public void deleteAaiAR_Ex() {
396         ExecutionEntity mex = setupMock()
397         initDeleteAaiAR(mex)
398
399         MockGetAllottedResource(wireMockRule, CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRGRollback/arGetById.xml")
400         MockDeleteAllottedResource(wireMockRule, CUST, SVC, INST, ARID, VERS)
401
402         when(mex.getVariable("aaiARPath")).thenThrow(new RuntimeException("expected exception"))
403
404         DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback()
405
406         assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRGRollback.deleteAaiAR(mex) }))
407     }
408
409     @Test
410     public void postProcessRequest() {
411         ExecutionEntity mex = setupMock()
412         initPostProcessRequest(mex)
413
414         DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback()
415         DoCreateAllottedResourceBRGRollback.postProcessRequest(mex)
416
417         verify(mex).setVariable("rollbackData", null)
418         verify(mex).setVariable("rolledBack", true)
419     }
420
421     @Test
422     public void postProcessRequest_RolledBack() {
423         ExecutionEntity mex = setupMock()
424         initPostProcessRequest(mex)
425
426         when(mex.getVariable("skipRollback")).thenReturn(true)
427
428         DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback()
429         DoCreateAllottedResourceBRGRollback.postProcessRequest(mex)
430
431         verify(mex).setVariable("rollbackData", null)
432         verify(mex, never()).setVariable("rolledBack", true)
433     }
434
435     @Test
436     public void postProcessRequest_BpmnError() {
437         ExecutionEntity mex = setupMock()
438         initPostProcessRequest(mex)
439
440         when(mex.getVariable("skipRollback")).thenThrow(new BpmnError("expected exception"))
441
442         DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback()
443         DoCreateAllottedResourceBRGRollback.postProcessRequest(mex)
444
445         verify(mex).setVariable("rollbackData", null)
446         verify(mex, never()).setVariable("rolledBack", true)
447     }
448
449     @Test
450     public void postProcessRequest_Ex() {
451         ExecutionEntity mex = setupMock()
452         initPostProcessRequest(mex)
453
454         when(mex.getVariable("skipRollback")).thenThrow(new RuntimeException("expected exception"))
455
456         DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback()
457         DoCreateAllottedResourceBRGRollback.postProcessRequest(mex)
458
459         verify(mex).setVariable("rollbackData", null)
460         verify(mex, never()).setVariable("rolledBack", true)
461     }
462
463     @Test
464     public void processRollbackException() {
465         ExecutionEntity mex = setupMock()
466         initProcessRollbackException(mex)
467
468         DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback()
469         DoCreateAllottedResourceBRGRollback.processRollbackException(mex)
470
471         verify(mex).setVariable("rollbackData", null)
472         verify(mex).setVariable("rolledBack", false)
473         verify(mex).setVariable("rollbackError", "Caught exception in AllottedResource Create Rollback")
474         verify(mex).setVariable("WorkflowException", null)
475     }
476
477     @Test
478     public void processRollbackException_BpmnError() {
479         ExecutionEntity mex = setupMock()
480         initProcessRollbackException(mex)
481
482         doThrow(new BpmnError("expected exception")).when(mex).setVariable("rollbackData", null)
483
484         DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback()
485         DoCreateAllottedResourceBRGRollback.processRollbackException(mex)
486     }
487
488     @Test
489     public void processRollbackException_Ex() {
490         ExecutionEntity mex = setupMock()
491         initProcessRollbackException(mex)
492
493         doThrow(new RuntimeException("expected exception")).when(mex).setVariable("rollbackData", null)
494
495         DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback()
496         DoCreateAllottedResourceBRGRollback.processRollbackException(mex)
497     }
498
499     @Test
500     public void processRollbackJavaException() {
501         ExecutionEntity mex = setupMock()
502         initProcessRollbackException(mex)
503
504         DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback()
505         DoCreateAllottedResourceBRGRollback.processRollbackJavaException(mex)
506
507         verify(mex).setVariable("rollbackData", null)
508         verify(mex).setVariable("rolledBack", false)
509         verify(mex).setVariable("rollbackError", "Caught Java exception in AllottedResource Create Rollback")
510         verify(mex, never()).setVariable("WorkflowException", null)
511     }
512
513     @Test
514     public void processRollbackJavaException_BpmnError() {
515         ExecutionEntity mex = setupMock()
516         initProcessRollbackException(mex)
517
518         doThrow(new BpmnError("expected exception")).when(mex).setVariable("rollbackData", null)
519
520         DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback()
521         DoCreateAllottedResourceBRGRollback.processRollbackJavaException(mex)
522     }
523
524     @Test
525     public void processRollbackJavaException_Ex() {
526         ExecutionEntity mex = setupMock()
527         initProcessRollbackException(mex)
528
529         doThrow(new RuntimeException("expected exception")).when(mex).setVariable("rollbackData", null)
530
531         DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback()
532         DoCreateAllottedResourceBRGRollback.processRollbackJavaException(mex)
533     }
534
535     private RollbackData initPreProcess(ExecutionEntity mex) {
536         def data = new RollbackData()
537
538         when(mex.getVariable(DBGFLAG)).thenReturn("true")
539         when(mex.getVariable("rollbackData")).thenReturn(data)
540         when(mex.getVariable("rollbackAAI")).thenReturn(true)
541         when(mex.getVariable("rollbackSDNC")).thenReturn(true)
542         when(mex.getVariable("disableRollback")).thenReturn("false")
543
544         data.put("SERVICEINSTANCE", "allottedResourceId", "myid")
545
546         data.put(RbType, "serviceInstanceId", "sii")
547         data.put(RbType, "parentServiceInstanceId", "psii")
548
549         data.put(RbType, "rollbackAAI", "true")
550         data.put(RbType, "aaiARPath", "mypath")
551
552         data.put(RbType, "rollbackSDNCassign", "true")
553         data.put(RbType, "rollbackSDNCactivate", "myactivate")
554         data.put(RbType, "rollbackSDNCcreate", "mycreate")
555         data.put(RbType, "sdncActivateRollbackReq", "activatereq")
556         data.put(RbType, "sdncCreateRollbackReq", "createreq")
557         data.put(RbType, "sdncAssignRollbackReq", "assignreq")
558
559         return data
560     }
561
562     private initUpdateAaiAROrchStatus(ExecutionEntity mex) {
563         when(mex.getVariable(DBGFLAG)).thenReturn("true")
564         when(mex.getVariable("aaiARPath")).thenReturn("/business/customers/customer/" + CUST + "/service-subscriptions/service-subscription/" + SVC + "/service-instances/service-instance/" + INST + "/allotted-resources/allotted-resource/" + ARID)
565         when(mex.getVariable("aai.endpoint")).thenReturn(aaiUriPfx)
566     }
567
568     private initValidateSDNCResp(ExecutionEntity mex) {
569         when(mex.getVariable(DBGFLAG)).thenReturn("true")
570         when(mex.getVariable("prefix")).thenReturn(Prefix)
571         when(mex.getVariable("SDNCA_SuccessIndicator")).thenReturn(true)
572     }
573
574     private String initValidateSDNCResp_Resp() {
575         return "<response-data>&lt;response-code&gt;200&lt;/response-code&gt;</response-data>"
576     }
577
578     private initDeleteAaiAR(ExecutionEntity mex) {
579         when(mex.getVariable(DBGFLAG)).thenReturn("true")
580         when(mex.getVariable("aaiARResourceVersion")).thenReturn(VERS)
581         when(mex.getVariable("aaiARPath")).thenReturn("/business/customers/customer/" + CUST + "/service-subscriptions/service-subscription/" + SVC + "/service-instances/service-instance/" + INST + "/allotted-resources/allotted-resource/" + ARID)
582         when(mex.getVariable("aai.endpoint")).thenReturn(aaiUriPfx)
583     }
584
585     private initPostProcessRequest(ExecutionEntity mex) {
586         when(mex.getVariable(DBGFLAG)).thenReturn("true")
587         when(mex.getVariable("skipRollback")).thenReturn(false)
588     }
589
590     private initProcessRollbackException(ExecutionEntity mex) {
591         when(mex.getVariable(DBGFLAG)).thenReturn("true")
592     }
593
594     private initProcessRollbackJavaException(ExecutionEntity mex) {
595         when(mex.getVariable(DBGFLAG)).thenReturn("true")
596     }
597
598 }