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