2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.openecomp.mso.bpmn.vcpe.scripts
23 import org.camunda.bpm.engine.ProcessEngineServices
24 import org.camunda.bpm.engine.RepositoryService
25 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
26 import org.camunda.bpm.engine.repository.ProcessDefinition
27 import org.camunda.bpm.engine.runtime.Execution
28 import org.junit.Before
29 import org.junit.BeforeClass
32 import org.junit.Ignore
33 import org.mockito.MockitoAnnotations
34 import org.camunda.bpm.engine.delegate.BpmnError
35 import org.openecomp.mso.bpmn.core.WorkflowException
36 import org.openecomp.mso.bpmn.mock.FileUtil
38 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse
39 import static com.github.tomakehurst.wiremock.client.WireMock.put
40 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor
41 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching
42 import static org.junit.Assert.*;
43 import static org.mockito.Mockito.*
44 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetAllottedResource
45 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPatchAllottedResource
46 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPutAllottedResource
47 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPutAllottedResource_500
49 import org.openecomp.mso.bpmn.core.RollbackData
50 import org.openecomp.mso.bpmn.vcpe.scripts.MapSetter
52 import com.github.tomakehurst.wiremock.junit.WireMockRule
54 class DoCreateAllottedResourceBRGTest extends GroovyTestBase {
57 public WireMockRule wireMockRule = new WireMockRule(PORT)
59 String Prefix = "DCARBRG_"
62 public static void setUpBeforeClass() {
69 MockitoAnnotations.initMocks(this)
72 public DoCreateAllottedResourceBRGTest() {
73 super("DoCreateAllottedResourceBRG")
77 // ***** preProcessRequest *****
81 public void preProcessRequest() {
82 ExecutionEntity mex = setupMock()
85 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
86 DoCreateAllottedResourceBRG.preProcessRequest(mex)
88 verify(mex).getVariable(DBGFLAG)
89 verify(mex).setVariable("prefix", Prefix)
91 assertTrue(checkMissingPreProcessRequest("URN_mso_workflow_sdncadapter_callback"))
92 assertTrue(checkMissingPreProcessRequest("URN_mso_workflow_sdnc_replication_delay"))
93 assertTrue(checkMissingPreProcessRequest("serviceInstanceId"))
94 assertTrue(checkMissingPreProcessRequest("parentServiceInstanceId"))
95 assertTrue(checkMissingPreProcessRequest("allottedResourceModelInfo"))
96 assertTrue(checkMissingPreProcessRequest("vni"))
97 assertTrue(checkMissingPreProcessRequest("vgmuxBearerIP"))
98 assertTrue(checkMissingPreProcessRequest("brgWanMacAddress"))
99 assertTrue(checkMissingPreProcessRequest("allottedResourceRole"))
100 assertTrue(checkMissingPreProcessRequest("allottedResourceType"))
104 // ***** getAaiAR *****
108 public void getAaiAR() {
109 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRG/getArBrg.xml")
111 ExecutionEntity mex = setupMock()
114 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
115 DoCreateAllottedResourceBRG.getAaiAR(mex)
117 verify(mex).setVariable("foundActiveAR", true)
122 public void getAaiAR_Duplicate() {
123 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRG/getArBrg.xml")
125 ExecutionEntity mex = setupMock()
129 when(mex.getVariable("failExists")).thenReturn("true")
131 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
133 assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceBRG.getAaiAR(mex) }))
138 public void getAaiAR_NotActive() {
139 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRG/getArBrg.xml")
141 ExecutionEntity mex = setupMock()
145 when(mex.getVariable("aaiAROrchStatus")).thenReturn("not-active")
147 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
149 assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceBRG.getAaiAR(mex) }))
154 public void getAaiAR_NoStatus() {
155 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRG/getArBrg.xml")
157 ExecutionEntity mex = setupMock()
160 when(mex.getVariable("aaiAROrchStatus")).thenReturn(null)
162 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
163 DoCreateAllottedResourceBRG.getAaiAR(mex)
165 verify(mex, never()).setVariable("foundActiveAR", true)
169 // ***** createAaiAR *****
173 public void createAaiAR() {
174 ExecutionEntity mex = setupMock()
175 def map = setupMap(mex)
178 MockPutAllottedResource(CUST, SVC, INST, ARID)
180 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
181 DoCreateAllottedResourceBRG.createAaiAR(mex)
183 def data = map.get("rollbackData")
185 assertTrue(data instanceof RollbackData)
187 assertEquals("45", data.get(Prefix, "disableRollback"))
188 assertEquals("true", data.get(Prefix, "rollbackAAI"))
189 assertEquals(ARID, data.get(Prefix, "allottedResourceId"))
190 assertEquals("sii", data.get(Prefix, "serviceInstanceId"))
191 assertEquals("psii", data.get(Prefix, "parentServiceInstanceId"))
192 assertEquals(mex.getVariable("PSI_resourceLink")+"/allotted-resources/allotted-resource/"+ARID, data.get(Prefix, "aaiARPath"))
197 public void createAaiAR_NoArid_NoModelUuids() {
198 ExecutionEntity mex = setupMock()
199 def map = setupMap(mex)
202 // no allottedResourceId - will be generated
204 when(mex.getVariable("allottedResourceId")).thenReturn(null)
207 .stubFor(put(urlMatching("/aai/.*/allotted-resource/.*"))
208 .willReturn(aResponse()
211 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
212 DoCreateAllottedResourceBRG.createAaiAR(mex)
214 def arid = map.get("allottedResourceId")
216 assertFalse(arid.isEmpty())
218 def data = map.get("rollbackData")
220 assertTrue(data instanceof RollbackData)
222 assertEquals(arid, data.get(Prefix, "allottedResourceId"))
227 public void createAaiAR_MissingPsiLink() {
228 ExecutionEntity mex = setupMock()
231 when(mex.getVariable("PSI_resourceLink")).thenReturn(null)
233 MockPutAllottedResource(CUST, SVC, INST, ARID)
235 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
237 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.createAaiAR(mex) }))
242 public void createAaiAR_HttpFailed() {
243 ExecutionEntity mex = setupMock()
246 MockPutAllottedResource_500(CUST, SVC, INST, ARID)
248 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
250 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.createAaiAR(mex) }))
255 public void createAaiAR_BpmnError() {
256 ExecutionEntity mex = setupMock()
259 when(mex.getVariable("URN_aai_endpoint")).thenThrow(new BpmnError("expected exception"))
261 MockPutAllottedResource(CUST, SVC, INST, ARID)
263 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
265 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.createAaiAR(mex) }))
270 public void createAaiAR_Ex() {
271 ExecutionEntity mex = setupMock()
274 when(mex.getVariable("URN_aai_endpoint")).thenThrow(new RuntimeException("expected exception"))
276 MockPutAllottedResource(CUST, SVC, INST, ARID)
278 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
280 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.createAaiAR(mex) }))
284 // ***** buildSDNCRequest *****
288 public void buildSDNCRequest() {
289 ExecutionEntity mex = setupMock()
290 initBuildSDNCRequest(mex)
292 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
294 String result = DoCreateAllottedResourceBRG.buildSDNCRequest(mex, "myact", "myreq")
296 assertTrue(result.indexOf("<sdncadapter:RequestId>myreq</") >= 0)
297 assertTrue(result.indexOf("<sdncadapter:SvcAction>myact</") >= 0)
298 assertTrue(result.indexOf("<allotted-resource-id>ari</") >= 0)
299 assertTrue(result.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
300 assertTrue(result.indexOf("<service-instance-id>sii</") >= 0)
301 assertTrue(result.indexOf("<parent-service-instance-id>psii</") >= 0)
302 assertTrue(result.indexOf("<subscription-service-type>sst</") >= 0)
303 assertTrue(result.indexOf("<global-customer-id>gci</") >= 0)
304 assertTrue(result.indexOf("<sdncadapter:CallbackUrl>scu</") >= 0)
305 assertTrue(result.indexOf("<request-id>mri</") >= 0)
306 assertTrue(result.indexOf("<brg-wan-mac-address>bwma</") >= 0)
307 assertTrue(result.indexOf("<vni>myvni</") >= 0)
308 assertTrue(result.indexOf("<vgmux-bearer-ip>vbi</") >= 0)
309 assertTrue(result.indexOf("<model-invariant-uuid>miu</") >= 0)
310 assertTrue(result.indexOf("<model-uuid>mu</") >= 0)
311 assertTrue(result.indexOf("<model-customization-uuid>mcu</") >= 0)
312 assertTrue(result.indexOf("<model-version>mv</") >= 0)
313 assertTrue(result.indexOf("<model-name>mn</") >= 0)
318 public void buildSDNCRequest_EmptyModelInfo() {
319 ExecutionEntity mex = setupMock()
320 initBuildSDNCRequest(mex)
322 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("{}")
324 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
326 String result = DoCreateAllottedResourceBRG.buildSDNCRequest(mex, "myact", "myreq")
328 assertTrue(result.indexOf("<sdncadapter:RequestId>myreq</") >= 0)
329 assertTrue(result.indexOf("<sdncadapter:SvcAction>myact</") >= 0)
330 assertTrue(result.indexOf("<allotted-resource-id>ari</") >= 0)
331 assertTrue(result.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
332 assertTrue(result.indexOf("<service-instance-id>sii</") >= 0)
333 assertTrue(result.indexOf("<parent-service-instance-id>psii</") >= 0)
334 assertTrue(result.indexOf("<subscription-service-type>sst</") >= 0)
335 assertTrue(result.indexOf("<global-customer-id>gci</") >= 0)
336 assertTrue(result.indexOf("<sdncadapter:CallbackUrl>scu</") >= 0)
337 assertTrue(result.indexOf("<request-id>mri</") >= 0)
338 assertTrue(result.indexOf("<brg-wan-mac-address>bwma</") >= 0)
339 assertTrue(result.indexOf("<vni>myvni</") >= 0)
340 assertTrue(result.indexOf("<vgmux-bearer-ip>vbi</") >= 0)
341 assertTrue(result.indexOf("<model-invariant-uuid/>") >= 0)
342 assertTrue(result.indexOf("<model-uuid/>") >= 0)
343 assertTrue(result.indexOf("<model-customization-uuid/>") >= 0)
344 assertTrue(result.indexOf("<model-version/>") >= 0)
345 assertTrue(result.indexOf("<model-name/>") >= 0)
350 public void buildSDNCRequest_Ex() {
351 ExecutionEntity mex = setupMock()
352 initBuildSDNCRequest(mex)
354 when(mex.getVariable("allottedResourceId")).thenThrow(new RuntimeException("expected exception"))
356 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
358 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.buildSDNCRequest(mex, "myact", "myreq") }))
362 // ***** preProcessSDNCAssign *****
366 public void preProcessSDNCAssign() {
367 ExecutionEntity mex = setupMock()
368 def map = setupMap(mex)
369 def data = initPreProcessSDNC(mex)
371 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
372 DoCreateAllottedResourceBRG.preProcessSDNCAssign(mex)
374 def req = map.get("sdncAssignRequest")
377 assertEquals(data, map.get("rollbackData"))
379 def rbreq = data.get(Prefix, "sdncAssignRollbackReq")
381 assertTrue(req.indexOf("<sdncadapter:SvcAction>assign</") >= 0)
382 assertTrue(req.indexOf("<request-action>CreateBRGInstance</") >= 0)
383 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
385 assertTrue(rbreq.indexOf("<sdncadapter:SvcAction>unassign</") >= 0)
386 assertTrue(rbreq.indexOf("<request-action>DeleteBRGInstance</") >= 0)
387 assertTrue(rbreq.indexOf("<sdncadapter:RequestId>") >= 0)
392 public void preProcessSDNCAssign_BpmnError() {
393 ExecutionEntity mex = setupMock()
394 initPreProcessSDNC(mex)
396 when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception"))
398 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
400 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCAssign(mex) }))
405 public void preProcessSDNCAssign_Ex() {
406 ExecutionEntity mex = setupMock()
407 initPreProcessSDNC(mex)
409 when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception"))
411 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
413 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCAssign(mex) }))
417 // ***** preProcessSDNCCreate *****
421 public void preProcessSDNCCreate() {
422 ExecutionEntity mex = setupMock()
423 def map = setupMap(mex)
424 def data = initPreProcessSDNC(mex)
426 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
427 DoCreateAllottedResourceBRG.preProcessSDNCCreate(mex)
429 def req = map.get("sdncCreateRequest")
432 assertEquals(data, map.get("rollbackData"))
434 def rbreq = data.get(Prefix, "sdncCreateRollbackReq")
436 assertTrue(req.indexOf("<sdncadapter:SvcAction>create</") >= 0)
437 assertTrue(req.indexOf("<request-action>CreateBRGInstance</") >= 0)
438 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
440 assertTrue(rbreq.indexOf("<sdncadapter:SvcAction>delete</") >= 0)
441 assertTrue(rbreq.indexOf("<request-action>DeleteBRGInstance</") >= 0)
442 assertTrue(rbreq.indexOf("<sdncadapter:RequestId>") >= 0)
448 public void preProcessSDNCCreate_BpmnError() {
449 ExecutionEntity mex = setupMock()
450 initPreProcessSDNC(mex)
452 when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception"))
454 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
456 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCCreate(mex) }))
461 public void preProcessSDNCCreate_Ex() {
462 ExecutionEntity mex = setupMock()
463 initPreProcessSDNC(mex)
465 when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception"))
467 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
469 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCCreate(mex) }))
473 // ***** preProcessSDNCActivate *****
477 public void preProcessSDNCActivate() {
478 ExecutionEntity mex = setupMock()
479 def map = setupMap(mex)
480 def data = initPreProcessSDNC(mex)
482 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
483 DoCreateAllottedResourceBRG.preProcessSDNCActivate(mex)
485 def req = map.get("sdncActivateRequest")
488 assertEquals(data, map.get("rollbackData"))
490 def rbreq = data.get(Prefix, "sdncActivateRollbackReq")
492 assertTrue(req.indexOf("<sdncadapter:SvcAction>activate</") >= 0)
493 assertTrue(req.indexOf("<request-action>CreateBRGInstance</") >= 0)
494 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
496 assertTrue(rbreq.indexOf("<sdncadapter:SvcAction>deactivate</") >= 0)
497 assertTrue(rbreq.indexOf("<request-action>DeleteBRGInstance</") >= 0)
498 assertTrue(rbreq.indexOf("<sdncadapter:RequestId>") >= 0)
504 public void preProcessSDNCActivate_BpmnError() {
505 ExecutionEntity mex = setupMock()
506 initPreProcessSDNC(mex)
508 when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception"))
510 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
512 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCActivate(mex) }))
517 public void preProcessSDNCActivate_Ex() {
518 ExecutionEntity mex = setupMock()
519 initPreProcessSDNC(mex)
521 when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception"))
523 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
525 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCActivate(mex) }))
529 // ***** validateSDNCResp *****
533 public void validateSDNCResp() {
534 ExecutionEntity mex = setupMock()
535 def map = setupMap(mex)
536 def data = initValidateSDNCResp(mex)
537 def resp = initValidateSDNCResp_Resp()
539 when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true)
541 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
543 DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create")
545 verify(mex).getVariable("WorkflowException")
546 verify(mex).getVariable("SDNCA_SuccessIndicator")
547 verify(mex).getVariable("rollbackData")
549 assertEquals(data, map.get("rollbackData"))
551 assertEquals("true", data.get(Prefix, "rollback" + "SDNCcreate"))
557 public void validateSDNCResp_Get() {
558 ExecutionEntity mex = setupMock()
559 def data = initValidateSDNCResp(mex)
560 def resp = initValidateSDNCResp_Resp()
562 when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true)
564 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
566 DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "get")
568 verify(mex).getVariable("WorkflowException")
569 verify(mex).getVariable("SDNCA_SuccessIndicator")
571 verify(mex, never()).getVariable("rollbackData")
576 public void validateSDNCResp_Unsuccessful() {
577 ExecutionEntity mex = setupMock()
578 initValidateSDNCResp(mex)
579 def resp = initValidateSDNCResp_Resp()
582 when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(false)
584 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
586 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create") }))
591 public void validateSDNCResp_BpmnError() {
592 ExecutionEntity mex = setupMock()
593 initValidateSDNCResp(mex)
594 def resp = initValidateSDNCResp_Resp()
596 when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception"))
598 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
600 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create") }))
605 public void validateSDNCResp_Ex() {
606 ExecutionEntity mex = setupMock()
607 initValidateSDNCResp(mex)
608 def resp = initValidateSDNCResp_Resp()
610 when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
612 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
614 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create") }))
618 // ***** preProcessSDNCGet *****
622 public void preProcessSDNCGet_FoundAR() {
623 ExecutionEntity mex = setupMock()
624 def map = setupMap(mex)
625 initPreProcessSDNCGet(mex)
627 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
628 DoCreateAllottedResourceBRG.preProcessSDNCGet(mex)
630 String req = map.get("sdncGetRequest")
632 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
633 assertTrue(req.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
634 assertTrue(req.indexOf("<sdncadapter:SvcOperation>arlink</") >= 0)
635 assertTrue(req.indexOf("<sdncadapter:CallbackUrl>myurl</") >= 0)
641 public void preProcessSDNCGet_NotFoundAR() {
642 ExecutionEntity mex = setupMock()
643 def map = setupMap(mex)
644 initPreProcessSDNCGet(mex)
646 when(mex.getVariable("foundActiveAR")).thenReturn(false)
648 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
649 DoCreateAllottedResourceBRG.preProcessSDNCGet(mex)
651 String req = map.get("sdncGetRequest")
653 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
654 assertTrue(req.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
655 assertTrue(req.indexOf("<sdncadapter:SvcOperation>assignlink</") >= 0)
656 assertTrue(req.indexOf("<sdncadapter:CallbackUrl>myurl</") >= 0)
662 public void preProcessSDNCGet_Ex() {
663 ExecutionEntity mex = setupMock()
664 initPreProcessSDNCGet(mex)
666 when(mex.getVariable("foundActiveAR")).thenThrow(new RuntimeException("expected exception"))
668 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
670 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCGet(mex) }))
674 // ***** updateAaiAROrchStatus *****
678 public void updateAaiAROrchStatus() {
679 MockPatchAllottedResource(CUST, SVC, INST, ARID)
681 ExecutionEntity mex = setupMock()
682 initUpdateAaiAROrchStatus(mex)
684 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
685 DoCreateAllottedResourceBRG.updateAaiAROrchStatus(mex, "success")
689 // ***** generateOutputs *****
693 public void generateOutputs() {
694 ExecutionEntity mex = setupMock()
695 def brgtop = FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceBRG/SDNCTopologyQueryCallback.xml")
697 when(mex.getVariable(DBGFLAG)).thenReturn("true")
698 when(mex.getVariable("enhancedCallbackRequestData")).thenReturn(brgtop)
700 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
701 DoCreateAllottedResourceBRG.generateOutputs(mex)
703 verify(mex).setVariable("allotedResourceName", "namefromrequest")
709 public void generateOutputs_BadXml() {
710 ExecutionEntity mex = setupMock()
712 when(mex.getVariable(DBGFLAG)).thenReturn("true")
713 when(mex.getVariable("enhancedCallbackRequestData")).thenReturn("invalid xml")
715 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
716 DoCreateAllottedResourceBRG.generateOutputs(mex)
718 verify(mex, never()).setVariable(anyString(), anyString())
724 public void generateOutputs_BpmnError() {
725 ExecutionEntity mex = setupMock()
727 when(mex.getVariable(DBGFLAG)).thenReturn("true")
728 when(mex.getVariable("enhancedCallbackRequestData")).thenThrow(new BpmnError("expected exception"))
730 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
732 DoCreateAllottedResourceBRG.generateOutputs(mex)
733 verify(mex, never()).setVariable(anyString(), anyString())
739 public void generateOutputs_Ex() {
740 ExecutionEntity mex = setupMock()
742 when(mex.getVariable(DBGFLAG)).thenReturn("true")
743 when(mex.getVariable("enhancedCallbackRequestData")).thenThrow(new RuntimeException("expected exception"))
745 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
747 DoCreateAllottedResourceBRG.generateOutputs(mex)
748 verify(mex, never()).setVariable(anyString(), anyString())
753 // ***** preProcessRollback *****
757 public void preProcessRollback() {
758 ExecutionEntity mex = setupMock()
759 WorkflowException wfe = mock(WorkflowException.class)
761 when(mex.getVariable(DBGFLAG)).thenReturn("true")
762 when(mex.getVariable("WorkflowException")).thenReturn(wfe)
764 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
765 DoCreateAllottedResourceBRG.preProcessRollback(mex)
767 verify(mex).setVariable("prevWorkflowException", wfe)
773 public void preProcessRollback_NotWFE() {
774 ExecutionEntity mex = setupMock()
776 when(mex.getVariable(DBGFLAG)).thenReturn("true")
777 when(mex.getVariable("WorkflowException")).thenReturn("I'm not a WFE")
779 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
780 DoCreateAllottedResourceBRG.preProcessRollback(mex)
782 // verify(mex, never()).setVariable("prevWorkflowException", any())
788 public void preProcessRollback_BpmnError() {
789 ExecutionEntity mex = setupMock()
791 when(mex.getVariable(DBGFLAG)).thenReturn("true")
792 when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception"))
794 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
796 DoCreateAllottedResourceBRG.preProcessRollback(mex)
802 public void preProcessRollback_Ex() {
803 ExecutionEntity mex = setupMock()
805 when(mex.getVariable(DBGFLAG)).thenReturn("true")
806 when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
808 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
810 DoCreateAllottedResourceBRG.preProcessRollback(mex)
815 // ***** postProcessRollback *****
819 public void postProcessRollback() {
820 ExecutionEntity mex = setupMock()
821 WorkflowException wfe = mock(WorkflowException.class)
823 when(mex.getVariable(DBGFLAG)).thenReturn("true")
824 when(mex.getVariable("prevWorkflowException")).thenReturn(wfe)
826 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
827 DoCreateAllottedResourceBRG.postProcessRollback(mex)
829 verify(mex).setVariable("WorkflowException", wfe)
830 verify(mex).setVariable("rollbackData", null)
836 public void postProcessRollback_NotWFE() {
837 ExecutionEntity mex = setupMock()
839 when(mex.getVariable(DBGFLAG)).thenReturn("true")
840 when(mex.getVariable("prevWorkflowException")).thenReturn("I'm not a WFE")
842 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
843 DoCreateAllottedResourceBRG.postProcessRollback(mex)
845 // verify(mex, never()).setVariable("WorkflowException", any())
846 verify(mex).setVariable("rollbackData", null)
852 public void postProcessRollback_BpmnError() {
853 ExecutionEntity mex = setupMock()
855 when(mex.getVariable(DBGFLAG)).thenReturn("true")
856 when(mex.getVariable("prevWorkflowException")).thenThrow(new BpmnError("expected exception"))
858 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
860 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.postProcessRollback(mex) }))
861 verify(mex, never()).setVariable("rollbackData", null)
867 public void postProcessRollback_Ex() {
868 ExecutionEntity mex = setupMock()
870 when(mex.getVariable(DBGFLAG)).thenReturn("true")
871 when(mex.getVariable("prevWorkflowException")).thenThrow(new RuntimeException("expected exception"))
873 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
875 DoCreateAllottedResourceBRG.postProcessRollback(mex)
876 verify(mex, never()).setVariable("rollbackData", null)
880 private boolean checkMissingPreProcessRequest(String fieldnm) {
881 ExecutionEntity mex = setupMock()
884 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
886 when(mex.getVariable(fieldnm)).thenReturn("")
888 return doBpmnError( { _ -> DoCreateAllottedResourceBRG.preProcessRequest(mex) })
891 private void initPreProcess(ExecutionEntity mex) {
892 when(mex.getVariable(DBGFLAG)).thenReturn("true")
893 when(mex.getVariable("URN_mso_workflow_sdncadapter_callback")).thenReturn("sdncurn")
894 when(mex.getVariable("URN_mso_workflow_sdnc_replication_delay")).thenReturn("sdncdelay")
895 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
896 when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii")
897 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("armi")
898 when(mex.getVariable("vni")).thenReturn("myvni")
899 when(mex.getVariable("vgmuxBearerIP")).thenReturn("vbi")
900 when(mex.getVariable("brgWanMacAddress")).thenReturn("bwma")
901 when(mex.getVariable("allottedResourceRole")).thenReturn("arr")
902 when(mex.getVariable("allottedResourceType")).thenReturn("art")
905 private void initGetAaiAR(ExecutionEntity mex) {
906 when(mex.getVariable(DBGFLAG)).thenReturn("true")
907 when(mex.getVariable("allottedResourceType")).thenReturn("BRGt")
908 when(mex.getVariable("allottedResourceRole")).thenReturn("BRGr")
909 when(mex.getVariable("CSI_service")).thenReturn(FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceBRG/getAR.xml"))
910 when(mex.getVariable("URN_aai_endpoint")).thenReturn(aaiUriPfx)
911 when(mex.getVariable("aaiAROrchStatus")).thenReturn("Active")
914 private initCreateAaiAr(ExecutionEntity mex) {
915 when(mex.getVariable("disableRollback")).thenReturn(45)
916 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
917 when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii")
918 when(mex.getVariable(DBGFLAG)).thenReturn("true")
919 when(mex.getVariable("allottedResourceId")).thenReturn(ARID)
920 when(mex.getVariable("URN_aai_endpoint")).thenReturn(aaiUriPfx)
921 when(mex.getVariable("URN_mso_workflow_global_default_aai_namespace")).thenReturn(urnProps.get("mso.workflow.global.default.aai.namespace"))
922 when(mex.getVariable("PSI_resourceLink")).thenReturn(aaiUriPfx + "/aai/v9/business/customers/customer/"+CUST+"/service-subscriptions/service-subscription/"+SVC+"/service-instances/service-instance/"+INST)
923 when(mex.getVariable("allottedResourceType")).thenReturn("BRGt")
924 when(mex.getVariable("allottedResourceRole")).thenReturn("BRGr")
925 when(mex.getVariable("CSI_resourceLink")).thenReturn(aaiUriPfx+"/aai/v9/mycsi")
926 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("""
928 "modelInvariantUuid":"modelinvuuid",
929 "modelUuid":"modeluuid",
930 "modelCustomizationUuid":"modelcustuuid"
935 private initBuildSDNCRequest(ExecutionEntity mex) {
936 when(mex.getVariable(DBGFLAG)).thenReturn("true")
937 when(mex.getVariable("allottedResourceId")).thenReturn("ari")
938 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
939 when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii")
940 when(mex.getVariable("subscriptionServiceType")).thenReturn("sst")
941 when(mex.getVariable("globalCustomerId")).thenReturn("gci")
942 when(mex.getVariable("sdncCallbackUrl")).thenReturn("scu")
943 when(mex.getVariable("msoRequestId")).thenReturn("mri")
944 when(mex.getVariable("brgWanMacAddress")).thenReturn("bwma")
945 when(mex.getVariable("vni")).thenReturn("myvni")
946 when(mex.getVariable("vgmuxBearerIP")).thenReturn("vbi")
947 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("""
949 "modelInvariantUuid":"miu",
951 "modelCustomizationUuid":"mcu",
958 private RollbackData initPreProcessSDNC(ExecutionEntity mex) {
959 def data = new RollbackData()
961 when(mex.getVariable(DBGFLAG)).thenReturn("true")
962 when(mex.getVariable("rollbackData")).thenReturn(data)
967 private initPreProcessSDNCGet(ExecutionEntity mex) {
968 when(mex.getVariable(DBGFLAG)).thenReturn("true")
969 when(mex.getVariable("sdncCallbackUrl")).thenReturn("myurl")
970 when(mex.getVariable("foundActiveAR")).thenReturn(true)
971 when(mex.getVariable("aaiARGetResponse")).thenReturn("<selflink>arlink</selflink>")
972 when(mex.getVariable("sdncAssignResponse")).thenReturn("<response-data><object-path>assignlink</object-path></response-data>")
973 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
974 when(mex.getVariable("sdncCallbackUrl")).thenReturn("myurl")
977 private RollbackData initValidateSDNCResp(ExecutionEntity mex) {
978 def data = new RollbackData()
980 when(mex.getVariable(DBGFLAG)).thenReturn("true")
981 when(mex.getVariable("prefix")).thenReturn(Prefix)
982 when(mex.getVariable("SDNCA_SuccessIndicator")).thenReturn(true)
983 when(mex.getVariable("rollbackData")).thenReturn(data)
988 private String initValidateSDNCResp_Resp() {
989 return "<response-data><response-code>200</response-code></response-data>"
992 private initUpdateAaiAROrchStatus(ExecutionEntity mex) {
993 when(mex.getVariable(DBGFLAG)).thenReturn("true")
994 when(mex.getVariable("aaiARPath")).thenReturn(aaiUriPfx + "/aai/v9/business/customers/customer/"+CUST+"/service-subscriptions/service-subscription/"+SVC+"/service-instances/service-instance/"+INST+"/allotted-resources/allotted-resource/"+ARID)