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