Dynamic Cloud Owner Support
[so.git] / bpmn / so-bpmn-infrastructure-common / src / test / groovy / org / onap / so / bpmn / vcpe / scripts / DeleteVcpeResCustServiceTest.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.onap.so.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.onap.so.bpmn.core.WorkflowException
35 import org.onap.so.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.patch
40 import static com.github.tomakehurst.wiremock.client.WireMock.put
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.MockGetAllottedResource
46 import org.onap.so.bpmn.core.domain.ServiceDecomposition
47 import org.onap.so.bpmn.core.domain.VnfResource
48 import org.onap.so.bpmn.core.domain.AllottedResource
49 import org.onap.so.bpmn.core.domain.ModelInfo
50
51 import org.onap.so.bpmn.core.RollbackData
52 import org.onap.so.bpmn.vcpe.scripts.MapGetter
53 import org.onap.so.bpmn.vcpe.scripts.MapSetter
54
55 import com.github.tomakehurst.wiremock.junit.WireMockRule
56
57 class DeleteVcpeResCustServiceTest extends GroovyTestBase {
58         
59         private static String request
60         
61         @Rule
62         public WireMockRule wireMockRule = new WireMockRule(PORT)
63
64         String Prefix = "DVRCS_"
65         String RbType = "DCRENI_"
66
67         @BeforeClass
68         public static void setUpBeforeClass() {
69                 request = FileUtil.readResourceFile("__files/VCPE/DeleteVcpeResCustService/request.json")
70         }
71           
72     @Before
73         public void init()
74         {
75                 MockitoAnnotations.initMocks(this)
76         }
77         
78         public DeleteVcpeResCustServiceTest() {
79                 super("DeleteVcpeResCustService")
80         }
81         
82         
83         // ***** preProcessRequest *****
84                         
85         @Test
86 //      @Ignore  
87         public void preProcessRequest() {
88                 ExecutionEntity mex = setupMock()
89                 def map = setupMap(mex)
90                 initPreProcess(mex)
91                 
92                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
93                 DeleteVcpeResCustService.preProcessRequest(mex)
94
95                 verify(mex).getVariable(DBGFLAG)
96                 
97                 assertEquals(Prefix, map.get("prefix"))
98                 assertEquals(request, map.get("DeleteVcpeResCustServiceRequest"))
99                 assertEquals("mri", map.get("msoRequestId"))
100                 assertEquals("ra", map.get("requestAction"))
101                 assertEquals("VID", map.get("source"))
102                 assertEquals(CUST, map.get("globalSubscriberId"))
103                 assertEquals(CUST, map.get("globalCustomerId"))
104                 assertEquals("false", map.get("disableRollback"))
105                 assertEquals("a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", map.get("productFamilyId"))
106                 assertEquals(SVC, map.get("subscriptionServiceType"))
107                 
108                 assertEquals("mdt1", map.get("lcpCloudRegionId"))
109                 assertEquals("8b1df54faa3b49078e3416e21370a3ba", map.get("tenantId"))
110                 assertEquals("1707", map.get("sdncVersion"))
111                 assertEquals("service-instance", map.get("GENGS_type"))
112                 assertEquals("""{"tenantId":"8b1df54faa3b49078e3416e21370a3ba","lcpCloudRegionId":"mdt1"}""", map.get("cloudConfiguration"))
113                 assertTrue(map.containsKey(Prefix+"requestInfo"))
114                 
115                 def reqinfo = map.get(Prefix+"requestInfo")
116                 assertTrue(reqinfo.indexOf("<request-id>mri</") >= 0)
117                 assertTrue(reqinfo.indexOf("<source>VID</") >= 0)
118         }
119                         
120         @Test
121 //      @Ignore  
122         public void preProcessRequest_EmptyParts() {
123                 ExecutionEntity mex = setupMock()
124                 def map = setupMap(mex)
125                 initPreProcess(mex)
126                 
127                 def req = request
128                                         .replace('"source"', '"sourceXXX"')
129                 
130                 when(mex.getVariable("bpmnRequest")).thenReturn(req)
131                 
132                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
133                 DeleteVcpeResCustService.preProcessRequest(mex)
134
135                 verify(mex).getVariable(DBGFLAG)
136                 verify(mex).setVariable("prefix", Prefix)
137                 verify(mex).setVariable("DeleteVcpeResCustServiceRequest", req)
138                 verify(mex).setVariable("msoRequestId", "mri")
139                 verify(mex).setVariable("requestAction", "ra")
140                 verify(mex).setVariable("source", "VID")
141                 verify(mex).setVariable("globalSubscriberId", CUST)
142                 verify(mex).setVariable("globalCustomerId", CUST)
143                 verify(mex).setVariable("disableRollback", "false")
144                 verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb")
145                 verify(mex).setVariable("subscriptionServiceType", SVC) 
146                 
147                 verify(mex).setVariable("lcpCloudRegionId", "mdt1")
148                 verify(mex).setVariable("cloudOwner", "my-cloud-owner")
149                 verify(mex).setVariable("tenantId", "8b1df54faa3b49078e3416e21370a3ba")
150                 assertEquals("""{"tenantId":"8b1df54faa3b49078e3416e21370a3ba","lcpCloudRegionId":"mdt1"}""", map.get("cloudConfiguration"))
151                 verify(mex).setVariable("sdncVersion", "1707")
152                 verify(mex).setVariable("GENGS_type", "service-instance")
153                 assertTrue(map.containsKey(Prefix+"requestInfo"))
154                 
155                 def reqinfo = map.get(Prefix+"requestInfo")
156                 println reqinfo
157                 assertTrue(reqinfo.indexOf("<request-id>mri</") >= 0)
158                 assertTrue(reqinfo.indexOf("<source>VID</") >= 0)
159         }
160                         
161         @Test
162 //      @Ignore  
163         public void preProcessRequest_MissingServiceInstanceId() {
164                 ExecutionEntity mex = setupMock()
165                 initPreProcess(mex)
166                 
167                 when(mex.getVariable("serviceInstanceId")).thenReturn(null)
168                 
169                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
170                 
171                 assertTrue(doBpmnError( { _ -> DeleteVcpeResCustService.preProcessRequest(mex) }))
172         }
173                         
174         @Test
175 //      @Ignore  
176         public void preProcessRequest_BpmnError() {
177                 ExecutionEntity mex = setupMock()
178                 initPreProcess(mex)
179                 
180                 when(mex.getVariable("bpmnRequest")).thenThrow(new BpmnError("expected exception"))
181                 
182                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
183                 
184                 assertTrue(doBpmnError( { _ -> DeleteVcpeResCustService.preProcessRequest(mex) }))
185         }
186                         
187         @Test
188 //      @Ignore  
189         public void preProcessRequest_Ex() {
190                 ExecutionEntity mex = setupMock()
191                 initPreProcess(mex)
192                 
193                 when(mex.getVariable("bpmnRequest")).thenThrow(new RuntimeException("expected exception"))
194                 
195                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
196                 
197                 assertTrue(doBpmnError( { _ -> DeleteVcpeResCustService.preProcessRequest(mex) }))
198         }
199         
200         private void initPreProcess(ExecutionEntity mex) {
201                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
202                 when(mex.getVariable("bpmnRequest")).thenReturn(request)
203                 when(mex.getVariable("mso-request-id")).thenReturn("mri")
204                 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
205                 when(mex.getVariable("requestAction")).thenReturn("ra")
206         }
207         
208         // ***** sendSyncResponse *****
209                         
210         @Test
211 //      @Ignore  
212         public void sendSyncResponse() {
213                 ExecutionEntity mex = setupMock()
214                 def map = setupMap(mex)
215                 initSendSyncResponse(mex)
216                 
217                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
218                 DeleteVcpeResCustService.sendSyncResponse(mex)
219
220                 verify(mex, times(2)).getVariable(DBGFLAG)
221                 
222                 verify(mex).setVariable(processName+"WorkflowResponseSent", "true")
223                 
224                 assertEquals("202", map.get(processName+"ResponseCode"))
225                 assertEquals("Success", map.get(processName+"Status"))
226                 
227                 def resp = map.get(processName+"Response")
228                 
229                 assertTrue(resp.indexOf('"instanceId":"sii"') >= 0)
230                 assertTrue(resp.indexOf('"requestId":"mri"') >= 0)
231         }
232                         
233         @Test
234 //      @Ignore  
235         public void sendSyncResponse_Ex() {
236                 ExecutionEntity mex = setupMock()
237                 initSendSyncResponse(mex)
238                 
239                 when(mex.getVariable("serviceInstanceId")).thenThrow(new RuntimeException("expected exception"))
240                 
241                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
242                 
243                 assertTrue(doBpmnError( { _ -> DeleteVcpeResCustService.sendSyncResponse(mex) }))
244         }
245         
246         private initSendSyncResponse(ExecutionEntity mex) {
247                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
248                 when(mex.getVariable("mso-request-id")).thenReturn("mri")
249                 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
250         }
251         
252         // ***** prepareServiceDelete *****
253                         
254         @Test
255 //      @Ignore  
256         public void prepareServiceDelete() {
257                 ExecutionEntity mex = setupMock()
258                 def map = setupMap(mex)
259                 initPrepareServiceDelete(mex)
260                 
261                 myMockGetAr("/aai/v11/anytxc", 200, "arGetTXCById.xml");
262                 myMockGetAr("/aai/v11/anybrg", 200, "arGetBRGById.xml");
263                 myMockGetAr("/aai/v11/other", 200, "arGetOtherById.xml");
264                 
265                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
266                 DeleteVcpeResCustService.prepareServiceDelete(mex)
267                 
268                 verify(mex).setVariable(Prefix+"TunnelXConn", true)
269                 assertEquals("ar-txcA", map.get("TXC_allottedResourceId"))
270                 
271                 verify(mex).setVariable(Prefix+"BRG", true)
272                 assertEquals("ar-brgB", map.get("BRG_allottedResourceId"))
273                 
274                 verify(mex).setVariable(Prefix+"vnfsCount", 2)
275                 assertNotNull(map.get(Prefix+"relatedVnfIdList"))
276                 assertEquals("[vnfX, vnfY]", map.get(Prefix+"relatedVnfIdList").toString())
277                 
278                 verify(mex, never()).setVariable(processName+"WorkflowResponseSent", "true")
279         }
280                         
281         @Test
282 //      @Ignore  
283         public void prepareServiceDelete_NotFound() {
284                 ExecutionEntity mex = setupMock()
285                 initPrepareServiceDelete(mex)
286                 
287                 when(mex.getVariable("GENGS_FoundIndicator")).thenReturn(false)
288                 
289                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
290                 
291                 assertTrue(doBpmnError({ _ -> DeleteVcpeResCustService.prepareServiceDelete(mex) }))
292                 
293                 verify(mex, never()).setVariable(processName+"WorkflowResponseSent", "true")
294         }
295                         
296         @Test
297 //      @Ignore  
298         public void prepareServiceDelete_Empty() {
299                 ExecutionEntity mex = setupMock()
300                 def map = setupMap(mex)
301                 initPrepareServiceDelete(mex)
302                 
303                 when(mex.getVariable("GENGS_service")).thenReturn("<empty></empty>")
304                 
305                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
306                 DeleteVcpeResCustService.prepareServiceDelete(mex)
307
308                 verify(mex).getVariable(DBGFLAG)
309                 
310                 verify(mex).setVariable(Prefix+"TunnelXConn", false)
311                 assertNull(map.get("TXC_allottedResourceId"))
312                 
313                 verify(mex).setVariable(Prefix+"BRG", false)
314                 assertNull(map.get("BRG_allottedResourceId"))
315                 
316                 assertEquals(0, map.get(Prefix+"vnfsCount"))
317                 assertFalse(map.containsKey(Prefix+"relatedVnfIdList"))
318                 
319                 verify(mex, never()).setVariable(processName+"WorkflowResponseSent", "true")
320         }
321                         
322         @Test
323 //      @Ignore  
324         public void prepareServiceDelete_BpmnError() {
325                 ExecutionEntity mex = setupMock()
326                 initPrepareServiceDelete(mex)
327                 
328                 when(mex.getVariable("GENGS_FoundIndicator")).thenThrow(new BpmnError("expected exception"))
329                 
330                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
331                 
332                 assertTrue(doBpmnError({ _ -> DeleteVcpeResCustService.prepareServiceDelete(mex) }))
333                 
334                 verify(mex, never()).setVariable(processName+"WorkflowResponseSent", "true")
335         }
336                         
337         @Test
338 //      @Ignore  
339         public void prepareServiceDelete_Ex() {
340                 ExecutionEntity mex = setupMock()
341                 initPrepareServiceDelete(mex)
342                 
343                 when(mex.getVariable("GENGS_FoundIndicator")).thenThrow(new RuntimeException("expected exception"))
344                 
345                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
346                 
347                 assertTrue(doBpmnError({ _ -> DeleteVcpeResCustService.prepareServiceDelete(mex) }))
348                 
349                 verify(mex).setVariable(processName+"WorkflowResponseSent", "true")
350         }
351         
352         private initPrepareServiceDelete(ExecutionEntity mex) {
353                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
354                 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
355                 when(mex.getVariable("GENGS_FoundIndicator")).thenReturn(true)
356                 when(mex.getVariable("mso-request-id")).thenReturn("mri")
357                 when(mex.getVariable("DeleteVcpeResCustServiceRequest")).thenReturn(request)
358                 when(mex.getVariable("URN_aai_endpoint")).thenReturn(aaiUriPfx)
359                 when(mex.getVariable("GENGS_service")).thenReturn(FileUtil.readResourceFile("__files/VCPE/DeleteVcpeResCustService/serviceToDelete.xml"))
360         }
361         
362         // ***** getAaiAr *****
363         
364         @Test
365 //      @Ignore
366         public void getAaiAr() {
367                 myMockGetAr("/myurl/ar1", 200, "arGetBRGById.xml");
368                 
369                 ExecutionEntity mex = setupMock()
370                 initGetAaiAr(mex)
371                                 
372                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
373                 def (type, id) = DeleteVcpeResCustService.getAaiAr(mex, "/myurl/ar1")
374                 
375                 assertEquals("BRG", type)
376                 assertEquals("ar-brgB", id)
377         }
378         
379         @Test
380 //      @Ignore
381         public void getAaiAr_401() {
382                 myMockGetAr("/myurl/ar1", 401, "arGetBRGById.xml");
383                 
384                 ExecutionEntity mex = setupMock()
385                 initGetAaiAr(mex)
386                                 
387                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
388                 def (type, id) = DeleteVcpeResCustService.getAaiAr(mex, "/myurl/ar1")
389                 
390                 assertEquals(null, type)
391                 assertEquals(null, id)
392         }
393         
394         @Test
395 //      @Ignore
396         public void getAaiAr_EmptyResponse() {
397                 myMockGetAr("/myurl/ar1", 200, "empty.txt");
398                 
399                 ExecutionEntity mex = setupMock()
400                 initGetAaiAr(mex)
401                                 
402                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
403                 def (type, id) = DeleteVcpeResCustService.getAaiAr(mex, "/myurl/ar1")
404                 
405                 assertEquals(null, type)
406                 assertEquals(null, id)
407         }
408         
409         private void initGetAaiAr(ExecutionEntity mex) {
410                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
411                 when(mex.getVariable("URN_aai_endpoint")).thenReturn(aaiUriPfx)
412         }
413         
414         // ***** prepareVnfAndModulesDelete *****
415                         
416         @Test
417 //      @Ignore  
418         public void prepareVnfAndModulesDelete() {
419                 ExecutionEntity mex = setupMock()
420                 initPrepareVnfAndModulesDelete(mex)
421                 
422                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
423                 DeleteVcpeResCustService.prepareVnfAndModulesDelete(mex)
424
425                 verify(mex).getVariable(DBGFLAG)
426                 
427                 verify(mex).setVariable("vnfId", "vnfB")
428         }
429                         
430         @Test
431 //      @Ignore  
432         public void prepareVnfAndModulesDelete_Empty() {
433                 ExecutionEntity mex = setupMock()
434                 initPrepareVnfAndModulesDelete(mex)
435                 
436                 when(mex.getVariable(Prefix+"relatedVnfIdList")).thenReturn(new LinkedList())
437                 
438                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
439                 DeleteVcpeResCustService.prepareVnfAndModulesDelete(mex)
440
441                 verify(mex).getVariable(DBGFLAG)
442                 
443                 verify(mex).setVariable("vnfId", "")
444         }
445                         
446         @Test
447 //      @Ignore  
448         public void prepareVnfAndModulesDelete_Ex() {
449                 ExecutionEntity mex = setupMock()
450                 initPrepareVnfAndModulesDelete(mex)
451                 
452                 when(mex.getVariable(Prefix+"relatedVnfIdList")).thenThrow(new RuntimeException("expected exception"))
453                 
454                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
455                 
456                 assertTrue(doBpmnError({ _ -> DeleteVcpeResCustService.prepareVnfAndModulesDelete(mex) }))
457         }
458         
459         private initPrepareVnfAndModulesDelete(ExecutionEntity mex) {
460                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
461                 when(mex.getVariable(Prefix+"relatedVnfIdList")).thenReturn(Arrays.asList("vnfA", "vnfB", "vnfC"))
462                 when(mex.getVariable(Prefix+"vnfsDeletedCount")).thenReturn(1)
463         }
464         
465         // ***** validateVnfDelete *****
466                         
467         @Test
468 //      @Ignore  
469         public void validateVnfDelete() {
470                 ExecutionEntity mex = setupMock()
471                 initValidateVnfDelete(mex)
472                 
473                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
474                 DeleteVcpeResCustService.validateVnfDelete(mex)
475
476                 verify(mex).getVariable(DBGFLAG)
477                 
478                 verify(mex).setVariable(Prefix+"vnfsDeletedCount", 3)
479         }
480                         
481         @Test
482 //      @Ignore  
483         public void validateVnfDelete_Ex() {
484                 ExecutionEntity mex = setupMock()
485                 initValidateVnfDelete(mex)
486                 
487                 when(mex.getVariable(Prefix+"vnfsDeletedCount")).thenThrow(new RuntimeException("expected exception"))
488                 
489                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
490                 
491                 assertTrue(doBpmnError({ _ -> DeleteVcpeResCustService.validateVnfDelete(mex) }))
492         }
493         
494         private initValidateVnfDelete(ExecutionEntity mex) {
495                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
496                 when(mex.getVariable(Prefix+"vnfsDeletedCount")).thenReturn(2)
497         }
498         
499         // ***** postProcessResponse *****
500                         
501         @Test
502 //      @Ignore  
503         public void postProcessResponse() {
504                 ExecutionEntity mex = setupMock()
505                 def map = setupMap(mex)
506                 initPostProcessResponse(mex)
507                 
508                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
509                 DeleteVcpeResCustService.postProcessResponse(mex)
510
511                 verify(mex).getVariable(DBGFLAG)
512                 
513                 assertEquals(true, map.get(Prefix+"Success"))
514                 
515                 def req = map.get(Prefix+"CompleteMsoProcessRequest")
516                 
517                 assertTrue(req.indexOf("<request-id>mri</") >= 0)
518                 assertTrue(req.indexOf("<source>mysrc</") >= 0)
519         }
520                         
521         @Test
522 //      @Ignore  
523         public void postProcessResponse_BpmnError() {
524                 ExecutionEntity mex = setupMock()
525                 initPostProcessResponse(mex)
526                 
527                 when(mex.getVariable("source")).thenThrow(new BpmnError("expected exception"))
528                 
529                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
530                 
531                 assertTrue(doBpmnError( { _ -> DeleteVcpeResCustService.postProcessResponse(mex) }))
532         }
533                         
534         @Test
535 //      @Ignore  
536         public void postProcessResponse_Ex() {
537                 ExecutionEntity mex = setupMock()
538                 initPostProcessResponse(mex)
539                 
540                 when(mex.getVariable("source")).thenThrow(new RuntimeException("expected exception"))
541                 
542                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
543                 
544                 assertTrue(doBpmnError( { _ -> DeleteVcpeResCustService.postProcessResponse(mex) }))
545         }
546         
547         private initPostProcessResponse(ExecutionEntity mex) {
548                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
549                 when(mex.getVariable("source")).thenReturn("mysrc")
550                 when(mex.getVariable("msoRequestId")).thenReturn("mri")
551         }
552         
553         
554         // ***** prepareFalloutRequest *****
555                         
556         @Test
557 //      @Ignore  
558         public void prepareFalloutRequest() {
559                 ExecutionEntity mex = setupMock()
560                 def map = setupMap(mex)
561                 initPrepareFalloutRequest(mex)
562                 
563                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
564                 DeleteVcpeResCustService.prepareFalloutRequest(mex)
565
566                 verify(mex, times(2)).getVariable(DBGFLAG)
567                 
568                 def fo = map.get(Prefix+"falloutRequest")
569                 
570                 assertTrue(fo.indexOf("<hello>world</") >= 0)
571                 assertTrue(fo.indexOf("ErrorMessage>mymsg</") >= 0)
572                 assertTrue(fo.indexOf("ErrorCode>999</") >= 0)
573         }
574                         
575         @Test
576 //      @Ignore  
577         public void prepareFalloutRequest_Ex() {
578                 ExecutionEntity mex = setupMock()
579                 def map = setupMap(mex)
580                 initPrepareFalloutRequest(mex)
581                 
582                 when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
583                 
584                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
585                 
586                 assertTrue(doBpmnError( { _ -> DeleteVcpeResCustService.prepareFalloutRequest(mex) }))
587         }
588         
589         private initPrepareFalloutRequest(ExecutionEntity mex) {
590                 WorkflowException wfe = mock(WorkflowException.class)
591                 
592                 when(wfe.getErrorMessage()).thenReturn("mymsg")
593                 when(wfe.getErrorCode()).thenReturn(999)
594                 
595                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
596                 when(mex.getVariable("WorkflowException")).thenReturn(wfe)
597                 when(mex.getVariable(Prefix+"requestInfo")).thenReturn("<hello>world</hello>")
598                 
599                 return wfe
600         }
601         
602         // ***** sendSyncError *****
603                         
604         @Test
605 //      @Ignore  
606         public void sendSyncError() {
607                 ExecutionEntity mex = setupMock()
608                 def map = setupMap(mex)
609                 initSendSyncError(mex)
610                 
611                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
612                 DeleteVcpeResCustService.sendSyncError(mex)
613
614                 verify(mex, times(2)).getVariable(DBGFLAG)
615                 
616                 verify(mex).setVariable(processName+"WorkflowResponseSent", "true")
617                 
618                 assertEquals("500", map.get(processName+"ResponseCode"))
619                 assertEquals("Fail", map.get(processName+"Status"))
620                 
621                 def resp = map.get(processName+"Response")
622                 
623                 assertTrue(resp.indexOf("ErrorMessage>mymsg</") >= 0)
624                 
625                 verify(mex).setVariable("WorkflowResponse", resp)
626         }
627                         
628         @Test
629 //      @Ignore  
630         public void sendSyncError_NotWfe() {
631                 ExecutionEntity mex = setupMock()
632                 def map = setupMap(mex)
633                 initSendSyncError(mex)
634                 
635                 when(mex.getVariable("WorkflowException")).thenReturn("not a WFE")
636                 
637                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
638                 DeleteVcpeResCustService.sendSyncError(mex)
639
640                 verify(mex, times(2)).getVariable(DBGFLAG)
641                 
642                 verify(mex).setVariable(processName+"WorkflowResponseSent", "true")
643                 
644                 assertEquals("500", map.get(processName+"ResponseCode"))
645                 assertEquals("Fail", map.get(processName+"Status"))
646                 
647                 def resp = map.get(processName+"Response")
648                 
649                 assertTrue(resp.indexOf("ErrorMessage>Sending Sync Error.</") >= 0)
650                 
651                 verify(mex).setVariable("WorkflowResponse", resp)
652         }
653                         
654         @Test
655 //      @Ignore  
656         public void sendSyncError_NullWfe() {
657                 ExecutionEntity mex = setupMock()
658                 def map = setupMap(mex)
659                 initSendSyncError(mex)
660                 
661                 when(mex.getVariable("WorkflowException")).thenReturn(null)
662                 
663                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
664                 DeleteVcpeResCustService.sendSyncError(mex)
665
666                 verify(mex, times(2)).getVariable(DBGFLAG)
667                 
668                 verify(mex).setVariable(processName+"WorkflowResponseSent", "true")
669                 
670                 assertEquals("500", map.get(processName+"ResponseCode"))
671                 assertEquals("Fail", map.get(processName+"Status"))
672                 
673                 def resp = map.get(processName+"Response")
674                 
675                 assertTrue(resp.indexOf("ErrorMessage>Sending Sync Error.</") >= 0)
676                 
677                 verify(mex).setVariable("WorkflowResponse", resp)
678         }
679                         
680         @Test
681 //      @Ignore  
682         public void sendSyncError_Ex() {
683                 ExecutionEntity mex = setupMock()
684                 def map = setupMap(mex)
685                 initSendSyncError(mex)
686                 
687                 when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
688                 
689                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
690                 
691                 DeleteVcpeResCustService.sendSyncError(mex)
692                 
693                 assertFalse(map.containsKey(processName+"ResponseCode"))
694         }
695         
696         private initSendSyncError(ExecutionEntity mex) {
697                 WorkflowException wfe = mock(WorkflowException.class)
698                 
699                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
700                 when(mex.getVariable("mso-request-id")).thenReturn("mri")
701                 when(mex.getVariable("WorkflowException")).thenReturn(wfe)
702                 
703                 when(wfe.getErrorMessage()).thenReturn("mymsg")
704         }
705         
706         
707         // ***** processJavaException *****
708                         
709         @Test
710 //      @Ignore  
711         public void processJavaException() {
712                 ExecutionEntity mex = setupMock()
713                 def map = setupMap(mex)
714                 initProcessJavaException(mex)
715                 
716                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
717                 
718                 assertTrue(doBpmnError( { _ -> DeleteVcpeResCustService.processJavaException(mex) }))
719
720                 verify(mex, times(2)).getVariable(DBGFLAG)
721                 
722                 verify(mex).setVariable("prefix", Prefix)
723                 
724                 def wfe = map.get("WorkflowException")
725                 
726                 assertEquals("Caught a Java Lang Exception", wfe.getErrorMessage())
727         }
728                         
729         @Test
730 //      @Ignore  
731         public void processJavaException_BpmnError() {
732                 ExecutionEntity mex = setupMock()
733                 def map = setupMap(mex)
734                 initProcessJavaException(mex)
735                 
736                 when(mex.getVariables()).thenThrow(new BpmnError("expected exception"))
737                 
738                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
739                 
740                 assertTrue(doBpmnError( { _ -> DeleteVcpeResCustService.processJavaException(mex) }))
741                 
742                 assertFalse(map.containsKey("WorkflowException"))
743         }
744                         
745         @Test
746 //      @Ignore  
747         public void processJavaException_Ex() {
748                 ExecutionEntity mex = setupMock()
749                 def map = setupMap(mex)
750                 initProcessJavaException(mex)
751                 
752                 when(mex.getVariables()).thenThrow(new RuntimeException("expected exception"))
753                 
754                 DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService()
755                 
756                 assertTrue(doBpmnError( { _ -> DeleteVcpeResCustService.processJavaException(mex) }))
757                 
758                 def wfe = map.get("WorkflowException")
759                 
760                 assertEquals("Exception in processJavaException method", wfe.getErrorMessage())
761         }
762         
763         private initProcessJavaException(ExecutionEntity mex) {
764                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
765         }
766         
767         private void myMockGetAr(String url, int status, String fileResp) {
768                 stubFor(get(urlMatching(url))
769                                 .willReturn(aResponse()
770                                                 .withStatus(status)
771                                                 .withHeader("Content-Type", "text/xml")
772                                                 .withBodyFile("VCPE/DeleteVcpeResCustService/" + fileResp)));
773         }
774 }