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