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=========================================================
21 package org.onap.so.bpmn.vcpe.scripts
24 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
25 import org.junit.Before
26 import org.junit.BeforeClass
29 import org.junit.Ignore
30 import org.mockito.MockitoAnnotations
31 import org.camunda.bpm.engine.delegate.BpmnError
32 import org.onap.so.bpmn.core.UrnPropertiesReader
33 import org.onap.so.bpmn.core.WorkflowException
34 import org.onap.so.bpmn.mock.FileUtil
35 import org.onap.so.client.aai.AAIObjectType
36 import org.onap.so.client.aai.AAIResourcesClient
37 import org.onap.so.client.aai.entities.uri.AAIUriFactory
39 import javax.ws.rs.core.UriBuilder
41 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse
42 import static com.github.tomakehurst.wiremock.client.WireMock.put
43 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching
44 import static org.junit.Assert.*;
45 import static org.mockito.Mockito.*
46 import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetAllottedResource
47 import static org.onap.so.bpmn.mock.StubResponseAAI.MockPatchAllottedResource
48 import static org.onap.so.bpmn.mock.StubResponseAAI.MockPutAllottedResource
49 import static org.onap.so.bpmn.mock.StubResponseAAI.MockPutAllottedResource_500
51 import org.onap.so.bpmn.core.RollbackData
53 import com.github.tomakehurst.wiremock.junit.WireMockRule
55 class DoCreateAllottedResourceBRGTest extends GroovyTestBase {
58 public WireMockRule wireMockRule = new WireMockRule(PORT)
60 String Prefix = "DCARBRG_"
63 public static void setUpBeforeClass() {
64 aaiUriPfx = UrnPropertiesReader.getVariable("aai.endpoint")
70 MockitoAnnotations.initMocks(this)
73 public DoCreateAllottedResourceBRGTest() {
74 super("DoCreateAllottedResourceBRG")
78 // ***** preProcessRequest *****
82 public void preProcessRequest() {
83 ExecutionEntity mex = setupMock()
86 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
87 DoCreateAllottedResourceBRG.preProcessRequest(mex)
89 //verify(mex).getVariable(DBGFLAG)
90 verify(mex).setVariable("prefix", Prefix)
92 assertTrue(checkMissingPreProcessRequest("mso.workflow.sdncadapter.callback"))
93 assertTrue(checkMissingPreProcessRequest("mso.workflow.sdnc.replication.delay"))
94 assertTrue(checkMissingPreProcessRequest("serviceInstanceId"))
95 assertTrue(checkMissingPreProcessRequest("parentServiceInstanceId"))
96 assertTrue(checkMissingPreProcessRequest("allottedResourceModelInfo"))
97 assertTrue(checkMissingPreProcessRequest("vni"))
98 assertTrue(checkMissingPreProcessRequest("vgmuxBearerIP"))
99 assertTrue(checkMissingPreProcessRequest("brgWanMacAddress"))
100 assertTrue(checkMissingPreProcessRequest("allottedResourceRole"))
101 assertTrue(checkMissingPreProcessRequest("allottedResourceType"))
105 // ***** getAaiAR *****
109 public void getAaiAR() {
110 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRG/getArBrg.xml")
112 ExecutionEntity mex = setupMock()
115 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
116 DoCreateAllottedResourceBRG.getAaiAR(mex)
118 verify(mex).setVariable("foundActiveAR", true)
123 public void getAaiAR_Duplicate() {
124 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRG/getArBrg.xml")
126 ExecutionEntity mex = setupMock()
130 when(mex.getVariable("failExists")).thenReturn("true")
132 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
134 assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceBRG.getAaiAR(mex) }))
139 public void getAaiAR_NotActive() {
140 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRG/getArBrg.xml")
142 ExecutionEntity mex = setupMock()
146 when(mex.getVariable("aaiAROrchStatus")).thenReturn("not-active")
148 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
150 assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceBRG.getAaiAR(mex) }))
155 public void getAaiAR_NoStatus() {
156 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRG/getArBrg.xml")
158 ExecutionEntity mex = setupMock()
161 when(mex.getVariable("aaiAROrchStatus")).thenReturn(null)
163 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
164 DoCreateAllottedResourceBRG.getAaiAR(mex)
166 verify(mex, never()).setVariable("foundActiveAR", true)
170 // ***** createAaiAR *****
173 public void createAaiAR() {
174 ExecutionEntity mockExecution = setupMock()
175 AAIResourcesClient client = mock(AAIResourcesClient.class)
176 when(mockExecution.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()))
177 when(mockExecution.getVariable("CSI_resourceLink")).thenReturn("/aai/v9/business/customers/customer/"+CUST+"/service-subscriptions/service-subscription/"+SVC+"/service-instances/service-instance/"+INST)
178 when(mockExecution.getVariable("allottedResourceModelInfo")).thenReturn("{\n" +
179 " \"modelInvariantUuid\":\"modelInvariantUuid\",\n" +
180 " \"modelUuid\" : \"modelUuid\"\n" +
182 DoCreateAllottedResourceBRG doCreateAllottedResourceBRG = spy(DoCreateAllottedResourceBRG.class)
183 when(doCreateAllottedResourceBRG.getAAIClient()).thenReturn(client)
184 doCreateAllottedResourceBRG.createAaiAR(mockExecution)
189 public void createAaiAR_NoArid_NoModelUuids() {
190 ExecutionEntity mex = setupMock()
191 def map = setupMap(mex)
194 // no allottedResourceId - will be generated
196 when(mex.getVariable("allottedResourceId")).thenReturn(null)
199 .stubFor(put(urlMatching("/aai/.*/allotted-resource/.*"))
200 .willReturn(aResponse()
203 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
204 DoCreateAllottedResourceBRG.createAaiAR(mex)
206 def arid = map.get("allottedResourceId")
208 assertFalse(arid.isEmpty())
210 def data = map.get("rollbackData")
212 assertTrue(data instanceof RollbackData)
214 assertEquals(arid, data.get(Prefix, "allottedResourceId"))
218 public void createAaiAR_MissingPsiLink() {
219 ExecutionEntity mex = setupMock()
222 when(mex.getVariable("PSI_resourceLink")).thenReturn(null)
224 MockPutAllottedResource(CUST, SVC, INST, ARID)
226 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
228 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.createAaiAR(mex) }))
232 public void createAaiAR_HttpFailed() {
233 ExecutionEntity mex = setupMock()
236 MockPutAllottedResource_500(CUST, SVC, INST, ARID)
238 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
240 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.createAaiAR(mex) }))
244 public void createAaiAR_BpmnError() {
245 ExecutionEntity mex = setupMock()
248 when(mex.getVariable("aai.endpoint")).thenThrow(new BpmnError("expected exception"))
250 MockPutAllottedResource(CUST, SVC, INST, ARID)
252 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
254 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.createAaiAR(mex) }))
258 public void createAaiAR_Ex() {
259 ExecutionEntity mex = setupMock()
262 when(mex.getVariable("aai.endpoint")).thenThrow(new RuntimeException("expected exception"))
264 MockPutAllottedResource(CUST, SVC, INST, ARID)
266 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
268 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.createAaiAR(mex) }))
272 // ***** buildSDNCRequest *****
276 public void buildSDNCRequest() {
277 ExecutionEntity mex = setupMock()
278 initBuildSDNCRequest(mex)
280 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
282 String result = DoCreateAllottedResourceBRG.buildSDNCRequest(mex, "myact", "myreq")
284 assertTrue(result.indexOf("<sdncadapter:RequestId>myreq</") >= 0)
285 assertTrue(result.indexOf("<sdncadapter:SvcAction>myact</") >= 0)
286 assertTrue(result.indexOf("<allotted-resource-id>ari</") >= 0)
287 assertTrue(result.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
288 assertTrue(result.indexOf("<service-instance-id>sii</") >= 0)
289 assertTrue(result.indexOf("<parent-service-instance-id>psii</") >= 0)
290 assertTrue(result.indexOf("<subscription-service-type>sst</") >= 0)
291 assertTrue(result.indexOf("<global-customer-id>gci</") >= 0)
292 assertTrue(result.indexOf("<sdncadapter:CallbackUrl>scu</") >= 0)
293 assertTrue(result.indexOf("<request-id>mri</") >= 0)
294 assertTrue(result.indexOf("<brg-wan-mac-address>bwma</") >= 0)
295 assertTrue(result.indexOf("<vni>myvni</") >= 0)
296 assertTrue(result.indexOf("<vgmux-bearer-ip>vbi</") >= 0)
297 assertTrue(result.indexOf("<model-invariant-uuid>miu</") >= 0)
298 assertTrue(result.indexOf("<model-uuid>mu</") >= 0)
299 assertTrue(result.indexOf("<model-customization-uuid>mcu</") >= 0)
300 assertTrue(result.indexOf("<model-version>mv</") >= 0)
301 assertTrue(result.indexOf("<model-name>mn</") >= 0)
306 public void buildSDNCRequest_EmptyModelInfo() {
307 ExecutionEntity mex = setupMock()
308 initBuildSDNCRequest(mex)
310 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("{}")
312 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
314 String result = DoCreateAllottedResourceBRG.buildSDNCRequest(mex, "myact", "myreq")
316 assertTrue(result.indexOf("<sdncadapter:RequestId>myreq</") >= 0)
317 assertTrue(result.indexOf("<sdncadapter:SvcAction>myact</") >= 0)
318 assertTrue(result.indexOf("<allotted-resource-id>ari</") >= 0)
319 assertTrue(result.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
320 assertTrue(result.indexOf("<service-instance-id>sii</") >= 0)
321 assertTrue(result.indexOf("<parent-service-instance-id>psii</") >= 0)
322 assertTrue(result.indexOf("<subscription-service-type>sst</") >= 0)
323 assertTrue(result.indexOf("<global-customer-id>gci</") >= 0)
324 assertTrue(result.indexOf("<sdncadapter:CallbackUrl>scu</") >= 0)
325 assertTrue(result.indexOf("<request-id>mri</") >= 0)
326 assertTrue(result.indexOf("<brg-wan-mac-address>bwma</") >= 0)
327 assertTrue(result.indexOf("<vni>myvni</") >= 0)
328 assertTrue(result.indexOf("<vgmux-bearer-ip>vbi</") >= 0)
329 assertTrue(result.indexOf("<model-invariant-uuid/>") >= 0)
330 assertTrue(result.indexOf("<model-uuid/>") >= 0)
331 assertTrue(result.indexOf("<model-customization-uuid/>") >= 0)
332 assertTrue(result.indexOf("<model-version/>") >= 0)
333 assertTrue(result.indexOf("<model-name/>") >= 0)
338 public void buildSDNCRequest_Ex() {
339 ExecutionEntity mex = setupMock()
340 initBuildSDNCRequest(mex)
342 when(mex.getVariable("allottedResourceId")).thenThrow(new RuntimeException("expected exception"))
344 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
346 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.buildSDNCRequest(mex, "myact", "myreq") }))
350 // ***** preProcessSDNCAssign *****
354 public void preProcessSDNCAssign() {
355 ExecutionEntity mex = setupMock()
356 def map = setupMap(mex)
357 def data = initPreProcessSDNC(mex)
359 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
360 DoCreateAllottedResourceBRG.preProcessSDNCAssign(mex)
362 def req = map.get("sdncAssignRequest")
365 assertEquals(data, map.get("rollbackData"))
367 def rbreq = data.get(Prefix, "sdncAssignRollbackReq")
369 assertTrue(req.indexOf("<sdncadapter:SvcAction>assign</") >= 0)
370 assertTrue(req.indexOf("<request-action>CreateBRGInstance</") >= 0)
371 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
373 assertTrue(rbreq.indexOf("<sdncadapter:SvcAction>unassign</") >= 0)
374 assertTrue(rbreq.indexOf("<request-action>DeleteBRGInstance</") >= 0)
375 assertTrue(rbreq.indexOf("<sdncadapter:RequestId>") >= 0)
380 public void preProcessSDNCAssign_BpmnError() {
381 ExecutionEntity mex = setupMock()
382 initPreProcessSDNC(mex)
384 when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception"))
386 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
388 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCAssign(mex) }))
393 public void preProcessSDNCAssign_Ex() {
394 ExecutionEntity mex = setupMock()
395 initPreProcessSDNC(mex)
397 when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception"))
399 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
401 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCAssign(mex) }))
405 // ***** preProcessSDNCCreate *****
409 public void preProcessSDNCCreate() {
410 ExecutionEntity mex = setupMock()
411 def map = setupMap(mex)
412 def data = initPreProcessSDNC(mex)
414 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
415 DoCreateAllottedResourceBRG.preProcessSDNCCreate(mex)
417 def req = map.get("sdncCreateRequest")
420 assertEquals(data, map.get("rollbackData"))
422 def rbreq = data.get(Prefix, "sdncCreateRollbackReq")
424 assertTrue(req.indexOf("<sdncadapter:SvcAction>create</") >= 0)
425 assertTrue(req.indexOf("<request-action>CreateBRGInstance</") >= 0)
426 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
428 assertTrue(rbreq.indexOf("<sdncadapter:SvcAction>delete</") >= 0)
429 assertTrue(rbreq.indexOf("<request-action>DeleteBRGInstance</") >= 0)
430 assertTrue(rbreq.indexOf("<sdncadapter:RequestId>") >= 0)
436 public void preProcessSDNCCreate_BpmnError() {
437 ExecutionEntity mex = setupMock()
438 initPreProcessSDNC(mex)
440 when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception"))
442 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
444 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCCreate(mex) }))
449 public void preProcessSDNCCreate_Ex() {
450 ExecutionEntity mex = setupMock()
451 initPreProcessSDNC(mex)
453 when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception"))
455 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
457 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCCreate(mex) }))
461 // ***** preProcessSDNCActivate *****
465 public void preProcessSDNCActivate() {
466 ExecutionEntity mex = setupMock()
467 def map = setupMap(mex)
468 def data = initPreProcessSDNC(mex)
470 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
471 DoCreateAllottedResourceBRG.preProcessSDNCActivate(mex)
473 def req = map.get("sdncActivateRequest")
476 assertEquals(data, map.get("rollbackData"))
478 def rbreq = data.get(Prefix, "sdncActivateRollbackReq")
480 assertTrue(req.indexOf("<sdncadapter:SvcAction>activate</") >= 0)
481 assertTrue(req.indexOf("<request-action>CreateBRGInstance</") >= 0)
482 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
484 assertTrue(rbreq.indexOf("<sdncadapter:SvcAction>deactivate</") >= 0)
485 assertTrue(rbreq.indexOf("<request-action>DeleteBRGInstance</") >= 0)
486 assertTrue(rbreq.indexOf("<sdncadapter:RequestId>") >= 0)
492 public void preProcessSDNCActivate_BpmnError() {
493 ExecutionEntity mex = setupMock()
494 initPreProcessSDNC(mex)
496 when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception"))
498 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
500 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCActivate(mex) }))
505 public void preProcessSDNCActivate_Ex() {
506 ExecutionEntity mex = setupMock()
507 initPreProcessSDNC(mex)
509 when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception"))
511 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
513 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCActivate(mex) }))
517 // ***** validateSDNCResp *****
521 public void validateSDNCResp() {
522 ExecutionEntity mex = setupMock()
523 def map = setupMap(mex)
524 def data = initValidateSDNCResp(mex)
525 def resp = initValidateSDNCResp_Resp()
527 when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true)
529 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
531 DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create")
533 verify(mex).getVariable("WorkflowException")
534 verify(mex).getVariable("SDNCA_SuccessIndicator")
535 verify(mex).getVariable("rollbackData")
537 assertEquals(data, map.get("rollbackData"))
539 assertEquals("true", data.get(Prefix, "rollback" + "SDNCcreate"))
545 public void validateSDNCResp_Get() {
546 ExecutionEntity mex = setupMock()
547 def data = initValidateSDNCResp(mex)
548 def resp = initValidateSDNCResp_Resp()
550 when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true)
552 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
554 DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "get")
556 verify(mex).getVariable("WorkflowException")
557 verify(mex).getVariable("SDNCA_SuccessIndicator")
559 verify(mex, never()).getVariable("rollbackData")
564 public void validateSDNCResp_Unsuccessful() {
565 ExecutionEntity mex = setupMock()
566 initValidateSDNCResp(mex)
567 def resp = initValidateSDNCResp_Resp()
570 when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(false)
572 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
574 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create") }))
579 public void validateSDNCResp_BpmnError() {
580 ExecutionEntity mex = setupMock()
581 initValidateSDNCResp(mex)
582 def resp = initValidateSDNCResp_Resp()
584 when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception"))
586 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
588 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create") }))
593 public void validateSDNCResp_Ex() {
594 ExecutionEntity mex = setupMock()
595 initValidateSDNCResp(mex)
596 def resp = initValidateSDNCResp_Resp()
598 when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
600 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
602 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create") }))
606 // ***** preProcessSDNCGet *****
610 public void preProcessSDNCGet_FoundAR() {
611 ExecutionEntity mex = setupMock()
612 def map = setupMap(mex)
613 initPreProcessSDNCGet(mex)
615 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
616 DoCreateAllottedResourceBRG.preProcessSDNCGet(mex)
618 String req = map.get("sdncGetRequest")
620 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
621 assertTrue(req.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
622 assertTrue(req.indexOf("<sdncadapter:SvcOperation>arlink</") >= 0)
623 assertTrue(req.indexOf("<sdncadapter:CallbackUrl>myurl</") >= 0)
629 public void preProcessSDNCGet_NotFoundAR() {
630 ExecutionEntity mex = setupMock()
631 def map = setupMap(mex)
632 initPreProcessSDNCGet(mex)
634 when(mex.getVariable("foundActiveAR")).thenReturn(false)
636 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
637 DoCreateAllottedResourceBRG.preProcessSDNCGet(mex)
639 String req = map.get("sdncGetRequest")
641 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
642 assertTrue(req.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
643 assertTrue(req.indexOf("<sdncadapter:SvcOperation>assignlink</") >= 0)
644 assertTrue(req.indexOf("<sdncadapter:CallbackUrl>myurl</") >= 0)
650 public void preProcessSDNCGet_Ex() {
651 ExecutionEntity mex = setupMock()
652 initPreProcessSDNCGet(mex)
654 when(mex.getVariable("foundActiveAR")).thenThrow(new RuntimeException("expected exception"))
656 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
658 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCGet(mex) }))
662 // ***** updateAaiAROrchStatus *****
666 public void updateAaiAROrchStatus() {
667 MockPatchAllottedResource(CUST, SVC, INST, ARID)
669 ExecutionEntity mex = setupMock()
670 initUpdateAaiAROrchStatus(mex)
672 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
673 DoCreateAllottedResourceBRG.updateAaiAROrchStatus(mex, "success")
677 // ***** generateOutputs *****
681 public void generateOutputs() {
682 ExecutionEntity mex = setupMock()
683 def brgtop = FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceBRG/SDNCTopologyQueryCallback.xml")
685 when(mex.getVariable(DBGFLAG)).thenReturn("true")
686 when(mex.getVariable("enhancedCallbackRequestData")).thenReturn(brgtop)
688 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
689 DoCreateAllottedResourceBRG.generateOutputs(mex)
691 verify(mex).setVariable("allotedResourceName", "namefromrequest")
697 public void generateOutputs_BadXml() {
698 ExecutionEntity mex = setupMock()
700 when(mex.getVariable(DBGFLAG)).thenReturn("true")
701 when(mex.getVariable("enhancedCallbackRequestData")).thenReturn("invalid xml")
703 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
704 DoCreateAllottedResourceBRG.generateOutputs(mex)
706 verify(mex, never()).setVariable(anyString(), anyString())
712 public void generateOutputs_BpmnError() {
713 ExecutionEntity mex = setupMock()
715 when(mex.getVariable(DBGFLAG)).thenReturn("true")
716 when(mex.getVariable("enhancedCallbackRequestData")).thenThrow(new BpmnError("expected exception"))
718 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
720 DoCreateAllottedResourceBRG.generateOutputs(mex)
721 verify(mex, never()).setVariable(anyString(), anyString())
727 public void generateOutputs_Ex() {
728 ExecutionEntity mex = setupMock()
730 when(mex.getVariable(DBGFLAG)).thenReturn("true")
731 when(mex.getVariable("enhancedCallbackRequestData")).thenThrow(new RuntimeException("expected exception"))
733 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
735 DoCreateAllottedResourceBRG.generateOutputs(mex)
736 verify(mex, never()).setVariable(anyString(), anyString())
741 // ***** preProcessRollback *****
745 public void preProcessRollback() {
746 ExecutionEntity mex = setupMock()
747 WorkflowException wfe = mock(WorkflowException.class)
749 when(mex.getVariable(DBGFLAG)).thenReturn("true")
750 when(mex.getVariable("WorkflowException")).thenReturn(wfe)
752 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
753 DoCreateAllottedResourceBRG.preProcessRollback(mex)
755 verify(mex).setVariable("prevWorkflowException", wfe)
761 public void preProcessRollback_NotWFE() {
762 ExecutionEntity mex = setupMock()
764 when(mex.getVariable(DBGFLAG)).thenReturn("true")
765 when(mex.getVariable("WorkflowException")).thenReturn("I'm not a WFE")
767 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
768 DoCreateAllottedResourceBRG.preProcessRollback(mex)
770 // verify(mex, never()).setVariable("prevWorkflowException", any())
776 public void preProcessRollback_BpmnError() {
777 ExecutionEntity mex = setupMock()
779 when(mex.getVariable(DBGFLAG)).thenReturn("true")
780 when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception"))
782 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
784 DoCreateAllottedResourceBRG.preProcessRollback(mex)
790 public void preProcessRollback_Ex() {
791 ExecutionEntity mex = setupMock()
793 when(mex.getVariable(DBGFLAG)).thenReturn("true")
794 when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
796 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
798 DoCreateAllottedResourceBRG.preProcessRollback(mex)
803 // ***** postProcessRollback *****
807 public void postProcessRollback() {
808 ExecutionEntity mex = setupMock()
809 WorkflowException wfe = mock(WorkflowException.class)
811 when(mex.getVariable(DBGFLAG)).thenReturn("true")
812 when(mex.getVariable("prevWorkflowException")).thenReturn(wfe)
814 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
815 DoCreateAllottedResourceBRG.postProcessRollback(mex)
817 verify(mex).setVariable("WorkflowException", wfe)
818 verify(mex).setVariable("rollbackData", null)
824 public void postProcessRollback_NotWFE() {
825 ExecutionEntity mex = setupMock()
827 when(mex.getVariable(DBGFLAG)).thenReturn("true")
828 when(mex.getVariable("prevWorkflowException")).thenReturn("I'm not a WFE")
830 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
831 DoCreateAllottedResourceBRG.postProcessRollback(mex)
833 // verify(mex, never()).setVariable("WorkflowException", any())
834 verify(mex).setVariable("rollbackData", null)
840 public void postProcessRollback_BpmnError() {
841 ExecutionEntity mex = setupMock()
843 when(mex.getVariable(DBGFLAG)).thenReturn("true")
844 when(mex.getVariable("prevWorkflowException")).thenThrow(new BpmnError("expected exception"))
846 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
848 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.postProcessRollback(mex) }))
849 verify(mex, never()).setVariable("rollbackData", null)
855 public void postProcessRollback_Ex() {
856 ExecutionEntity mex = setupMock()
858 when(mex.getVariable(DBGFLAG)).thenReturn("true")
859 when(mex.getVariable("prevWorkflowException")).thenThrow(new RuntimeException("expected exception"))
861 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
863 DoCreateAllottedResourceBRG.postProcessRollback(mex)
864 verify(mex, never()).setVariable("rollbackData", null)
868 private boolean checkMissingPreProcessRequest(String fieldnm) {
869 ExecutionEntity mex = setupMock()
872 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
874 when(mex.getVariable(fieldnm)).thenReturn("")
876 return doBpmnError( { _ -> DoCreateAllottedResourceBRG.preProcessRequest(mex) })
879 private void initPreProcess(ExecutionEntity mex) {
880 when(mex.getVariable(DBGFLAG)).thenReturn("true")
881 when(mex.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("sdncurn")
882 when(mex.getVariable("mso.workflow.sdnc.replication.delay")).thenReturn("sdncdelay")
883 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
884 when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii")
885 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("armi")
886 when(mex.getVariable("vni")).thenReturn("myvni")
887 when(mex.getVariable("vgmuxBearerIP")).thenReturn("vbi")
888 when(mex.getVariable("brgWanMacAddress")).thenReturn("bwma")
889 when(mex.getVariable("allottedResourceRole")).thenReturn("arr")
890 when(mex.getVariable("allottedResourceType")).thenReturn("art")
893 private void initGetAaiAR(ExecutionEntity mex) {
894 when(mex.getVariable(DBGFLAG)).thenReturn("true")
895 when(mex.getVariable("allottedResourceType")).thenReturn("BRGt")
896 when(mex.getVariable("allottedResourceRole")).thenReturn("BRGr")
897 when(mex.getVariable("CSI_service")).thenReturn(FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceBRG/getAR.xml"))
898 when(mex.getVariable("aai.endpoint")).thenReturn(aaiUriPfx)
899 when(mex.getVariable("aaiAROrchStatus")).thenReturn("Active")
902 private initCreateAaiAr(ExecutionEntity mex) {
903 when(mex.getVariable("disableRollback")).thenReturn(45)
904 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
905 when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii")
906 when(mex.getVariable(DBGFLAG)).thenReturn("true")
907 when(mex.getVariable("allottedResourceId")).thenReturn(ARID)
908 when(mex.getVariable("aai.endpoint")).thenReturn(aaiUriPfx)
909 when(mex.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn(UrnPropertiesReader.getVariable("mso.workflow.global.default.aai.namespace"))
910 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()))
911 when(mex.getVariable("allottedResourceType")).thenReturn("BRGt")
912 when(mex.getVariable("allottedResourceRole")).thenReturn("BRGr")
913 when(mex.getVariable("CSI_resourceLink")).thenReturn(aaiUriPfx+"/aai/v9/mycsi")
914 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("""
916 "modelInvariantUuid":"modelinvuuid",
917 "modelUuid":"modeluuid",
918 "modelCustomizationUuid":"modelcustuuid"
923 private initBuildSDNCRequest(ExecutionEntity mex) {
924 when(mex.getVariable(DBGFLAG)).thenReturn("true")
925 when(mex.getVariable("allottedResourceId")).thenReturn("ari")
926 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
927 when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii")
928 when(mex.getVariable("subscriptionServiceType")).thenReturn("sst")
929 when(mex.getVariable("globalCustomerId")).thenReturn("gci")
930 when(mex.getVariable("sdncCallbackUrl")).thenReturn("scu")
931 when(mex.getVariable("msoRequestId")).thenReturn("mri")
932 when(mex.getVariable("brgWanMacAddress")).thenReturn("bwma")
933 when(mex.getVariable("vni")).thenReturn("myvni")
934 when(mex.getVariable("vgmuxBearerIP")).thenReturn("vbi")
935 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("""
937 "modelInvariantUuid":"miu",
939 "modelCustomizationUuid":"mcu",
946 private RollbackData initPreProcessSDNC(ExecutionEntity mex) {
947 def data = new RollbackData()
949 when(mex.getVariable(DBGFLAG)).thenReturn("true")
950 when(mex.getVariable("rollbackData")).thenReturn(data)
955 private initPreProcessSDNCGet(ExecutionEntity mex) {
956 when(mex.getVariable(DBGFLAG)).thenReturn("true")
957 when(mex.getVariable("sdncCallbackUrl")).thenReturn("myurl")
958 when(mex.getVariable("foundActiveAR")).thenReturn(true)
959 when(mex.getVariable("aaiARGetResponse")).thenReturn("<selflink>arlink</selflink>")
960 when(mex.getVariable("sdncAssignResponse")).thenReturn("<response-data><object-path>assignlink</object-path></response-data>")
961 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
962 when(mex.getVariable("sdncCallbackUrl")).thenReturn("myurl")
965 private RollbackData initValidateSDNCResp(ExecutionEntity mex) {
966 def data = new RollbackData()
968 when(mex.getVariable(DBGFLAG)).thenReturn("true")
969 when(mex.getVariable("prefix")).thenReturn(Prefix)
970 when(mex.getVariable("SDNCA_SuccessIndicator")).thenReturn(true)
971 when(mex.getVariable("rollbackData")).thenReturn(data)
976 private String initValidateSDNCResp_Resp() {
977 return "<response-data><response-code>200</response-code></response-data>"
980 private initUpdateAaiAROrchStatus(ExecutionEntity mex) {
981 when(mex.getVariable(DBGFLAG)).thenReturn("true")
982 when(mex.getVariable("aaiARPath")).thenReturn("/business/customers/customer/"+CUST+"/service-subscriptions/service-subscription/"+SVC+"/service-instances/service-instance/"+INST+"/allotted-resources/allotted-resource/"+ARID)