Merge "JUnit tests for MsoMulticloudUtils"
[so.git] / bpmn / so-bpmn-infrastructure-common / src / test / groovy / org / onap / so / bpmn / vcpe / scripts / DoCreateAllottedResourceTXCTest.groovy
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.bpmn.vcpe.scripts
24
25 import org.camunda.bpm.engine.delegate.BpmnError
26 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
27 import org.junit.*
28 import org.mockito.MockitoAnnotations
29 import org.onap.so.bpmn.core.UrnPropertiesReader
30 import org.onap.so.bpmn.core.WorkflowException
31 import org.onap.so.bpmn.mock.FileUtil
32 import org.onap.so.client.aai.AAIObjectType
33 import org.onap.so.client.aai.AAIResourcesClient
34 import org.onap.so.client.aai.entities.uri.AAIUriFactory
35
36 import javax.ws.rs.core.UriBuilder
37
38 import static org.junit.Assert.*
39 import static org.mockito.Mockito.*
40 import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetAllottedResource
41 import static org.onap.so.bpmn.mock.StubResponseAAI.MockPatchAllottedResource
42 import static org.onap.so.bpmn.mock.StubResponseAAI.MockPutAllottedResource
43 import static org.onap.so.bpmn.mock.StubResponseAAI.MockPutAllottedResource_500
44
45 import org.onap.so.bpmn.core.RollbackData
46
47 import com.github.tomakehurst.wiremock.junit.WireMockRule
48
49 class DoCreateAllottedResourceTXCTest extends GroovyTestBase {
50
51     @Rule
52     public WireMockRule wireMockRule = new WireMockRule(PORT)
53
54     String Prefix = "DCARTXC_"
55
56     @BeforeClass
57     public static void setUpBeforeClass() {
58         aaiUriPfx = UrnPropertiesReader.getVariable("aai.endpoint")
59     }
60
61     @Before
62     public void init() {
63         MockitoAnnotations.initMocks(this)
64     }
65
66     public DoCreateAllottedResourceTXCTest() {
67         super("DoCreateAllottedResourceTXC")
68     }
69
70     // ***** preProcessRequest *****
71     @Test
72     public void preProcessRequest() {
73         ExecutionEntity mex = setupMock()
74         initPreProcess(mex)
75
76         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
77         DoCreateAllottedResourceTXC.preProcessRequest(mex)
78
79         verify(mex).setVariable("prefix", Prefix)
80
81         assertTrue(checkMissingPreProcessRequest("mso.workflow.sdncadapter.callback"))
82         assertTrue(checkMissingPreProcessRequest("mso.workflow.sdnc.replication.delay"))
83         assertTrue(checkMissingPreProcessRequest("serviceInstanceId"))
84         assertTrue(checkMissingPreProcessRequest("parentServiceInstanceId"))
85         assertTrue(checkMissingPreProcessRequest("allottedResourceModelInfo"))
86         assertTrue(checkMissingPreProcessRequest("brgWanMacAddress"))
87         assertTrue(checkMissingPreProcessRequest("allottedResourceRole"))
88         assertTrue(checkMissingPreProcessRequest("allottedResourceType"))
89     }
90
91     // ***** getAaiAR *****
92
93     @Test
94     @Ignore
95     public void getAaiAR() {
96         MockGetAllottedResource(wireMockRule, CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXC/getArTxc.xml")
97
98         ExecutionEntity mex = setupMock()
99         initGetAaiAR(mex)
100
101         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
102         DoCreateAllottedResourceTXC.getAaiAR(mex)
103
104         verify(mex).setVariable("foundActiveAR", true)
105     }
106
107     @Test
108
109     public void getAaiAR_Duplicate() {
110         MockGetAllottedResource(wireMockRule, CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXC/getArTxc.xml")
111
112         ExecutionEntity mex = setupMock()
113         initGetAaiAR(mex)
114
115         // fail if duplicate
116         when(mex.getVariable("failExists")).thenReturn("true")
117
118         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
119
120         assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.getAaiAR(mex) }))
121     }
122
123     @Test
124     public void getAaiAR_NotActive() {
125         MockGetAllottedResource(wireMockRule, CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXC/getArTxc.xml")
126
127         ExecutionEntity mex = setupMock()
128         initGetAaiAR(mex)
129
130         // not active
131         when(mex.getVariable("aaiAROrchStatus")).thenReturn("not-active")
132
133         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
134
135         assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.getAaiAR(mex) }))
136     }
137
138     @Test
139     @Ignore
140     public void getAaiAR_NoStatus() {
141         MockGetAllottedResource(wireMockRule, CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXC/getArTxc.xml")
142
143         ExecutionEntity mex = setupMock()
144         initGetAaiAR(mex)
145
146         when(mex.getVariable("aaiAROrchStatus")).thenReturn(null)
147
148         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
149         DoCreateAllottedResourceTXC.getAaiAR(mex)
150
151         verify(mex, never()).setVariable("foundActiveAR", true)
152     }
153
154     // ***** createAaiAR *****
155
156     @Test
157     public void createAaiAR() {
158         ExecutionEntity mex = setupMock()
159         initCreateAaiAr(mex)
160         when(mex.getVariable("PSI_resourceLink")).thenReturn(AAIUriFactory.createResourceFromExistingURI(AAIObjectType.SERVICE_INSTANCE, UriBuilder.fromPath("/aai/v9/business/customers/customer/" + CUST + "/service-subscriptions/service-subscription/" + SVC + "/service-instances/service-instance/" + INST).build()))
161         when(mex.getVariable("CSI_resourceLink")).thenReturn("/aai/v9/business/customers/customer/" + CUST + "/service-subscriptions/service-subscription/" + SVC + "/service-instances/service-instance/" + INST)
162         when(mex.getVariable("allottedResourceModelInfo")).thenReturn("{\n" +
163                 "  \"modelInvariantUuid\":\"modelInvariantUuid\",\n" +
164                 "  \"modelUuid\" : \"modelUuid\"\n" +
165                 "}")
166         AAIResourcesClient client = mock(AAIResourcesClient.class)
167         DoCreateAllottedResourceTXC doCreateAllottedResourceTXC = spy(DoCreateAllottedResourceTXC.class)
168         when(doCreateAllottedResourceTXC.getAAIClient()).thenReturn(client)
169         doCreateAllottedResourceTXC.createAaiAR(mex)
170     }
171
172
173     @Test
174     public void createAaiAR_MissingPsiLink() {
175         ExecutionEntity mex = setupMock()
176         initCreateAaiAr(mex)
177
178         when(mex.getVariable("PSI_resourceLink")).thenReturn(null)
179
180         MockPutAllottedResource(wireMockRule, CUST, SVC, INST, ARID)
181
182         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
183
184         assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.createAaiAR(mex) }))
185     }
186
187     @Test
188     public void createAaiAR_HttpFailed() {
189         ExecutionEntity mex = setupMock()
190         initCreateAaiAr(mex)
191
192         MockPutAllottedResource_500(wireMockRule, CUST, SVC, INST, ARID)
193
194         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
195
196         assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.createAaiAR(mex) }))
197     }
198
199     @Test
200     public void createAaiAR_BpmnError() {
201         ExecutionEntity mex = setupMock()
202         initCreateAaiAr(mex)
203
204         when(mex.getVariable("aai.endpoint")).thenThrow(new BpmnError("expected exception"))
205
206         MockPutAllottedResource(wireMockRule, CUST, SVC, INST, ARID)
207
208         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
209
210         assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.createAaiAR(mex) }))
211     }
212
213     @Test
214     public void createAaiAR_Ex() {
215         ExecutionEntity mex = setupMock()
216         initCreateAaiAr(mex)
217
218         when(mex.getVariable("aai.endpoint")).thenThrow(new RuntimeException("expected exception"))
219
220         MockPutAllottedResource(wireMockRule, CUST, SVC, INST, ARID)
221
222         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
223
224         assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.createAaiAR(mex) }))
225     }
226
227     // ***** buildSDNCRequest *****
228
229     @Test
230     public void buildSDNCRequest() {
231         ExecutionEntity mex = setupMock()
232         initBuildSDNCRequest(mex)
233
234         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
235
236         String result = DoCreateAllottedResourceTXC.buildSDNCRequest(mex, "myact", "myreq")
237
238         assertTrue(result.indexOf("<sdncadapter:RequestId>myreq</") >= 0)
239         assertTrue(result.indexOf("<sdncadapter:SvcAction>myact</") >= 0)
240         assertTrue(result.indexOf("<allotted-resource-id>ari</") >= 0)
241         assertTrue(result.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
242         assertTrue(result.indexOf("<service-instance-id>sii</") >= 0)
243         assertTrue(result.indexOf("<parent-service-instance-id>psii</") >= 0)
244         assertTrue(result.indexOf("<subscription-service-type>sst</") >= 0)
245         assertTrue(result.indexOf("<global-customer-id>gci</") >= 0)
246         assertTrue(result.indexOf("<sdncadapter:CallbackUrl>scu</") >= 0)
247         assertTrue(result.indexOf("<request-id>mri</") >= 0)
248         assertTrue(result.indexOf("<model-invariant-uuid/>") >= 0)
249         assertTrue(result.indexOf("<model-uuid/>") >= 0)
250         assertTrue(result.indexOf("<model-customization-uuid/>") >= 0)
251         assertTrue(result.indexOf("<model-version/>") >= 0)
252         assertTrue(result.indexOf("<model-name/>") >= 0)
253     }
254
255     @Test
256     public void buildSDNCRequest_Ex() {
257         ExecutionEntity mex = setupMock()
258         initBuildSDNCRequest(mex)
259
260         when(mex.getVariable("allottedResourceId")).thenThrow(new RuntimeException("expected exception"))
261
262         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
263
264         assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.buildSDNCRequest(mex, "myact", "myreq") }))
265     }
266
267     // ***** preProcessSDNCAssign *****
268
269     @Test
270     public void preProcessSDNCAssign() {
271         ExecutionEntity mex = setupMock()
272         def map = setupMap(mex)
273         def data = initPreProcessSDNC(mex)
274
275         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
276         DoCreateAllottedResourceTXC.preProcessSDNCAssign(mex)
277
278         def req = map.get("sdncAssignRequest")
279         assertNotNull(req)
280
281         assertEquals(data, map.get("rollbackData"))
282
283         def rbreq = data.get(Prefix, "sdncAssignRollbackReq")
284
285         assertTrue(req.indexOf("<sdncadapter:SvcAction>assign</") >= 0)
286         assertTrue(req.indexOf("<request-action>CreateTunnelXConnInstance</") >= 0)
287         assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
288
289         assertTrue(rbreq.indexOf("<sdncadapter:SvcAction>unassign</") >= 0)
290         assertTrue(rbreq.indexOf("<request-action>DeleteTunnelXConnInstance</") >= 0)
291         assertTrue(rbreq.indexOf("<sdncadapter:RequestId>") >= 0)
292     }
293
294     @Test
295     public void preProcessSDNCAssign_BpmnError() {
296         ExecutionEntity mex = setupMock()
297         initPreProcessSDNC(mex)
298
299         when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception"))
300
301         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
302
303         assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCAssign(mex) }))
304     }
305
306     @Test
307     public void preProcessSDNCAssign_Ex() {
308         ExecutionEntity mex = setupMock()
309         initPreProcessSDNC(mex)
310
311         when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception"))
312
313         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
314
315         assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCAssign(mex) }))
316     }
317
318     // ***** preProcessSDNCCreate *****
319
320     @Test
321     public void preProcessSDNCCreate() {
322         ExecutionEntity mex = setupMock()
323         def map = setupMap(mex)
324         def data = initPreProcessSDNC(mex)
325
326         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
327         DoCreateAllottedResourceTXC.preProcessSDNCCreate(mex)
328
329         def req = map.get("sdncCreateRequest")
330         assertNotNull(req)
331
332         assertEquals(data, map.get("rollbackData"))
333
334         def rbreq = data.get(Prefix, "sdncCreateRollbackReq")
335
336         assertTrue(req.indexOf("<sdncadapter:SvcAction>create</") >= 0)
337         assertTrue(req.indexOf("<request-action>CreateTunnelXConnInstance</") >= 0)
338         assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
339
340         assertTrue(rbreq.indexOf("<sdncadapter:SvcAction>delete</") >= 0)
341         assertTrue(rbreq.indexOf("<request-action>DeleteTunnelXConnInstance</") >= 0)
342         assertTrue(rbreq.indexOf("<sdncadapter:RequestId>") >= 0)
343
344     }
345
346     @Test
347     public void preProcessSDNCCreate_BpmnError() {
348         ExecutionEntity mex = setupMock()
349         initPreProcessSDNC(mex)
350
351         when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception"))
352
353         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
354
355         assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCCreate(mex) }))
356     }
357
358     @Test
359     public void preProcessSDNCCreate_Ex() {
360         ExecutionEntity mex = setupMock()
361         initPreProcessSDNC(mex)
362
363         when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception"))
364
365         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
366
367         assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCCreate(mex) }))
368     }
369
370     // ***** preProcessSDNCActivate *****
371
372     @Test
373     public void preProcessSDNCActivate() {
374         ExecutionEntity mex = setupMock()
375         def map = setupMap(mex)
376         def data = initPreProcessSDNC(mex)
377
378         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
379         DoCreateAllottedResourceTXC.preProcessSDNCActivate(mex)
380
381         def req = map.get("sdncActivateRequest")
382         assertNotNull(req)
383
384         assertEquals(data, map.get("rollbackData"))
385
386         def rbreq = data.get(Prefix, "sdncActivateRollbackReq")
387
388         assertTrue(req.indexOf("<sdncadapter:SvcAction>activate</") >= 0)
389         assertTrue(req.indexOf("<request-action>CreateTunnelXConnInstance</") >= 0)
390         assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
391
392         assertTrue(rbreq.indexOf("<sdncadapter:SvcAction>deactivate</") >= 0)
393         assertTrue(rbreq.indexOf("<request-action>DeleteTunnelXConnInstance</") >= 0)
394         assertTrue(rbreq.indexOf("<sdncadapter:RequestId>") >= 0)
395
396     }
397
398     @Test
399     public void preProcessSDNCActivate_BpmnError() {
400         ExecutionEntity mex = setupMock()
401         initPreProcessSDNC(mex)
402
403         when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception"))
404
405         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
406
407         assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCActivate(mex) }))
408     }
409
410     @Test
411     public void preProcessSDNCActivate_Ex() {
412         ExecutionEntity mex = setupMock()
413         initPreProcessSDNC(mex)
414
415         when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception"))
416
417         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
418
419         assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCActivate(mex) }))
420     }
421
422     // ***** validateSDNCResp *****
423
424     @Test
425     public void validateSDNCResp() {
426         ExecutionEntity mex = setupMock()
427         def map = setupMap(mex)
428         def data = initValidateSDNCResp(mex)
429         def resp = initValidateSDNCResp_Resp()
430
431         when(mex.getVariable(Prefix + "sdncResponseSuccess")).thenReturn(true)
432
433         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
434
435         DoCreateAllottedResourceTXC.validateSDNCResp(mex, resp, "create")
436
437         verify(mex).getVariable("WorkflowException")
438         verify(mex).getVariable("SDNCA_SuccessIndicator")
439         verify(mex).getVariable("rollbackData")
440
441         assertEquals(data, map.get("rollbackData"))
442
443         assertEquals("true", data.get(Prefix, "rollback" + "SDNCcreate"))
444
445     }
446
447     @Test
448     public void validateSDNCResp_Get() {
449         ExecutionEntity mex = setupMock()
450         initValidateSDNCResp(mex)
451         def resp = initValidateSDNCResp_Resp()
452
453         when(mex.getVariable(Prefix + "sdncResponseSuccess")).thenReturn(true)
454
455         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
456
457         DoCreateAllottedResourceTXC.validateSDNCResp(mex, resp, "get")
458
459         verify(mex).getVariable("WorkflowException")
460         verify(mex).getVariable("SDNCA_SuccessIndicator")
461
462         verify(mex, never()).getVariable("rollbackData")
463     }
464
465     @Test
466     public void validateSDNCResp_Unsuccessful() {
467         ExecutionEntity mex = setupMock()
468         initValidateSDNCResp(mex)
469         def resp = initValidateSDNCResp_Resp()
470
471         // unsuccessful
472         when(mex.getVariable(Prefix + "sdncResponseSuccess")).thenReturn(false)
473
474         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
475
476         assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.validateSDNCResp(mex, resp, "create") }))
477     }
478
479     @Test
480     public void validateSDNCResp_BpmnError() {
481         ExecutionEntity mex = setupMock()
482         initValidateSDNCResp(mex)
483         def resp = initValidateSDNCResp_Resp()
484
485         when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception"))
486
487         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
488
489         assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.validateSDNCResp(mex, resp, "create") }))
490     }
491
492     @Test
493     public void validateSDNCResp_Ex() {
494         ExecutionEntity mex = setupMock()
495         initValidateSDNCResp(mex)
496         def resp = initValidateSDNCResp_Resp()
497
498         when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
499
500         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
501
502         assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.validateSDNCResp(mex, resp, "create") }))
503     }
504
505     // ***** preProcessSDNCGet *****
506
507     @Test
508     public void preProcessSDNCGet_FoundAR() {
509         ExecutionEntity mex = setupMock()
510         def map = setupMap(mex)
511         initPreProcessSDNCGet(mex)
512
513         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
514         DoCreateAllottedResourceTXC.preProcessSDNCGet(mex)
515
516         String req = map.get("sdncGetRequest")
517
518         assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
519         assertTrue(req.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
520         assertTrue(req.indexOf("<sdncadapter:SvcOperation>arlink</") >= 0)
521         assertTrue(req.indexOf("<sdncadapter:CallbackUrl>myurl</") >= 0)
522
523     }
524
525     @Test
526     public void preProcessSDNCGet_NotFoundAR() {
527         ExecutionEntity mex = setupMock()
528         def map = setupMap(mex)
529         initPreProcessSDNCGet(mex)
530
531         when(mex.getVariable("foundActiveAR")).thenReturn(false)
532
533         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
534         DoCreateAllottedResourceTXC.preProcessSDNCGet(mex)
535
536         String req = map.get("sdncGetRequest")
537
538         assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
539         assertTrue(req.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
540         assertTrue(req.indexOf("<sdncadapter:SvcOperation>assignlink</") >= 0)
541         assertTrue(req.indexOf("<sdncadapter:CallbackUrl>myurl</") >= 0)
542
543     }
544
545     @Test
546     public void preProcessSDNCGet_Ex() {
547         ExecutionEntity mex = setupMock()
548         initPreProcessSDNCGet(mex)
549
550         when(mex.getVariable("foundActiveAR")).thenThrow(new RuntimeException("expected exception"))
551
552         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
553
554         assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCGet(mex) }))
555     }
556
557     // ***** updateAaiAROrchStatus *****
558
559     @Test
560     @Ignore
561     public void updateAaiAROrchStatus() {
562         MockPatchAllottedResource(wireMockRule, CUST, SVC, INST, ARID)
563
564         ExecutionEntity mex = setupMock()
565         initUpdateAaiAROrchStatus(mex)
566
567         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
568         DoCreateAllottedResourceTXC.updateAaiAROrchStatus(mex, "success")
569     }
570
571     // ***** generateOutputs *****
572
573     @Test
574     public void generateOutputs() {
575         ExecutionEntity mex = setupMock()
576         def txctop = FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceTXC/SDNCTopologyQueryCallback.xml")
577
578         when(mex.getVariable(DBGFLAG)).thenReturn("true")
579         when(mex.getVariable("enhancedCallbackRequestData")).thenReturn(txctop)
580
581         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
582         DoCreateAllottedResourceTXC.generateOutputs(mex)
583
584         verify(mex).setVariable("allotedResourceName", "namefromrequest")
585         verify(mex).setVariable("vni", "my-vni")
586         verify(mex).setVariable("vgmuxBearerIP", "my-bearer-ip")
587         verify(mex).setVariable("vgmuxLanIP", "my-lan-ip")
588
589     }
590
591     @Test
592     public void generateOutputs_BadXml() {
593         ExecutionEntity mex = setupMock()
594
595         when(mex.getVariable(DBGFLAG)).thenReturn("true")
596         when(mex.getVariable("enhancedCallbackRequestData")).thenReturn("invalid xml")
597
598         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
599         DoCreateAllottedResourceTXC.generateOutputs(mex)
600
601         verify(mex, never()).setVariable(anyString(), anyString())
602
603     }
604
605     @Test
606     public void generateOutputs_BpmnError() {
607         ExecutionEntity mex = setupMock()
608
609         when(mex.getVariable(DBGFLAG)).thenReturn("true")
610         when(mex.getVariable("enhancedCallbackRequestData")).thenThrow(new BpmnError("expected exception"))
611
612         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
613
614         DoCreateAllottedResourceTXC.generateOutputs(mex)
615         verify(mex, never()).setVariable(anyString(), anyString())
616
617     }
618
619     @Test
620     public void generateOutputs_Ex() {
621         ExecutionEntity mex = setupMock()
622
623         when(mex.getVariable(DBGFLAG)).thenReturn("true")
624         when(mex.getVariable("enhancedCallbackRequestData")).thenThrow(new RuntimeException("expected exception"))
625
626         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
627
628         DoCreateAllottedResourceTXC.generateOutputs(mex)
629         verify(mex, never()).setVariable(anyString(), anyString())
630
631     }
632
633     // ***** preProcessRollback *****
634
635     @Test
636     public void preProcessRollback() {
637         ExecutionEntity mex = setupMock()
638         WorkflowException wfe = mock(WorkflowException.class)
639
640         when(mex.getVariable(DBGFLAG)).thenReturn("true")
641         when(mex.getVariable("WorkflowException")).thenReturn(wfe)
642
643         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
644         DoCreateAllottedResourceTXC.preProcessRollback(mex)
645
646         verify(mex).setVariable("prevWorkflowException", wfe)
647
648     }
649
650     @Test
651     public void preProcessRollback_NotWFE() {
652         ExecutionEntity mex = setupMock()
653
654         when(mex.getVariable(DBGFLAG)).thenReturn("true")
655         when(mex.getVariable("WorkflowException")).thenReturn("I'm not a WFE")
656
657         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
658         DoCreateAllottedResourceTXC.preProcessRollback(mex)
659
660         verify(mex, never()).setVariable(eq("prevWorkflowException"), any())
661
662     }
663
664     @Test
665     public void preProcessRollback_BpmnError() {
666         ExecutionEntity mex = setupMock()
667
668         when(mex.getVariable(DBGFLAG)).thenReturn("true")
669         when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception"))
670
671         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
672
673         DoCreateAllottedResourceTXC.preProcessRollback(mex)
674
675     }
676
677     @Test
678     public void preProcessRollback_Ex() {
679         ExecutionEntity mex = setupMock()
680
681         when(mex.getVariable(DBGFLAG)).thenReturn("true")
682         when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
683
684         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
685
686         DoCreateAllottedResourceTXC.preProcessRollback(mex)
687
688     }
689
690     // ***** postProcessRollback *****
691
692     @Test
693     public void postProcessRollback() {
694         ExecutionEntity mex = setupMock()
695         WorkflowException wfe = mock(WorkflowException.class)
696
697         when(mex.getVariable(DBGFLAG)).thenReturn("true")
698         when(mex.getVariable("prevWorkflowException")).thenReturn(wfe)
699
700         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
701         DoCreateAllottedResourceTXC.postProcessRollback(mex)
702
703         verify(mex).setVariable("WorkflowException", wfe)
704         verify(mex).setVariable("rollbackData", null)
705
706     }
707
708     @Test
709     public void postProcessRollback_NotWFE() {
710         ExecutionEntity mex = setupMock()
711
712         when(mex.getVariable(DBGFLAG)).thenReturn("true")
713         when(mex.getVariable("prevWorkflowException")).thenReturn("I'm not a WFE")
714
715         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
716         DoCreateAllottedResourceTXC.postProcessRollback(mex)
717
718         verify(mex, never()).setVariable(eq("WorkflowException"), any())
719         verify(mex).setVariable("rollbackData", null)
720
721     }
722
723     @Test
724     public void postProcessRollback_BpmnError() {
725         ExecutionEntity mex = setupMock()
726
727         when(mex.getVariable(DBGFLAG)).thenReturn("true")
728         when(mex.getVariable("prevWorkflowException")).thenThrow(new BpmnError("expected exception"))
729
730         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
731
732         assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.postProcessRollback(mex) }))
733         verify(mex, never()).setVariable("rollbackData", null)
734
735     }
736
737     @Test
738     public void postProcessRollback_Ex() {
739         ExecutionEntity mex = setupMock()
740
741         when(mex.getVariable(DBGFLAG)).thenReturn("true")
742         when(mex.getVariable("prevWorkflowException")).thenThrow(new RuntimeException("expected exception"))
743
744         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
745
746         DoCreateAllottedResourceTXC.postProcessRollback(mex)
747         verify(mex, never()).setVariable("rollbackData", null)
748
749     }
750
751     private boolean checkMissingPreProcessRequest(String fieldnm) {
752         ExecutionEntity mex = setupMock()
753         initPreProcess(mex)
754
755         DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
756
757         when(mex.getVariable(fieldnm)).thenReturn("")
758
759         return doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessRequest(mex) })
760     }
761
762     private void initPreProcess(ExecutionEntity mex) {
763         when(mex.getVariable(DBGFLAG)).thenReturn("true")
764         when(mex.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("sdncurn")
765         when(mex.getVariable("mso.workflow.sdnc.replication.delay")).thenReturn("sdncdelay")
766         when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
767         when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii")
768         when(mex.getVariable("allottedResourceModelInfo")).thenReturn("armi")
769         when(mex.getVariable("brgWanMacAddress")).thenReturn("bwma")
770         when(mex.getVariable("allottedResourceRole")).thenReturn("arr")
771         when(mex.getVariable("allottedResourceType")).thenReturn("art")
772     }
773
774     private void initGetAaiAR(ExecutionEntity mex) {
775         when(mex.getVariable(DBGFLAG)).thenReturn("true")
776         when(mex.getVariable("allottedResourceType")).thenReturn("TXCt")
777         when(mex.getVariable("allottedResourceRole")).thenReturn("TXCr")
778         when(mex.getVariable("CSI_service")).thenReturn(FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceTXC/getAR.xml"))
779         when(mex.getVariable("aai.endpoint")).thenReturn(aaiUriPfx)
780         when(mex.getVariable("aaiAROrchStatus")).thenReturn("Active")
781     }
782
783     private initCreateAaiAr(ExecutionEntity mex) {
784         when(mex.getVariable("disableRollback")).thenReturn(45)
785         when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
786         when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii")
787         when(mex.getVariable(DBGFLAG)).thenReturn("true")
788         when(mex.getVariable("allottedResourceId")).thenReturn(ARID)
789         when(mex.getVariable("aai.endpoint")).thenReturn(aaiUriPfx)
790         when(mex.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn(UrnPropertiesReader.getVariable("mso.workflow.global.default.aai.namespace"))
791         when(mex.getVariable("PSI_resourceLink")).thenReturn(AAIUriFactory.createResourceFromExistingURI(AAIObjectType.SERVICE_INSTANCE, UriBuilder.fromPath("/business/customers/customer/" + CUST + "/service-subscriptions/service-subscription/" + SVC + "/service-instances/service-instance/" + INST).build()))
792         when(mex.getVariable("allottedResourceType")).thenReturn("TXCt")
793         when(mex.getVariable("allottedResourceRole")).thenReturn("TXCr")
794         when(mex.getVariable("CSI_resourceLink")).thenReturn(aaiUriPfx + "/aai/v9/mycsi")
795         when(mex.getVariable("allottedResourceModelInfo")).thenReturn("""
796                 {
797                     "modelInvariantUuid":"modelinvuuid",
798                     "modelUuid":"modeluuid",
799                     "modelCustomizationUuid":"modelcustuuid"
800                 }
801             """)
802     }
803
804     private initBuildSDNCRequest(ExecutionEntity mex) {
805         when(mex.getVariable(DBGFLAG)).thenReturn("true")
806         when(mex.getVariable("allottedResourceId")).thenReturn("ari")
807         when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
808         when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii")
809         when(mex.getVariable("subscriptionServiceType")).thenReturn("sst")
810         when(mex.getVariable("globalCustomerId")).thenReturn("gci")
811         when(mex.getVariable("sdncCallbackUrl")).thenReturn("scu")
812         when(mex.getVariable("msoRequestId")).thenReturn("mri")
813     }
814
815     private RollbackData initPreProcessSDNC(ExecutionEntity mex) {
816         def data = new RollbackData()
817
818         when(mex.getVariable(DBGFLAG)).thenReturn("true")
819         when(mex.getVariable("rollbackData")).thenReturn(data)
820
821         return data
822     }
823
824     private initPreProcessSDNCGet(ExecutionEntity mex) {
825         when(mex.getVariable(DBGFLAG)).thenReturn("true")
826         when(mex.getVariable("sdncCallbackUrl")).thenReturn("myurl")
827         when(mex.getVariable("foundActiveAR")).thenReturn(true)
828         when(mex.getVariable("aaiARGetResponse")).thenReturn("<selflink>arlink</selflink>")
829         when(mex.getVariable("sdncAssignResponse")).thenReturn("<response-data>&lt;object-path&gt;assignlink&lt;/object-path&gt;</response-data>")
830         when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
831         when(mex.getVariable("sdncCallbackUrl")).thenReturn("myurl")
832     }
833
834     private RollbackData initValidateSDNCResp(ExecutionEntity mex) {
835         def data = new RollbackData()
836
837         when(mex.getVariable(DBGFLAG)).thenReturn("true")
838         when(mex.getVariable("prefix")).thenReturn(Prefix)
839         when(mex.getVariable("SDNCA_SuccessIndicator")).thenReturn(true)
840         when(mex.getVariable("rollbackData")).thenReturn(data)
841
842         return data
843     }
844
845     private String initValidateSDNCResp_Resp() {
846         return "<response-data>&lt;response-code&gt;200&lt;/response-code&gt;</response-data>"
847     }
848
849     private initUpdateAaiAROrchStatus(ExecutionEntity mex) {
850         when(mex.getVariable(DBGFLAG)).thenReturn("true")
851         when(mex.getVariable("aaiARPath")).thenReturn("/business/customers/customer/" + CUST + "/service-subscriptions/service-subscription/" + SVC + "/service-instances/service-instance/" + INST + "/allotted-resources/allotted-resource/" + ARID)
852     }
853
854 }