Merge "Remove unneeded script"
[so.git] / bpmn / MSOInfrastructureBPMN / src / test / groovy / org / openecomp / mso / bpmn / vcpe / scripts / CreateVcpeResCustServiceTest.groovy
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.openecomp.mso.bpmn.vcpe.scripts
21
22
23 import org.camunda.bpm.engine.ProcessEngineServices
24 import org.camunda.bpm.engine.RepositoryService
25 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
26 import org.camunda.bpm.engine.repository.ProcessDefinition
27 import org.junit.Before
28 import org.junit.BeforeClass
29 import org.junit.Rule
30 import org.junit.Test
31 import org.junit.Ignore
32 import org.mockito.MockitoAnnotations
33 import org.camunda.bpm.engine.delegate.BpmnError
34 import org.openecomp.mso.bpmn.core.WorkflowException
35 import org.openecomp.mso.bpmn.mock.FileUtil
36
37 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse
38 import static com.github.tomakehurst.wiremock.client.WireMock.get
39 import static com.github.tomakehurst.wiremock.client.WireMock.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.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetAllottedResource
46 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition
47 import org.openecomp.mso.bpmn.core.domain.VnfResource
48 import org.openecomp.mso.bpmn.core.domain.AllottedResource
49 import org.openecomp.mso.bpmn.core.domain.ModelInfo
50 import org.openecomp.mso.bpmn.core.domain.HomingSolution
51 import org.openecomp.mso.bpmn.core.RollbackData
52 import org.openecomp.mso.bpmn.vcpe.scripts.MapGetter
53 import org.openecomp.mso.bpmn.vcpe.scripts.MapSetter
54
55 import com.github.tomakehurst.wiremock.junit.WireMockRule
56
57 class CreateVcpeResCustServiceTest extends GroovyTestBase {
58         
59         private static String request
60         
61         @Rule
62         public WireMockRule wireMockRule = new WireMockRule(PORT)
63
64         String Prefix = "CVRCS_"
65         String RbType = "DCRENI_"
66
67         @BeforeClass
68         public static void setUpBeforeClass() {
69                 request = FileUtil.readResourceFile("__files/VCPE/CreateVcpeResCustService/request.json")
70         }
71           
72     @Before
73         public void init()
74         {
75                 MockitoAnnotations.initMocks(this)
76         }
77         
78         public CreateVcpeResCustServiceTest() {
79                 super("CreateVcpeResCustService")
80         }
81         
82         
83         // ***** preProcessRequest *****
84                         
85         @Test
86         @Ignore // 1802 merge
87         public void preProcessRequest() {
88                 ExecutionEntity mex = setupMock()
89                 def map = setupMap(mex)
90                 initPreProcess(mex)
91                 
92                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
93                 CreateVcpeResCustService.preProcessRequest(mex)
94
95                 verify(mex).getVariable(DBGFLAG)
96                 verify(mex).setVariable("prefix", Prefix)
97                 verify(mex).setVariable("aaiDistDelay", "aaidelay")
98                 verify(mex).setVariable("createVcpeServiceRequest", request)
99                 verify(mex).setVariable("msoRequestId", "mri")
100                 assertEquals("sii", map.get("serviceInstanceId"))
101                 verify(mex).setVariable("requestAction", "ra")
102                 verify(mex).setVariable("source", "VID")
103                 verify(mex).setVariable("globalSubscriberId", CUST)
104                 verify(mex).setVariable("globalCustomerId", CUST)
105                 verify(mex).setVariable("subscriptionServiceType", SVC)
106                 verify(mex).setVariable("disableRollback", "false")
107                 verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb")              
108                 assertTrue(map.containsKey("subscriberInfo"))
109                 
110                 verify(mex).setVariable("brgWanMacAddress", "brgmac")
111                 verify(mex).setVariable("customerLocation", ["customerLatitude":"32.897480", "customerLongitude":"-97.040443", "customerName":"some_company"])
112                 assertTrue(map.containsKey("serviceInputParams"))
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_MissingAaiDistDelay() {
123                 ExecutionEntity mex = setupMock()
124                 def map = setupMap(mex)
125                 initPreProcess(mex)
126                 
127                 when(mex.getVariable("URN_mso_workflow_aai_distribution_delay")).thenReturn(null)
128                 
129                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
130                 
131                 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.preProcessRequest(mex) }))
132         }
133                         
134         @Test
135         @Ignore // 1802 merge
136         public void preProcessRequest_EmptyParts() {
137                 ExecutionEntity mex = setupMock()
138                 def map = setupMap(mex)
139                 initPreProcess(mex)
140                 
141                 def req = request
142                                         .replace('"source"', '"sourceXXX"')
143                                         .replace('"BRG_WAN_MAC_Address"', '"BRG_WAN_MAC_AddressXXX"')
144                                         .replace('"Customer_Location"', '"Customer_LocationXXX"')
145                 
146                 when(mex.getVariable("bpmnRequest")).thenReturn(req)
147                 when(mex.getVariable("serviceInstanceId")).thenReturn(null)
148                 
149                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
150                 CreateVcpeResCustService.preProcessRequest(mex)
151
152                 verify(mex).getVariable(DBGFLAG)
153                 verify(mex).setVariable("prefix", Prefix)
154                 verify(mex).setVariable("createVcpeServiceRequest", req)
155                 verify(mex).setVariable("msoRequestId", "mri")
156                 assertNotNull(map.get("serviceInstanceId"))
157                 assertFalse(map.get("serviceInstanceId").isEmpty())
158                 verify(mex).setVariable("requestAction", "ra")
159                 verify(mex).setVariable("source", "VID")
160                 verify(mex).setVariable("globalSubscriberId", CUST)
161                 verify(mex).setVariable("globalCustomerId", CUST)
162                 verify(mex).setVariable("subscriptionServiceType", SVC)
163                 verify(mex).setVariable("disableRollback", "false")
164                 verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb")
165                 assertTrue(map.containsKey("subscriberInfo"))
166                 
167                 assertEquals("", map.get("brgWanMacAddress"))
168                 assertEquals("", map.get("customerLocation"))
169                 assertTrue(map.containsKey("serviceInputParams"))
170                 assertTrue(map.containsKey(Prefix+"requestInfo"))
171                 
172                 def reqinfo = map.get(Prefix+"requestInfo")
173                 println reqinfo
174                 assertTrue(reqinfo.indexOf("<request-id>mri</") >= 0)
175                 assertTrue(reqinfo.indexOf("<source>VID</") >= 0)
176         }
177                         
178         @Test
179         // @Ignore  
180         public void preProcessRequest_MissingSubscriberId() {
181                 ExecutionEntity mex = setupMock()
182                 def map = setupMap(mex)
183                 initPreProcess(mex)
184                 
185                 def req = request
186                                         .replace('"globalSubscriberId"', '"globalSubscriberIdXXX"')
187                 
188                 when(mex.getVariable("bpmnRequest")).thenReturn(req)
189                 when(mex.getVariable("serviceInstanceId")).thenReturn(null)
190                 
191                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
192                 
193                 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.preProcessRequest(mex) }))
194         }
195                         
196         @Test
197         // @Ignore  
198         public void preProcessRequest_BpmnError() {
199                 ExecutionEntity mex = setupMock()
200                 initPreProcess(mex)
201                 
202                 when(mex.getVariable("bpmnRequest")).thenThrow(new BpmnError("expected exception"))
203                 
204                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
205                 
206                 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.preProcessRequest(mex) }))
207         }
208                         
209         @Test
210         // @Ignore  
211         public void preProcessRequest_Ex() {
212                 ExecutionEntity mex = setupMock()
213                 initPreProcess(mex)
214                 
215                 when(mex.getVariable("bpmnRequest")).thenThrow(new RuntimeException("expected exception"))
216                 
217                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
218                 
219                 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.preProcessRequest(mex) }))
220         }
221         
222         // ***** sendSyncResponse *****
223                         
224         @Test
225         // @Ignore  
226         public void sendSyncResponse() {
227                 ExecutionEntity mex = setupMock()
228                 def map = setupMap(mex)
229                 initSendSyncResponse(mex)
230                 
231                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
232                 CreateVcpeResCustService.sendSyncResponse(mex)
233
234                 verify(mex, times(2)).getVariable(DBGFLAG)
235                 
236                 verify(mex).setVariable(processName+"WorkflowResponseSent", "true")
237                 
238                 assertEquals("202", map.get(processName+"ResponseCode"))
239                 assertEquals("Success", map.get(processName+"Status"))
240                 
241                 def resp = map.get(processName+"Response")
242                 
243                 assertTrue(resp.indexOf('"instanceId":"sii"') >= 0)
244                 assertTrue(resp.indexOf('"requestId":"mri"') >= 0)
245         }
246                         
247         @Test
248         // @Ignore  
249         public void sendSyncResponse_Ex() {
250                 ExecutionEntity mex = setupMock()
251                 initSendSyncResponse(mex)
252                 
253                 when(mex.getVariable("serviceInstanceId")).thenThrow(new RuntimeException("expected exception"))
254                 
255                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
256                 
257                 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.sendSyncResponse(mex) }))
258         }
259         
260         
261         // ***** prepareDecomposeService *****
262                         
263         @Test
264         // @Ignore  
265         public void prepareDecomposeService() {
266                 ExecutionEntity mex = setupMock()
267                 initPrepareDecomposeService(mex)
268                 
269                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
270                 CreateVcpeResCustService.prepareDecomposeService(mex)
271
272                 verify(mex).getVariable(DBGFLAG)
273                 verify(mex).setVariable("serviceModelInfo", "mi")
274         }
275                         
276         @Test
277         // @Ignore  
278         public void prepareDecomposeService_Ex() {
279                 ExecutionEntity mex = setupMock()
280                 initPrepareDecomposeService(mex)
281                 
282                 when(mex.getVariable("createVcpeServiceRequest")).thenThrow(new RuntimeException("expected exception"))
283                 
284                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
285                 
286                 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.prepareDecomposeService(mex) }))
287         }
288         
289         
290         // ***** prepareCreateServiceInstance *****
291                         
292         @Test
293         // @Ignore  
294         public void prepareCreateServiceInstance() {
295                 ExecutionEntity mex = setupMock()
296                 initPrepareCreateServiceInstance(mex)
297                 
298                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
299                 CreateVcpeResCustService.prepareCreateServiceInstance(mex)
300
301                 verify(mex).getVariable(DBGFLAG)
302                 verify(mex).setVariable("serviceInstanceName", "VCPE1")
303                 verify(mex).setVariable("serviceDecompositionString", "mydecomp")
304         }
305                         
306         @Test
307         // @Ignore  
308         public void prepareCreateServiceInstance_Ex() {
309                 ExecutionEntity mex = setupMock()
310                 initPrepareCreateServiceInstance(mex)
311                 
312                 when(mex.getVariable("createVcpeServiceRequest")).thenThrow(new RuntimeException("expected exception"))
313                 
314                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
315                 
316                 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.prepareCreateServiceInstance(mex) }))
317         }
318         
319         
320         // ***** postProcessServiceInstanceCreate *****
321                         
322         @Test
323         // @Ignore  
324         public void postProcessServiceInstanceCreate() {
325                 ExecutionEntity mex = setupMock()
326                 def map = setupMap(mex)
327                 initPostProcessServiceInstanceCreate(mex)
328                 
329                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
330                 CreateVcpeResCustService.postProcessServiceInstanceCreate(mex)
331
332                 verify(mex).getVariable(DBGFLAG)
333                 
334                 def reqinfo = map.get(Prefix+"setUpdateDbInstancePayload")
335                 
336                 assertTrue(reqinfo.indexOf("<requestId>mri</") >= 0)
337                 assertTrue(reqinfo.indexOf("<serviceInstanceId>sii</") >= 0)
338                 assertTrue(reqinfo.indexOf("<serviceInstanceName>sin</") >= 0)
339         }
340                         
341         @Test
342         // @Ignore  
343         public void postProcessServiceInstanceCreate_BpmnError() {
344                 ExecutionEntity mex = setupMock()
345                 initPostProcessServiceInstanceCreate(mex)
346                 
347                 doThrow(new BpmnError("expected exception")).when(mex).setVariable(endsWith("setUpdateDbInstancePayload"), any())
348                 
349                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
350                 
351                 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.postProcessServiceInstanceCreate(mex) }))
352         }
353                         
354         @Test
355         // @Ignore  
356         public void postProcessServiceInstanceCreate_Ex() {
357                 ExecutionEntity mex = setupMock()
358                 initPostProcessServiceInstanceCreate(mex)
359                 
360                 doThrow(new RuntimeException("expected exception")).when(mex).setVariable(endsWith("setUpdateDbInstancePayload"), any())
361                 
362                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
363                 
364                 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.postProcessServiceInstanceCreate(mex) }))
365         }
366         
367         
368         // ***** processDecomposition *****
369                         
370         @Test
371         // @Ignore  
372         public void processDecomposition() {
373                 ExecutionEntity mex = setupMock()
374                 def svcdecomp = initProcessDecomposition(mex)
375                 
376                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
377                 CreateVcpeResCustService.processDecomposition(mex)
378
379                 verify(mex).getVariable(DBGFLAG)
380                 
381                 verify(mex).setVariable("vnfList", svcdecomp.getServiceVnfs())
382                 verify(mex).setVariable("vnfListString", '[myvnf]')
383                 verify(mex).setVariable(Prefix+"VNFsCount", 1)
384                 
385                 verify(mex).setVariable("vnfModelInfo", "mymodel")
386                 verify(mex).setVariable("vnfModelInfoString", "mymodel")
387         }
388                         
389         @Test
390         // @Ignore  
391         public void processDecomposition_EmptyNet_EmptyVnf() {
392                 ExecutionEntity mex = setupMock()
393                 def svcdecomp = initProcessDecomposition(mex)
394                 
395                 when(svcdecomp.getServiceVnfs()).thenReturn(new LinkedList<VnfResource>())
396                 
397                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
398                 CreateVcpeResCustService.processDecomposition(mex)
399
400                 verify(mex).getVariable(DBGFLAG)
401                 
402                 verify(mex).setVariable("vnfList", svcdecomp.getServiceVnfs())
403                 verify(mex).setVariable("vnfListString", '[]')
404                 verify(mex).setVariable(Prefix+"VNFsCount", 0)
405                 
406                 verify(mex).setVariable("vnfModelInfo", "")
407                 verify(mex).setVariable("vnfModelInfoString", "")
408         }
409                         
410         @Test
411         // @Ignore  
412         public void processDecomposition_Ex() {
413                 ExecutionEntity mex = setupMock()
414                 def svcdecomp = initProcessDecomposition(mex)
415                 
416                 when(svcdecomp.getServiceVnfs()).thenThrow(new RuntimeException("expected exception"))
417                 
418                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
419                 
420                 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.processDecomposition(mex) }))
421         }
422         
423         
424         // ***** filterVnfs *****
425                         
426         @Test
427         // @Ignore  
428         public void filterVnfs() {
429                 ExecutionEntity mex = setupMock()
430                 def svcdecomp = initFilterVnfs(mex)
431                 
432                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
433                 CreateVcpeResCustService.processDecomposition(mex)
434                 
435                 verify(mex).setVariable("vnfListString", '[myvnf3, myvnf5]')
436         }
437                         
438         @Test
439         // @Ignore  
440         public void filterVnfs_Null() {
441                 ExecutionEntity mex = setupMock()
442                 def svcdecomp = initFilterVnfs(mex)
443                 
444                 when(svcdecomp.getServiceVnfs()).thenReturn(null)
445                 
446                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
447                 CreateVcpeResCustService.processDecomposition(mex)
448                 
449                 // nothing more to check, as long as it didn't throw an exception
450         }
451         
452         
453         // ***** prepareCreateAllottedResourceTXC *****
454                         
455         @Test
456         // @Ignore  
457         public void prepareCreateAllottedResourceTXC() {
458                 ExecutionEntity mex = setupMock()
459                 initPrepareCreateAllottedResourceTXC(mex)
460                 
461                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
462                 CreateVcpeResCustService.prepareCreateAllottedResourceTXC(mex)
463
464                 verify(mex).getVariable(DBGFLAG)
465                 
466                 verify(mex).setVariable("createTXCAR", true)
467                 verify(mex).setVariable("allottedResourceModelInfoTXC", "modelB")
468                 verify(mex).setVariable("allottedResourceRoleTXC", "TXCr")
469                 verify(mex).setVariable("allottedResourceTypeTXC", "TunnelXConn")
470                 verify(mex).setVariable("parentServiceInstanceIdTXC", "homeB")
471         }
472                         
473         @Test
474         // @Ignore  
475         public void prepareCreateAllottedResourceTXC_NullArList() {
476                 ExecutionEntity mex = setupMock()
477                 def svcdecomp = initPrepareCreateAllottedResourceTXC(mex)
478                 
479                 when(svcdecomp.getServiceAllottedResources()).thenReturn(null)
480                 
481                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
482                 CreateVcpeResCustService.prepareCreateAllottedResourceTXC(mex)
483
484                 verify(mex).getVariable(DBGFLAG)
485                 
486                 verify(mex, never()).setVariable("createTXCAR", true)
487                 verify(mex, never()).setVariable("allottedResourceModelInfoTXC", "modelB")
488                 verify(mex, never()).setVariable("allottedResourceRoleTXC", "TXCr")
489                 verify(mex, never()).setVariable("allottedResourceTypeTXC", "TunnelXConn")
490                 verify(mex, never()).setVariable("parentServiceInstanceIdTXC", "homeB")
491         }
492                         
493         @Test
494         // @Ignore  
495         public void prepareCreateAllottedResourceTXC_Ex() {
496                 ExecutionEntity mex = setupMock()
497                 initPrepareCreateAllottedResourceTXC(mex)
498                 
499                 when(mex.getVariable("createVcpeServiceRequest")).thenThrow(new RuntimeException("expected exception"))
500                 
501                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
502                 
503                 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.prepareCreateAllottedResourceTXC(mex) }))
504         }
505         
506         
507         // ***** prepareCreateAllottedResourceBRG *****
508                         
509         @Test
510         // @Ignore  
511         public void prepareCreateAllottedResourceBRG() {
512                 ExecutionEntity mex = setupMock()
513                 initPrepareCreateAllottedResourceBRG(mex)
514                 
515                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
516                 CreateVcpeResCustService.prepareCreateAllottedResourceBRG(mex)
517
518                 verify(mex).getVariable(DBGFLAG)
519                 
520                 verify(mex).setVariable("createBRGAR", true)
521                 verify(mex).setVariable("allottedResourceModelInfoBRG", "modelB")
522                 verify(mex).setVariable("allottedResourceRoleBRG", "BRGr")
523                 verify(mex).setVariable("allottedResourceTypeBRG", "BRG")
524                 verify(mex).setVariable("parentServiceInstanceIdBRG", "homeB")
525         }
526                         
527         @Test
528         // @Ignore  
529         public void prepareCreateAllottedResourceBRG_NullArList() {
530                 ExecutionEntity mex = setupMock()
531                 def svcdecomp = initPrepareCreateAllottedResourceBRG(mex)
532                 
533                 when(svcdecomp.getServiceAllottedResources()).thenReturn(null)
534                 
535                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
536                 CreateVcpeResCustService.prepareCreateAllottedResourceBRG(mex)
537
538                 verify(mex).getVariable(DBGFLAG)
539                 
540                 verify(mex, never()).setVariable("createBRGAR", true)
541                 verify(mex, never()).setVariable("allottedResourceModelInfoBRG", "modelB")
542                 verify(mex, never()).setVariable("allottedResourceRoleBRG", "BRGr")
543                 verify(mex, never()).setVariable("allottedResourceTypeBRG", "BRG")
544                 verify(mex, never()).setVariable("parentServiceInstanceIdBRG", "homeB")
545         }
546                         
547         @Test
548         // @Ignore  
549         public void prepareCreateAllottedResourceBRG_Ex() {
550                 ExecutionEntity mex = setupMock()
551                 initPrepareCreateAllottedResourceBRG(mex)
552                 
553                 when(mex.getVariable("createVcpeServiceRequest")).thenThrow(new RuntimeException("expected exception"))
554                 
555                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
556                 
557                 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.prepareCreateAllottedResourceBRG(mex) }))
558         }
559         
560         
561         // ***** prepareVnfAndModulesCreate *****
562                         
563         @Test
564         // @Ignore  
565         public void prepareVnfAndModulesCreate() {
566                 ExecutionEntity mex = setupMock()
567                 initPrepareVnfAndModulesCreate(mex)
568                 
569                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
570                 CreateVcpeResCustService.prepareVnfAndModulesCreate(mex)
571
572                 verify(mex).getVariable(DBGFLAG)
573                 
574                 verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb")
575                 verify(mex).setVariable("lcpCloudRegionId", "mdt1")
576                 verify(mex).setVariable("tenantId", "8b1df54faa3b49078e3416e21370a3ba")
577         }
578                         
579         @Test
580         // @Ignore  
581         public void prepareVnfAndModulesCreate_EmptyList() {
582                 ExecutionEntity mex = setupMock()
583                 initPrepareVnfAndModulesCreate(mex)
584                 
585                 when(mex.getVariable("vnfList")).thenReturn(new LinkedList<VnfResource>())
586                 
587                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
588                 CreateVcpeResCustService.prepareVnfAndModulesCreate(mex)
589
590                 verify(mex).getVariable(DBGFLAG)
591                 
592                 verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb")
593                 verify(mex).setVariable("lcpCloudRegionId", "mdt1")
594                 verify(mex).setVariable("tenantId", "8b1df54faa3b49078e3416e21370a3ba")
595         }
596                         
597         @Test
598         // @Ignore  
599         public void prepareVnfAndModulesCreate_NullList() {
600                 ExecutionEntity mex = setupMock()
601                 initPrepareVnfAndModulesCreate(mex)
602                 
603                 when(mex.getVariable("vnfList")).thenReturn(null)
604                 
605                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
606                 CreateVcpeResCustService.prepareVnfAndModulesCreate(mex)
607
608                 verify(mex).getVariable(DBGFLAG)
609                 
610                 verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb")
611                 verify(mex).setVariable("lcpCloudRegionId", "mdt1")
612                 verify(mex).setVariable("tenantId", "8b1df54faa3b49078e3416e21370a3ba")
613         }
614                         
615         @Test
616         // @Ignore  
617         public void prepareVnfAndModulesCreate_Ex() {
618                 ExecutionEntity mex = setupMock()
619                 initPrepareVnfAndModulesCreate(mex)
620                 
621                 when(mex.getVariable("vnfList")).thenThrow(new RuntimeException("expected exception"))
622                 
623                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
624                 
625                 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.prepareVnfAndModulesCreate(mex) }))
626         }
627         
628         
629         // ***** validateVnfCreate *****
630                         
631         @Test
632         // @Ignore  
633         public void validateVnfCreate() {
634                 ExecutionEntity mex = setupMock()
635                 initValidateVnfCreate(mex)
636                 
637                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
638                 CreateVcpeResCustService.validateVnfCreate(mex)
639
640                 verify(mex).getVariable(DBGFLAG)
641                 
642                 verify(mex).setVariable(Prefix+"VnfsCreatedCount", 3)
643         }
644                         
645         @Test
646         // @Ignore  
647         public void validateVnfCreate_Ex() {
648                 ExecutionEntity mex = setupMock()
649                 initValidateVnfCreate(mex)
650                 
651                 when(mex.getVariable(Prefix+"VnfsCreatedCount")).thenThrow(new RuntimeException("expected exception"))
652                 
653                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
654                 
655                 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.validateVnfCreate(mex) }))
656         }
657         
658         
659         // ***** postProcessResponse *****
660                         
661         @Test
662         // @Ignore  
663         public void postProcessResponse() {
664                 ExecutionEntity mex = setupMock()
665                 def map = setupMap(mex)
666                 initPostProcessResponse(mex)
667                 
668                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
669                 CreateVcpeResCustService.postProcessResponse(mex)
670
671                 verify(mex).getVariable(DBGFLAG)
672                 
673                 verify(mex).setVariable(Prefix+"Success", true)
674                 
675                 def reqinfo = map.get(Prefix+"CompleteMsoProcessRequest")
676                 
677                 assertTrue(reqinfo.indexOf("request-id>mri</") >= 0)
678                 assertTrue(reqinfo.indexOf("source>mysrc</") >= 0)
679                 assertTrue(reqinfo.indexOf("serviceInstanceId>sii</") >= 0)
680         }
681                         
682         @Test
683         // @Ignore  
684         public void postProcessResponse_BpmnError() {
685                 ExecutionEntity mex = setupMock()
686                 def map = setupMap(mex)
687                 initPostProcessResponse(mex)
688                 
689                 when(mex.getVariable("source")).thenThrow(new BpmnError("expected exception"))
690                 
691                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
692                 
693                 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.postProcessResponse(mex) }))
694         }
695                         
696         @Test
697         // @Ignore  
698         public void postProcessResponse_Ex() {
699                 ExecutionEntity mex = setupMock()
700                 def map = setupMap(mex)
701                 initPostProcessResponse(mex)
702                 
703                 when(mex.getVariable("source")).thenThrow(new RuntimeException("expected exception"))
704                 
705                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
706                 
707                 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.postProcessResponse(mex) }))
708         }
709         
710         
711         // ***** preProcessRollback *****
712                         
713         @Test
714         // @Ignore  
715         public void preProcessRollback() {
716                 ExecutionEntity mex = setupMock()
717                 def wfe = initPreProcessRollback(mex)
718                 
719                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
720                 CreateVcpeResCustService.preProcessRollback(mex)
721
722                 verify(mex).getVariable(DBGFLAG)
723                 
724                 verify(mex).setVariable("prevWorkflowException", wfe)
725         }
726                         
727         @Test
728         // @Ignore  
729         public void preProcessRollback_NullWfe() {
730                 ExecutionEntity mex = setupMock()
731                 def map = setupMap(mex)
732                 def wfe = initPreProcessRollback(mex)
733                 
734                 when(mex.getVariable("WorkflowException")).thenReturn(null)
735                 
736                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
737                 CreateVcpeResCustService.preProcessRollback(mex)
738
739                 verify(mex).getVariable(DBGFLAG)
740                 
741                 assertFalse(map.containsKey("prevWorkflowException"))
742         }
743                         
744         @Test
745         // @Ignore  
746         public void preProcessRollback_BpmnError() {
747                 ExecutionEntity mex = setupMock()
748                 def map = setupMap(mex)
749                 def wfe = initPreProcessRollback(mex)
750                 
751                 when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception"))
752                 
753                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
754                 CreateVcpeResCustService.preProcessRollback(mex)
755
756                 verify(mex).getVariable(DBGFLAG)
757                 
758                 assertFalse(map.containsKey("prevWorkflowException"))
759         }
760                         
761         @Test
762         // @Ignore  
763         public void preProcessRollback_Ex() {
764                 ExecutionEntity mex = setupMock()
765                 def map = setupMap(mex)
766                 def wfe = initPreProcessRollback(mex)
767                 
768                 when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
769                 
770                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
771                 CreateVcpeResCustService.preProcessRollback(mex)
772
773                 verify(mex).getVariable(DBGFLAG)
774                 
775                 assertFalse(map.containsKey("prevWorkflowException"))
776         }
777         
778         
779         // ***** postProcessRollback *****
780                         
781         @Test
782         // @Ignore  
783         public void postProcessRollback() {
784                 ExecutionEntity mex = setupMock()
785                 def wfe = initPostProcessRollback(mex)
786                 
787                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
788                 CreateVcpeResCustService.postProcessRollback(mex)
789
790                 verify(mex).getVariable(DBGFLAG)
791                 
792                 verify(mex).setVariable("WorkflowException", wfe)
793         }
794                         
795         @Test
796         // @Ignore  
797         public void postProcessRollback_NullWfe() {
798                 ExecutionEntity mex = setupMock()
799                 def map = setupMap(mex)
800                 def wfe = initPostProcessRollback(mex)
801                 
802                 when(mex.getVariable("prevWorkflowException")).thenReturn(null)
803                 
804                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
805                 CreateVcpeResCustService.postProcessRollback(mex)
806
807                 verify(mex).getVariable(DBGFLAG)
808                 
809                 assertFalse(map.containsKey("WorkflowException"))
810         }
811                         
812         @Test
813         // @Ignore  
814         public void postProcessRollback_BpmnError() {
815                 ExecutionEntity mex = setupMock()
816                 def map = setupMap(mex)
817                 def wfe = initPostProcessRollback(mex)
818                 
819                 when(mex.getVariable("prevWorkflowException")).thenThrow(new BpmnError("expected exception"))
820                 
821                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
822                 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.postProcessRollback(mex) }))
823         }
824                         
825         @Test
826         // @Ignore  
827         public void postProcessRollback_Ex() {
828                 ExecutionEntity mex = setupMock()
829                 def map = setupMap(mex)
830                 def wfe = initPostProcessRollback(mex)
831                 
832                 when(mex.getVariable("prevWorkflowException")).thenThrow(new RuntimeException("expected exception"))
833                 
834                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
835                 CreateVcpeResCustService.postProcessRollback(mex)
836
837                 verify(mex).getVariable(DBGFLAG)
838                 
839                 assertFalse(map.containsKey("WorkflowException"))
840         }
841         
842         
843         // ***** prepareFalloutRequest *****
844                         
845         @Test
846         // @Ignore  
847         public void prepareFalloutRequest() {
848                 ExecutionEntity mex = setupMock()
849                 def map = setupMap(mex)
850                 initPrepareFalloutRequest(mex)
851                 
852                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
853                 CreateVcpeResCustService.prepareFalloutRequest(mex)
854
855                 verify(mex, times(2)).getVariable(DBGFLAG)
856                 
857                 def fo = map.get(Prefix+"falloutRequest")
858                 
859                 assertTrue(fo.indexOf("<hello>world</") >= 0)
860                 assertTrue(fo.indexOf("ErrorMessage>mymsg</") >= 0)
861                 assertTrue(fo.indexOf("ErrorCode>999</") >= 0)
862         }
863                         
864         @Test
865         // @Ignore  
866         public void prepareFalloutRequest_Ex() {
867                 ExecutionEntity mex = setupMock()
868                 def map = setupMap(mex)
869                 initPrepareFalloutRequest(mex)
870                 
871                 when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
872                 
873                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
874                 
875                 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.prepareFalloutRequest(mex) }))
876         }
877         
878         // ***** sendSyncError *****
879                         
880         @Test
881         // @Ignore  
882         public void sendSyncError() {
883                 ExecutionEntity mex = setupMock()
884                 def map = setupMap(mex)
885                 initSendSyncError(mex)
886                 
887                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
888                 CreateVcpeResCustService.sendSyncError(mex)
889
890                 verify(mex, times(2)).getVariable(DBGFLAG)
891                 
892                 verify(mex).setVariable(processName+"WorkflowResponseSent", "true")
893                 
894                 assertEquals("500", map.get(processName+"ResponseCode"))
895                 assertEquals("Fail", map.get(processName+"Status"))
896                 
897                 def resp = map.get(processName+"Response")
898                 
899                 assertTrue(resp.indexOf("ErrorMessage>mymsg</") >= 0)
900                 
901                 verify(mex).setVariable("WorkflowResponse", resp)
902         }
903                         
904         @Test
905         // @Ignore  
906         public void sendSyncError_NotWfe() {
907                 ExecutionEntity mex = setupMock()
908                 def map = setupMap(mex)
909                 initSendSyncError(mex)
910                 
911                 when(mex.getVariable("WorkflowException")).thenReturn("not a WFE")
912                 
913                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
914                 CreateVcpeResCustService.sendSyncError(mex)
915
916                 verify(mex, times(2)).getVariable(DBGFLAG)
917                 
918                 verify(mex).setVariable(processName+"WorkflowResponseSent", "true")
919                 
920                 assertEquals("500", map.get(processName+"ResponseCode"))
921                 assertEquals("Fail", map.get(processName+"Status"))
922                 
923                 def resp = map.get(processName+"Response")
924                 
925                 assertTrue(resp.indexOf("ErrorMessage>Sending Sync Error.</") >= 0)
926                 
927                 verify(mex).setVariable("WorkflowResponse", resp)
928         }
929                         
930         @Test
931         // @Ignore  
932         public void sendSyncError_NullWfe() {
933                 ExecutionEntity mex = setupMock()
934                 def map = setupMap(mex)
935                 initSendSyncError(mex)
936                 
937                 when(mex.getVariable("WorkflowException")).thenReturn(null)
938                 
939                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
940                 CreateVcpeResCustService.sendSyncError(mex)
941
942                 verify(mex, times(2)).getVariable(DBGFLAG)
943                 
944                 verify(mex).setVariable(processName+"WorkflowResponseSent", "true")
945                 
946                 assertEquals("500", map.get(processName+"ResponseCode"))
947                 assertEquals("Fail", map.get(processName+"Status"))
948                 
949                 def resp = map.get(processName+"Response")
950                 
951                 assertTrue(resp.indexOf("ErrorMessage>Sending Sync Error.</") >= 0)
952                 
953                 verify(mex).setVariable("WorkflowResponse", resp)
954         }
955                         
956         @Test
957         // @Ignore  
958         public void sendSyncError_Ex() {
959                 ExecutionEntity mex = setupMock()
960                 def map = setupMap(mex)
961                 initSendSyncError(mex)
962                 
963                 when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
964                 
965                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
966                 
967                 CreateVcpeResCustService.sendSyncError(mex)
968                 
969                 assertFalse(map.containsKey(processName+"ResponseCode"))
970         }
971         
972         
973         // ***** processJavaException *****
974                         
975         @Test
976         // @Ignore  
977         public void processJavaException() {
978                 ExecutionEntity mex = setupMock()
979                 def map = setupMap(mex)
980                 initProcessJavaException(mex)
981                 
982                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
983                 
984                 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.processJavaException(mex) }))
985
986                 verify(mex, times(2)).getVariable(DBGFLAG)
987                 
988                 verify(mex).setVariable("prefix", Prefix)
989                 
990                 def wfe = map.get("WorkflowException")
991                 
992                 assertEquals("Caught a Java Lang Exception", wfe.getErrorMessage())
993         }
994                         
995         @Test
996         // @Ignore  
997         public void processJavaException_BpmnError() {
998                 ExecutionEntity mex = setupMock()
999                 def map = setupMap(mex)
1000                 initProcessJavaException(mex)
1001                 
1002                 when(mex.getVariables()).thenThrow(new BpmnError("expected exception"))
1003                 
1004                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
1005                 
1006                 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.processJavaException(mex) }))
1007                 
1008                 assertFalse(map.containsKey("WorkflowException"))
1009         }
1010                         
1011         @Test
1012         // @Ignore  
1013         public void processJavaException_Ex() {
1014                 ExecutionEntity mex = setupMock()
1015                 def map = setupMap(mex)
1016                 initProcessJavaException(mex)
1017                 
1018                 when(mex.getVariables()).thenThrow(new RuntimeException("expected exception"))
1019                 
1020                 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
1021                 
1022                 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.processJavaException(mex) }))
1023                 
1024                 def wfe = map.get("WorkflowException")
1025                 
1026                 assertEquals("Exception in processJavaException method", wfe.getErrorMessage())
1027         }
1028         
1029         
1030         private void initPreProcess(ExecutionEntity mex) {
1031                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1032                 when(mex.getVariable("bpmnRequest")).thenReturn(request)
1033                 when(mex.getVariable("URN_mso_workflow_aai_distribution_delay")).thenReturn("aaidelay")
1034                 when(mex.getVariable("mso-request-id")).thenReturn("mri")
1035                 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
1036                 when(mex.getVariable("requestAction")).thenReturn("ra")
1037         }
1038         
1039         private initSendSyncResponse(ExecutionEntity mex) {
1040                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1041                 when(mex.getVariable("mso-request-id")).thenReturn("mri")
1042                 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
1043         }
1044         
1045         private void initPrepareDecomposeService(ExecutionEntity mex) {
1046                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1047                 when(mex.getVariable("createVcpeServiceRequest")).thenReturn('{"requestDetails":{"modelInfo":"mi"}}')
1048         }
1049         
1050         private void initPrepareCreateServiceInstance(ExecutionEntity mex) {
1051                 ServiceDecomposition svcdecomp = mock(ServiceDecomposition.class)
1052                 
1053                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1054                 when(mex.getVariable("createVcpeServiceRequest")).thenReturn(request)
1055                 when(mex.getVariable("serviceDecomposition")).thenReturn(svcdecomp)
1056                 
1057                 when(svcdecomp.toJsonStringNoRootName()).thenReturn("mydecomp")
1058         }
1059         
1060         private void initPostProcessServiceInstanceCreate(ExecutionEntity mex) {
1061                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1062                 when(mex.getVariable("mso-request-id")).thenReturn("mri")
1063                 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
1064                 when(mex.getVariable("serviceInstanceName")).thenReturn("sin")
1065         }
1066         
1067         private ServiceDecomposition initProcessDecomposition(ExecutionEntity mex) {
1068                 List<VnfResource> vnflst = new LinkedList<>()
1069                 vnflst.add(makeVnf("", ""))
1070                 vnflst.add(makeVnf("2", "BRG"))
1071                 vnflst.add(makeVnf("3", "BRG"))
1072                         
1073                 ServiceDecomposition svcdecomp = mock(ServiceDecomposition.class)
1074                 when(svcdecomp.getServiceVnfs()).thenReturn(vnflst)
1075                 
1076                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1077                 when(mex.getVariable("serviceDecomposition")).thenReturn(svcdecomp)
1078                 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
1079                 when(mex.getVariable("serviceInstanceName")).thenReturn("sin")
1080                 
1081                 return svcdecomp
1082         }
1083         
1084         private ServiceDecomposition initFilterVnfs(ExecutionEntity mex) {
1085                 List<VnfResource> vnflst = new LinkedList<>()
1086                 vnflst.add(makeVnf("", "BRG"))
1087                 vnflst.add(makeVnf("2", "TunnelXConn"))
1088                 vnflst.add(makeVnf("3", ""))
1089                 vnflst.add(makeVnf("4", "BRG"))
1090                 vnflst.add(makeVnf("5", "other"))
1091                         
1092                 ServiceDecomposition svcdecomp = mock(ServiceDecomposition.class)
1093                 when(svcdecomp.getServiceVnfs()).thenReturn(vnflst)
1094                 
1095                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1096                 when(mex.getVariable("serviceDecomposition")).thenReturn(svcdecomp)
1097                 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
1098                 when(mex.getVariable("serviceInstanceName")).thenReturn("sin")
1099                 
1100                 return svcdecomp
1101         }
1102         
1103         private initAwaitAaiDistribution(ExecutionEntity mex) {
1104                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1105         }
1106         
1107         private ServiceDecomposition initPrepareCreateAllottedResourceTXC(ExecutionEntity mex) {
1108                 ServiceDecomposition svcdecomp = mock(ServiceDecomposition.class)
1109                 List<AllottedResource> arlst = new LinkedList<>()
1110                 
1111                 arlst.add(makeArBRG("A"))
1112                 arlst.add(makeArTXC("B"))
1113                 arlst.add(makeArBRG("C"))
1114                 
1115                 when(svcdecomp.getServiceAllottedResources()).thenReturn(arlst)
1116                 
1117                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1118                 when(mex.getVariable("createVcpeServiceRequest")).thenReturn(request)
1119                 when(mex.getVariable("serviceDecomposition")).thenReturn(svcdecomp)
1120                 when(mex.getVariable("allottedResourceId")).thenReturn(ARID)
1121                 
1122                 return svcdecomp
1123         }
1124         
1125         private ServiceDecomposition initPrepareCreateAllottedResourceBRG(ExecutionEntity mex) {
1126                 ServiceDecomposition svcdecomp = mock(ServiceDecomposition.class)
1127                 List<AllottedResource> arlst = new LinkedList<>()
1128                 
1129                 arlst.add(makeArTXC("A"))
1130                 arlst.add(makeArBRG("B"))
1131                 arlst.add(makeArTXC("C"))
1132                 
1133                 when(svcdecomp.getServiceAllottedResources()).thenReturn(arlst)
1134                 
1135                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1136                 when(mex.getVariable("createVcpeServiceRequest")).thenReturn(request)
1137                 when(mex.getVariable("serviceDecomposition")).thenReturn(svcdecomp)
1138                 when(mex.getVariable("allottedResourceId")).thenReturn(ARID)
1139                 
1140                 return svcdecomp
1141         }
1142         
1143         private AllottedResource makeArTXC(String id) {
1144                 AllottedResource ar = mock(AllottedResource.class)
1145                 ModelInfo mod = mock(ModelInfo.class)
1146                 HomingSolution home = mock(HomingSolution.class)
1147                 
1148                 when(ar.toJsonStringNoRootName()).thenReturn("json"+id)
1149                 when(ar.getAllottedResourceType()).thenReturn("TunnelXConn")
1150                 when(ar.getModelInfo()).thenReturn(mod)
1151                 when(ar.getAllottedResourceRole()).thenReturn("TXCr")
1152                 when(ar.getHomingSolution()).thenReturn(home)
1153                 
1154                 when(mod.toJsonStringNoRootName()).thenReturn("model"+id)
1155                 
1156                 when(home.getServiceInstanceId()).thenReturn("home"+id)
1157                 
1158                 return ar
1159         }
1160         
1161         private AllottedResource makeArBRG(String id) {
1162                 AllottedResource ar = mock(AllottedResource.class)
1163                 ModelInfo mod = mock(ModelInfo.class)
1164                 HomingSolution home = mock(HomingSolution.class)
1165                 
1166                 when(ar.toJsonStringNoRootName()).thenReturn("json"+id)
1167                 when(ar.getAllottedResourceType()).thenReturn("BRG")
1168                 when(ar.getModelInfo()).thenReturn(mod)
1169                 when(ar.getAllottedResourceRole()).thenReturn("BRGr")
1170                 when(ar.getHomingSolution()).thenReturn(home)
1171                 
1172                 when(mod.toJsonStringNoRootName()).thenReturn("model"+id)
1173                 
1174                 when(home.getServiceInstanceId()).thenReturn("home"+id)
1175                 
1176                 return ar
1177         }
1178         
1179         private initPrepareVnfAndModulesCreate(ExecutionEntity mex) {
1180                 
1181                 List<VnfResource> vnflst = new LinkedList<>()
1182                 
1183                 vnflst.add(makeVnf("A", "BRG"))
1184                 vnflst.add(makeVnf("B", ""))
1185                 vnflst.add(makeVnf("C", ""))
1186                 vnflst.add(makeVnf("D", "TunnelXConn"))
1187                 
1188                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1189                 when(mex.getVariable("createVcpeServiceRequest")).thenReturn(request)
1190                 when(mex.getVariable("vnfList")).thenReturn(vnflst)
1191                 when(mex.getVariable(Prefix+"VnfsCreatedCount")).thenReturn(2)
1192                 when(mex.getVariable("vnfModelInfo")).thenReturn("nomodel")
1193                 when(mex.getVariable("sdncVersion")).thenReturn("myvers")
1194         }
1195         
1196         private VnfResource makeVnf(String id, String role) {           
1197                 ModelInfo mod = mock(ModelInfo.class)           
1198                 VnfResource vnf = mock(VnfResource.class)
1199                 
1200                 when(mod.toString()).thenReturn('{"modelInfo":"mymodel'+id+'"}')
1201                 
1202                 when(vnf.toString()).thenReturn("myvnf"+id)
1203                 when(vnf.getModelInfo()).thenReturn(mod)
1204                 when(vnf.getNfRole()).thenReturn(role)
1205
1206                 return vnf
1207         }
1208         
1209         private initValidateVnfCreate(ExecutionEntity mex) {
1210                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1211                 when(mex.getVariable(Prefix+"VnfsCreatedCount")).thenReturn(2)
1212         }
1213         
1214         private initPostProcessResponse(ExecutionEntity mex) {
1215                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1216                 when(mex.getVariable("source")).thenReturn("mysrc")
1217                 when(mex.getVariable("mso-request-id")).thenReturn("mri")
1218                 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
1219         }
1220         
1221         private WorkflowException initPreProcessRollback(ExecutionEntity mex) {
1222                 WorkflowException wfe = mock(WorkflowException.class)
1223                 
1224                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1225                 when(mex.getVariable("WorkflowException")).thenReturn(wfe)
1226                 
1227                 return wfe
1228         }
1229         
1230         private WorkflowException initPostProcessRollback(ExecutionEntity mex) {
1231                 WorkflowException wfe = mock(WorkflowException.class)
1232                 
1233                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1234                 when(mex.getVariable("prevWorkflowException")).thenReturn(wfe)
1235                 
1236                 return wfe
1237         }
1238         
1239         private initPrepareFalloutRequest(ExecutionEntity mex) {
1240                 WorkflowException wfe = mock(WorkflowException.class)
1241                 
1242                 when(wfe.getErrorMessage()).thenReturn("mymsg")
1243                 when(wfe.getErrorCode()).thenReturn(999)
1244                 
1245                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1246                 when(mex.getVariable("WorkflowException")).thenReturn(wfe)
1247                 when(mex.getVariable(Prefix+"requestInfo")).thenReturn("<hello>world</hello>")
1248                 
1249                 return wfe
1250         }
1251         
1252         private initSendSyncError(ExecutionEntity mex) {
1253                 WorkflowException wfe = mock(WorkflowException.class)
1254                 
1255                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1256                 when(mex.getVariable("mso-request-id")).thenReturn("mri")
1257                 when(mex.getVariable("WorkflowException")).thenReturn(wfe)
1258                 
1259                 when(wfe.getErrorMessage()).thenReturn("mymsg")
1260         }
1261         
1262         private initProcessJavaException(ExecutionEntity mex) {
1263                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1264         }
1265                 
1266 }