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
\r
24 import org.camunda.bpm.engine.RepositoryService
\r
25 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
\r
26 import org.camunda.bpm.engine.repository.ProcessDefinition
\r
27 import org.camunda.bpm.engine.runtime.Execution
\r
28 import org.junit.Before
29 import org.junit.BeforeClass
\r
30 import org.junit.Rule
\r
32 import org.junit.Ignore
\r
33 import org.mockito.MockitoAnnotations
34 import org.camunda.bpm.engine.delegate.BpmnError
\r
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.*;
\r
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
\r
54 class DoCreateAllottedResourceBRGTest extends GroovyTestBase {
57 public WireMockRule wireMockRule = new WireMockRule(PORT)
59 String Prefix = "DCARBRG_"
\r
62 public static void setUpBeforeClass() {
63 super.setUpBeforeClass()
69 MockitoAnnotations.initMocks(this)
\r
72 public DoCreateAllottedResourceBRGTest() {
73 super("DoCreateAllottedResourceBRG")
77 // ***** preProcessRequest *****
\r
81 public void preProcessRequest() {
\r
82 ExecutionEntity mex = setupMock()
85 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
\r
86 DoCreateAllottedResourceBRG.preProcessRequest(mex)
\r
88 verify(mex).getVariable(DBGFLAG)
\r
89 verify(mex).setVariable("prefix", Prefix)
\r
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"))
\r
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>psii</") >= 0)
301 assertTrue(result.indexOf("<parent-service-instance-id>psii</") >= 0)
302 assertTrue(result.indexOf("<sdncadapter:CallbackUrl>scu</") >= 0)
303 assertTrue(result.indexOf("<request-id>mri</") >= 0)
304 assertTrue(result.indexOf("<brg-wan-mac-address>bwma</") >= 0)
305 assertTrue(result.indexOf("<vni>myvni</") >= 0)
306 assertTrue(result.indexOf("<vgmux-bearer-ip>vbi</") >= 0)
307 assertTrue(result.indexOf("<model-invariant-uuid>miu</") >= 0)
308 assertTrue(result.indexOf("<model-uuid>mu</") >= 0)
309 assertTrue(result.indexOf("<model-customization-uuid>mcu</") >= 0)
310 assertTrue(result.indexOf("<model-version>mv</") >= 0)
311 assertTrue(result.indexOf("<model-name>mn</") >= 0)
316 public void buildSDNCRequest_EmptyModelInfo() {
317 ExecutionEntity mex = setupMock()
318 initBuildSDNCRequest(mex)
320 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("{}")
322 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
324 String result = DoCreateAllottedResourceBRG.buildSDNCRequest(mex, "myact", "myreq")
326 assertTrue(result.indexOf("<sdncadapter:RequestId>myreq</") >= 0)
327 assertTrue(result.indexOf("<sdncadapter:SvcAction>myact</") >= 0)
328 assertTrue(result.indexOf("<allotted-resource-id>ari</") >= 0)
329 assertTrue(result.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
330 assertTrue(result.indexOf("<service-instance-id>psii</") >= 0)
331 assertTrue(result.indexOf("<parent-service-instance-id>psii</") >= 0)
332 assertTrue(result.indexOf("<sdncadapter:CallbackUrl>scu</") >= 0)
333 assertTrue(result.indexOf("<request-id>mri</") >= 0)
334 assertTrue(result.indexOf("<brg-wan-mac-address>bwma</") >= 0)
335 assertTrue(result.indexOf("<vni>myvni</") >= 0)
336 assertTrue(result.indexOf("<vgmux-bearer-ip>vbi</") >= 0)
337 assertTrue(result.indexOf("<model-invariant-uuid/>") >= 0)
338 assertTrue(result.indexOf("<model-uuid/>") >= 0)
339 assertTrue(result.indexOf("<model-customization-uuid/>") >= 0)
340 assertTrue(result.indexOf("<model-version/>") >= 0)
341 assertTrue(result.indexOf("<model-name/>") >= 0)
346 public void buildSDNCRequest_Ex() {
347 ExecutionEntity mex = setupMock()
348 initBuildSDNCRequest(mex)
350 when(mex.getVariable("allottedResourceId")).thenThrow(new RuntimeException("expected exception"))
352 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
354 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.buildSDNCRequest(mex, "myact", "myreq") }))
358 // ***** preProcessSDNCAssign *****
362 public void preProcessSDNCAssign() {
363 ExecutionEntity mex = setupMock()
364 def map = setupMap(mex)
365 def data = initPreProcessSDNC(mex)
367 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
368 DoCreateAllottedResourceBRG.preProcessSDNCAssign(mex)
370 def req = map.get("sdncAssignRequest")
373 assertEquals(data, map.get("rollbackData"))
375 def rbreq = data.get(Prefix, "sdncAssignRollbackReq")
377 assertTrue(req.indexOf("<sdncadapter:SvcAction>assign</") >= 0)
378 assertTrue(req.indexOf("<request-action>CreateBRGInstance</") >= 0)
379 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
381 assertTrue(rbreq.indexOf("<sdncadapter:SvcAction>unassign</") >= 0)
382 assertTrue(rbreq.indexOf("<request-action>DeleteBRGInstance</") >= 0)
383 assertTrue(rbreq.indexOf("<sdncadapter:RequestId>") >= 0)
388 public void preProcessSDNCAssign_BpmnError() {
389 ExecutionEntity mex = setupMock()
390 initPreProcessSDNC(mex)
392 when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception"))
394 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
396 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCAssign(mex) }))
401 public void preProcessSDNCAssign_Ex() {
402 ExecutionEntity mex = setupMock()
403 initPreProcessSDNC(mex)
405 when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception"))
407 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
409 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCAssign(mex) }))
413 // ***** preProcessSDNCCreate *****
417 public void preProcessSDNCCreate() {
418 ExecutionEntity mex = setupMock()
419 def map = setupMap(mex)
420 def data = initPreProcessSDNC(mex)
422 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
423 DoCreateAllottedResourceBRG.preProcessSDNCCreate(mex)
425 def req = map.get("sdncCreateRequest")
428 assertEquals(data, map.get("rollbackData"))
430 def rbreq = data.get(Prefix, "sdncCreateRollbackReq")
432 assertTrue(req.indexOf("<sdncadapter:SvcAction>create</") >= 0)
433 assertTrue(req.indexOf("<request-action>CreateBRGInstance</") >= 0)
434 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
436 assertTrue(rbreq.indexOf("<sdncadapter:SvcAction>delete</") >= 0)
437 assertTrue(rbreq.indexOf("<request-action>DeleteBRGInstance</") >= 0)
438 assertTrue(rbreq.indexOf("<sdncadapter:RequestId>") >= 0)
444 public void preProcessSDNCCreate_BpmnError() {
445 ExecutionEntity mex = setupMock()
446 initPreProcessSDNC(mex)
448 when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception"))
450 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
452 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCCreate(mex) }))
457 public void preProcessSDNCCreate_Ex() {
458 ExecutionEntity mex = setupMock()
459 initPreProcessSDNC(mex)
461 when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception"))
463 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
465 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCCreate(mex) }))
469 // ***** preProcessSDNCActivate *****
473 public void preProcessSDNCActivate() {
474 ExecutionEntity mex = setupMock()
475 def map = setupMap(mex)
476 def data = initPreProcessSDNC(mex)
478 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
479 DoCreateAllottedResourceBRG.preProcessSDNCActivate(mex)
481 def req = map.get("sdncActivateRequest")
484 assertEquals(data, map.get("rollbackData"))
486 def rbreq = data.get(Prefix, "sdncActivateRollbackReq")
488 assertTrue(req.indexOf("<sdncadapter:SvcAction>activate</") >= 0)
489 assertTrue(req.indexOf("<request-action>CreateBRGInstance</") >= 0)
490 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
492 assertTrue(rbreq.indexOf("<sdncadapter:SvcAction>deactivate</") >= 0)
493 assertTrue(rbreq.indexOf("<request-action>DeleteBRGInstance</") >= 0)
494 assertTrue(rbreq.indexOf("<sdncadapter:RequestId>") >= 0)
500 public void preProcessSDNCActivate_BpmnError() {
501 ExecutionEntity mex = setupMock()
502 initPreProcessSDNC(mex)
504 when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception"))
506 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
508 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCActivate(mex) }))
513 public void preProcessSDNCActivate_Ex() {
514 ExecutionEntity mex = setupMock()
515 initPreProcessSDNC(mex)
517 when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception"))
519 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
521 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCActivate(mex) }))
525 // ***** validateSDNCResp *****
529 public void validateSDNCResp() {
530 ExecutionEntity mex = setupMock()
531 def map = setupMap(mex)
532 def data = initValidateSDNCResp(mex)
533 def resp = initValidateSDNCResp_Resp()
535 when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true)
537 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
539 DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create")
541 verify(mex).getVariable("WorkflowException")
542 verify(mex).getVariable("SDNCA_SuccessIndicator")
543 verify(mex).getVariable("rollbackData")
545 assertEquals(data, map.get("rollbackData"))
547 assertEquals("true", data.get(Prefix, "rollback" + "SDNCcreate"))
553 public void validateSDNCResp_Get() {
554 ExecutionEntity mex = setupMock()
555 def data = initValidateSDNCResp(mex)
556 def resp = initValidateSDNCResp_Resp()
558 when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true)
560 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
562 DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "get")
564 verify(mex).getVariable("WorkflowException")
565 verify(mex).getVariable("SDNCA_SuccessIndicator")
567 verify(mex, never()).getVariable("rollbackData")
572 public void validateSDNCResp_Unsuccessful() {
573 ExecutionEntity mex = setupMock()
574 initValidateSDNCResp(mex)
575 def resp = initValidateSDNCResp_Resp()
578 when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(false)
580 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
582 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create") }))
587 public void validateSDNCResp_BpmnError() {
588 ExecutionEntity mex = setupMock()
589 initValidateSDNCResp(mex)
590 def resp = initValidateSDNCResp_Resp()
592 when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception"))
594 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
596 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create") }))
601 public void validateSDNCResp_Ex() {
602 ExecutionEntity mex = setupMock()
603 initValidateSDNCResp(mex)
604 def resp = initValidateSDNCResp_Resp()
606 when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
608 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
610 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create") }))
614 // ***** preProcessSDNCGet *****
618 public void preProcessSDNCGet_FoundAR() {
619 ExecutionEntity mex = setupMock()
620 def map = setupMap(mex)
621 initPreProcessSDNCGet(mex)
623 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
624 DoCreateAllottedResourceBRG.preProcessSDNCGet(mex)
626 String req = map.get("sdncGetRequest")
628 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
629 assertTrue(req.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
630 assertTrue(req.indexOf("<sdncadapter:SvcOperation>arlink</") >= 0)
631 assertTrue(req.indexOf("<sdncadapter:CallbackUrl>myurl</") >= 0)
637 public void preProcessSDNCGet_NotFoundAR() {
638 ExecutionEntity mex = setupMock()
639 def map = setupMap(mex)
640 initPreProcessSDNCGet(mex)
642 when(mex.getVariable("foundActiveAR")).thenReturn(false)
644 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
645 DoCreateAllottedResourceBRG.preProcessSDNCGet(mex)
647 String req = map.get("sdncGetRequest")
649 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
650 assertTrue(req.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
651 assertTrue(req.indexOf("<sdncadapter:SvcOperation>assignlink</") >= 0)
652 assertTrue(req.indexOf("<sdncadapter:CallbackUrl>myurl</") >= 0)
658 public void preProcessSDNCGet_Ex() {
659 ExecutionEntity mex = setupMock()
660 initPreProcessSDNCGet(mex)
662 when(mex.getVariable("foundActiveAR")).thenThrow(new RuntimeException("expected exception"))
664 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
666 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCGet(mex) }))
670 // ***** updateAaiAROrchStatus *****
674 public void updateAaiAROrchStatus() {
675 MockPatchAllottedResource(CUST, SVC, INST, ARID)
677 ExecutionEntity mex = setupMock()
678 initUpdateAaiAROrchStatus(mex)
680 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
681 DoCreateAllottedResourceBRG.updateAaiAROrchStatus(mex, "success")
685 // ***** generateOutputs *****
689 public void generateOutputs() {
690 ExecutionEntity mex = setupMock()
691 def brgtop = FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceBRG/SDNCTopologyQueryCallback.xml")
693 when(mex.getVariable(DBGFLAG)).thenReturn("true")
694 when(mex.getVariable("enhancedCallbackRequestData")).thenReturn(brgtop)
696 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
697 DoCreateAllottedResourceBRG.generateOutputs(mex)
699 verify(mex).setVariable("allotedResourceName", "namefromrequest")
705 public void generateOutputs_BadXml() {
706 ExecutionEntity mex = setupMock()
708 when(mex.getVariable(DBGFLAG)).thenReturn("true")
709 when(mex.getVariable("enhancedCallbackRequestData")).thenReturn("invalid xml")
711 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
712 DoCreateAllottedResourceBRG.generateOutputs(mex)
714 verify(mex, never()).setVariable(anyString(), anyString())
720 public void generateOutputs_BpmnError() {
721 ExecutionEntity mex = setupMock()
723 when(mex.getVariable(DBGFLAG)).thenReturn("true")
724 when(mex.getVariable("enhancedCallbackRequestData")).thenThrow(new BpmnError("expected exception"))
726 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
728 DoCreateAllottedResourceBRG.generateOutputs(mex)
729 verify(mex, never()).setVariable(anyString(), anyString())
735 public void generateOutputs_Ex() {
736 ExecutionEntity mex = setupMock()
738 when(mex.getVariable(DBGFLAG)).thenReturn("true")
739 when(mex.getVariable("enhancedCallbackRequestData")).thenThrow(new RuntimeException("expected exception"))
741 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
743 DoCreateAllottedResourceBRG.generateOutputs(mex)
744 verify(mex, never()).setVariable(anyString(), anyString())
749 // ***** preProcessRollback *****
753 public void preProcessRollback() {
754 ExecutionEntity mex = setupMock()
755 WorkflowException wfe = mock(WorkflowException.class)
757 when(mex.getVariable(DBGFLAG)).thenReturn("true")
758 when(mex.getVariable("WorkflowException")).thenReturn(wfe)
760 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
761 DoCreateAllottedResourceBRG.preProcessRollback(mex)
763 verify(mex).setVariable("prevWorkflowException", wfe)
769 public void preProcessRollback_NotWFE() {
770 ExecutionEntity mex = setupMock()
772 when(mex.getVariable(DBGFLAG)).thenReturn("true")
773 when(mex.getVariable("WorkflowException")).thenReturn("I'm not a WFE")
775 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
776 DoCreateAllottedResourceBRG.preProcessRollback(mex)
778 // verify(mex, never()).setVariable("prevWorkflowException", any())
784 public void preProcessRollback_BpmnError() {
785 ExecutionEntity mex = setupMock()
787 when(mex.getVariable(DBGFLAG)).thenReturn("true")
788 when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception"))
790 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
792 DoCreateAllottedResourceBRG.preProcessRollback(mex)
798 public void preProcessRollback_Ex() {
799 ExecutionEntity mex = setupMock()
801 when(mex.getVariable(DBGFLAG)).thenReturn("true")
802 when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
804 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
806 DoCreateAllottedResourceBRG.preProcessRollback(mex)
811 // ***** postProcessRollback *****
815 public void postProcessRollback() {
816 ExecutionEntity mex = setupMock()
817 WorkflowException wfe = mock(WorkflowException.class)
819 when(mex.getVariable(DBGFLAG)).thenReturn("true")
820 when(mex.getVariable("prevWorkflowException")).thenReturn(wfe)
822 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
823 DoCreateAllottedResourceBRG.postProcessRollback(mex)
825 verify(mex).setVariable("WorkflowException", wfe)
826 verify(mex).setVariable("rollbackData", null)
832 public void postProcessRollback_NotWFE() {
833 ExecutionEntity mex = setupMock()
835 when(mex.getVariable(DBGFLAG)).thenReturn("true")
836 when(mex.getVariable("prevWorkflowException")).thenReturn("I'm not a WFE")
838 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
839 DoCreateAllottedResourceBRG.postProcessRollback(mex)
841 // verify(mex, never()).setVariable("WorkflowException", any())
842 verify(mex).setVariable("rollbackData", null)
848 public void postProcessRollback_BpmnError() {
849 ExecutionEntity mex = setupMock()
851 when(mex.getVariable(DBGFLAG)).thenReturn("true")
852 when(mex.getVariable("prevWorkflowException")).thenThrow(new BpmnError("expected exception"))
854 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
856 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.postProcessRollback(mex) }))
857 verify(mex, never()).setVariable("rollbackData", null)
863 public void postProcessRollback_Ex() {
864 ExecutionEntity mex = setupMock()
866 when(mex.getVariable(DBGFLAG)).thenReturn("true")
867 when(mex.getVariable("prevWorkflowException")).thenThrow(new RuntimeException("expected exception"))
869 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
871 DoCreateAllottedResourceBRG.postProcessRollback(mex)
872 verify(mex, never()).setVariable("rollbackData", null)
876 private boolean checkMissingPreProcessRequest(String fieldnm) {
877 ExecutionEntity mex = setupMock()
880 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
882 when(mex.getVariable(fieldnm)).thenReturn("")
884 return doBpmnError( { _ -> DoCreateAllottedResourceBRG.preProcessRequest(mex) })
887 private void initPreProcess(ExecutionEntity mex) {
888 when(mex.getVariable(DBGFLAG)).thenReturn("true")
889 when(mex.getVariable("URN_mso_workflow_sdncadapter_callback")).thenReturn("sdncurn")
890 when(mex.getVariable("URN_mso_workflow_sdnc_replication_delay")).thenReturn("sdncdelay")
891 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
892 when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii")
893 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("armi")
894 when(mex.getVariable("vni")).thenReturn("myvni")
895 when(mex.getVariable("vgmuxBearerIP")).thenReturn("vbi")
896 when(mex.getVariable("brgWanMacAddress")).thenReturn("bwma")
897 when(mex.getVariable("allottedResourceRole")).thenReturn("arr")
898 when(mex.getVariable("allottedResourceType")).thenReturn("art")
901 private void initGetAaiAR(ExecutionEntity mex) {
902 when(mex.getVariable(DBGFLAG)).thenReturn("true")
903 when(mex.getVariable("allottedResourceType")).thenReturn("BRGt")
904 when(mex.getVariable("allottedResourceRole")).thenReturn("BRGr")
905 when(mex.getVariable("CSI_service")).thenReturn(FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceBRG/getAR.xml"))
906 when(mex.getVariable("URN_aai_endpoint")).thenReturn(aaiUriPfx)
907 when(mex.getVariable("aaiAROrchStatus")).thenReturn("Active")
910 private initCreateAaiAr(ExecutionEntity mex) {
911 when(mex.getVariable("disableRollback")).thenReturn(45)
912 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
913 when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii")
914 when(mex.getVariable(DBGFLAG)).thenReturn("true")
915 when(mex.getVariable("allottedResourceId")).thenReturn(ARID)
916 when(mex.getVariable("URN_aai_endpoint")).thenReturn(aaiUriPfx)
917 when(mex.getVariable("URN_mso_workflow_global_default_aai_namespace")).thenReturn(urnProps.get("mso.workflow.global.default.aai.namespace"))
918 when(mex.getVariable("PSI_resourceLink")).thenReturn(aaiUriPfx + "/aai/v9/business/customers/customer/"+CUST+"/service-subscriptions/service-subscription/"+SVC+"/service-instances/service-instance/"+INST)
919 when(mex.getVariable("allottedResourceType")).thenReturn("BRGt")
920 when(mex.getVariable("allottedResourceRole")).thenReturn("BRGr")
921 when(mex.getVariable("CSI_resourceLink")).thenReturn(aaiUriPfx+"/aai/v9/mycsi")
922 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("""
924 "modelInvariantUuid":"modelinvuuid",
925 "modelUuid":"modeluuid",
926 "modelCustomizationUuid":"modelcustuuid"
931 private initBuildSDNCRequest(ExecutionEntity mex) {
932 when(mex.getVariable(DBGFLAG)).thenReturn("true")
933 when(mex.getVariable("allottedResourceId")).thenReturn("ari")
934 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
935 when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii")
936 when(mex.getVariable("sdncCallbackUrl")).thenReturn("scu")
937 when(mex.getVariable("msoRequestId")).thenReturn("mri")
938 when(mex.getVariable("brgWanMacAddress")).thenReturn("bwma")
939 when(mex.getVariable("vni")).thenReturn("myvni")
940 when(mex.getVariable("vgmuxBearerIP")).thenReturn("vbi")
941 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("""
943 "modelInvariantUuid":"miu",
945 "modelCustomizationUuid":"mcu",
952 private RollbackData initPreProcessSDNC(ExecutionEntity mex) {
953 def data = new RollbackData()
955 when(mex.getVariable(DBGFLAG)).thenReturn("true")
956 when(mex.getVariable("rollbackData")).thenReturn(data)
961 private initPreProcessSDNCGet(ExecutionEntity mex) {
962 when(mex.getVariable(DBGFLAG)).thenReturn("true")
963 when(mex.getVariable("sdncCallbackUrl")).thenReturn("myurl")
964 when(mex.getVariable("foundActiveAR")).thenReturn(true)
965 when(mex.getVariable("aaiARGetResponse")).thenReturn("<selflink>arlink</selflink>")
966 when(mex.getVariable("sdncAssignResponse")).thenReturn("<response-data><object-path>assignlink</object-path></response-data>")
967 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
968 when(mex.getVariable("sdncCallbackUrl")).thenReturn("myurl")
971 private RollbackData initValidateSDNCResp(ExecutionEntity mex) {
972 def data = new RollbackData()
974 when(mex.getVariable(DBGFLAG)).thenReturn("true")
975 when(mex.getVariable("prefix")).thenReturn(Prefix)
976 when(mex.getVariable("SDNCA_SuccessIndicator")).thenReturn(true)
977 when(mex.getVariable("rollbackData")).thenReturn(data)
982 private String initValidateSDNCResp_Resp() {
983 return "<response-data><response-code>200</response-code></response-data>"
986 private initUpdateAaiAROrchStatus(ExecutionEntity mex) {
987 when(mex.getVariable(DBGFLAG)).thenReturn("true")
988 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)