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