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.get
40 import static com.github.tomakehurst.wiremock.client.WireMock.patch
41 import static com.github.tomakehurst.wiremock.client.WireMock.put
42 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor
43 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching
44 import static org.junit.Assert.*;
\r
45 import static org.mockito.Mockito.*
46 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetAllottedResource
47 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition
48 import org.openecomp.mso.bpmn.core.domain.VnfResource
49 import org.openecomp.mso.bpmn.core.domain.AllottedResource
50 import org.openecomp.mso.bpmn.core.domain.ModelInfo
51 import org.openecomp.mso.bpmn.core.domain.HomingSolution
52 import org.openecomp.mso.bpmn.core.RollbackData
53 import org.openecomp.mso.bpmn.vcpe.scripts.MapGetter
54 import org.openecomp.mso.bpmn.vcpe.scripts.MapSetter
56 import com.github.tomakehurst.wiremock.junit.WireMockRule
\r
58 class CreateVcpeResCustServiceTest extends GroovyTestBase {
60 private static String request
\r
63 public WireMockRule wireMockRule = new WireMockRule(PORT)
65 String Prefix = "CVRCS_"
66 String RbType = "DCRENI_"
\r
69 public static void setUpBeforeClass() {
70 super.setUpBeforeClass()
71 request = FileUtil.readResourceFile("__files/VCPE/CreateVcpeResCustService/request.json")
77 MockitoAnnotations.initMocks(this)
\r
80 public CreateVcpeResCustServiceTest() {
81 super("CreateVcpeResCustService")
85 // ***** preProcessRequest *****
\r
89 public void preProcessRequest() {
\r
90 ExecutionEntity mex = setupMock()
91 def map = setupMap(mex)
94 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
\r
95 CreateVcpeResCustService.preProcessRequest(mex)
\r
97 verify(mex).getVariable(DBGFLAG)
\r
98 verify(mex).setVariable("prefix", Prefix)
99 verify(mex).setVariable("aaiDistDelay", "aaidelay")
100 verify(mex).setVariable("createVcpeServiceRequest", request)
101 verify(mex).setVariable("msoRequestId", "mri")
102 assertEquals("sii", map.get("serviceInstanceId"))
103 verify(mex).setVariable("requestAction", "ra")
104 verify(mex).setVariable("source", "VID")
105 verify(mex).setVariable("globalSubscriberId", CUST)
106 verify(mex).setVariable("globalCustomerId", CUST)
107 verify(mex).setVariable("subscriptionServiceType", SVC)
108 verify(mex).setVariable("disableRollback", "false")
109 verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb")
110 assertTrue(map.containsKey("subscriberInfo"))
112 verify(mex).setVariable("brgWanMacAddress", "brgmac")
113 assertTrue(map.containsKey("serviceInputParams"))
114 assertTrue(map.containsKey(Prefix+"requestInfo"))
116 def reqinfo = map.get(Prefix+"requestInfo")
117 assertTrue(reqinfo.indexOf("<request-id>mri</") >= 0)
118 assertTrue(reqinfo.indexOf("<source>VID</") >= 0)
\r
123 public void preProcessRequest_MissingAaiDistDelay() {
124 ExecutionEntity mex = setupMock()
125 def map = setupMap(mex)
128 when(mex.getVariable("URN_mso_workflow_aai_distribution_delay")).thenReturn(null)
130 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
132 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.preProcessRequest(mex) }))
137 public void preProcessRequest_EmptyParts() {
138 ExecutionEntity mex = setupMock()
139 def map = setupMap(mex)
143 .replace('"source"', '"sourceXXX"')
144 .replace('"BRG_WAN_MAC_Address"', '"BRG_WAN_MAC_AddressXXX"')
146 when(mex.getVariable("bpmnRequest")).thenReturn(req)
147 when(mex.getVariable("serviceInstanceId")).thenReturn(null)
149 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
150 CreateVcpeResCustService.preProcessRequest(mex)
152 verify(mex).getVariable(DBGFLAG)
153 verify(mex).setVariable("prefix", Prefix)
154 verify(mex).setVariable("createVcpeServiceRequest", req)
155 verify(mex).setVariable("msoRequestId", "mri")
156 assertNotNull(map.get("serviceInstanceId"))
157 assertFalse(map.get("serviceInstanceId").isEmpty())
158 verify(mex).setVariable("requestAction", "ra")
159 verify(mex).setVariable("source", "VID")
160 verify(mex).setVariable("globalSubscriberId", CUST)
161 verify(mex).setVariable("globalCustomerId", CUST)
162 verify(mex).setVariable("subscriptionServiceType", SVC)
163 verify(mex).setVariable("disableRollback", "false")
164 verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb")
165 assertTrue(map.containsKey("subscriberInfo"))
167 assertEquals("", map.get("brgWanMacAddress"))
168 assertTrue(map.containsKey("serviceInputParams"))
169 assertTrue(map.containsKey(Prefix+"requestInfo"))
171 def reqinfo = map.get(Prefix+"requestInfo")
173 assertTrue(reqinfo.indexOf("<request-id>mri</") >= 0)
174 assertTrue(reqinfo.indexOf("<source>VID</") >= 0)
179 public void preProcessRequest_MissingSubscriberId() {
180 ExecutionEntity mex = setupMock()
181 def map = setupMap(mex)
185 .replace('"globalSubscriberId"', '"globalSubscriberIdXXX"')
187 when(mex.getVariable("bpmnRequest")).thenReturn(req)
188 when(mex.getVariable("serviceInstanceId")).thenReturn(null)
190 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
192 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.preProcessRequest(mex) }))
197 public void preProcessRequest_BpmnError() {
198 ExecutionEntity mex = setupMock()
201 when(mex.getVariable("bpmnRequest")).thenThrow(new BpmnError("expected exception"))
203 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
205 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.preProcessRequest(mex) }))
210 public void preProcessRequest_Ex() {
211 ExecutionEntity mex = setupMock()
214 when(mex.getVariable("bpmnRequest")).thenThrow(new RuntimeException("expected exception"))
216 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
218 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.preProcessRequest(mex) }))
221 // ***** sendSyncResponse *****
225 public void sendSyncResponse() {
226 ExecutionEntity mex = setupMock()
227 def map = setupMap(mex)
228 initSendSyncResponse(mex)
230 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
231 CreateVcpeResCustService.sendSyncResponse(mex)
233 verify(mex, times(2)).getVariable(DBGFLAG)
235 verify(mex).setVariable(processName+"WorkflowResponseSent", "true")
237 assertEquals("202", map.get(processName+"ResponseCode"))
238 assertEquals("Success", map.get(processName+"Status"))
240 def resp = map.get(processName+"Response")
242 assertTrue(resp.indexOf('"instanceId":"sii"') >= 0)
243 assertTrue(resp.indexOf('"requestId":"mri"') >= 0)
248 public void sendSyncResponse_Ex() {
249 ExecutionEntity mex = setupMock()
250 initSendSyncResponse(mex)
252 when(mex.getVariable("serviceInstanceId")).thenThrow(new RuntimeException("expected exception"))
254 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
256 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.sendSyncResponse(mex) }))
260 // ***** prepareDecomposeService *****
264 public void prepareDecomposeService() {
265 ExecutionEntity mex = setupMock()
266 initPrepareDecomposeService(mex)
268 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
269 CreateVcpeResCustService.prepareDecomposeService(mex)
271 verify(mex).getVariable(DBGFLAG)
272 verify(mex).setVariable("serviceModelInfo", "mi")
277 public void prepareDecomposeService_Ex() {
278 ExecutionEntity mex = setupMock()
279 initPrepareDecomposeService(mex)
281 when(mex.getVariable("createVcpeServiceRequest")).thenThrow(new RuntimeException("expected exception"))
283 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
285 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.prepareDecomposeService(mex) }))
289 // ***** prepareCreateServiceInstance *****
293 public void prepareCreateServiceInstance() {
294 ExecutionEntity mex = setupMock()
295 initPrepareCreateServiceInstance(mex)
297 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
298 CreateVcpeResCustService.prepareCreateServiceInstance(mex)
300 verify(mex).getVariable(DBGFLAG)
301 verify(mex).setVariable("serviceInstanceName", "VCPE1")
302 verify(mex).setVariable("serviceDecompositionString", "mydecomp")
307 public void prepareCreateServiceInstance_Ex() {
308 ExecutionEntity mex = setupMock()
309 initPrepareCreateServiceInstance(mex)
311 when(mex.getVariable("createVcpeServiceRequest")).thenThrow(new RuntimeException("expected exception"))
313 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
315 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.prepareCreateServiceInstance(mex) }))
319 // ***** postProcessServiceInstanceCreate *****
323 public void postProcessServiceInstanceCreate() {
324 ExecutionEntity mex = setupMock()
325 def map = setupMap(mex)
326 initPostProcessServiceInstanceCreate(mex)
328 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
329 CreateVcpeResCustService.postProcessServiceInstanceCreate(mex)
331 verify(mex).getVariable(DBGFLAG)
333 def reqinfo = map.get(Prefix+"setUpdateDbInstancePayload")
335 assertTrue(reqinfo.indexOf("<requestId>mri</") >= 0)
336 assertTrue(reqinfo.indexOf("<serviceInstanceId>sii</") >= 0)
337 assertTrue(reqinfo.indexOf("<serviceInstanceName>sin</") >= 0)
342 public void postProcessServiceInstanceCreate_BpmnError() {
343 ExecutionEntity mex = setupMock()
344 initPostProcessServiceInstanceCreate(mex)
346 doThrow(new BpmnError("expected exception")).when(mex).setVariable(endsWith("setUpdateDbInstancePayload"), any())
348 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
350 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.postProcessServiceInstanceCreate(mex) }))
355 public void postProcessServiceInstanceCreate_Ex() {
356 ExecutionEntity mex = setupMock()
357 initPostProcessServiceInstanceCreate(mex)
359 doThrow(new RuntimeException("expected exception")).when(mex).setVariable(endsWith("setUpdateDbInstancePayload"), any())
361 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
363 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.postProcessServiceInstanceCreate(mex) }))
367 // ***** processDecomposition *****
371 public void processDecomposition() {
372 ExecutionEntity mex = setupMock()
373 def svcdecomp = initProcessDecomposition(mex)
375 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
376 CreateVcpeResCustService.processDecomposition(mex)
378 verify(mex).getVariable(DBGFLAG)
380 verify(mex).setVariable("vnfList", svcdecomp.getServiceVnfs())
381 verify(mex).setVariable("vnfListString", '[myvnf]')
382 verify(mex).setVariable(Prefix+"VNFsCount", 1)
384 verify(mex).setVariable("vnfModelInfo", "mymodel")
385 verify(mex).setVariable("vnfModelInfoString", "mymodel")
390 public void processDecomposition_EmptyNet_EmptyVnf() {
391 ExecutionEntity mex = setupMock()
392 def svcdecomp = initProcessDecomposition(mex)
394 when(svcdecomp.getServiceVnfs()).thenReturn(new LinkedList<VnfResource>())
396 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
397 CreateVcpeResCustService.processDecomposition(mex)
399 verify(mex).getVariable(DBGFLAG)
401 verify(mex).setVariable("vnfList", svcdecomp.getServiceVnfs())
402 verify(mex).setVariable("vnfListString", '[]')
403 verify(mex).setVariable(Prefix+"VNFsCount", 0)
405 verify(mex).setVariable("vnfModelInfo", "")
406 verify(mex).setVariable("vnfModelInfoString", "")
411 public void processDecomposition_Ex() {
412 ExecutionEntity mex = setupMock()
413 def svcdecomp = initProcessDecomposition(mex)
415 when(svcdecomp.getServiceVnfs()).thenThrow(new RuntimeException("expected exception"))
417 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
419 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.processDecomposition(mex) }))
423 // ***** filterVnfs *****
427 public void filterVnfs() {
428 ExecutionEntity mex = setupMock()
429 def svcdecomp = initFilterVnfs(mex)
431 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
432 CreateVcpeResCustService.processDecomposition(mex)
434 verify(mex).setVariable("vnfListString", '[myvnf3, myvnf5]')
439 public void filterVnfs_Null() {
440 ExecutionEntity mex = setupMock()
441 def svcdecomp = initFilterVnfs(mex)
443 when(svcdecomp.getServiceVnfs()).thenReturn(null)
445 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
446 CreateVcpeResCustService.processDecomposition(mex)
448 // nothing more to check, as long as it didn't throw an exception
452 // ***** prepareCreateAllottedResourceTXC *****
456 public void prepareCreateAllottedResourceTXC() {
457 ExecutionEntity mex = setupMock()
458 initPrepareCreateAllottedResourceTXC(mex)
460 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
461 CreateVcpeResCustService.prepareCreateAllottedResourceTXC(mex)
463 verify(mex).getVariable(DBGFLAG)
465 verify(mex).setVariable("createTXCAR", true)
466 verify(mex).setVariable("allottedResourceModelInfoTXC", "modelB")
467 verify(mex).setVariable("allottedResourceRoleTXC", "TXCr")
468 verify(mex).setVariable("allottedResourceTypeTXC", "TunnelXConn")
469 verify(mex).setVariable("parentServiceInstanceIdTXC", "homeB")
474 public void prepareCreateAllottedResourceTXC_NullArList() {
475 ExecutionEntity mex = setupMock()
476 def svcdecomp = initPrepareCreateAllottedResourceTXC(mex)
478 when(svcdecomp.getServiceAllottedResources()).thenReturn(null)
480 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
481 CreateVcpeResCustService.prepareCreateAllottedResourceTXC(mex)
483 verify(mex).getVariable(DBGFLAG)
485 verify(mex, never()).setVariable("createTXCAR", true)
486 verify(mex, never()).setVariable("allottedResourceModelInfoTXC", "modelB")
487 verify(mex, never()).setVariable("allottedResourceRoleTXC", "TXCr")
488 verify(mex, never()).setVariable("allottedResourceTypeTXC", "TunnelXConn")
489 verify(mex, never()).setVariable("parentServiceInstanceIdTXC", "homeB")
494 public void prepareCreateAllottedResourceTXC_Ex() {
495 ExecutionEntity mex = setupMock()
496 initPrepareCreateAllottedResourceTXC(mex)
498 when(mex.getVariable("createVcpeServiceRequest")).thenThrow(new RuntimeException("expected exception"))
500 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
502 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.prepareCreateAllottedResourceTXC(mex) }))
506 // ***** prepareCreateAllottedResourceBRG *****
510 public void prepareCreateAllottedResourceBRG() {
511 ExecutionEntity mex = setupMock()
512 initPrepareCreateAllottedResourceBRG(mex)
514 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
515 CreateVcpeResCustService.prepareCreateAllottedResourceBRG(mex)
517 verify(mex).getVariable(DBGFLAG)
519 verify(mex).setVariable("createBRGAR", true)
520 verify(mex).setVariable("allottedResourceModelInfoBRG", "modelB")
521 verify(mex).setVariable("allottedResourceRoleBRG", "BRGr")
522 verify(mex).setVariable("allottedResourceTypeBRG", "BRG")
523 verify(mex).setVariable("parentServiceInstanceIdBRG", "homeB")
528 public void prepareCreateAllottedResourceBRG_NullArList() {
529 ExecutionEntity mex = setupMock()
530 def svcdecomp = initPrepareCreateAllottedResourceBRG(mex)
532 when(svcdecomp.getServiceAllottedResources()).thenReturn(null)
534 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
535 CreateVcpeResCustService.prepareCreateAllottedResourceBRG(mex)
537 verify(mex).getVariable(DBGFLAG)
539 verify(mex, never()).setVariable("createBRGAR", true)
540 verify(mex, never()).setVariable("allottedResourceModelInfoBRG", "modelB")
541 verify(mex, never()).setVariable("allottedResourceRoleBRG", "BRGr")
542 verify(mex, never()).setVariable("allottedResourceTypeBRG", "BRG")
543 verify(mex, never()).setVariable("parentServiceInstanceIdBRG", "homeB")
548 public void prepareCreateAllottedResourceBRG_Ex() {
549 ExecutionEntity mex = setupMock()
550 initPrepareCreateAllottedResourceBRG(mex)
552 when(mex.getVariable("createVcpeServiceRequest")).thenThrow(new RuntimeException("expected exception"))
554 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
556 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.prepareCreateAllottedResourceBRG(mex) }))
560 // ***** prepareVnfAndModulesCreate *****
564 public void prepareVnfAndModulesCreate() {
565 ExecutionEntity mex = setupMock()
566 initPrepareVnfAndModulesCreate(mex)
568 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
569 CreateVcpeResCustService.prepareVnfAndModulesCreate(mex)
571 verify(mex).getVariable(DBGFLAG)
573 verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb")
574 verify(mex).setVariable("lcpCloudRegionId", "mdt1")
575 verify(mex).setVariable("tenantId", "8b1df54faa3b49078e3416e21370a3ba")
580 public void prepareVnfAndModulesCreate_EmptyList() {
581 ExecutionEntity mex = setupMock()
582 initPrepareVnfAndModulesCreate(mex)
584 when(mex.getVariable("vnfList")).thenReturn(new LinkedList<VnfResource>())
586 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
587 CreateVcpeResCustService.prepareVnfAndModulesCreate(mex)
589 verify(mex).getVariable(DBGFLAG)
591 verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb")
592 verify(mex).setVariable("lcpCloudRegionId", "mdt1")
593 verify(mex).setVariable("tenantId", "8b1df54faa3b49078e3416e21370a3ba")
598 public void prepareVnfAndModulesCreate_NullList() {
599 ExecutionEntity mex = setupMock()
600 initPrepareVnfAndModulesCreate(mex)
602 when(mex.getVariable("vnfList")).thenReturn(null)
604 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
605 CreateVcpeResCustService.prepareVnfAndModulesCreate(mex)
607 verify(mex).getVariable(DBGFLAG)
609 verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb")
610 verify(mex).setVariable("lcpCloudRegionId", "mdt1")
611 verify(mex).setVariable("tenantId", "8b1df54faa3b49078e3416e21370a3ba")
616 public void prepareVnfAndModulesCreate_Ex() {
617 ExecutionEntity mex = setupMock()
618 initPrepareVnfAndModulesCreate(mex)
620 when(mex.getVariable("vnfList")).thenThrow(new RuntimeException("expected exception"))
622 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
624 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.prepareVnfAndModulesCreate(mex) }))
628 // ***** validateVnfCreate *****
632 public void validateVnfCreate() {
633 ExecutionEntity mex = setupMock()
634 initValidateVnfCreate(mex)
636 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
637 CreateVcpeResCustService.validateVnfCreate(mex)
639 verify(mex).getVariable(DBGFLAG)
641 verify(mex).setVariable(Prefix+"VnfsCreatedCount", 3)
646 public void validateVnfCreate_Ex() {
647 ExecutionEntity mex = setupMock()
648 initValidateVnfCreate(mex)
650 when(mex.getVariable(Prefix+"VnfsCreatedCount")).thenThrow(new RuntimeException("expected exception"))
652 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
654 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.validateVnfCreate(mex) }))
658 // ***** postProcessResponse *****
662 public void postProcessResponse() {
663 ExecutionEntity mex = setupMock()
664 def map = setupMap(mex)
665 initPostProcessResponse(mex)
667 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
668 CreateVcpeResCustService.postProcessResponse(mex)
670 verify(mex).getVariable(DBGFLAG)
672 verify(mex).setVariable(Prefix+"Success", true)
674 def reqinfo = map.get(Prefix+"CompleteMsoProcessRequest")
676 assertTrue(reqinfo.indexOf("request-id>mri</") >= 0)
677 assertTrue(reqinfo.indexOf("source>mysrc</") >= 0)
678 assertTrue(reqinfo.indexOf("serviceInstanceId>sii</") >= 0)
683 public void postProcessResponse_BpmnError() {
684 ExecutionEntity mex = setupMock()
685 def map = setupMap(mex)
686 initPostProcessResponse(mex)
688 when(mex.getVariable("source")).thenThrow(new BpmnError("expected exception"))
690 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
692 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.postProcessResponse(mex) }))
697 public void postProcessResponse_Ex() {
698 ExecutionEntity mex = setupMock()
699 def map = setupMap(mex)
700 initPostProcessResponse(mex)
702 when(mex.getVariable("source")).thenThrow(new RuntimeException("expected exception"))
704 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
706 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.postProcessResponse(mex) }))
710 // ***** preProcessRollback *****
714 public void preProcessRollback() {
715 ExecutionEntity mex = setupMock()
716 def wfe = initPreProcessRollback(mex)
718 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
719 CreateVcpeResCustService.preProcessRollback(mex)
721 verify(mex).getVariable(DBGFLAG)
723 verify(mex).setVariable("prevWorkflowException", wfe)
728 public void preProcessRollback_NullWfe() {
729 ExecutionEntity mex = setupMock()
730 def map = setupMap(mex)
731 def wfe = initPreProcessRollback(mex)
733 when(mex.getVariable("WorkflowException")).thenReturn(null)
735 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
736 CreateVcpeResCustService.preProcessRollback(mex)
738 verify(mex).getVariable(DBGFLAG)
740 assertFalse(map.containsKey("prevWorkflowException"))
745 public void preProcessRollback_BpmnError() {
746 ExecutionEntity mex = setupMock()
747 def map = setupMap(mex)
748 def wfe = initPreProcessRollback(mex)
750 when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception"))
752 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
753 CreateVcpeResCustService.preProcessRollback(mex)
755 verify(mex).getVariable(DBGFLAG)
757 assertFalse(map.containsKey("prevWorkflowException"))
762 public void preProcessRollback_Ex() {
763 ExecutionEntity mex = setupMock()
764 def map = setupMap(mex)
765 def wfe = initPreProcessRollback(mex)
767 when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
769 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
770 CreateVcpeResCustService.preProcessRollback(mex)
772 verify(mex).getVariable(DBGFLAG)
774 assertFalse(map.containsKey("prevWorkflowException"))
778 // ***** postProcessRollback *****
782 public void postProcessRollback() {
783 ExecutionEntity mex = setupMock()
784 def wfe = initPostProcessRollback(mex)
786 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
787 CreateVcpeResCustService.postProcessRollback(mex)
789 verify(mex).getVariable(DBGFLAG)
791 verify(mex).setVariable("WorkflowException", wfe)
796 public void postProcessRollback_NullWfe() {
797 ExecutionEntity mex = setupMock()
798 def map = setupMap(mex)
799 def wfe = initPostProcessRollback(mex)
801 when(mex.getVariable("prevWorkflowException")).thenReturn(null)
803 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
804 CreateVcpeResCustService.postProcessRollback(mex)
806 verify(mex).getVariable(DBGFLAG)
808 assertFalse(map.containsKey("WorkflowException"))
813 public void postProcessRollback_BpmnError() {
814 ExecutionEntity mex = setupMock()
815 def map = setupMap(mex)
816 def wfe = initPostProcessRollback(mex)
818 when(mex.getVariable("prevWorkflowException")).thenThrow(new BpmnError("expected exception"))
820 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
821 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.postProcessRollback(mex) }))
826 public void postProcessRollback_Ex() {
827 ExecutionEntity mex = setupMock()
828 def map = setupMap(mex)
829 def wfe = initPostProcessRollback(mex)
831 when(mex.getVariable("prevWorkflowException")).thenThrow(new RuntimeException("expected exception"))
833 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
834 CreateVcpeResCustService.postProcessRollback(mex)
836 verify(mex).getVariable(DBGFLAG)
838 assertFalse(map.containsKey("WorkflowException"))
842 // ***** prepareFalloutRequest *****
846 public void prepareFalloutRequest() {
847 ExecutionEntity mex = setupMock()
848 def map = setupMap(mex)
849 initPrepareFalloutRequest(mex)
851 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
852 CreateVcpeResCustService.prepareFalloutRequest(mex)
854 verify(mex, times(2)).getVariable(DBGFLAG)
856 def fo = map.get(Prefix+"falloutRequest")
858 assertTrue(fo.indexOf("<hello>world</") >= 0)
859 assertTrue(fo.indexOf("ErrorMessage>mymsg</") >= 0)
860 assertTrue(fo.indexOf("ErrorCode>999</") >= 0)
865 public void prepareFalloutRequest_Ex() {
866 ExecutionEntity mex = setupMock()
867 def map = setupMap(mex)
868 initPrepareFalloutRequest(mex)
870 when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
872 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
874 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.prepareFalloutRequest(mex) }))
877 // ***** sendSyncError *****
881 public void sendSyncError() {
882 ExecutionEntity mex = setupMock()
883 def map = setupMap(mex)
884 initSendSyncError(mex)
886 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
887 CreateVcpeResCustService.sendSyncError(mex)
889 verify(mex, times(2)).getVariable(DBGFLAG)
891 verify(mex).setVariable(processName+"WorkflowResponseSent", "true")
893 assertEquals("500", map.get(processName+"ResponseCode"))
894 assertEquals("Fail", map.get(processName+"Status"))
896 def resp = map.get(processName+"Response")
898 assertTrue(resp.indexOf("ErrorMessage>mymsg</") >= 0)
900 verify(mex).setVariable("WorkflowResponse", resp)
905 public void sendSyncError_NotWfe() {
906 ExecutionEntity mex = setupMock()
907 def map = setupMap(mex)
908 initSendSyncError(mex)
910 when(mex.getVariable("WorkflowException")).thenReturn("not a WFE")
912 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
913 CreateVcpeResCustService.sendSyncError(mex)
915 verify(mex, times(2)).getVariable(DBGFLAG)
917 verify(mex).setVariable(processName+"WorkflowResponseSent", "true")
919 assertEquals("500", map.get(processName+"ResponseCode"))
920 assertEquals("Fail", map.get(processName+"Status"))
922 def resp = map.get(processName+"Response")
924 assertTrue(resp.indexOf("ErrorMessage>Sending Sync Error.</") >= 0)
926 verify(mex).setVariable("WorkflowResponse", resp)
931 public void sendSyncError_NullWfe() {
932 ExecutionEntity mex = setupMock()
933 def map = setupMap(mex)
934 initSendSyncError(mex)
936 when(mex.getVariable("WorkflowException")).thenReturn(null)
938 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
939 CreateVcpeResCustService.sendSyncError(mex)
941 verify(mex, times(2)).getVariable(DBGFLAG)
943 verify(mex).setVariable(processName+"WorkflowResponseSent", "true")
945 assertEquals("500", map.get(processName+"ResponseCode"))
946 assertEquals("Fail", map.get(processName+"Status"))
948 def resp = map.get(processName+"Response")
950 assertTrue(resp.indexOf("ErrorMessage>Sending Sync Error.</") >= 0)
952 verify(mex).setVariable("WorkflowResponse", resp)
957 public void sendSyncError_Ex() {
958 ExecutionEntity mex = setupMock()
959 def map = setupMap(mex)
960 initSendSyncError(mex)
962 when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
964 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
966 CreateVcpeResCustService.sendSyncError(mex)
968 assertFalse(map.containsKey(processName+"ResponseCode"))
972 // ***** processJavaException *****
976 public void processJavaException() {
977 ExecutionEntity mex = setupMock()
978 def map = setupMap(mex)
979 initProcessJavaException(mex)
981 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
983 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.processJavaException(mex) }))
985 verify(mex, times(2)).getVariable(DBGFLAG)
987 verify(mex).setVariable("prefix", Prefix)
989 def wfe = map.get("WorkflowException")
991 assertEquals("Caught a Java Lang Exception", wfe.getErrorMessage())
996 public void processJavaException_BpmnError() {
997 ExecutionEntity mex = setupMock()
998 def map = setupMap(mex)
999 initProcessJavaException(mex)
1001 when(mex.getVariables()).thenThrow(new BpmnError("expected exception"))
1003 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
1005 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.processJavaException(mex) }))
1007 assertFalse(map.containsKey("WorkflowException"))
1012 public void processJavaException_Ex() {
1013 ExecutionEntity mex = setupMock()
1014 def map = setupMap(mex)
1015 initProcessJavaException(mex)
1017 when(mex.getVariables()).thenThrow(new RuntimeException("expected exception"))
1019 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
1021 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.processJavaException(mex) }))
1023 def wfe = map.get("WorkflowException")
1025 assertEquals("Exception in processJavaException method", wfe.getErrorMessage())
1029 private void initPreProcess(ExecutionEntity mex) {
1030 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1031 when(mex.getVariable("bpmnRequest")).thenReturn(request)
1032 when(mex.getVariable("URN_mso_workflow_aai_distribution_delay")).thenReturn("aaidelay")
1033 when(mex.getVariable("mso-request-id")).thenReturn("mri")
1034 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
1035 when(mex.getVariable("requestAction")).thenReturn("ra")
1038 private initSendSyncResponse(ExecutionEntity mex) {
1039 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1040 when(mex.getVariable("mso-request-id")).thenReturn("mri")
1041 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
1044 private void initPrepareDecomposeService(ExecutionEntity mex) {
1045 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1046 when(mex.getVariable("createVcpeServiceRequest")).thenReturn('{"requestDetails":{"modelInfo":"mi"}}')
1049 private void initPrepareCreateServiceInstance(ExecutionEntity mex) {
1050 ServiceDecomposition svcdecomp = mock(ServiceDecomposition.class)
1052 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1053 when(mex.getVariable("createVcpeServiceRequest")).thenReturn(request)
1054 when(mex.getVariable("serviceDecomposition")).thenReturn(svcdecomp)
1056 when(svcdecomp.toJsonStringNoRootName()).thenReturn("mydecomp")
1059 private void initPostProcessServiceInstanceCreate(ExecutionEntity mex) {
1060 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1061 when(mex.getVariable("mso-request-id")).thenReturn("mri")
1062 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
1063 when(mex.getVariable("serviceInstanceName")).thenReturn("sin")
1066 private ServiceDecomposition initProcessDecomposition(ExecutionEntity mex) {
1067 List<VnfResource> vnflst = new LinkedList<>()
1068 vnflst.add(makeVnf("", ""))
1069 vnflst.add(makeVnf("2", "BRG"))
1070 vnflst.add(makeVnf("3", "BRG"))
1072 ServiceDecomposition svcdecomp = mock(ServiceDecomposition.class)
1073 when(svcdecomp.getServiceVnfs()).thenReturn(vnflst)
1075 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1076 when(mex.getVariable("serviceDecomposition")).thenReturn(svcdecomp)
1077 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
1078 when(mex.getVariable("serviceInstanceName")).thenReturn("sin")
1083 private ServiceDecomposition initFilterVnfs(ExecutionEntity mex) {
1084 List<VnfResource> vnflst = new LinkedList<>()
1085 vnflst.add(makeVnf("", "BRG"))
1086 vnflst.add(makeVnf("2", "TunnelXConn"))
1087 vnflst.add(makeVnf("3", ""))
1088 vnflst.add(makeVnf("4", "BRG"))
1089 vnflst.add(makeVnf("5", "other"))
1091 ServiceDecomposition svcdecomp = mock(ServiceDecomposition.class)
1092 when(svcdecomp.getServiceVnfs()).thenReturn(vnflst)
1094 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1095 when(mex.getVariable("serviceDecomposition")).thenReturn(svcdecomp)
1096 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
1097 when(mex.getVariable("serviceInstanceName")).thenReturn("sin")
1102 private initAwaitAaiDistribution(ExecutionEntity mex) {
1103 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1106 private ServiceDecomposition initPrepareCreateAllottedResourceTXC(ExecutionEntity mex) {
1107 ServiceDecomposition svcdecomp = mock(ServiceDecomposition.class)
1108 List<AllottedResource> arlst = new LinkedList<>()
1110 arlst.add(makeArBRG("A"))
1111 arlst.add(makeArTXC("B"))
1112 arlst.add(makeArBRG("C"))
1114 when(svcdecomp.getServiceAllottedResources()).thenReturn(arlst)
1116 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1117 when(mex.getVariable("createVcpeServiceRequest")).thenReturn(request)
1118 when(mex.getVariable("serviceDecomposition")).thenReturn(svcdecomp)
1119 when(mex.getVariable("allottedResourceId")).thenReturn(ARID)
1124 private ServiceDecomposition initPrepareCreateAllottedResourceBRG(ExecutionEntity mex) {
1125 ServiceDecomposition svcdecomp = mock(ServiceDecomposition.class)
1126 List<AllottedResource> arlst = new LinkedList<>()
1128 arlst.add(makeArTXC("A"))
1129 arlst.add(makeArBRG("B"))
1130 arlst.add(makeArTXC("C"))
1132 when(svcdecomp.getServiceAllottedResources()).thenReturn(arlst)
1134 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1135 when(mex.getVariable("createVcpeServiceRequest")).thenReturn(request)
1136 when(mex.getVariable("serviceDecomposition")).thenReturn(svcdecomp)
1137 when(mex.getVariable("allottedResourceId")).thenReturn(ARID)
1142 private AllottedResource makeArTXC(String id) {
1143 AllottedResource ar = mock(AllottedResource.class)
1144 ModelInfo mod = mock(ModelInfo.class)
1145 HomingSolution home = mock(HomingSolution.class)
1147 when(ar.toJsonStringNoRootName()).thenReturn("json"+id)
1148 when(ar.getAllottedResourceType()).thenReturn("TunnelXConn")
1149 when(ar.getModelInfo()).thenReturn(mod)
1150 when(ar.getAllottedResourceRole()).thenReturn("TXCr")
1151 when(ar.getHomingSolution()).thenReturn(home)
1153 when(mod.toJsonStringNoRootName()).thenReturn("model"+id)
1155 when(home.getServiceInstanceId()).thenReturn("home"+id)
1160 private AllottedResource makeArBRG(String id) {
1161 AllottedResource ar = mock(AllottedResource.class)
1162 ModelInfo mod = mock(ModelInfo.class)
1163 HomingSolution home = mock(HomingSolution.class)
1165 when(ar.toJsonStringNoRootName()).thenReturn("json"+id)
1166 when(ar.getAllottedResourceType()).thenReturn("BRG")
1167 when(ar.getModelInfo()).thenReturn(mod)
1168 when(ar.getAllottedResourceRole()).thenReturn("BRGr")
1169 when(ar.getHomingSolution()).thenReturn(home)
1171 when(mod.toJsonStringNoRootName()).thenReturn("model"+id)
1173 when(home.getServiceInstanceId()).thenReturn("home"+id)
1178 private initPrepareVnfAndModulesCreate(ExecutionEntity mex) {
1180 List<VnfResource> vnflst = new LinkedList<>()
1182 vnflst.add(makeVnf("A", "BRG"))
1183 vnflst.add(makeVnf("B", ""))
1184 vnflst.add(makeVnf("C", ""))
1185 vnflst.add(makeVnf("D", "TunnelXConn"))
1187 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1188 when(mex.getVariable("createVcpeServiceRequest")).thenReturn(request)
1189 when(mex.getVariable("vnfList")).thenReturn(vnflst)
1190 when(mex.getVariable(Prefix+"VnfsCreatedCount")).thenReturn(2)
1191 when(mex.getVariable("vnfModelInfo")).thenReturn("nomodel")
1192 when(mex.getVariable("sdncVersion")).thenReturn("myvers")
1195 private VnfResource makeVnf(String id, String role) {
1196 ModelInfo mod = mock(ModelInfo.class)
1197 VnfResource vnf = mock(VnfResource.class)
1199 when(mod.toString()).thenReturn('{"modelInfo":"mymodel'+id+'"}')
1201 when(vnf.toString()).thenReturn("myvnf"+id)
1202 when(vnf.getModelInfo()).thenReturn(mod)
1203 when(vnf.getNfRole()).thenReturn(role)
1208 private initValidateVnfCreate(ExecutionEntity mex) {
1209 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1210 when(mex.getVariable(Prefix+"VnfsCreatedCount")).thenReturn(2)
1213 private initPostProcessResponse(ExecutionEntity mex) {
1214 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1215 when(mex.getVariable("source")).thenReturn("mysrc")
1216 when(mex.getVariable("mso-request-id")).thenReturn("mri")
1217 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
1220 private WorkflowException initPreProcessRollback(ExecutionEntity mex) {
1221 WorkflowException wfe = mock(WorkflowException.class)
1223 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1224 when(mex.getVariable("WorkflowException")).thenReturn(wfe)
1229 private WorkflowException initPostProcessRollback(ExecutionEntity mex) {
1230 WorkflowException wfe = mock(WorkflowException.class)
1232 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1233 when(mex.getVariable("prevWorkflowException")).thenReturn(wfe)
1238 private initPrepareFalloutRequest(ExecutionEntity mex) {
1239 WorkflowException wfe = mock(WorkflowException.class)
1241 when(wfe.getErrorMessage()).thenReturn("mymsg")
1242 when(wfe.getErrorCode()).thenReturn(999)
1244 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1245 when(mex.getVariable("WorkflowException")).thenReturn(wfe)
1246 when(mex.getVariable(Prefix+"requestInfo")).thenReturn("<hello>world</hello>")
1251 private initSendSyncError(ExecutionEntity mex) {
1252 WorkflowException wfe = mock(WorkflowException.class)
1254 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1255 when(mex.getVariable("mso-request-id")).thenReturn("mri")
1256 when(mex.getVariable("WorkflowException")).thenReturn(wfe)
1258 when(wfe.getErrorMessage()).thenReturn("mymsg")
1261 private initProcessJavaException(ExecutionEntity mex) {
1262 when(mex.getVariable(DBGFLAG)).thenReturn("true")