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