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("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"))
\r
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>psii</") >= 0)
300 assertTrue(result.indexOf("<parent-service-instance-id>psii</") >= 0)
301 assertTrue(result.indexOf("<sdncadapter:CallbackUrl>scu</") >= 0)
302 assertTrue(result.indexOf("<request-id>mri</") >= 0)
303 assertTrue(result.indexOf("<brg-wan-mac-address>bwma</") >= 0)
304 assertTrue(result.indexOf("<vni>myvni</") >= 0)
305 assertTrue(result.indexOf("<vgmux-bearer-ip>vbi</") >= 0)
306 assertTrue(result.indexOf("<model-invariant-uuid>miu</") >= 0)
307 assertTrue(result.indexOf("<model-uuid>mu</") >= 0)
308 assertTrue(result.indexOf("<model-customization-uuid>mcu</") >= 0)
309 assertTrue(result.indexOf("<model-version>mv</") >= 0)
310 assertTrue(result.indexOf("<model-name>mn</") >= 0)
315 public void buildSDNCRequest_EmptyModelInfo() {
316 ExecutionEntity mex = setupMock()
317 initBuildSDNCRequest(mex)
319 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("{}")
321 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
323 String result = DoCreateAllottedResourceBRG.buildSDNCRequest(mex, "myact", "myreq")
325 assertTrue(result.indexOf("<sdncadapter:RequestId>myreq</") >= 0)
326 assertTrue(result.indexOf("<sdncadapter:SvcAction>myact</") >= 0)
327 assertTrue(result.indexOf("<allotted-resource-id>ari</") >= 0)
328 assertTrue(result.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
329 assertTrue(result.indexOf("<service-instance-id>psii</") >= 0)
330 assertTrue(result.indexOf("<parent-service-instance-id>psii</") >= 0)
331 assertTrue(result.indexOf("<sdncadapter:CallbackUrl>scu</") >= 0)
332 assertTrue(result.indexOf("<request-id>mri</") >= 0)
333 assertTrue(result.indexOf("<brg-wan-mac-address>bwma</") >= 0)
334 assertTrue(result.indexOf("<vni>myvni</") >= 0)
335 assertTrue(result.indexOf("<vgmux-bearer-ip>vbi</") >= 0)
336 assertTrue(result.indexOf("<model-invariant-uuid/>") >= 0)
337 assertTrue(result.indexOf("<model-uuid/>") >= 0)
338 assertTrue(result.indexOf("<model-customization-uuid/>") >= 0)
339 assertTrue(result.indexOf("<model-version/>") >= 0)
340 assertTrue(result.indexOf("<model-name/>") >= 0)
345 public void buildSDNCRequest_Ex() {
346 ExecutionEntity mex = setupMock()
347 initBuildSDNCRequest(mex)
349 when(mex.getVariable("allottedResourceId")).thenThrow(new RuntimeException("expected exception"))
351 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
353 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.buildSDNCRequest(mex, "myact", "myreq") }))
357 // ***** preProcessSDNCAssign *****
361 public void preProcessSDNCAssign() {
362 ExecutionEntity mex = setupMock()
363 def map = setupMap(mex)
364 def data = initPreProcessSDNC(mex)
366 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
367 DoCreateAllottedResourceBRG.preProcessSDNCAssign(mex)
369 def req = map.get("sdncAssignRequest")
372 assertEquals(data, map.get("rollbackData"))
374 def rbreq = data.get(Prefix, "sdncAssignRollbackReq")
376 assertTrue(req.indexOf("<sdncadapter:SvcAction>assign</") >= 0)
377 assertTrue(req.indexOf("<request-action>CreateBRGInstance</") >= 0)
378 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
380 assertTrue(rbreq.indexOf("<sdncadapter:SvcAction>unassign</") >= 0)
381 assertTrue(rbreq.indexOf("<request-action>DeleteBRGInstance</") >= 0)
382 assertTrue(rbreq.indexOf("<sdncadapter:RequestId>") >= 0)
387 public void preProcessSDNCAssign_BpmnError() {
388 ExecutionEntity mex = setupMock()
389 initPreProcessSDNC(mex)
391 when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception"))
393 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
395 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCAssign(mex) }))
400 public void preProcessSDNCAssign_Ex() {
401 ExecutionEntity mex = setupMock()
402 initPreProcessSDNC(mex)
404 when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception"))
406 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
408 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCAssign(mex) }))
412 // ***** preProcessSDNCCreate *****
416 public void preProcessSDNCCreate() {
417 ExecutionEntity mex = setupMock()
418 def map = setupMap(mex)
419 def data = initPreProcessSDNC(mex)
421 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
422 DoCreateAllottedResourceBRG.preProcessSDNCCreate(mex)
424 def req = map.get("sdncCreateRequest")
427 assertEquals(data, map.get("rollbackData"))
429 def rbreq = data.get(Prefix, "sdncCreateRollbackReq")
431 assertTrue(req.indexOf("<sdncadapter:SvcAction>create</") >= 0)
432 assertTrue(req.indexOf("<request-action>CreateBRGInstance</") >= 0)
433 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
435 assertTrue(rbreq.indexOf("<sdncadapter:SvcAction>delete</") >= 0)
436 assertTrue(rbreq.indexOf("<request-action>DeleteBRGInstance</") >= 0)
437 assertTrue(rbreq.indexOf("<sdncadapter:RequestId>") >= 0)
443 public void preProcessSDNCCreate_BpmnError() {
444 ExecutionEntity mex = setupMock()
445 initPreProcessSDNC(mex)
447 when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception"))
449 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
451 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCCreate(mex) }))
456 public void preProcessSDNCCreate_Ex() {
457 ExecutionEntity mex = setupMock()
458 initPreProcessSDNC(mex)
460 when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception"))
462 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
464 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCCreate(mex) }))
468 // ***** preProcessSDNCActivate *****
472 public void preProcessSDNCActivate() {
473 ExecutionEntity mex = setupMock()
474 def map = setupMap(mex)
475 def data = initPreProcessSDNC(mex)
477 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
478 DoCreateAllottedResourceBRG.preProcessSDNCActivate(mex)
480 def req = map.get("sdncActivateRequest")
483 assertEquals(data, map.get("rollbackData"))
485 def rbreq = data.get(Prefix, "sdncActivateRollbackReq")
487 assertTrue(req.indexOf("<sdncadapter:SvcAction>activate</") >= 0)
488 assertTrue(req.indexOf("<request-action>CreateBRGInstance</") >= 0)
489 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
491 assertTrue(rbreq.indexOf("<sdncadapter:SvcAction>deactivate</") >= 0)
492 assertTrue(rbreq.indexOf("<request-action>DeleteBRGInstance</") >= 0)
493 assertTrue(rbreq.indexOf("<sdncadapter:RequestId>") >= 0)
499 public void preProcessSDNCActivate_BpmnError() {
500 ExecutionEntity mex = setupMock()
501 initPreProcessSDNC(mex)
503 when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception"))
505 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
507 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCActivate(mex) }))
512 public void preProcessSDNCActivate_Ex() {
513 ExecutionEntity mex = setupMock()
514 initPreProcessSDNC(mex)
516 when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception"))
518 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
520 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCActivate(mex) }))
524 // ***** validateSDNCResp *****
528 public void validateSDNCResp() {
529 ExecutionEntity mex = setupMock()
530 def map = setupMap(mex)
531 def data = initValidateSDNCResp(mex)
532 def resp = initValidateSDNCResp_Resp()
534 when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true)
536 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
538 DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create")
540 verify(mex).getVariable("WorkflowException")
541 verify(mex).getVariable("SDNCA_SuccessIndicator")
542 verify(mex).getVariable("rollbackData")
544 assertEquals(data, map.get("rollbackData"))
546 assertEquals("true", data.get(Prefix, "rollback" + "SDNCcreate"))
552 public void validateSDNCResp_Get() {
553 ExecutionEntity mex = setupMock()
554 def data = initValidateSDNCResp(mex)
555 def resp = initValidateSDNCResp_Resp()
557 when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true)
559 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
561 DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "get")
563 verify(mex).getVariable("WorkflowException")
564 verify(mex).getVariable("SDNCA_SuccessIndicator")
566 verify(mex, never()).getVariable("rollbackData")
571 public void validateSDNCResp_Unsuccessful() {
572 ExecutionEntity mex = setupMock()
573 initValidateSDNCResp(mex)
574 def resp = initValidateSDNCResp_Resp()
577 when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(false)
579 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
581 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create") }))
586 public void validateSDNCResp_BpmnError() {
587 ExecutionEntity mex = setupMock()
588 initValidateSDNCResp(mex)
589 def resp = initValidateSDNCResp_Resp()
591 when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception"))
593 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
595 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create") }))
600 public void validateSDNCResp_Ex() {
601 ExecutionEntity mex = setupMock()
602 initValidateSDNCResp(mex)
603 def resp = initValidateSDNCResp_Resp()
605 when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
607 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
609 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create") }))
613 // ***** preProcessSDNCGet *****
617 public void preProcessSDNCGet_FoundAR() {
618 ExecutionEntity mex = setupMock()
619 def map = setupMap(mex)
620 initPreProcessSDNCGet(mex)
622 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
623 DoCreateAllottedResourceBRG.preProcessSDNCGet(mex)
625 String req = map.get("sdncGetRequest")
627 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
628 assertTrue(req.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
629 assertTrue(req.indexOf("<sdncadapter:SvcOperation>arlink</") >= 0)
630 assertTrue(req.indexOf("<sdncadapter:CallbackUrl>myurl</") >= 0)
636 public void preProcessSDNCGet_NotFoundAR() {
637 ExecutionEntity mex = setupMock()
638 def map = setupMap(mex)
639 initPreProcessSDNCGet(mex)
641 when(mex.getVariable("foundActiveAR")).thenReturn(false)
643 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
644 DoCreateAllottedResourceBRG.preProcessSDNCGet(mex)
646 String req = map.get("sdncGetRequest")
648 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
649 assertTrue(req.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
650 assertTrue(req.indexOf("<sdncadapter:SvcOperation>assignlink</") >= 0)
651 assertTrue(req.indexOf("<sdncadapter:CallbackUrl>myurl</") >= 0)
657 public void preProcessSDNCGet_Ex() {
658 ExecutionEntity mex = setupMock()
659 initPreProcessSDNCGet(mex)
661 when(mex.getVariable("foundActiveAR")).thenThrow(new RuntimeException("expected exception"))
663 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
665 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCGet(mex) }))
669 // ***** updateAaiAROrchStatus *****
673 public void updateAaiAROrchStatus() {
674 MockPatchAllottedResource(CUST, SVC, INST, ARID)
676 ExecutionEntity mex = setupMock()
677 initUpdateAaiAROrchStatus(mex)
679 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
680 DoCreateAllottedResourceBRG.updateAaiAROrchStatus(mex, "success")
684 // ***** generateOutputs *****
688 public void generateOutputs() {
689 ExecutionEntity mex = setupMock()
690 def brgtop = FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceBRG/SDNCTopologyQueryCallback.xml")
692 when(mex.getVariable(DBGFLAG)).thenReturn("true")
693 when(mex.getVariable("enhancedCallbackRequestData")).thenReturn(brgtop)
695 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
696 DoCreateAllottedResourceBRG.generateOutputs(mex)
698 verify(mex).setVariable("allotedResourceName", "namefromrequest")
704 public void generateOutputs_BadXml() {
705 ExecutionEntity mex = setupMock()
707 when(mex.getVariable(DBGFLAG)).thenReturn("true")
708 when(mex.getVariable("enhancedCallbackRequestData")).thenReturn("invalid xml")
710 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
711 DoCreateAllottedResourceBRG.generateOutputs(mex)
713 verify(mex, never()).setVariable(anyString(), anyString())
719 public void generateOutputs_BpmnError() {
720 ExecutionEntity mex = setupMock()
722 when(mex.getVariable(DBGFLAG)).thenReturn("true")
723 when(mex.getVariable("enhancedCallbackRequestData")).thenThrow(new BpmnError("expected exception"))
725 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
727 DoCreateAllottedResourceBRG.generateOutputs(mex)
728 verify(mex, never()).setVariable(anyString(), anyString())
734 public void generateOutputs_Ex() {
735 ExecutionEntity mex = setupMock()
737 when(mex.getVariable(DBGFLAG)).thenReturn("true")
738 when(mex.getVariable("enhancedCallbackRequestData")).thenThrow(new RuntimeException("expected exception"))
740 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
742 DoCreateAllottedResourceBRG.generateOutputs(mex)
743 verify(mex, never()).setVariable(anyString(), anyString())
748 // ***** preProcessRollback *****
752 public void preProcessRollback() {
753 ExecutionEntity mex = setupMock()
754 WorkflowException wfe = mock(WorkflowException.class)
756 when(mex.getVariable(DBGFLAG)).thenReturn("true")
757 when(mex.getVariable("WorkflowException")).thenReturn(wfe)
759 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
760 DoCreateAllottedResourceBRG.preProcessRollback(mex)
762 verify(mex).setVariable("prevWorkflowException", wfe)
768 public void preProcessRollback_NotWFE() {
769 ExecutionEntity mex = setupMock()
771 when(mex.getVariable(DBGFLAG)).thenReturn("true")
772 when(mex.getVariable("WorkflowException")).thenReturn("I'm not a WFE")
774 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
775 DoCreateAllottedResourceBRG.preProcessRollback(mex)
777 // verify(mex, never()).setVariable("prevWorkflowException", any())
783 public void preProcessRollback_BpmnError() {
784 ExecutionEntity mex = setupMock()
786 when(mex.getVariable(DBGFLAG)).thenReturn("true")
787 when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception"))
789 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
791 DoCreateAllottedResourceBRG.preProcessRollback(mex)
797 public void preProcessRollback_Ex() {
798 ExecutionEntity mex = setupMock()
800 when(mex.getVariable(DBGFLAG)).thenReturn("true")
801 when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
803 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
805 DoCreateAllottedResourceBRG.preProcessRollback(mex)
810 // ***** postProcessRollback *****
814 public void postProcessRollback() {
815 ExecutionEntity mex = setupMock()
816 WorkflowException wfe = mock(WorkflowException.class)
818 when(mex.getVariable(DBGFLAG)).thenReturn("true")
819 when(mex.getVariable("prevWorkflowException")).thenReturn(wfe)
821 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
822 DoCreateAllottedResourceBRG.postProcessRollback(mex)
824 verify(mex).setVariable("WorkflowException", wfe)
825 verify(mex).setVariable("rollbackData", null)
831 public void postProcessRollback_NotWFE() {
832 ExecutionEntity mex = setupMock()
834 when(mex.getVariable(DBGFLAG)).thenReturn("true")
835 when(mex.getVariable("prevWorkflowException")).thenReturn("I'm not a WFE")
837 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
838 DoCreateAllottedResourceBRG.postProcessRollback(mex)
840 // verify(mex, never()).setVariable("WorkflowException", any())
841 verify(mex).setVariable("rollbackData", null)
847 public void postProcessRollback_BpmnError() {
848 ExecutionEntity mex = setupMock()
850 when(mex.getVariable(DBGFLAG)).thenReturn("true")
851 when(mex.getVariable("prevWorkflowException")).thenThrow(new BpmnError("expected exception"))
853 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
855 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.postProcessRollback(mex) }))
856 verify(mex, never()).setVariable("rollbackData", null)
862 public void postProcessRollback_Ex() {
863 ExecutionEntity mex = setupMock()
865 when(mex.getVariable(DBGFLAG)).thenReturn("true")
866 when(mex.getVariable("prevWorkflowException")).thenThrow(new RuntimeException("expected exception"))
868 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
870 DoCreateAllottedResourceBRG.postProcessRollback(mex)
871 verify(mex, never()).setVariable("rollbackData", null)
875 private boolean checkMissingPreProcessRequest(String fieldnm) {
876 ExecutionEntity mex = setupMock()
879 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
881 when(mex.getVariable(fieldnm)).thenReturn("")
883 return doBpmnError( { _ -> DoCreateAllottedResourceBRG.preProcessRequest(mex) })
886 private void initPreProcess(ExecutionEntity mex) {
887 when(mex.getVariable(DBGFLAG)).thenReturn("true")
888 when(mex.getVariable("URN_mso_workflow_sdncadapter_callback")).thenReturn("sdncurn")
889 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
890 when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii")
891 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("armi")
892 when(mex.getVariable("vni")).thenReturn("myvni")
893 when(mex.getVariable("vgmuxBearerIP")).thenReturn("vbi")
894 when(mex.getVariable("brgWanMacAddress")).thenReturn("bwma")
895 when(mex.getVariable("allottedResourceRole")).thenReturn("arr")
896 when(mex.getVariable("allottedResourceType")).thenReturn("art")
899 private void initGetAaiAR(ExecutionEntity mex) {
900 when(mex.getVariable(DBGFLAG)).thenReturn("true")
901 when(mex.getVariable("allottedResourceType")).thenReturn("BRGt")
902 when(mex.getVariable("allottedResourceRole")).thenReturn("BRGr")
903 when(mex.getVariable("CSI_service")).thenReturn(FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceBRG/getAR.xml"))
904 when(mex.getVariable("URN_aai_endpoint")).thenReturn(aaiUriPfx)
905 when(mex.getVariable("aaiAROrchStatus")).thenReturn("Active")
908 private initCreateAaiAr(ExecutionEntity mex) {
909 when(mex.getVariable("disableRollback")).thenReturn(45)
910 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
911 when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii")
912 when(mex.getVariable(DBGFLAG)).thenReturn("true")
913 when(mex.getVariable("allottedResourceId")).thenReturn(ARID)
914 when(mex.getVariable("URN_aai_endpoint")).thenReturn(aaiUriPfx)
915 when(mex.getVariable("URN_mso_workflow_global_default_aai_namespace")).thenReturn(urnProps.get("mso.workflow.global.default.aai.namespace"))
916 when(mex.getVariable("PSI_resourceLink")).thenReturn(aaiUriPfx + "/aai/v9/business/customers/customer/"+CUST+"/service-subscriptions/service-subscription/"+SVC+"/service-instances/service-instance/"+INST)
917 when(mex.getVariable("allottedResourceType")).thenReturn("BRGt")
918 when(mex.getVariable("allottedResourceRole")).thenReturn("BRGr")
919 when(mex.getVariable("CSI_resourceLink")).thenReturn(aaiUriPfx+"/aai/v9/mycsi")
920 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("""
922 "modelInvariantUuid":"modelinvuuid",
923 "modelUuid":"modeluuid",
924 "modelCustomizationUuid":"modelcustuuid"
929 private initBuildSDNCRequest(ExecutionEntity mex) {
930 when(mex.getVariable(DBGFLAG)).thenReturn("true")
931 when(mex.getVariable("allottedResourceId")).thenReturn("ari")
932 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
933 when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii")
934 when(mex.getVariable("sdncCallbackUrl")).thenReturn("scu")
935 when(mex.getVariable("msoRequestId")).thenReturn("mri")
936 when(mex.getVariable("brgWanMacAddress")).thenReturn("bwma")
937 when(mex.getVariable("vni")).thenReturn("myvni")
938 when(mex.getVariable("vgmuxBearerIP")).thenReturn("vbi")
939 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("""
941 "modelInvariantUuid":"miu",
943 "modelCustomizationUuid":"mcu",
950 private RollbackData initPreProcessSDNC(ExecutionEntity mex) {
951 def data = new RollbackData()
953 when(mex.getVariable(DBGFLAG)).thenReturn("true")
954 when(mex.getVariable("rollbackData")).thenReturn(data)
959 private initPreProcessSDNCGet(ExecutionEntity mex) {
960 when(mex.getVariable(DBGFLAG)).thenReturn("true")
961 when(mex.getVariable("sdncCallbackUrl")).thenReturn("myurl")
962 when(mex.getVariable("foundActiveAR")).thenReturn(true)
963 when(mex.getVariable("aaiARGetResponse")).thenReturn("<selflink>arlink</selflink>")
964 when(mex.getVariable("sdncAssignResponse")).thenReturn("<response-data><object-path>assignlink</object-path></response-data>")
965 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
966 when(mex.getVariable("junitSleepMs")).thenReturn("5")
967 when(mex.getVariable("sdncCallbackUrl")).thenReturn("myurl")
970 private RollbackData initValidateSDNCResp(ExecutionEntity mex) {
971 def data = new RollbackData()
973 when(mex.getVariable(DBGFLAG)).thenReturn("true")
974 when(mex.getVariable("prefix")).thenReturn(Prefix)
975 when(mex.getVariable("SDNCA_SuccessIndicator")).thenReturn(true)
976 when(mex.getVariable("rollbackData")).thenReturn(data)
981 private String initValidateSDNCResp_Resp() {
982 return "<response-data><response-code>200</response-code></response-data>"
985 private initUpdateAaiAROrchStatus(ExecutionEntity mex) {
986 when(mex.getVariable(DBGFLAG)).thenReturn("true")
987 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)