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