2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.openecomp.mso.bpmn.vcpe.scripts
23 import org.camunda.bpm.engine.ProcessEngineServices
24 import org.camunda.bpm.engine.RepositoryService
25 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
26 import org.camunda.bpm.engine.repository.ProcessDefinition
27 import org.junit.Before
28 import org.junit.BeforeClass
31 import org.junit.Ignore
32 import org.mockito.MockitoAnnotations
33 import org.camunda.bpm.engine.delegate.BpmnError
34 import org.openecomp.mso.bpmn.core.WorkflowException
35 import org.openecomp.mso.bpmn.core.domain.HomingSolution
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.*;
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
58 class CreateVcpeResCustServiceTest extends GroovyTestBase {
60 private static String request
63 public WireMockRule wireMockRule = new WireMockRule(PORT)
65 String Prefix = "CVRCS_"
66 String RbType = "DCRENI_"
69 public static void setUpBeforeClass() {
70 request = FileUtil.readResourceFile("__files/VCPE/CreateVcpeResCustService/request.json")
76 MockitoAnnotations.initMocks(this)
79 public CreateVcpeResCustServiceTest() {
80 super("CreateVcpeResCustService")
84 // ***** preProcessRequest *****
88 public void preProcessRequest() {
89 ExecutionEntity mex = setupMock()
90 def map = setupMap(mex)
93 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
94 CreateVcpeResCustService.preProcessRequest(mex)
96 verify(mex).getVariable(DBGFLAG)
97 verify(mex).setVariable("prefix", Prefix)
98 verify(mex).setVariable("aaiDistDelay", "aaidelay")
99 verify(mex).setVariable("createVcpeServiceRequest", request)
100 verify(mex).setVariable("msoRequestId", "mri")
101 assertEquals("sii", map.get("serviceInstanceId"))
102 verify(mex).setVariable("requestAction", "ra")
103 verify(mex).setVariable("source", "VID")
104 verify(mex).setVariable("globalSubscriberId", CUST)
105 verify(mex).setVariable("globalCustomerId", CUST)
106 verify(mex).setVariable("subscriptionServiceType", SVC)
107 verify(mex).setVariable("disableRollback", "false")
108 verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb")
109 assertTrue(map.containsKey("subscriberInfo"))
111 verify(mex).setVariable("brgWanMacAddress", "brgmac")
112 verify(mex).setVariable("customerLocation", ["customerLatitude":"32.897480", "customerLongitude":"-97.040443", "customerName":"some_company"])
113 verify(mex).setVariable("homingService", "sniro")
114 assertTrue(map.containsKey("serviceInputParams"))
115 assertTrue(map.containsKey(Prefix+"requestInfo"))
117 def reqinfo = map.get(Prefix+"requestInfo")
118 assertTrue(reqinfo.indexOf("<request-id>mri</") >= 0)
119 assertTrue(reqinfo.indexOf("<source>VID</") >= 0)
124 public void preProcessRequest_MissingAaiDistDelay() {
125 ExecutionEntity mex = setupMock()
126 def map = setupMap(mex)
129 when(mex.getVariable("URN_mso_workflow_aai_distribution_delay")).thenReturn(null)
131 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
133 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.preProcessRequest(mex) }))
137 @Ignore // 1802 merge
138 public void preProcessRequest_EmptyParts() {
139 ExecutionEntity mex = setupMock()
140 def map = setupMap(mex)
144 .replace('"source"', '"sourceXXX"')
145 .replace('"BRG_WAN_MAC_Address"', '"BRG_WAN_MAC_AddressXXX"')
146 .replace('"Customer_Location"', '"Customer_LocationXXX"')
148 when(mex.getVariable("bpmnRequest")).thenReturn(req)
149 when(mex.getVariable("serviceInstanceId")).thenReturn(null)
151 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
152 CreateVcpeResCustService.preProcessRequest(mex)
154 verify(mex).getVariable(DBGFLAG)
155 verify(mex).setVariable("prefix", Prefix)
156 verify(mex).setVariable("createVcpeServiceRequest", req)
157 verify(mex).setVariable("msoRequestId", "mri")
158 assertNotNull(map.get("serviceInstanceId"))
159 assertFalse(map.get("serviceInstanceId").isEmpty())
160 verify(mex).setVariable("requestAction", "ra")
161 verify(mex).setVariable("source", "VID")
162 verify(mex).setVariable("globalSubscriberId", CUST)
163 verify(mex).setVariable("globalCustomerId", CUST)
164 verify(mex).setVariable("subscriptionServiceType", SVC)
165 verify(mex).setVariable("disableRollback", "false")
166 verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb")
167 assertTrue(map.containsKey("subscriberInfo"))
169 assertEquals("", map.get("brgWanMacAddress"))
170 assertEquals("", map.get("customerLocation"))
171 assertEquals("oof", map.get("homingService"))
172 assertTrue(map.containsKey("serviceInputParams"))
173 assertTrue(map.containsKey(Prefix+"requestInfo"))
175 def reqinfo = map.get(Prefix+"requestInfo")
177 assertTrue(reqinfo.indexOf("<request-id>mri</") >= 0)
178 assertTrue(reqinfo.indexOf("<source>VID</") >= 0)
183 public void preProcessRequest_MissingSubscriberId() {
184 ExecutionEntity mex = setupMock()
185 def map = setupMap(mex)
189 .replace('"globalSubscriberId"', '"globalSubscriberIdXXX"')
191 when(mex.getVariable("bpmnRequest")).thenReturn(req)
192 when(mex.getVariable("serviceInstanceId")).thenReturn(null)
194 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
196 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.preProcessRequest(mex) }))
201 public void preProcessRequest_BpmnError() {
202 ExecutionEntity mex = setupMock()
205 when(mex.getVariable("bpmnRequest")).thenThrow(new BpmnError("expected exception"))
207 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
209 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.preProcessRequest(mex) }))
214 public void preProcessRequest_Ex() {
215 ExecutionEntity mex = setupMock()
218 when(mex.getVariable("bpmnRequest")).thenThrow(new RuntimeException("expected exception"))
220 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
222 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.preProcessRequest(mex) }))
225 // ***** sendSyncResponse *****
229 public void sendSyncResponse() {
230 ExecutionEntity mex = setupMock()
231 def map = setupMap(mex)
232 initSendSyncResponse(mex)
234 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
235 CreateVcpeResCustService.sendSyncResponse(mex)
237 verify(mex, times(2)).getVariable(DBGFLAG)
239 verify(mex).setVariable(processName+"WorkflowResponseSent", "true")
241 assertEquals("202", map.get(processName+"ResponseCode"))
242 assertEquals("Success", map.get(processName+"Status"))
244 def resp = map.get(processName+"Response")
246 assertTrue(resp.indexOf('"instanceId":"sii"') >= 0)
247 assertTrue(resp.indexOf('"requestId":"mri"') >= 0)
252 public void sendSyncResponse_Ex() {
253 ExecutionEntity mex = setupMock()
254 initSendSyncResponse(mex)
256 when(mex.getVariable("serviceInstanceId")).thenThrow(new RuntimeException("expected exception"))
258 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
260 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.sendSyncResponse(mex) }))
264 // ***** prepareDecomposeService *****
268 public void prepareDecomposeService() {
269 ExecutionEntity mex = setupMock()
270 initPrepareDecomposeService(mex)
272 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
273 CreateVcpeResCustService.prepareDecomposeService(mex)
275 verify(mex).getVariable(DBGFLAG)
276 verify(mex).setVariable("serviceModelInfo", "mi")
281 public void prepareDecomposeService_Ex() {
282 ExecutionEntity mex = setupMock()
283 initPrepareDecomposeService(mex)
285 when(mex.getVariable("createVcpeServiceRequest")).thenThrow(new RuntimeException("expected exception"))
287 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
289 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.prepareDecomposeService(mex) }))
293 // ***** prepareCreateServiceInstance *****
297 public void prepareCreateServiceInstance() {
298 ExecutionEntity mex = setupMock()
299 initPrepareCreateServiceInstance(mex)
301 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
302 CreateVcpeResCustService.prepareCreateServiceInstance(mex)
304 verify(mex).getVariable(DBGFLAG)
305 verify(mex).setVariable("serviceInstanceName", "VCPE1")
306 verify(mex).setVariable("serviceDecompositionString", "mydecomp")
311 public void prepareCreateServiceInstance_Ex() {
312 ExecutionEntity mex = setupMock()
313 initPrepareCreateServiceInstance(mex)
315 when(mex.getVariable("createVcpeServiceRequest")).thenThrow(new RuntimeException("expected exception"))
317 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
319 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.prepareCreateServiceInstance(mex) }))
323 // ***** postProcessServiceInstanceCreate *****
327 public void postProcessServiceInstanceCreate() {
328 ExecutionEntity mex = setupMock()
329 def map = setupMap(mex)
330 initPostProcessServiceInstanceCreate(mex)
332 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
333 CreateVcpeResCustService.postProcessServiceInstanceCreate(mex)
335 verify(mex).getVariable(DBGFLAG)
337 def reqinfo = map.get(Prefix+"setUpdateDbInstancePayload")
339 assertTrue(reqinfo.indexOf("<requestId>mri</") >= 0)
340 assertTrue(reqinfo.indexOf("<serviceInstanceId>sii</") >= 0)
341 assertTrue(reqinfo.indexOf("<serviceInstanceName>sin</") >= 0)
346 public void postProcessServiceInstanceCreate_BpmnError() {
347 ExecutionEntity mex = setupMock()
348 initPostProcessServiceInstanceCreate(mex)
350 doThrow(new BpmnError("expected exception")).when(mex).setVariable(endsWith("setUpdateDbInstancePayload"), any())
352 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
354 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.postProcessServiceInstanceCreate(mex) }))
359 public void postProcessServiceInstanceCreate_Ex() {
360 ExecutionEntity mex = setupMock()
361 initPostProcessServiceInstanceCreate(mex)
363 doThrow(new RuntimeException("expected exception")).when(mex).setVariable(endsWith("setUpdateDbInstancePayload"), any())
365 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
367 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.postProcessServiceInstanceCreate(mex) }))
371 // ***** processDecomposition *****
375 public void processDecomposition() {
376 ExecutionEntity mex = setupMock()
377 def svcdecomp = initProcessDecomposition(mex)
379 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
380 CreateVcpeResCustService.processDecomposition(mex)
382 verify(mex).getVariable(DBGFLAG)
384 verify(mex).setVariable("vnfList", svcdecomp.getServiceVnfs())
385 verify(mex).setVariable("vnfListString", '[myvnf]')
386 verify(mex).setVariable(Prefix+"VNFsCount", 1)
388 verify(mex).setVariable("vnfModelInfo", "mymodel")
389 verify(mex).setVariable("vnfModelInfoString", "mymodel")
394 public void processDecomposition_EmptyNet_EmptyVnf() {
395 ExecutionEntity mex = setupMock()
396 def svcdecomp = initProcessDecomposition(mex)
398 when(svcdecomp.getServiceVnfs()).thenReturn(new LinkedList<VnfResource>())
400 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
401 CreateVcpeResCustService.processDecomposition(mex)
403 verify(mex).getVariable(DBGFLAG)
405 verify(mex).setVariable("vnfList", svcdecomp.getServiceVnfs())
406 verify(mex).setVariable("vnfListString", '[]')
407 verify(mex).setVariable(Prefix+"VNFsCount", 0)
409 verify(mex).setVariable("vnfModelInfo", "")
410 verify(mex).setVariable("vnfModelInfoString", "")
415 public void processDecomposition_Ex() {
416 ExecutionEntity mex = setupMock()
417 def svcdecomp = initProcessDecomposition(mex)
419 when(svcdecomp.getServiceVnfs()).thenThrow(new RuntimeException("expected exception"))
421 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
423 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.processDecomposition(mex) }))
427 // ***** filterVnfs *****
431 public void filterVnfs() {
432 ExecutionEntity mex = setupMock()
433 def svcdecomp = initFilterVnfs(mex)
435 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
436 CreateVcpeResCustService.processDecomposition(mex)
438 verify(mex).setVariable("vnfListString", '[myvnf3, myvnf5]')
443 public void filterVnfs_Null() {
444 ExecutionEntity mex = setupMock()
445 def svcdecomp = initFilterVnfs(mex)
447 when(svcdecomp.getServiceVnfs()).thenReturn(null)
449 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
450 CreateVcpeResCustService.processDecomposition(mex)
452 // nothing more to check, as long as it didn't throw an exception
456 // ***** prepareCreateAllottedResourceTXC *****
460 public void prepareCreateAllottedResourceTXC() {
461 ExecutionEntity mex = setupMock()
462 initPrepareCreateAllottedResourceTXC(mex)
464 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
465 CreateVcpeResCustService.prepareCreateAllottedResourceTXC(mex)
467 verify(mex).getVariable(DBGFLAG)
469 verify(mex).setVariable("createTXCAR", true)
470 verify(mex).setVariable("allottedResourceModelInfoTXC", "modelB")
471 verify(mex).setVariable("allottedResourceRoleTXC", "TXCr")
472 verify(mex).setVariable("allottedResourceTypeTXC", "Tunnel XConn")
473 verify(mex).setVariable("parentServiceInstanceIdTXC", "homeB")
478 public void prepareCreateAllottedResourceTXC_NullArList() {
479 ExecutionEntity mex = setupMock()
480 def svcdecomp = initPrepareCreateAllottedResourceTXC(mex)
482 when(svcdecomp.getServiceAllottedResources()).thenReturn(null)
484 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
485 CreateVcpeResCustService.prepareCreateAllottedResourceTXC(mex)
487 verify(mex).getVariable(DBGFLAG)
489 verify(mex, never()).setVariable("createTXCAR", true)
490 verify(mex, never()).setVariable("allottedResourceModelInfoTXC", "modelB")
491 verify(mex, never()).setVariable("allottedResourceRoleTXC", "TXCr")
492 verify(mex, never()).setVariable("allottedResourceTypeTXC", "Tunnel XConn")
493 verify(mex, never()).setVariable("parentServiceInstanceIdTXC", "homeB")
498 public void prepareCreateAllottedResourceTXC_Ex() {
499 ExecutionEntity mex = setupMock()
500 initPrepareCreateAllottedResourceTXC(mex)
502 when(mex.getVariable("createVcpeServiceRequest")).thenThrow(new RuntimeException("expected exception"))
504 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
506 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.prepareCreateAllottedResourceTXC(mex) }))
510 // ***** prepareCreateAllottedResourceBRG *****
514 public void prepareCreateAllottedResourceBRG() {
515 ExecutionEntity mex = setupMock()
516 initPrepareCreateAllottedResourceBRG(mex)
518 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
519 CreateVcpeResCustService.prepareCreateAllottedResourceBRG(mex)
521 verify(mex).getVariable(DBGFLAG)
523 verify(mex).setVariable("createBRGAR", true)
524 verify(mex).setVariable("allottedResourceModelInfoBRG", "modelB")
525 verify(mex).setVariable("allottedResourceRoleBRG", "BRGr")
526 verify(mex).setVariable("allottedResourceTypeBRG", "BRG")
527 verify(mex).setVariable("parentServiceInstanceIdBRG", "homeB")
532 public void prepareCreateAllottedResourceBRG_NullArList() {
533 ExecutionEntity mex = setupMock()
534 def svcdecomp = initPrepareCreateAllottedResourceBRG(mex)
536 when(svcdecomp.getServiceAllottedResources()).thenReturn(null)
538 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
539 CreateVcpeResCustService.prepareCreateAllottedResourceBRG(mex)
541 verify(mex).getVariable(DBGFLAG)
543 verify(mex, never()).setVariable("createBRGAR", true)
544 verify(mex, never()).setVariable("allottedResourceModelInfoBRG", "modelB")
545 verify(mex, never()).setVariable("allottedResourceRoleBRG", "BRGr")
546 verify(mex, never()).setVariable("allottedResourceTypeBRG", "BRG")
547 verify(mex, never()).setVariable("parentServiceInstanceIdBRG", "homeB")
552 public void prepareCreateAllottedResourceBRG_Ex() {
553 ExecutionEntity mex = setupMock()
554 initPrepareCreateAllottedResourceBRG(mex)
556 when(mex.getVariable("createVcpeServiceRequest")).thenThrow(new RuntimeException("expected exception"))
558 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
560 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.prepareCreateAllottedResourceBRG(mex) }))
564 // ***** prepareVnfAndModulesCreate *****
568 public void prepareVnfAndModulesCreate() {
569 ExecutionEntity mex = setupMock()
570 initPrepareVnfAndModulesCreate(mex)
572 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
573 CreateVcpeResCustService.prepareVnfAndModulesCreate(mex)
575 verify(mex).getVariable(DBGFLAG)
577 verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb")
578 verify(mex).setVariable("lcpCloudRegionId", "mdt1")
579 verify(mex).setVariable("tenantId", "8b1df54faa3b49078e3416e21370a3ba")
584 public void prepareVnfAndModulesCreate_EmptyList() {
585 ExecutionEntity mex = setupMock()
586 initPrepareVnfAndModulesCreate(mex)
588 when(mex.getVariable("vnfList")).thenReturn(new LinkedList<VnfResource>())
590 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
591 CreateVcpeResCustService.prepareVnfAndModulesCreate(mex)
593 verify(mex).getVariable(DBGFLAG)
595 verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb")
596 verify(mex).setVariable("lcpCloudRegionId", "mdt1")
597 verify(mex).setVariable("tenantId", "8b1df54faa3b49078e3416e21370a3ba")
602 public void prepareVnfAndModulesCreate_NullList() {
603 ExecutionEntity mex = setupMock()
604 initPrepareVnfAndModulesCreate(mex)
606 when(mex.getVariable("vnfList")).thenReturn(null)
608 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
609 CreateVcpeResCustService.prepareVnfAndModulesCreate(mex)
611 verify(mex).getVariable(DBGFLAG)
613 verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb")
614 verify(mex).setVariable("lcpCloudRegionId", "mdt1")
615 verify(mex).setVariable("tenantId", "8b1df54faa3b49078e3416e21370a3ba")
620 public void prepareVnfAndModulesCreate_Ex() {
621 ExecutionEntity mex = setupMock()
622 initPrepareVnfAndModulesCreate(mex)
624 when(mex.getVariable("vnfList")).thenThrow(new RuntimeException("expected exception"))
626 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
628 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.prepareVnfAndModulesCreate(mex) }))
632 // ***** validateVnfCreate *****
636 public void validateVnfCreate() {
637 ExecutionEntity mex = setupMock()
638 initValidateVnfCreate(mex)
640 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
641 CreateVcpeResCustService.validateVnfCreate(mex)
643 verify(mex).getVariable(DBGFLAG)
645 verify(mex).setVariable(Prefix+"VnfsCreatedCount", 3)
650 public void validateVnfCreate_Ex() {
651 ExecutionEntity mex = setupMock()
652 initValidateVnfCreate(mex)
654 when(mex.getVariable(Prefix+"VnfsCreatedCount")).thenThrow(new RuntimeException("expected exception"))
656 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
658 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.validateVnfCreate(mex) }))
662 // ***** postProcessResponse *****
666 public void postProcessResponse() {
667 ExecutionEntity mex = setupMock()
668 def map = setupMap(mex)
669 initPostProcessResponse(mex)
671 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
672 CreateVcpeResCustService.postProcessResponse(mex)
674 verify(mex).getVariable(DBGFLAG)
676 verify(mex).setVariable(Prefix+"Success", true)
678 def reqinfo = map.get(Prefix+"CompleteMsoProcessRequest")
680 assertTrue(reqinfo.indexOf("request-id>mri</") >= 0)
681 assertTrue(reqinfo.indexOf("source>mysrc</") >= 0)
682 assertTrue(reqinfo.indexOf("serviceInstanceId>sii</") >= 0)
687 public void postProcessResponse_BpmnError() {
688 ExecutionEntity mex = setupMock()
689 def map = setupMap(mex)
690 initPostProcessResponse(mex)
692 when(mex.getVariable("source")).thenThrow(new BpmnError("expected exception"))
694 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
696 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.postProcessResponse(mex) }))
701 public void postProcessResponse_Ex() {
702 ExecutionEntity mex = setupMock()
703 def map = setupMap(mex)
704 initPostProcessResponse(mex)
706 when(mex.getVariable("source")).thenThrow(new RuntimeException("expected exception"))
708 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
710 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.postProcessResponse(mex) }))
714 // ***** preProcessRollback *****
718 public void preProcessRollback() {
719 ExecutionEntity mex = setupMock()
720 def wfe = initPreProcessRollback(mex)
722 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
723 CreateVcpeResCustService.preProcessRollback(mex)
725 verify(mex).getVariable(DBGFLAG)
727 verify(mex).setVariable("prevWorkflowException", wfe)
732 public void preProcessRollback_NullWfe() {
733 ExecutionEntity mex = setupMock()
734 def map = setupMap(mex)
735 def wfe = initPreProcessRollback(mex)
737 when(mex.getVariable("WorkflowException")).thenReturn(null)
739 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
740 CreateVcpeResCustService.preProcessRollback(mex)
742 verify(mex).getVariable(DBGFLAG)
744 assertFalse(map.containsKey("prevWorkflowException"))
749 public void preProcessRollback_BpmnError() {
750 ExecutionEntity mex = setupMock()
751 def map = setupMap(mex)
752 def wfe = initPreProcessRollback(mex)
754 when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception"))
756 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
757 CreateVcpeResCustService.preProcessRollback(mex)
759 verify(mex).getVariable(DBGFLAG)
761 assertFalse(map.containsKey("prevWorkflowException"))
766 public void preProcessRollback_Ex() {
767 ExecutionEntity mex = setupMock()
768 def map = setupMap(mex)
769 def wfe = initPreProcessRollback(mex)
771 when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
773 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
774 CreateVcpeResCustService.preProcessRollback(mex)
776 verify(mex).getVariable(DBGFLAG)
778 assertFalse(map.containsKey("prevWorkflowException"))
782 // ***** postProcessRollback *****
786 public void postProcessRollback() {
787 ExecutionEntity mex = setupMock()
788 def wfe = initPostProcessRollback(mex)
790 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
791 CreateVcpeResCustService.postProcessRollback(mex)
793 verify(mex).getVariable(DBGFLAG)
795 verify(mex).setVariable("WorkflowException", wfe)
800 public void postProcessRollback_NullWfe() {
801 ExecutionEntity mex = setupMock()
802 def map = setupMap(mex)
803 def wfe = initPostProcessRollback(mex)
805 when(mex.getVariable("prevWorkflowException")).thenReturn(null)
807 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
808 CreateVcpeResCustService.postProcessRollback(mex)
810 verify(mex).getVariable(DBGFLAG)
812 assertFalse(map.containsKey("WorkflowException"))
817 public void postProcessRollback_BpmnError() {
818 ExecutionEntity mex = setupMock()
819 def map = setupMap(mex)
820 def wfe = initPostProcessRollback(mex)
822 when(mex.getVariable("prevWorkflowException")).thenThrow(new BpmnError("expected exception"))
824 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
825 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.postProcessRollback(mex) }))
830 public void postProcessRollback_Ex() {
831 ExecutionEntity mex = setupMock()
832 def map = setupMap(mex)
833 def wfe = initPostProcessRollback(mex)
835 when(mex.getVariable("prevWorkflowException")).thenThrow(new RuntimeException("expected exception"))
837 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
838 CreateVcpeResCustService.postProcessRollback(mex)
840 verify(mex).getVariable(DBGFLAG)
842 assertFalse(map.containsKey("WorkflowException"))
846 // ***** prepareFalloutRequest *****
850 public void prepareFalloutRequest() {
851 ExecutionEntity mex = setupMock()
852 def map = setupMap(mex)
853 initPrepareFalloutRequest(mex)
855 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
856 CreateVcpeResCustService.prepareFalloutRequest(mex)
858 verify(mex, times(2)).getVariable(DBGFLAG)
860 def fo = map.get(Prefix+"falloutRequest")
862 assertTrue(fo.indexOf("<hello>world</") >= 0)
863 assertTrue(fo.indexOf("ErrorMessage>mymsg</") >= 0)
864 assertTrue(fo.indexOf("ErrorCode>999</") >= 0)
869 public void prepareFalloutRequest_Ex() {
870 ExecutionEntity mex = setupMock()
871 def map = setupMap(mex)
872 initPrepareFalloutRequest(mex)
874 when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
876 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
878 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.prepareFalloutRequest(mex) }))
881 // ***** sendSyncError *****
885 public void sendSyncError() {
886 ExecutionEntity mex = setupMock()
887 def map = setupMap(mex)
888 initSendSyncError(mex)
890 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
891 CreateVcpeResCustService.sendSyncError(mex)
893 verify(mex, times(2)).getVariable(DBGFLAG)
895 verify(mex).setVariable(processName+"WorkflowResponseSent", "true")
897 assertEquals("500", map.get(processName+"ResponseCode"))
898 assertEquals("Fail", map.get(processName+"Status"))
900 def resp = map.get(processName+"Response")
902 assertTrue(resp.indexOf("ErrorMessage>mymsg</") >= 0)
904 verify(mex).setVariable("WorkflowResponse", resp)
909 public void sendSyncError_NotWfe() {
910 ExecutionEntity mex = setupMock()
911 def map = setupMap(mex)
912 initSendSyncError(mex)
914 when(mex.getVariable("WorkflowException")).thenReturn("not a WFE")
916 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
917 CreateVcpeResCustService.sendSyncError(mex)
919 verify(mex, times(2)).getVariable(DBGFLAG)
921 verify(mex).setVariable(processName+"WorkflowResponseSent", "true")
923 assertEquals("500", map.get(processName+"ResponseCode"))
924 assertEquals("Fail", map.get(processName+"Status"))
926 def resp = map.get(processName+"Response")
928 assertTrue(resp.indexOf("ErrorMessage>Sending Sync Error.</") >= 0)
930 verify(mex).setVariable("WorkflowResponse", resp)
935 public void sendSyncError_NullWfe() {
936 ExecutionEntity mex = setupMock()
937 def map = setupMap(mex)
938 initSendSyncError(mex)
940 when(mex.getVariable("WorkflowException")).thenReturn(null)
942 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
943 CreateVcpeResCustService.sendSyncError(mex)
945 verify(mex, times(2)).getVariable(DBGFLAG)
947 verify(mex).setVariable(processName+"WorkflowResponseSent", "true")
949 assertEquals("500", map.get(processName+"ResponseCode"))
950 assertEquals("Fail", map.get(processName+"Status"))
952 def resp = map.get(processName+"Response")
954 assertTrue(resp.indexOf("ErrorMessage>Sending Sync Error.</") >= 0)
956 verify(mex).setVariable("WorkflowResponse", resp)
961 public void sendSyncError_Ex() {
962 ExecutionEntity mex = setupMock()
963 def map = setupMap(mex)
964 initSendSyncError(mex)
966 when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
968 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
970 CreateVcpeResCustService.sendSyncError(mex)
972 assertFalse(map.containsKey(processName+"ResponseCode"))
976 // ***** processJavaException *****
980 public void processJavaException() {
981 ExecutionEntity mex = setupMock()
982 def map = setupMap(mex)
983 initProcessJavaException(mex)
985 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
987 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.processJavaException(mex) }))
989 verify(mex, times(2)).getVariable(DBGFLAG)
991 verify(mex).setVariable("prefix", Prefix)
993 def wfe = map.get("WorkflowException")
995 assertEquals("Caught a Java Lang Exception", wfe.getErrorMessage())
1000 public void processJavaException_BpmnError() {
1001 ExecutionEntity mex = setupMock()
1002 def map = setupMap(mex)
1003 initProcessJavaException(mex)
1005 when(mex.getVariables()).thenThrow(new BpmnError("expected exception"))
1007 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
1009 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.processJavaException(mex) }))
1011 assertFalse(map.containsKey("WorkflowException"))
1016 public void processJavaException_Ex() {
1017 ExecutionEntity mex = setupMock()
1018 def map = setupMap(mex)
1019 initProcessJavaException(mex)
1021 when(mex.getVariables()).thenThrow(new RuntimeException("expected exception"))
1023 CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
1025 assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.processJavaException(mex) }))
1027 def wfe = map.get("WorkflowException")
1029 assertEquals("Exception in processJavaException method", wfe.getErrorMessage())
1033 private void initPreProcess(ExecutionEntity mex) {
1034 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1035 when(mex.getVariable("bpmnRequest")).thenReturn(request)
1036 when(mex.getVariable("URN_mso_workflow_aai_distribution_delay")).thenReturn("aaidelay")
1037 when(mex.getVariable("mso-request-id")).thenReturn("mri")
1038 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
1039 when(mex.getVariable("requestAction")).thenReturn("ra")
1042 private initSendSyncResponse(ExecutionEntity mex) {
1043 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1044 when(mex.getVariable("mso-request-id")).thenReturn("mri")
1045 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
1048 private void initPrepareDecomposeService(ExecutionEntity mex) {
1049 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1050 when(mex.getVariable("createVcpeServiceRequest")).thenReturn('{"requestDetails":{"modelInfo":"mi"}}')
1053 private void initPrepareCreateServiceInstance(ExecutionEntity mex) {
1054 ServiceDecomposition svcdecomp = mock(ServiceDecomposition.class)
1056 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1057 when(mex.getVariable("createVcpeServiceRequest")).thenReturn(request)
1058 when(mex.getVariable("serviceDecomposition")).thenReturn(svcdecomp)
1060 when(svcdecomp.toJsonStringNoRootName()).thenReturn("mydecomp")
1063 private void initPostProcessServiceInstanceCreate(ExecutionEntity mex) {
1064 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1065 when(mex.getVariable("mso-request-id")).thenReturn("mri")
1066 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
1067 when(mex.getVariable("serviceInstanceName")).thenReturn("sin")
1070 private ServiceDecomposition initProcessDecomposition(ExecutionEntity mex) {
1071 List<VnfResource> vnflst = new LinkedList<>()
1072 vnflst.add(makeVnf("", ""))
1073 vnflst.add(makeVnf("2", "BRG"))
1074 vnflst.add(makeVnf("3", "BRG"))
1076 ServiceDecomposition svcdecomp = mock(ServiceDecomposition.class)
1077 when(svcdecomp.getServiceVnfs()).thenReturn(vnflst)
1079 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1080 when(mex.getVariable("serviceDecomposition")).thenReturn(svcdecomp)
1081 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
1082 when(mex.getVariable("serviceInstanceName")).thenReturn("sin")
1087 private ServiceDecomposition initFilterVnfs(ExecutionEntity mex) {
1088 List<VnfResource> vnflst = new LinkedList<>()
1089 vnflst.add(makeVnf("", "BRG"))
1090 vnflst.add(makeVnf("2", "Tunnel XConn"))
1091 vnflst.add(makeVnf("3", ""))
1092 vnflst.add(makeVnf("4", "BRG"))
1093 vnflst.add(makeVnf("5", "other"))
1095 ServiceDecomposition svcdecomp = mock(ServiceDecomposition.class)
1096 when(svcdecomp.getServiceVnfs()).thenReturn(vnflst)
1098 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1099 when(mex.getVariable("serviceDecomposition")).thenReturn(svcdecomp)
1100 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
1101 when(mex.getVariable("serviceInstanceName")).thenReturn("sin")
1106 private initAwaitAaiDistribution(ExecutionEntity mex) {
1107 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1110 private ServiceDecomposition initPrepareCreateAllottedResourceTXC(ExecutionEntity mex) {
1111 ServiceDecomposition svcdecomp = mock(ServiceDecomposition.class)
1112 List<AllottedResource> arlst = new LinkedList<>()
1114 arlst.add(makeArBRG("A"))
1115 arlst.add(makeArTXC("B"))
1116 arlst.add(makeArBRG("C"))
1118 when(svcdecomp.getServiceAllottedResources()).thenReturn(arlst)
1120 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1121 when(mex.getVariable("createVcpeServiceRequest")).thenReturn(request)
1122 when(mex.getVariable("serviceDecomposition")).thenReturn(svcdecomp)
1123 when(mex.getVariable("allottedResourceId")).thenReturn(ARID)
1128 private ServiceDecomposition initPrepareCreateAllottedResourceBRG(ExecutionEntity mex) {
1129 ServiceDecomposition svcdecomp = mock(ServiceDecomposition.class)
1130 List<AllottedResource> arlst = new LinkedList<>()
1132 arlst.add(makeArTXC("A"))
1133 arlst.add(makeArBRG("B"))
1134 arlst.add(makeArTXC("C"))
1136 when(svcdecomp.getServiceAllottedResources()).thenReturn(arlst)
1138 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1139 when(mex.getVariable("createVcpeServiceRequest")).thenReturn(request)
1140 when(mex.getVariable("serviceDecomposition")).thenReturn(svcdecomp)
1141 when(mex.getVariable("allottedResourceId")).thenReturn(ARID)
1146 private AllottedResource makeArTXC(String id) {
1147 AllottedResource ar = mock(AllottedResource.class)
1148 ModelInfo mod = mock(ModelInfo.class)
1149 HomingSolution home = mock(HomingSolution.class)
1151 when(ar.toJsonStringNoRootName()).thenReturn("json"+id)
1152 when(ar.getAllottedResourceType()).thenReturn("Tunnel XConn")
1153 when(ar.getModelInfo()).thenReturn(mod)
1154 when(ar.getAllottedResourceRole()).thenReturn("TXCr")
1155 when(ar.getHomingSolution()).thenReturn(home)
1157 when(mod.toJsonStringNoRootName()).thenReturn("model"+id)
1159 when(home.getServiceInstanceId()).thenReturn("home"+id)
1164 private AllottedResource makeArBRG(String id) {
1165 AllottedResource ar = mock(AllottedResource.class)
1166 ModelInfo mod = mock(ModelInfo.class)
1167 HomingSolution home = mock(HomingSolution.class)
1169 when(ar.toJsonStringNoRootName()).thenReturn("json"+id)
1170 when(ar.getAllottedResourceType()).thenReturn("BRG")
1171 when(ar.getModelInfo()).thenReturn(mod)
1172 when(ar.getAllottedResourceRole()).thenReturn("BRGr")
1173 when(ar.getHomingSolution()).thenReturn(home)
1175 when(mod.toJsonStringNoRootName()).thenReturn("model"+id)
1177 when(home.getServiceInstanceId()).thenReturn("home"+id)
1182 private initPrepareVnfAndModulesCreate(ExecutionEntity mex) {
1184 List<VnfResource> vnflst = new LinkedList<>()
1186 vnflst.add(makeVnf("A", "BRG"))
1187 vnflst.add(makeVnf("B", ""))
1188 vnflst.add(makeVnf("C", ""))
1189 vnflst.add(makeVnf("D", "Tunnel XConn"))
1191 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1192 when(mex.getVariable("createVcpeServiceRequest")).thenReturn(request)
1193 when(mex.getVariable("vnfList")).thenReturn(vnflst)
1194 when(mex.getVariable(Prefix+"VnfsCreatedCount")).thenReturn(2)
1195 when(mex.getVariable("vnfModelInfo")).thenReturn("nomodel")
1196 when(mex.getVariable("sdncVersion")).thenReturn("myvers")
1199 private VnfResource makeVnf(String id, String role) {
1200 ModelInfo mod = mock(ModelInfo.class)
1201 VnfResource vnf = mock(VnfResource.class)
1203 when(mod.toString()).thenReturn('{"modelInfo":"mymodel'+id+'"}')
1205 when(vnf.toString()).thenReturn("myvnf"+id)
1206 when(vnf.getModelInfo()).thenReturn(mod)
1207 when(vnf.getNfRole()).thenReturn(role)
1212 private initValidateVnfCreate(ExecutionEntity mex) {
1213 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1214 when(mex.getVariable(Prefix+"VnfsCreatedCount")).thenReturn(2)
1217 private initPostProcessResponse(ExecutionEntity mex) {
1218 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1219 when(mex.getVariable("source")).thenReturn("mysrc")
1220 when(mex.getVariable("mso-request-id")).thenReturn("mri")
1221 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
1224 private WorkflowException initPreProcessRollback(ExecutionEntity mex) {
1225 WorkflowException wfe = mock(WorkflowException.class)
1227 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1228 when(mex.getVariable("WorkflowException")).thenReturn(wfe)
1233 private WorkflowException initPostProcessRollback(ExecutionEntity mex) {
1234 WorkflowException wfe = mock(WorkflowException.class)
1236 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1237 when(mex.getVariable("prevWorkflowException")).thenReturn(wfe)
1242 private initPrepareFalloutRequest(ExecutionEntity mex) {
1243 WorkflowException wfe = mock(WorkflowException.class)
1245 when(wfe.getErrorMessage()).thenReturn("mymsg")
1246 when(wfe.getErrorCode()).thenReturn(999)
1248 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1249 when(mex.getVariable("WorkflowException")).thenReturn(wfe)
1250 when(mex.getVariable(Prefix+"requestInfo")).thenReturn("<hello>world</hello>")
1255 private initSendSyncError(ExecutionEntity mex) {
1256 WorkflowException wfe = mock(WorkflowException.class)
1258 when(mex.getVariable(DBGFLAG)).thenReturn("true")
1259 when(mex.getVariable("mso-request-id")).thenReturn("mri")
1260 when(mex.getVariable("WorkflowException")).thenReturn(wfe)
1262 when(wfe.getErrorMessage()).thenReturn("mymsg")
1265 private initProcessJavaException(ExecutionEntity mex) {
1266 when(mex.getVariable(DBGFLAG)).thenReturn("true")