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