1 package org.openecomp.mso.bpmn.vcpe.scripts
4 import org.camunda.bpm.engine.ProcessEngineServices
\r
5 import org.camunda.bpm.engine.RepositoryService
\r
6 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
\r
7 import org.camunda.bpm.engine.repository.ProcessDefinition
\r
8 import org.camunda.bpm.engine.runtime.Execution
\r
9 import org.junit.Before
10 import org.junit.BeforeClass
\r
11 import org.junit.Rule
\r
13 import org.junit.Ignore
\r
14 import org.mockito.MockitoAnnotations
15 import org.mockito.ArgumentCaptor
16 import org.camunda.bpm.engine.delegate.BpmnError
\r
17 import org.openecomp.mso.bpmn.common.scripts.MsoUtils
\r
18 import org.openecomp.mso.bpmn.core.WorkflowException
19 import org.openecomp.mso.bpmn.mock.FileUtil
21 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse
22 import static com.github.tomakehurst.wiremock.client.WireMock.get
23 import static com.github.tomakehurst.wiremock.client.WireMock.patch
24 import static com.github.tomakehurst.wiremock.client.WireMock.put
25 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor
26 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching
27 import static org.junit.Assert.*;
\r
28 import static org.mockito.Mockito.*
29 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetAllottedResource
30 import org.openecomp.mso.bpmn.core.RollbackData
32 import com.github.tomakehurst.wiremock.junit.WireMockRule
\r
34 class DoCreateAllottedResourceBRGTest {
\r
37 public WireMockRule wireMockRule = new WireMockRule(28090)
\r
39 static def urnProps = new Properties()
42 String Prefix="DCARBRG_"
\r
43 def utils = new MsoUtils()
\r
46 public static void setUpBeforeClass() {
47 def fr = new FileReader("src/test/resources/mso.bpmn.urn.properties")
51 aaiUriPfx = urnProps.get("aai.endpoint")
57 MockitoAnnotations.initMocks(this)
\r
61 // ***** preProcessRequest *****
\r
65 public void preProcessRequest() {
\r
66 ExecutionEntity mex = setupMock()
69 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
\r
70 DoCreateAllottedResourceBRG.preProcessRequest(mex)
\r
72 verify(mex).getVariable("isDebugLogEnabled")
\r
73 verify(mex).setVariable("prefix", Prefix)
\r
75 assertTrue(checkMissingPreProcessRequest("URN_mso_workflow_sdncadapter_callback"))
76 assertTrue(checkMissingPreProcessRequest("serviceInstanceId"))
77 assertTrue(checkMissingPreProcessRequest("parentServiceInstanceId"))
78 assertTrue(checkMissingPreProcessRequest("allottedResourceModelInfo"))
79 assertTrue(checkMissingPreProcessRequest("vni"))
80 assertTrue(checkMissingPreProcessRequest("vgmuxBearerIP"))
81 assertTrue(checkMissingPreProcessRequest("brgWanMacAddress"))
82 assertTrue(checkMissingPreProcessRequest("allottedResourceRole"))
83 assertTrue(checkMissingPreProcessRequest("allottedResourceType"))
\r
87 // ***** getAaiAR *****
91 public void getAaiAR() {
92 def arData = FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceBRG/getAR.xml")
93 def arBrg = FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceBRG/getArBrg.xml")
96 .stubFor(get(urlMatching("/aai/v[0-9]+/mylink"))
97 .willReturn(aResponse()
99 .withHeader("Content-Type", "text/xml")
100 .withBodyFile("VCPE/DoCreateAllottedResourceBRG/getArBrg.xml")))
102 ExecutionEntity mex = setupMock()
104 when(mex.getVariable("isDebugLogEnabled")).thenReturn("true")
105 when(mex.getVariable("allottedResourceType")).thenReturn("BRGt")
106 when(mex.getVariable("allottedResourceRole")).thenReturn("BRGr")
107 when(mex.getVariable("CSI_service")).thenReturn(arData)
108 when(mex.getVariable("URN_aai_endpoint")).thenReturn(aaiUriPfx)
109 when(mex.getVariable("aaiAROrchStatus")).thenReturn("Active")
111 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
112 DoCreateAllottedResourceBRG.getAaiAR(mex)
114 verify(mex).setVariable("foundActiveAR", true)
119 public void getAaiAR_Duplicate() {
120 def arData = FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceBRG/getAR.xml")
121 def arBrg = FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceBRG/getArBrg.xml")
124 .stubFor(get(urlMatching("/aai/v[0-9]+/mylink"))
125 .willReturn(aResponse()
127 .withHeader("Content-Type", "text/xml")
128 .withBodyFile("VCPE/DoCreateAllottedResourceBRG/getArBrg.xml")))
130 ExecutionEntity mex = setupMock()
132 when(mex.getVariable("isDebugLogEnabled")).thenReturn("true")
133 when(mex.getVariable("allottedResourceType")).thenReturn("BRGt")
134 when(mex.getVariable("allottedResourceRole")).thenReturn("BRGr")
135 when(mex.getVariable("CSI_service")).thenReturn(arData)
136 when(mex.getVariable("URN_aai_endpoint")).thenReturn(aaiUriPfx)
137 when(mex.getVariable("aaiAROrchStatus")).thenReturn("Active")
140 when(mex.getVariable("failExists")).thenReturn("true")
142 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
144 assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceBRG.getAaiAR(mex) }))
149 public void getAaiAR_NotActive() {
150 def arData = FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceBRG/getAR.xml")
151 def arBrg = FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceBRG/getArBrg.xml")
154 .stubFor(get(urlMatching("/aai/v[0-9]+/mylink"))
155 .willReturn(aResponse()
157 .withHeader("Content-Type", "text/xml")
158 .withBodyFile("VCPE/DoCreateAllottedResourceBRG/getArBrg.xml")))
160 ExecutionEntity mex = setupMock()
162 when(mex.getVariable("isDebugLogEnabled")).thenReturn("true")
163 when(mex.getVariable("allottedResourceType")).thenReturn("BRGt")
164 when(mex.getVariable("allottedResourceRole")).thenReturn("BRGr")
165 when(mex.getVariable("CSI_service")).thenReturn(arData)
166 when(mex.getVariable("URN_aai_endpoint")).thenReturn(aaiUriPfx)
169 when(mex.getVariable("aaiAROrchStatus")).thenReturn("not-active")
171 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
173 assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceBRG.getAaiAR(mex) }))
178 public void getAaiAR_NoStatus() {
179 def arData = FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceBRG/getAR.xml")
180 def arBrg = FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceBRG/getArBrg.xml")
183 .stubFor(get(urlMatching("/aai/v[0-9]+/mylink"))
184 .willReturn(aResponse()
186 .withHeader("Content-Type", "text/xml")
187 .withBodyFile("VCPE/DoCreateAllottedResourceBRG/getArBrg.xml")))
189 ExecutionEntity mex = setupMock()
191 when(mex.getVariable("isDebugLogEnabled")).thenReturn("true")
192 when(mex.getVariable("allottedResourceType")).thenReturn("BRGt")
193 when(mex.getVariable("allottedResourceRole")).thenReturn("BRGr")
194 when(mex.getVariable("CSI_service")).thenReturn(arData)
195 when(mex.getVariable("URN_aai_endpoint")).thenReturn(aaiUriPfx)
197 when(mex.getVariable("aaiAROrchStatus")).thenReturn(null)
199 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
200 DoCreateAllottedResourceBRG.getAaiAR(mex)
202 verify(mex, never()).setVariable("foundActiveAR", true)
206 // ***** createAaiAR *****
210 public void createAaiAR() {
211 ExecutionEntity mex = setupMock()
215 .stubFor(put(urlMatching("/aai/v[0-9]+/mypsi/allotted-resources/allotted-resource/myid"))
216 .willReturn(aResponse()
219 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
220 DoCreateAllottedResourceBRG.createAaiAR(mex)
222 ArgumentCaptor<String> keycap = ArgumentCaptor.forClass(String.class)
223 ArgumentCaptor<Object> valcap = ArgumentCaptor.forClass(Object.class)
225 verify(mex, times(3)).setVariable(keycap.capture(), valcap.capture())
227 assertFalse(keycap.getAllValues().isEmpty())
228 assertEquals("rollbackData", keycap.getAllValues().get(keycap.getAllValues().size()-1))
230 def data = valcap.getAllValues().get(valcap.getAllValues().size()-1)
232 assertTrue(data instanceof RollbackData)
234 assertEquals("45", data.get(Prefix, "disableRollback"))
235 assertEquals("true", data.get(Prefix, "rollbackAAI"))
236 assertEquals("myid", data.get(Prefix, "allottedResourceId"))
237 assertEquals("sii", data.get(Prefix, "serviceInstanceId"))
238 assertEquals("psii", data.get(Prefix, "parentServiceInstanceId"))
239 assertEquals(aaiUriPfx+"/aai/v9/mypsi/allotted-resources/allotted-resource/myid", data.get(Prefix, "aaiARPath"))
244 public void createAaiAR_NoArid_NoModelUuids() {
245 ExecutionEntity mex = setupMock()
248 // no allottedResourceId - will be generated
250 when(mex.getVariable("allottedResourceId")).thenReturn(null)
253 .stubFor(put(urlMatching("/aai/v[0-9]+/mypsi/allotted-resources/allotted-resource/.*"))
254 .willReturn(aResponse()
257 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
258 DoCreateAllottedResourceBRG.createAaiAR(mex)
260 ArgumentCaptor<String> keycap = ArgumentCaptor.forClass(String.class)
261 ArgumentCaptor<Object> valcap = ArgumentCaptor.forClass(Object.class)
263 verify(mex, times(4)).setVariable(keycap.capture(), valcap.capture())
265 assertFalse(keycap.getAllValues().isEmpty())
266 assertEquals("allottedResourceId", keycap.getAllValues().get(0))
267 assertEquals("rollbackData", keycap.getAllValues().get(keycap.getAllValues().size()-1))
269 def arid = valcap.getAllValues().get(0)
271 assertFalse(arid.isEmpty())
273 def data = valcap.getAllValues().get(valcap.getAllValues().size()-1)
275 assertTrue(data instanceof RollbackData)
277 assertEquals(arid, data.get(Prefix, "allottedResourceId"))
282 public void createAaiAR_MissingPsiLink() {
283 ExecutionEntity mex = setupMock()
286 when(mex.getVariable("PSI_resourceLink")).thenReturn(null)
289 .stubFor(put(urlMatching("/aai/v[0-9]+/mypsi/allotted-resources/allotted-resource/myid"))
290 .willReturn(aResponse()
293 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
295 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.createAaiAR(mex) }))
300 public void createAaiAR_HttpFailed() {
301 ExecutionEntity mex = setupMock()
306 .stubFor(put(urlMatching("/aai/v[0-9]+/mypsi/allotted-resources/allotted-resource/myid"))
307 .willReturn(aResponse()
310 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
312 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.createAaiAR(mex) }))
317 public void createAaiAR_BpmnError() {
318 ExecutionEntity mex = setupMock()
321 when(mex.getVariable("URN_aai_endpoint")).thenThrow(new BpmnError("expected exception"))
324 .stubFor(put(urlMatching("/aai/v[0-9]+/mypsi/allotted-resources/allotted-resource/myid"))
325 .willReturn(aResponse()
328 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
330 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.createAaiAR(mex) }))
335 public void createAaiAR_Ex() {
336 ExecutionEntity mex = setupMock()
339 when(mex.getVariable("URN_aai_endpoint")).thenThrow(new RuntimeException("expected exception"))
342 .stubFor(put(urlMatching("/aai/v[0-9]+/mypsi/allotted-resources/allotted-resource/myid"))
343 .willReturn(aResponse()
346 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
348 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.createAaiAR(mex) }))
352 // ***** buildSDNCRequest *****
356 public void buildSDNCRequest() {
357 ExecutionEntity mex = setupMock()
358 initBuildSDNCRequest(mex)
360 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
362 String result = DoCreateAllottedResourceBRG.buildSDNCRequest(mex, "myact", "myreq")
364 assertTrue(result.indexOf("<sdncadapter:RequestId>myreq</") >= 0)
365 assertTrue(result.indexOf("<sdncadapter:SvcAction>myact</") >= 0)
366 assertTrue(result.indexOf("<allotted-resource-id>ari</") >= 0)
367 assertTrue(result.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
368 assertTrue(result.indexOf("<service-instance-id>psii</") >= 0)
369 assertTrue(result.indexOf("<parent-service-instance-id>psii</") >= 0)
370 assertTrue(result.indexOf("<sdncadapter:CallbackUrl>scu</") >= 0)
371 assertTrue(result.indexOf("<request-id>mri</") >= 0)
372 assertTrue(result.indexOf("<brg-wan-mac-address>bwma</") >= 0)
373 assertTrue(result.indexOf("<vni>myvni</") >= 0)
374 assertTrue(result.indexOf("<vgmux-bearer-ip>vbi</") >= 0)
375 assertTrue(result.indexOf("<model-invariant-uuid>miu</") >= 0)
376 assertTrue(result.indexOf("<model-uuid>mu</") >= 0)
377 assertTrue(result.indexOf("<model-customization-uuid>mcu</") >= 0)
378 assertTrue(result.indexOf("<model-version>mv</") >= 0)
379 assertTrue(result.indexOf("<model-name>mn</") >= 0)
384 public void buildSDNCRequest_EmptyModelInfo() {
385 ExecutionEntity mex = setupMock()
386 initBuildSDNCRequest(mex)
388 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("{}")
390 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
392 String result = DoCreateAllottedResourceBRG.buildSDNCRequest(mex, "myact", "myreq")
394 assertTrue(result.indexOf("<sdncadapter:RequestId>myreq</") >= 0)
395 assertTrue(result.indexOf("<sdncadapter:SvcAction>myact</") >= 0)
396 assertTrue(result.indexOf("<allotted-resource-id>ari</") >= 0)
397 assertTrue(result.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
398 assertTrue(result.indexOf("<service-instance-id>psii</") >= 0)
399 assertTrue(result.indexOf("<parent-service-instance-id>psii</") >= 0)
400 assertTrue(result.indexOf("<sdncadapter:CallbackUrl>scu</") >= 0)
401 assertTrue(result.indexOf("<request-id>mri</") >= 0)
402 assertTrue(result.indexOf("<brg-wan-mac-address>bwma</") >= 0)
403 assertTrue(result.indexOf("<vni>myvni</") >= 0)
404 assertTrue(result.indexOf("<vgmux-bearer-ip>vbi</") >= 0)
405 assertTrue(result.indexOf("<model-invariant-uuid/>") >= 0)
406 assertTrue(result.indexOf("<model-uuid/>") >= 0)
407 assertTrue(result.indexOf("<model-customization-uuid/>") >= 0)
408 assertTrue(result.indexOf("<model-version/>") >= 0)
409 assertTrue(result.indexOf("<model-name/>") >= 0)
414 public void buildSDNCRequest_Ex() {
415 ExecutionEntity mex = setupMock()
416 initBuildSDNCRequest(mex)
418 when(mex.getVariable("allottedResourceId")).thenThrow(new RuntimeException("expected exception"))
420 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
422 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.buildSDNCRequest(mex, "myact", "myreq") }))
426 // ***** preProcessSDNCAssign *****
430 public void preProcessSDNCAssign() {
431 ExecutionEntity mex = setupMock()
432 def data = initPreProcessSDNC(mex)
434 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
435 DoCreateAllottedResourceBRG.preProcessSDNCAssign(mex)
437 ArgumentCaptor<String> keycap = ArgumentCaptor.forClass(String.class)
438 ArgumentCaptor<Object> valcap = ArgumentCaptor.forClass(Object.class)
440 verify(mex, times(2)).setVariable(keycap.capture(), valcap.capture())
442 assertFalse(keycap.getAllValues().isEmpty())
443 assertEquals("sdncAssignRequest", keycap.getAllValues().get(0))
444 assertEquals("rollbackData", keycap.getAllValues().get(keycap.getAllValues().size()-1))
446 def req = valcap.getAllValues().get(0)
449 assertEquals(data, valcap.getAllValues().get(valcap.getAllValues().size()-1))
451 def rbreq = data.get(Prefix, "sdncAssignRollbackReq")
453 assertTrue(req.indexOf("<sdncadapter:SvcAction>assign</") >= 0)
454 assertTrue(req.indexOf("<request-action>CreateBRGInstance</") >= 0)
455 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
457 assertTrue(rbreq.indexOf("<sdncadapter:SvcAction>unassign</") >= 0)
458 assertTrue(rbreq.indexOf("<request-action>DeleteBRGInstance</") >= 0)
459 assertTrue(rbreq.indexOf("<sdncadapter:RequestId>") >= 0)
464 public void preProcessSDNCAssign_BpmnError() {
465 ExecutionEntity mex = setupMock()
466 initPreProcessSDNC(mex)
468 when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception"))
470 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
472 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCAssign(mex) }))
477 public void preProcessSDNCAssign_Ex() {
478 ExecutionEntity mex = setupMock()
479 initPreProcessSDNC(mex)
481 when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception"))
483 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
485 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCAssign(mex) }))
489 // ***** preProcessSDNCCreate *****
493 public void preProcessSDNCCreate() {
494 ExecutionEntity mex = setupMock()
495 def data = initPreProcessSDNC(mex)
497 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
498 DoCreateAllottedResourceBRG.preProcessSDNCCreate(mex)
500 ArgumentCaptor<String> keycap = ArgumentCaptor.forClass(String.class)
501 ArgumentCaptor<Object> valcap = ArgumentCaptor.forClass(Object.class)
503 verify(mex, times(2)).setVariable(keycap.capture(), valcap.capture())
505 assertFalse(keycap.getAllValues().isEmpty())
506 assertEquals("sdncCreateRequest", keycap.getAllValues().get(0))
507 assertEquals("rollbackData", keycap.getAllValues().get(keycap.getAllValues().size()-1))
509 def req = valcap.getAllValues().get(0)
512 assertEquals(data, valcap.getAllValues().get(valcap.getAllValues().size()-1))
514 def rbreq = data.get(Prefix, "sdncCreateRollbackReq")
516 assertTrue(req.indexOf("<sdncadapter:SvcAction>create</") >= 0)
517 assertTrue(req.indexOf("<request-action>CreateBRGInstance</") >= 0)
518 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
520 assertTrue(rbreq.indexOf("<sdncadapter:SvcAction>delete</") >= 0)
521 assertTrue(rbreq.indexOf("<request-action>DeleteBRGInstance</") >= 0)
522 assertTrue(rbreq.indexOf("<sdncadapter:RequestId>") >= 0)
528 public void preProcessSDNCCreate_BpmnError() {
529 ExecutionEntity mex = setupMock()
530 initPreProcessSDNC(mex)
532 when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception"))
534 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
536 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCCreate(mex) }))
541 public void preProcessSDNCCreate_Ex() {
542 ExecutionEntity mex = setupMock()
543 initPreProcessSDNC(mex)
545 when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception"))
547 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
549 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCCreate(mex) }))
553 // ***** preProcessSDNCActivate *****
557 public void preProcessSDNCActivate() {
558 ExecutionEntity mex = setupMock()
559 def data = initPreProcessSDNC(mex)
561 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
562 DoCreateAllottedResourceBRG.preProcessSDNCActivate(mex)
564 ArgumentCaptor<String> keycap = ArgumentCaptor.forClass(String.class)
565 ArgumentCaptor<Object> valcap = ArgumentCaptor.forClass(Object.class)
567 verify(mex, times(2)).setVariable(keycap.capture(), valcap.capture())
569 assertFalse(keycap.getAllValues().isEmpty())
570 assertEquals("sdncActivateRequest", keycap.getAllValues().get(0))
571 assertEquals("rollbackData", keycap.getAllValues().get(keycap.getAllValues().size()-1))
573 def req = valcap.getAllValues().get(0)
576 assertEquals(data, valcap.getAllValues().get(valcap.getAllValues().size()-1))
578 def rbreq = data.get(Prefix, "sdncActivateRollbackReq")
580 assertTrue(req.indexOf("<sdncadapter:SvcAction>activate</") >= 0)
581 assertTrue(req.indexOf("<request-action>CreateBRGInstance</") >= 0)
582 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
584 assertTrue(rbreq.indexOf("<sdncadapter:SvcAction>deactivate</") >= 0)
585 assertTrue(rbreq.indexOf("<request-action>DeleteBRGInstance</") >= 0)
586 assertTrue(rbreq.indexOf("<sdncadapter:RequestId>") >= 0)
592 public void preProcessSDNCActivate_BpmnError() {
593 ExecutionEntity mex = setupMock()
594 initPreProcessSDNC(mex)
596 when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception"))
598 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
600 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCActivate(mex) }))
605 public void preProcessSDNCActivate_Ex() {
606 ExecutionEntity mex = setupMock()
607 initPreProcessSDNC(mex)
609 when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception"))
611 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
613 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCActivate(mex) }))
617 // ***** validateSDNCResp *****
621 public void validateSDNCResp() {
622 ExecutionEntity mex = setupMock()
623 def data = initValidateSDNCResp(mex)
624 def resp = initValidateSDNCResp_Resp()
626 when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true)
628 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
630 DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create")
632 verify(mex).getVariable("WorkflowException")
633 verify(mex).getVariable("SDNCA_SuccessIndicator")
634 verify(mex).getVariable("rollbackData")
636 ArgumentCaptor<String> keycap = ArgumentCaptor.forClass(String.class)
637 ArgumentCaptor<Object> valcap = ArgumentCaptor.forClass(Object.class)
639 verify(mex, times(4)).setVariable(keycap.capture(), valcap.capture())
641 assertFalse(keycap.getAllValues().isEmpty())
642 assertEquals("rollbackData", keycap.getAllValues().get(keycap.getAllValues().size()-1))
644 assertEquals(data, valcap.getAllValues().get(valcap.getAllValues().size()-1))
646 assertEquals("true", data.get(Prefix, "rollback" + "SDNCcreate"))
652 public void validateSDNCResp_Get() {
653 ExecutionEntity mex = setupMock()
654 def data = initValidateSDNCResp(mex)
655 def resp = initValidateSDNCResp_Resp()
657 when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true)
659 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
661 DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "get")
663 verify(mex).getVariable("WorkflowException")
664 verify(mex).getVariable("SDNCA_SuccessIndicator")
666 verify(mex, never()).getVariable("rollbackData")
671 public void validateSDNCResp_Unsuccessful() {
672 ExecutionEntity mex = setupMock()
673 initValidateSDNCResp(mex)
674 def resp = initValidateSDNCResp_Resp()
677 when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(false)
679 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
681 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create") }))
686 public void validateSDNCResp_BpmnError() {
687 ExecutionEntity mex = setupMock()
688 initValidateSDNCResp(mex)
689 def resp = initValidateSDNCResp_Resp()
691 when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception"))
693 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
695 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create") }))
700 public void validateSDNCResp_Ex() {
701 ExecutionEntity mex = setupMock()
702 initValidateSDNCResp(mex)
703 def resp = initValidateSDNCResp_Resp()
705 when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
707 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
709 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create") }))
713 // ***** preProcessSDNCGet *****
717 public void preProcessSDNCGet_FoundAR() {
718 ExecutionEntity mex = setupMock()
719 initPreProcessSDNCGet(mex)
721 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
722 DoCreateAllottedResourceBRG.preProcessSDNCGet(mex)
724 ArgumentCaptor<String> keycap = ArgumentCaptor.forClass(String.class)
725 ArgumentCaptor<Object> valcap = ArgumentCaptor.forClass(Object.class)
727 verify(mex, times(1)).setVariable(keycap.capture(), valcap.capture())
729 assertFalse(keycap.getAllValues().isEmpty())
730 assertEquals("sdncGetRequest", keycap.getAllValues().get(keycap.getAllValues().size()-1))
732 String req = valcap.getAllValues().get(valcap.getAllValues().size()-1)
734 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
735 assertTrue(req.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
736 assertTrue(req.indexOf("<sdncadapter:SvcOperation>arlink</") >= 0)
737 assertTrue(req.indexOf("<sdncadapter:CallbackUrl>myurl</") >= 0)
743 public void preProcessSDNCGet_NotFoundAR() {
744 ExecutionEntity mex = setupMock()
745 initPreProcessSDNCGet(mex)
747 when(mex.getVariable("foundActiveAR")).thenReturn(false)
749 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
750 DoCreateAllottedResourceBRG.preProcessSDNCGet(mex)
752 ArgumentCaptor<String> keycap = ArgumentCaptor.forClass(String.class)
753 ArgumentCaptor<Object> valcap = ArgumentCaptor.forClass(Object.class)
755 verify(mex, times(1)).setVariable(keycap.capture(), valcap.capture())
757 assertFalse(keycap.getAllValues().isEmpty())
758 assertEquals("sdncGetRequest", keycap.getAllValues().get(keycap.getAllValues().size()-1))
760 String req = valcap.getAllValues().get(valcap.getAllValues().size()-1)
762 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
763 assertTrue(req.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
764 assertTrue(req.indexOf("<sdncadapter:SvcOperation>assignlink</") >= 0)
765 assertTrue(req.indexOf("<sdncadapter:CallbackUrl>myurl</") >= 0)
771 public void preProcessSDNCGet_Ex() {
772 ExecutionEntity mex = setupMock()
773 initPreProcessSDNCGet(mex)
775 when(mex.getVariable("foundActiveAR")).thenThrow(new RuntimeException("expected exception"))
777 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
779 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCGet(mex) }))
783 // ***** updateAaiAROrchStatus *****
787 public void updateAaiAROrchStatus() {
788 ExecutionEntity mex = setupMock()
789 initUpdateAaiAROrchStatus(mex)
791 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
792 DoCreateAllottedResourceBRG.updateAaiAROrchStatus(mex, "success")
796 // ***** generateOutputs *****
800 public void generateOutputs() {
801 ExecutionEntity mex = setupMock()
802 def brgtop = FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceBRG/SDNCTopologyQueryCallback.xml")
804 when(mex.getVariable("isDebugLogEnabled")).thenReturn("true")
805 when(mex.getVariable("enhancedCallbackRequestData")).thenReturn(brgtop)
807 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
808 DoCreateAllottedResourceBRG.generateOutputs(mex)
810 verify(mex).setVariable("allotedResourceName", "namefromrequest")
816 public void generateOutputs_BadXml() {
817 ExecutionEntity mex = setupMock()
819 when(mex.getVariable("isDebugLogEnabled")).thenReturn("true")
820 when(mex.getVariable("enhancedCallbackRequestData")).thenReturn("invalid xml")
822 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
823 DoCreateAllottedResourceBRG.generateOutputs(mex)
825 verify(mex, never()).setVariable(anyString(), anyString())
831 public void generateOutputs_BpmnError() {
832 ExecutionEntity mex = setupMock()
834 when(mex.getVariable("isDebugLogEnabled")).thenReturn("true")
835 when(mex.getVariable("enhancedCallbackRequestData")).thenThrow(new BpmnError("expected exception"))
837 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
839 DoCreateAllottedResourceBRG.generateOutputs(mex)
840 verify(mex, never()).setVariable(anyString(), anyString())
846 public void generateOutputs_Ex() {
847 ExecutionEntity mex = setupMock()
849 when(mex.getVariable("isDebugLogEnabled")).thenReturn("true")
850 when(mex.getVariable("enhancedCallbackRequestData")).thenThrow(new RuntimeException("expected exception"))
852 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
854 DoCreateAllottedResourceBRG.generateOutputs(mex)
855 verify(mex, never()).setVariable(anyString(), anyString())
860 // ***** preProcessRollback *****
864 public void preProcessRollback() {
865 ExecutionEntity mex = setupMock()
866 WorkflowException wfe = mock(WorkflowException.class)
868 when(mex.getVariable("isDebugLogEnabled")).thenReturn("true")
869 when(mex.getVariable("WorkflowException")).thenReturn(wfe)
871 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
872 DoCreateAllottedResourceBRG.preProcessRollback(mex)
874 verify(mex).setVariable("prevWorkflowException", wfe)
880 public void preProcessRollback_NotWFE() {
881 ExecutionEntity mex = setupMock()
883 when(mex.getVariable("isDebugLogEnabled")).thenReturn("true")
884 when(mex.getVariable("WorkflowException")).thenReturn("I'm not a WFE")
886 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
887 DoCreateAllottedResourceBRG.preProcessRollback(mex)
889 // verify(mex, never()).setVariable("prevWorkflowException", any())
895 public void preProcessRollback_BpmnError() {
896 ExecutionEntity mex = setupMock()
898 when(mex.getVariable("isDebugLogEnabled")).thenReturn("true")
899 when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception"))
901 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
903 DoCreateAllottedResourceBRG.preProcessRollback(mex)
909 public void preProcessRollback_Ex() {
910 ExecutionEntity mex = setupMock()
912 when(mex.getVariable("isDebugLogEnabled")).thenReturn("true")
913 when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
915 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
917 DoCreateAllottedResourceBRG.preProcessRollback(mex)
922 // ***** postProcessRollback *****
926 public void postProcessRollback() {
927 ExecutionEntity mex = setupMock()
928 WorkflowException wfe = mock(WorkflowException.class)
930 when(mex.getVariable("isDebugLogEnabled")).thenReturn("true")
931 when(mex.getVariable("prevWorkflowException")).thenReturn(wfe)
933 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
934 DoCreateAllottedResourceBRG.postProcessRollback(mex)
936 verify(mex).setVariable("WorkflowException", wfe)
937 verify(mex).setVariable("rollbackData", null)
943 public void postProcessRollback_NotWFE() {
944 ExecutionEntity mex = setupMock()
946 when(mex.getVariable("isDebugLogEnabled")).thenReturn("true")
947 when(mex.getVariable("prevWorkflowException")).thenReturn("I'm not a WFE")
949 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
950 DoCreateAllottedResourceBRG.postProcessRollback(mex)
952 // verify(mex, never()).setVariable("WorkflowException", any())
953 verify(mex).setVariable("rollbackData", null)
959 public void postProcessRollback_BpmnError() {
960 ExecutionEntity mex = setupMock()
962 when(mex.getVariable("isDebugLogEnabled")).thenReturn("true")
963 when(mex.getVariable("prevWorkflowException")).thenThrow(new BpmnError("expected exception"))
965 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
967 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.postProcessRollback(mex) }))
968 verify(mex, never()).setVariable("rollbackData", null)
974 public void postProcessRollback_Ex() {
975 ExecutionEntity mex = setupMock()
977 when(mex.getVariable("isDebugLogEnabled")).thenReturn("true")
978 when(mex.getVariable("prevWorkflowException")).thenThrow(new RuntimeException("expected exception"))
980 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
982 DoCreateAllottedResourceBRG.postProcessRollback(mex)
983 verify(mex, never()).setVariable("rollbackData", null)
987 private boolean checkMissingPreProcessRequest(String fieldnm) {
988 ExecutionEntity mex = setupMock()
991 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
993 when(mex.getVariable(fieldnm)).thenReturn("")
995 return doBpmnError( { _ -> DoCreateAllottedResourceBRG.preProcessRequest(mex) })
998 private boolean doBpmnError(def func) {
1004 } catch(BpmnError e) {
1009 private void initPreProcess(ExecutionEntity mex) {
1010 when(mex.getVariable("isDebugLogEnabled")).thenReturn("true")
1011 when(mex.getVariable("URN_mso_workflow_sdncadapter_callback")).thenReturn("sdncurn")
1012 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
1013 when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii")
1014 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("armi")
1015 when(mex.getVariable("vni")).thenReturn("myvni")
1016 when(mex.getVariable("vgmuxBearerIP")).thenReturn("vbi")
1017 when(mex.getVariable("brgWanMacAddress")).thenReturn("bwma")
1018 when(mex.getVariable("allottedResourceRole")).thenReturn("arr")
1019 when(mex.getVariable("allottedResourceType")).thenReturn("art")
1022 private initCreateAaiAr(ExecutionEntity mex) {
1023 when(mex.getVariable("disableRollback")).thenReturn(45)
1024 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
1025 when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii")
1026 when(mex.getVariable("isDebugLogEnabled")).thenReturn("true")
1027 when(mex.getVariable("allottedResourceId")).thenReturn("myid")
1028 when(mex.getVariable("URN_aai_endpoint")).thenReturn(aaiUriPfx)
1029 when(mex.getVariable("URN_mso_workflow_global_default_aai_namespace")).thenReturn(urnProps.get("mso.workflow.global.default.aai.namespace"))
1030 when(mex.getVariable("PSI_resourceLink")).thenReturn(aaiUriPfx+"/aai/v9/mypsi")
1031 when(mex.getVariable("allottedResourceType")).thenReturn("BRGt")
1032 when(mex.getVariable("allottedResourceRole")).thenReturn("BRGr")
1033 when(mex.getVariable("CSI_resourceLink")).thenReturn(aaiUriPfx+"/aai/v9/mycsi")
1034 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("""
1036 "modelInvariantUuid":"modelinvuuid",
1037 "modelUuid":"modeluuid",
1038 "modelCustomizationUuid":"modelcustuuid"
1043 private initBuildSDNCRequest(ExecutionEntity mex) {
1044 when(mex.getVariable("isDebugLogEnabled")).thenReturn("true")
1045 when(mex.getVariable("allottedResourceId")).thenReturn("ari")
1046 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
1047 when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii")
1048 when(mex.getVariable("sdncCallbackUrl")).thenReturn("scu")
1049 when(mex.getVariable("msoRequestId")).thenReturn("mri")
1050 when(mex.getVariable("brgWanMacAddress")).thenReturn("bwma")
1051 when(mex.getVariable("vni")).thenReturn("myvni")
1052 when(mex.getVariable("vgmuxBearerIP")).thenReturn("vbi")
1053 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("""
1055 "modelInvariantUuid":"miu",
1057 "modelCustomizationUuid":"mcu",
1058 "modelVersion":"mv",
1064 private RollbackData initPreProcessSDNC(ExecutionEntity mex) {
1065 def data = new RollbackData()
1067 when(mex.getVariable("isDebugLogEnabled")).thenReturn("true")
1068 when(mex.getVariable("rollbackData")).thenReturn(data)
1073 private initPreProcessSDNCGet(ExecutionEntity mex) {
1074 when(mex.getVariable("isDebugLogEnabled")).thenReturn("true")
1075 when(mex.getVariable("sdncCallbackUrl")).thenReturn("myurl")
1076 when(mex.getVariable("foundActiveAR")).thenReturn(true)
1077 when(mex.getVariable("aaiARGetResponse")).thenReturn("<selflink>arlink</selflink>")
1078 when(mex.getVariable("sdncAssignResponse")).thenReturn("<response-data><object-path>assignlink</object-path></response-data>")
1079 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
1080 when(mex.getVariable("junitSleepMs")).thenReturn("5")
1081 when(mex.getVariable("sdncCallbackUrl")).thenReturn("myurl")
1084 private RollbackData initValidateSDNCResp(ExecutionEntity mex) {
1085 def data = new RollbackData()
1087 when(mex.getVariable("isDebugLogEnabled")).thenReturn("true")
1088 when(mex.getVariable("prefix")).thenReturn(Prefix)
1089 when(mex.getVariable("SDNCA_SuccessIndicator")).thenReturn(true)
1090 when(mex.getVariable("rollbackData")).thenReturn(data)
1095 private String initValidateSDNCResp_Resp() {
1096 return "<response-data><response-code>200</response-code></response-data>"
1099 private initUpdateAaiAROrchStatus(ExecutionEntity mex) {
1100 when(mex.getVariable("isDebugLogEnabled")).thenReturn("true")
1101 when(mex.getVariable("aaiARPath")).thenReturn(aaiUriPfx+"/aai/v9/myurl")
1104 .stubFor(patch(urlMatching("/aai/v[0-9]+/myurl"))
1105 .willReturn(aResponse()
1109 private ExecutionEntity setupMock() {
\r
1111 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
\r
1112 when(mockProcessDefinition.getKey()).thenReturn("DoCreateAllottedResourceBRG")
\r
1113 RepositoryService mockRepositoryService = mock(RepositoryService.class)
\r
1114 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
\r
1115 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("DoCreateAllottedResourceBRG")
\r
1116 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
\r
1117 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
\r
1118 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
\r
1120 ExecutionEntity mex = mock(ExecutionEntity.class)
\r
1122 when(mex.getId()).thenReturn("100")
\r
1123 when(mex.getProcessDefinitionId()).thenReturn("DoCreateAllottedResourceBRG")
\r
1124 when(mex.getProcessInstanceId()).thenReturn("DoCreateAllottedResourceBRG")
\r
1125 when(mex.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
\r
1126 when(mex.getProcessEngineServices().getRepositoryService().getProcessDefinition(mex.getProcessDefinitionId())).thenReturn(mockProcessDefinition)
\r