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.junit.Before
28 import org.junit.BeforeClass
31 import org.junit.Ignore
32 import org.mockito.MockitoAnnotations
33 import org.camunda.bpm.engine.delegate.BpmnError
34 import org.openecomp.mso.bpmn.core.WorkflowException
35 import org.openecomp.mso.bpmn.mock.FileUtil
37 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse
38 import static com.github.tomakehurst.wiremock.client.WireMock.put
39 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor
40 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching
41 import static org.junit.Assert.*;
42 import static org.mockito.Mockito.*
43 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetAllottedResource
44 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPatchAllottedResource
45 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPutAllottedResource
46 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPutAllottedResource_500
48 import org.openecomp.mso.bpmn.core.RollbackData
49 import org.openecomp.mso.bpmn.vcpe.scripts.MapSetter
51 import com.github.tomakehurst.wiremock.junit.WireMockRule
53 class DoCreateAllottedResourceBRGTest extends GroovyTestBase {
56 public WireMockRule wireMockRule = new WireMockRule(PORT)
58 String Prefix = "DCARBRG_"
61 public static void setUpBeforeClass() {
68 MockitoAnnotations.initMocks(this)
71 public DoCreateAllottedResourceBRGTest() {
72 super("DoCreateAllottedResourceBRG")
76 // ***** preProcessRequest *****
80 public void preProcessRequest() {
81 ExecutionEntity mex = setupMock()
84 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
85 DoCreateAllottedResourceBRG.preProcessRequest(mex)
87 verify(mex).getVariable(DBGFLAG)
88 verify(mex).setVariable("prefix", Prefix)
90 assertTrue(checkMissingPreProcessRequest("URN_mso_workflow_sdncadapter_callback"))
91 assertTrue(checkMissingPreProcessRequest("URN_mso_workflow_sdnc_replication_delay"))
92 assertTrue(checkMissingPreProcessRequest("serviceInstanceId"))
93 assertTrue(checkMissingPreProcessRequest("parentServiceInstanceId"))
94 assertTrue(checkMissingPreProcessRequest("allottedResourceModelInfo"))
95 assertTrue(checkMissingPreProcessRequest("vni"))
96 assertTrue(checkMissingPreProcessRequest("vgmuxBearerIP"))
97 assertTrue(checkMissingPreProcessRequest("brgWanMacAddress"))
98 assertTrue(checkMissingPreProcessRequest("allottedResourceRole"))
99 assertTrue(checkMissingPreProcessRequest("allottedResourceType"))
103 // ***** getAaiAR *****
107 public void getAaiAR() {
108 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRG/getArBrg.xml")
110 ExecutionEntity mex = setupMock()
113 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
114 DoCreateAllottedResourceBRG.getAaiAR(mex)
116 verify(mex).setVariable("foundActiveAR", true)
121 public void getAaiAR_Duplicate() {
122 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRG/getArBrg.xml")
124 ExecutionEntity mex = setupMock()
128 when(mex.getVariable("failExists")).thenReturn("true")
130 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
132 assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceBRG.getAaiAR(mex) }))
137 public void getAaiAR_NotActive() {
138 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRG/getArBrg.xml")
140 ExecutionEntity mex = setupMock()
144 when(mex.getVariable("aaiAROrchStatus")).thenReturn("not-active")
146 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
148 assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceBRG.getAaiAR(mex) }))
153 public void getAaiAR_NoStatus() {
154 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRG/getArBrg.xml")
156 ExecutionEntity mex = setupMock()
159 when(mex.getVariable("aaiAROrchStatus")).thenReturn(null)
161 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
162 DoCreateAllottedResourceBRG.getAaiAR(mex)
164 verify(mex, never()).setVariable("foundActiveAR", true)
168 // ***** createAaiAR *****
172 public void createAaiAR() {
173 ExecutionEntity mex = setupMock()
174 def map = setupMap(mex)
177 MockPutAllottedResource(CUST, SVC, INST, ARID)
179 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
180 DoCreateAllottedResourceBRG.createAaiAR(mex)
182 def data = map.get("rollbackData")
184 assertTrue(data instanceof RollbackData)
186 assertEquals("45", data.get(Prefix, "disableRollback"))
187 assertEquals("true", data.get(Prefix, "rollbackAAI"))
188 assertEquals(ARID, data.get(Prefix, "allottedResourceId"))
189 assertEquals("sii", data.get(Prefix, "serviceInstanceId"))
190 assertEquals("psii", data.get(Prefix, "parentServiceInstanceId"))
191 assertEquals(mex.getVariable("PSI_resourceLink")+"/allotted-resources/allotted-resource/"+ARID, data.get(Prefix, "aaiARPath"))
196 public void createAaiAR_NoArid_NoModelUuids() {
197 ExecutionEntity mex = setupMock()
198 def map = setupMap(mex)
201 // no allottedResourceId - will be generated
203 when(mex.getVariable("allottedResourceId")).thenReturn(null)
206 .stubFor(put(urlMatching("/aai/.*/allotted-resource/.*"))
207 .willReturn(aResponse()
210 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
211 DoCreateAllottedResourceBRG.createAaiAR(mex)
213 def arid = map.get("allottedResourceId")
215 assertFalse(arid.isEmpty())
217 def data = map.get("rollbackData")
219 assertTrue(data instanceof RollbackData)
221 assertEquals(arid, data.get(Prefix, "allottedResourceId"))
226 public void createAaiAR_MissingPsiLink() {
227 ExecutionEntity mex = setupMock()
230 when(mex.getVariable("PSI_resourceLink")).thenReturn(null)
232 MockPutAllottedResource(CUST, SVC, INST, ARID)
234 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
236 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.createAaiAR(mex) }))
241 public void createAaiAR_HttpFailed() {
242 ExecutionEntity mex = setupMock()
245 MockPutAllottedResource_500(CUST, SVC, INST, ARID)
247 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
249 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.createAaiAR(mex) }))
254 public void createAaiAR_BpmnError() {
255 ExecutionEntity mex = setupMock()
258 when(mex.getVariable("URN_aai_endpoint")).thenThrow(new BpmnError("expected exception"))
260 MockPutAllottedResource(CUST, SVC, INST, ARID)
262 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
264 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.createAaiAR(mex) }))
269 public void createAaiAR_Ex() {
270 ExecutionEntity mex = setupMock()
273 when(mex.getVariable("URN_aai_endpoint")).thenThrow(new RuntimeException("expected exception"))
275 MockPutAllottedResource(CUST, SVC, INST, ARID)
277 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
279 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.createAaiAR(mex) }))
283 // ***** buildSDNCRequest *****
287 public void buildSDNCRequest() {
288 ExecutionEntity mex = setupMock()
289 initBuildSDNCRequest(mex)
291 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
293 String result = DoCreateAllottedResourceBRG.buildSDNCRequest(mex, "myact", "myreq")
295 assertTrue(result.indexOf("<sdncadapter:RequestId>myreq</") >= 0)
296 assertTrue(result.indexOf("<sdncadapter:SvcAction>myact</") >= 0)
297 assertTrue(result.indexOf("<allotted-resource-id>ari</") >= 0)
298 assertTrue(result.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
299 assertTrue(result.indexOf("<service-instance-id>sii</") >= 0)
300 assertTrue(result.indexOf("<parent-service-instance-id>psii</") >= 0)
301 assertTrue(result.indexOf("<subscription-service-type>sst</") >= 0)
302 assertTrue(result.indexOf("<global-customer-id>gci</") >= 0)
303 assertTrue(result.indexOf("<sdncadapter:CallbackUrl>scu</") >= 0)
304 assertTrue(result.indexOf("<request-id>mri</") >= 0)
305 assertTrue(result.indexOf("<brg-wan-mac-address>bwma</") >= 0)
306 assertTrue(result.indexOf("<vni>myvni</") >= 0)
307 assertTrue(result.indexOf("<vgmux-bearer-ip>vbi</") >= 0)
308 assertTrue(result.indexOf("<model-invariant-uuid>miu</") >= 0)
309 assertTrue(result.indexOf("<model-uuid>mu</") >= 0)
310 assertTrue(result.indexOf("<model-customization-uuid>mcu</") >= 0)
311 assertTrue(result.indexOf("<model-version>mv</") >= 0)
312 assertTrue(result.indexOf("<model-name>mn</") >= 0)
317 public void buildSDNCRequest_EmptyModelInfo() {
318 ExecutionEntity mex = setupMock()
319 initBuildSDNCRequest(mex)
321 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("{}")
323 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
325 String result = DoCreateAllottedResourceBRG.buildSDNCRequest(mex, "myact", "myreq")
327 assertTrue(result.indexOf("<sdncadapter:RequestId>myreq</") >= 0)
328 assertTrue(result.indexOf("<sdncadapter:SvcAction>myact</") >= 0)
329 assertTrue(result.indexOf("<allotted-resource-id>ari</") >= 0)
330 assertTrue(result.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
331 assertTrue(result.indexOf("<service-instance-id>sii</") >= 0)
332 assertTrue(result.indexOf("<parent-service-instance-id>psii</") >= 0)
333 assertTrue(result.indexOf("<subscription-service-type>sst</") >= 0)
334 assertTrue(result.indexOf("<global-customer-id>gci</") >= 0)
335 assertTrue(result.indexOf("<sdncadapter:CallbackUrl>scu</") >= 0)
336 assertTrue(result.indexOf("<request-id>mri</") >= 0)
337 assertTrue(result.indexOf("<brg-wan-mac-address>bwma</") >= 0)
338 assertTrue(result.indexOf("<vni>myvni</") >= 0)
339 assertTrue(result.indexOf("<vgmux-bearer-ip>vbi</") >= 0)
340 assertTrue(result.indexOf("<model-invariant-uuid/>") >= 0)
341 assertTrue(result.indexOf("<model-uuid/>") >= 0)
342 assertTrue(result.indexOf("<model-customization-uuid/>") >= 0)
343 assertTrue(result.indexOf("<model-version/>") >= 0)
344 assertTrue(result.indexOf("<model-name/>") >= 0)
349 public void buildSDNCRequest_Ex() {
350 ExecutionEntity mex = setupMock()
351 initBuildSDNCRequest(mex)
353 when(mex.getVariable("allottedResourceId")).thenThrow(new RuntimeException("expected exception"))
355 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
357 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.buildSDNCRequest(mex, "myact", "myreq") }))
361 // ***** preProcessSDNCAssign *****
365 public void preProcessSDNCAssign() {
366 ExecutionEntity mex = setupMock()
367 def map = setupMap(mex)
368 def data = initPreProcessSDNC(mex)
370 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
371 DoCreateAllottedResourceBRG.preProcessSDNCAssign(mex)
373 def req = map.get("sdncAssignRequest")
376 assertEquals(data, map.get("rollbackData"))
378 def rbreq = data.get(Prefix, "sdncAssignRollbackReq")
380 assertTrue(req.indexOf("<sdncadapter:SvcAction>assign</") >= 0)
381 assertTrue(req.indexOf("<request-action>CreateBRGInstance</") >= 0)
382 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
384 assertTrue(rbreq.indexOf("<sdncadapter:SvcAction>unassign</") >= 0)
385 assertTrue(rbreq.indexOf("<request-action>DeleteBRGInstance</") >= 0)
386 assertTrue(rbreq.indexOf("<sdncadapter:RequestId>") >= 0)
391 public void preProcessSDNCAssign_BpmnError() {
392 ExecutionEntity mex = setupMock()
393 initPreProcessSDNC(mex)
395 when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception"))
397 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
399 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCAssign(mex) }))
404 public void preProcessSDNCAssign_Ex() {
405 ExecutionEntity mex = setupMock()
406 initPreProcessSDNC(mex)
408 when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception"))
410 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
412 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCAssign(mex) }))
416 // ***** preProcessSDNCCreate *****
420 public void preProcessSDNCCreate() {
421 ExecutionEntity mex = setupMock()
422 def map = setupMap(mex)
423 def data = initPreProcessSDNC(mex)
425 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
426 DoCreateAllottedResourceBRG.preProcessSDNCCreate(mex)
428 def req = map.get("sdncCreateRequest")
431 assertEquals(data, map.get("rollbackData"))
433 def rbreq = data.get(Prefix, "sdncCreateRollbackReq")
435 assertTrue(req.indexOf("<sdncadapter:SvcAction>create</") >= 0)
436 assertTrue(req.indexOf("<request-action>CreateBRGInstance</") >= 0)
437 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
439 assertTrue(rbreq.indexOf("<sdncadapter:SvcAction>delete</") >= 0)
440 assertTrue(rbreq.indexOf("<request-action>DeleteBRGInstance</") >= 0)
441 assertTrue(rbreq.indexOf("<sdncadapter:RequestId>") >= 0)
447 public void preProcessSDNCCreate_BpmnError() {
448 ExecutionEntity mex = setupMock()
449 initPreProcessSDNC(mex)
451 when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception"))
453 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
455 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCCreate(mex) }))
460 public void preProcessSDNCCreate_Ex() {
461 ExecutionEntity mex = setupMock()
462 initPreProcessSDNC(mex)
464 when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception"))
466 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
468 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCCreate(mex) }))
472 // ***** preProcessSDNCActivate *****
476 public void preProcessSDNCActivate() {
477 ExecutionEntity mex = setupMock()
478 def map = setupMap(mex)
479 def data = initPreProcessSDNC(mex)
481 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
482 DoCreateAllottedResourceBRG.preProcessSDNCActivate(mex)
484 def req = map.get("sdncActivateRequest")
487 assertEquals(data, map.get("rollbackData"))
489 def rbreq = data.get(Prefix, "sdncActivateRollbackReq")
491 assertTrue(req.indexOf("<sdncadapter:SvcAction>activate</") >= 0)
492 assertTrue(req.indexOf("<request-action>CreateBRGInstance</") >= 0)
493 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
495 assertTrue(rbreq.indexOf("<sdncadapter:SvcAction>deactivate</") >= 0)
496 assertTrue(rbreq.indexOf("<request-action>DeleteBRGInstance</") >= 0)
497 assertTrue(rbreq.indexOf("<sdncadapter:RequestId>") >= 0)
503 public void preProcessSDNCActivate_BpmnError() {
504 ExecutionEntity mex = setupMock()
505 initPreProcessSDNC(mex)
507 when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception"))
509 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
511 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCActivate(mex) }))
516 public void preProcessSDNCActivate_Ex() {
517 ExecutionEntity mex = setupMock()
518 initPreProcessSDNC(mex)
520 when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception"))
522 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
524 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCActivate(mex) }))
528 // ***** validateSDNCResp *****
532 public void validateSDNCResp() {
533 ExecutionEntity mex = setupMock()
534 def map = setupMap(mex)
535 def data = initValidateSDNCResp(mex)
536 def resp = initValidateSDNCResp_Resp()
538 when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true)
540 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
542 DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create")
544 verify(mex).getVariable("WorkflowException")
545 verify(mex).getVariable("SDNCA_SuccessIndicator")
546 verify(mex).getVariable("rollbackData")
548 assertEquals(data, map.get("rollbackData"))
550 assertEquals("true", data.get(Prefix, "rollback" + "SDNCcreate"))
556 public void validateSDNCResp_Get() {
557 ExecutionEntity mex = setupMock()
558 def data = initValidateSDNCResp(mex)
559 def resp = initValidateSDNCResp_Resp()
561 when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true)
563 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
565 DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "get")
567 verify(mex).getVariable("WorkflowException")
568 verify(mex).getVariable("SDNCA_SuccessIndicator")
570 verify(mex, never()).getVariable("rollbackData")
575 public void validateSDNCResp_Unsuccessful() {
576 ExecutionEntity mex = setupMock()
577 initValidateSDNCResp(mex)
578 def resp = initValidateSDNCResp_Resp()
581 when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(false)
583 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
585 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create") }))
590 public void validateSDNCResp_BpmnError() {
591 ExecutionEntity mex = setupMock()
592 initValidateSDNCResp(mex)
593 def resp = initValidateSDNCResp_Resp()
595 when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception"))
597 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
599 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create") }))
604 public void validateSDNCResp_Ex() {
605 ExecutionEntity mex = setupMock()
606 initValidateSDNCResp(mex)
607 def resp = initValidateSDNCResp_Resp()
609 when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
611 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
613 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create") }))
617 // ***** preProcessSDNCGet *****
621 public void preProcessSDNCGet_FoundAR() {
622 ExecutionEntity mex = setupMock()
623 def map = setupMap(mex)
624 initPreProcessSDNCGet(mex)
626 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
627 DoCreateAllottedResourceBRG.preProcessSDNCGet(mex)
629 String req = map.get("sdncGetRequest")
631 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
632 assertTrue(req.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
633 assertTrue(req.indexOf("<sdncadapter:SvcOperation>arlink</") >= 0)
634 assertTrue(req.indexOf("<sdncadapter:CallbackUrl>myurl</") >= 0)
640 public void preProcessSDNCGet_NotFoundAR() {
641 ExecutionEntity mex = setupMock()
642 def map = setupMap(mex)
643 initPreProcessSDNCGet(mex)
645 when(mex.getVariable("foundActiveAR")).thenReturn(false)
647 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
648 DoCreateAllottedResourceBRG.preProcessSDNCGet(mex)
650 String req = map.get("sdncGetRequest")
652 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
653 assertTrue(req.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
654 assertTrue(req.indexOf("<sdncadapter:SvcOperation>assignlink</") >= 0)
655 assertTrue(req.indexOf("<sdncadapter:CallbackUrl>myurl</") >= 0)
661 public void preProcessSDNCGet_Ex() {
662 ExecutionEntity mex = setupMock()
663 initPreProcessSDNCGet(mex)
665 when(mex.getVariable("foundActiveAR")).thenThrow(new RuntimeException("expected exception"))
667 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
669 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCGet(mex) }))
673 // ***** updateAaiAROrchStatus *****
677 public void updateAaiAROrchStatus() {
678 MockPatchAllottedResource(CUST, SVC, INST, ARID)
680 ExecutionEntity mex = setupMock()
681 initUpdateAaiAROrchStatus(mex)
683 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
684 DoCreateAllottedResourceBRG.updateAaiAROrchStatus(mex, "success")
688 // ***** generateOutputs *****
692 public void generateOutputs() {
693 ExecutionEntity mex = setupMock()
694 def brgtop = FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceBRG/SDNCTopologyQueryCallback.xml")
696 when(mex.getVariable(DBGFLAG)).thenReturn("true")
697 when(mex.getVariable("enhancedCallbackRequestData")).thenReturn(brgtop)
699 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
700 DoCreateAllottedResourceBRG.generateOutputs(mex)
702 verify(mex).setVariable("allotedResourceName", "namefromrequest")
708 public void generateOutputs_BadXml() {
709 ExecutionEntity mex = setupMock()
711 when(mex.getVariable(DBGFLAG)).thenReturn("true")
712 when(mex.getVariable("enhancedCallbackRequestData")).thenReturn("invalid xml")
714 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
715 DoCreateAllottedResourceBRG.generateOutputs(mex)
717 verify(mex, never()).setVariable(anyString(), anyString())
723 public void generateOutputs_BpmnError() {
724 ExecutionEntity mex = setupMock()
726 when(mex.getVariable(DBGFLAG)).thenReturn("true")
727 when(mex.getVariable("enhancedCallbackRequestData")).thenThrow(new BpmnError("expected exception"))
729 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
731 DoCreateAllottedResourceBRG.generateOutputs(mex)
732 verify(mex, never()).setVariable(anyString(), anyString())
738 public void generateOutputs_Ex() {
739 ExecutionEntity mex = setupMock()
741 when(mex.getVariable(DBGFLAG)).thenReturn("true")
742 when(mex.getVariable("enhancedCallbackRequestData")).thenThrow(new RuntimeException("expected exception"))
744 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
746 DoCreateAllottedResourceBRG.generateOutputs(mex)
747 verify(mex, never()).setVariable(anyString(), anyString())
752 // ***** preProcessRollback *****
756 public void preProcessRollback() {
757 ExecutionEntity mex = setupMock()
758 WorkflowException wfe = mock(WorkflowException.class)
760 when(mex.getVariable(DBGFLAG)).thenReturn("true")
761 when(mex.getVariable("WorkflowException")).thenReturn(wfe)
763 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
764 DoCreateAllottedResourceBRG.preProcessRollback(mex)
766 verify(mex).setVariable("prevWorkflowException", wfe)
772 public void preProcessRollback_NotWFE() {
773 ExecutionEntity mex = setupMock()
775 when(mex.getVariable(DBGFLAG)).thenReturn("true")
776 when(mex.getVariable("WorkflowException")).thenReturn("I'm not a WFE")
778 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
779 DoCreateAllottedResourceBRG.preProcessRollback(mex)
781 // verify(mex, never()).setVariable("prevWorkflowException", any())
787 public void preProcessRollback_BpmnError() {
788 ExecutionEntity mex = setupMock()
790 when(mex.getVariable(DBGFLAG)).thenReturn("true")
791 when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception"))
793 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
795 DoCreateAllottedResourceBRG.preProcessRollback(mex)
801 public void preProcessRollback_Ex() {
802 ExecutionEntity mex = setupMock()
804 when(mex.getVariable(DBGFLAG)).thenReturn("true")
805 when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
807 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
809 DoCreateAllottedResourceBRG.preProcessRollback(mex)
814 // ***** postProcessRollback *****
818 public void postProcessRollback() {
819 ExecutionEntity mex = setupMock()
820 WorkflowException wfe = mock(WorkflowException.class)
822 when(mex.getVariable(DBGFLAG)).thenReturn("true")
823 when(mex.getVariable("prevWorkflowException")).thenReturn(wfe)
825 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
826 DoCreateAllottedResourceBRG.postProcessRollback(mex)
828 verify(mex).setVariable("WorkflowException", wfe)
829 verify(mex).setVariable("rollbackData", null)
835 public void postProcessRollback_NotWFE() {
836 ExecutionEntity mex = setupMock()
838 when(mex.getVariable(DBGFLAG)).thenReturn("true")
839 when(mex.getVariable("prevWorkflowException")).thenReturn("I'm not a WFE")
841 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
842 DoCreateAllottedResourceBRG.postProcessRollback(mex)
844 // verify(mex, never()).setVariable("WorkflowException", any())
845 verify(mex).setVariable("rollbackData", null)
851 public void postProcessRollback_BpmnError() {
852 ExecutionEntity mex = setupMock()
854 when(mex.getVariable(DBGFLAG)).thenReturn("true")
855 when(mex.getVariable("prevWorkflowException")).thenThrow(new BpmnError("expected exception"))
857 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
859 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.postProcessRollback(mex) }))
860 verify(mex, never()).setVariable("rollbackData", null)
866 public void postProcessRollback_Ex() {
867 ExecutionEntity mex = setupMock()
869 when(mex.getVariable(DBGFLAG)).thenReturn("true")
870 when(mex.getVariable("prevWorkflowException")).thenThrow(new RuntimeException("expected exception"))
872 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
874 DoCreateAllottedResourceBRG.postProcessRollback(mex)
875 verify(mex, never()).setVariable("rollbackData", null)
879 private boolean checkMissingPreProcessRequest(String fieldnm) {
880 ExecutionEntity mex = setupMock()
883 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
885 when(mex.getVariable(fieldnm)).thenReturn("")
887 return doBpmnError( { _ -> DoCreateAllottedResourceBRG.preProcessRequest(mex) })
890 private void initPreProcess(ExecutionEntity mex) {
891 when(mex.getVariable(DBGFLAG)).thenReturn("true")
892 when(mex.getVariable("URN_mso_workflow_sdncadapter_callback")).thenReturn("sdncurn")
893 when(mex.getVariable("URN_mso_workflow_sdnc_replication_delay")).thenReturn("sdncdelay")
894 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
895 when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii")
896 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("armi")
897 when(mex.getVariable("vni")).thenReturn("myvni")
898 when(mex.getVariable("vgmuxBearerIP")).thenReturn("vbi")
899 when(mex.getVariable("brgWanMacAddress")).thenReturn("bwma")
900 when(mex.getVariable("allottedResourceRole")).thenReturn("arr")
901 when(mex.getVariable("allottedResourceType")).thenReturn("art")
904 private void initGetAaiAR(ExecutionEntity mex) {
905 when(mex.getVariable(DBGFLAG)).thenReturn("true")
906 when(mex.getVariable("allottedResourceType")).thenReturn("BRGt")
907 when(mex.getVariable("allottedResourceRole")).thenReturn("BRGr")
908 when(mex.getVariable("CSI_service")).thenReturn(FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceBRG/getAR.xml"))
909 when(mex.getVariable("URN_aai_endpoint")).thenReturn(aaiUriPfx)
910 when(mex.getVariable("aaiAROrchStatus")).thenReturn("Active")
913 private initCreateAaiAr(ExecutionEntity mex) {
914 when(mex.getVariable("disableRollback")).thenReturn(45)
915 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
916 when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii")
917 when(mex.getVariable(DBGFLAG)).thenReturn("true")
918 when(mex.getVariable("allottedResourceId")).thenReturn(ARID)
919 when(mex.getVariable("URN_aai_endpoint")).thenReturn(aaiUriPfx)
920 when(mex.getVariable("URN_mso_workflow_global_default_aai_namespace")).thenReturn(urnProps.get("mso.workflow.global.default.aai.namespace"))
921 when(mex.getVariable("PSI_resourceLink")).thenReturn(aaiUriPfx + "/aai/v9/business/customers/customer/"+CUST+"/service-subscriptions/service-subscription/"+SVC+"/service-instances/service-instance/"+INST)
922 when(mex.getVariable("allottedResourceType")).thenReturn("BRGt")
923 when(mex.getVariable("allottedResourceRole")).thenReturn("BRGr")
924 when(mex.getVariable("CSI_resourceLink")).thenReturn(aaiUriPfx+"/aai/v9/mycsi")
925 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("""
927 "modelInvariantUuid":"modelinvuuid",
928 "modelUuid":"modeluuid",
929 "modelCustomizationUuid":"modelcustuuid"
934 private initBuildSDNCRequest(ExecutionEntity mex) {
935 when(mex.getVariable(DBGFLAG)).thenReturn("true")
936 when(mex.getVariable("allottedResourceId")).thenReturn("ari")
937 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
938 when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii")
939 when(mex.getVariable("subscriptionServiceType")).thenReturn("sst")
940 when(mex.getVariable("globalCustomerId")).thenReturn("gci")
941 when(mex.getVariable("sdncCallbackUrl")).thenReturn("scu")
942 when(mex.getVariable("msoRequestId")).thenReturn("mri")
943 when(mex.getVariable("brgWanMacAddress")).thenReturn("bwma")
944 when(mex.getVariable("vni")).thenReturn("myvni")
945 when(mex.getVariable("vgmuxBearerIP")).thenReturn("vbi")
946 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("""
948 "modelInvariantUuid":"miu",
950 "modelCustomizationUuid":"mcu",
957 private RollbackData initPreProcessSDNC(ExecutionEntity mex) {
958 def data = new RollbackData()
960 when(mex.getVariable(DBGFLAG)).thenReturn("true")
961 when(mex.getVariable("rollbackData")).thenReturn(data)
966 private initPreProcessSDNCGet(ExecutionEntity mex) {
967 when(mex.getVariable(DBGFLAG)).thenReturn("true")
968 when(mex.getVariable("sdncCallbackUrl")).thenReturn("myurl")
969 when(mex.getVariable("foundActiveAR")).thenReturn(true)
970 when(mex.getVariable("aaiARGetResponse")).thenReturn("<selflink>arlink</selflink>")
971 when(mex.getVariable("sdncAssignResponse")).thenReturn("<response-data><object-path>assignlink</object-path></response-data>")
972 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
973 when(mex.getVariable("sdncCallbackUrl")).thenReturn("myurl")
976 private RollbackData initValidateSDNCResp(ExecutionEntity mex) {
977 def data = new RollbackData()
979 when(mex.getVariable(DBGFLAG)).thenReturn("true")
980 when(mex.getVariable("prefix")).thenReturn(Prefix)
981 when(mex.getVariable("SDNCA_SuccessIndicator")).thenReturn(true)
982 when(mex.getVariable("rollbackData")).thenReturn(data)
987 private String initValidateSDNCResp_Resp() {
988 return "<response-data><response-code>200</response-code></response-data>"
991 private initUpdateAaiAROrchStatus(ExecutionEntity mex) {
992 when(mex.getVariable(DBGFLAG)).thenReturn("true")
993 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)