From 826a31411d410fbfeb88fc867cbc3fe6dd1ae46f Mon Sep 17 00:00:00 2001 From: "k.kazak" Date: Wed, 13 Mar 2019 16:29:13 +0100 Subject: Run groovy bpmn/vcpe tests Fixed groovy tests in bpmn/vcpe/scripts to be runnable Added them to build Reformatted the code and removed unnecessary imports Change-Id: Id85c88bee666fc7f513042e0a4e83f337ab2765c Issue-ID: SO-1649 Signed-off-by: k.kazak --- .../vcpe/scripts/DeleteVcpeResCustService.groovy | 1 + .../scripts/CreateVcpeResCustServiceTest.groovy | 2555 ++++++++++---------- .../scripts/DeleteVcpeResCustServiceTest.groovy | 1267 ++++------ .../DoCreateAllottedResourceBRGRollbackTest.groovy | 1184 +++++---- .../scripts/DoCreateAllottedResourceBRGTest.groovy | 1818 +++++++------- .../DoCreateAllottedResourceTXCRollbackTest.groovy | 1180 +++++---- .../scripts/DoCreateAllottedResourceTXCTest.groovy | 1667 ++++++------- .../scripts/DoDeleteAllottedResourceBRGTest.groovy | 1028 ++++---- .../scripts/DoDeleteAllottedResourceTXCTest.groovy | 1020 ++++---- .../so/bpmn/vcpe/scripts/GroovyTestBase.groovy | 139 +- .../org/onap/so/bpmn/vcpe/scripts/MapGetter.groovy | 49 +- .../org/onap/so/bpmn/vcpe/scripts/MapSetter.groovy | 53 +- .../java/org/onap/so/bpmn/AllTestsTestSuite.java | 6 +- .../VCPE/DeleteVcpeResCustService/request.json | 1 + 14 files changed, 5680 insertions(+), 6288 deletions(-) (limited to 'bpmn/so-bpmn-infrastructure-common') diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/DeleteVcpeResCustService.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/DeleteVcpeResCustService.groovy index 75f5ec9161..d2b727b537 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/DeleteVcpeResCustService.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/DeleteVcpeResCustService.groovy @@ -25,6 +25,7 @@ import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.delegate.DelegateExecution import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor import org.onap.so.bpmn.common.scripts.ExceptionUtil +import org.onap.so.bpmn.common.scripts.MsoUtils import org.onap.so.bpmn.common.scripts.NetworkUtils import org.onap.so.bpmn.common.scripts.VidUtils import org.onap.so.bpmn.core.WorkflowException diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/CreateVcpeResCustServiceTest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/CreateVcpeResCustServiceTest.groovy index 160eee2337..93a7115add 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/CreateVcpeResCustServiceTest.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/CreateVcpeResCustServiceTest.groovy @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,1338 +21,1251 @@ */ package org.onap.so.bpmn.vcpe.scripts - -import org.camunda.bpm.engine.ProcessEngineServices -import org.camunda.bpm.engine.RepositoryService +import com.github.tomakehurst.wiremock.junit.WireMockRule +import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity -import org.camunda.bpm.engine.repository.ProcessDefinition import org.junit.Before import org.junit.BeforeClass import org.junit.Rule import org.junit.Test -import org.junit.Ignore import org.mockito.MockitoAnnotations -import org.camunda.bpm.engine.delegate.BpmnError import org.onap.so.bpmn.core.UrnPropertiesReader import org.onap.so.bpmn.core.WorkflowException -import org.onap.so.bpmn.core.domain.HomingSolution +import org.onap.so.bpmn.core.domain.* import org.onap.so.bpmn.mock.FileUtil -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse -import static com.github.tomakehurst.wiremock.client.WireMock.get -import static com.github.tomakehurst.wiremock.client.WireMock.patch -import static com.github.tomakehurst.wiremock.client.WireMock.put -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor -import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching -import static org.junit.Assert.*; +import static org.junit.Assert.* +import static org.mockito.ArgumentMatchers.any +import static org.mockito.ArgumentMatchers.endsWith import static org.mockito.Mockito.* -import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetAllottedResource -import org.onap.so.bpmn.core.domain.ServiceDecomposition -import org.onap.so.bpmn.core.domain.VnfResource -import org.onap.so.bpmn.core.domain.AllottedResource -import org.onap.so.bpmn.core.domain.ModelInfo -import org.onap.so.bpmn.core.domain.HomingSolution -import org.onap.so.bpmn.core.RollbackData -import org.onap.so.bpmn.vcpe.scripts.MapGetter -import org.onap.so.bpmn.vcpe.scripts.MapSetter - -import com.github.tomakehurst.wiremock.junit.WireMockRule class CreateVcpeResCustServiceTest extends GroovyTestBase { - - private static String request - - @Rule - public WireMockRule wireMockRule = new WireMockRule(PORT) - - String Prefix = "CVRCS_" - String RbType = "DCRENI_" - - @BeforeClass - public static void setUpBeforeClass() { - request = FileUtil.readResourceFile("__files/VCPE/CreateVcpeResCustService/request.json") - } - + + private static String request + + @Rule + public WireMockRule wireMockRule = new WireMockRule(PORT) + + String Prefix = "CVRCS_" + + @BeforeClass + public static void setUpBeforeClass() { + request = FileUtil.readResourceFile("__files/VCPE/CreateVcpeResCustService/request.json") + } + @Before - public void init() - { - MockitoAnnotations.initMocks(this) - } - - public CreateVcpeResCustServiceTest() { - super("CreateVcpeResCustService") - } - - - // ***** preProcessRequest ***** - - @Test - public void preProcessRequest() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - - initPreProcess(mex) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.preProcessRequest(mex) - - verify(mex).getVariable(DBGFLAG) - verify(mex).setVariable("prefix", Prefix) - verify(mex).setVariable("createVcpeServiceRequest", request) - verify(mex).setVariable("msoRequestId", "mri") - assertEquals("sii", map.get("serviceInstanceId")) - verify(mex).setVariable("requestAction", "ra") - verify(mex).setVariable("source", "VID") - verify(mex).setVariable("globalSubscriberId", CUST) - verify(mex).setVariable("globalCustomerId", CUST) - verify(mex).setVariable("subscriptionServiceType", SVC) - verify(mex).setVariable("disableRollback", "false") - verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb") - assertTrue(map.containsKey("subscriberInfo")) - - verify(mex).setVariable("brgWanMacAddress", "brgmac") - verify(mex).setVariable("customerLocation", ["customerLatitude":"32.897480", "customerLongitude":"-97.040443", "customerName":"some_company"]) - verify(mex).setVariable("homingService", "sniro") - assertTrue(map.containsKey("serviceInputParams")) - assertTrue(map.containsKey(Prefix+"requestInfo")) - - def reqinfo = map.get(Prefix+"requestInfo") - assertTrue(reqinfo.indexOf("mri= 0) - assertTrue(reqinfo.indexOf("VID= 0) - - assertTrue(map.containsKey("vfModuleNames")) - } - - @Test - // @Ignore - public void preProcessRequest_MissingAaiDistDelay() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initPreProcess(mex) - - when(mex.getVariable("aai.workflowAaiDistributionDelay")).thenReturn(null) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - - assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.preProcessRequest(mex) })) - } - - @Test - @Ignore // 1802 merge - public void preProcessRequest_EmptyParts() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initPreProcess(mex) - - def req = request - .replace('"source"', '"sourceXXX"') - .replace('"BRG_WAN_MAC_Address"', '"BRG_WAN_MAC_AddressXXX"') - .replace('"Customer_Location"', '"Customer_LocationXXX"') - - when(mex.getVariable("bpmnRequest")).thenReturn(req) - when(mex.getVariable("serviceInstanceId")).thenReturn(null) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.preProcessRequest(mex) - - verify(mex).getVariable(DBGFLAG) - verify(mex).setVariable("prefix", Prefix) - verify(mex).setVariable("createVcpeServiceRequest", req) - verify(mex).setVariable("msoRequestId", "mri") - assertNotNull(map.get("serviceInstanceId")) - assertFalse(map.get("serviceInstanceId").isEmpty()) - verify(mex).setVariable("requestAction", "ra") - verify(mex).setVariable("source", "VID") - verify(mex).setVariable("globalSubscriberId", CUST) - verify(mex).setVariable("globalCustomerId", CUST) - verify(mex).setVariable("subscriptionServiceType", SVC) - verify(mex).setVariable("disableRollback", "false") - verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb") - assertTrue(map.containsKey("subscriberInfo")) - - assertEquals("", map.get("brgWanMacAddress")) - assertEquals("", map.get("customerLocation")) - assertEquals("oof", map.get("homingService")) - assertTrue(map.containsKey("serviceInputParams")) - assertTrue(map.containsKey(Prefix+"requestInfo")) - - def reqinfo = map.get(Prefix+"requestInfo") - println reqinfo - assertTrue(reqinfo.indexOf("mri= 0) - assertTrue(reqinfo.indexOf("VID= 0) - } - - @Test - // @Ignore - public void preProcessRequest_MissingSubscriberId() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initPreProcess(mex) - - def req = request - .replace('"globalSubscriberId"', '"globalSubscriberIdXXX"') - - when(mex.getVariable("bpmnRequest")).thenReturn(req) - when(mex.getVariable("serviceInstanceId")).thenReturn(null) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - - assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.preProcessRequest(mex) })) - } - - @Test - @Ignore - public void preProcessRequest_vimId() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initPreProcess(mex) - UrnPropertiesReader - - def req = request - .replace('"mdt1"', '"CloudOwner_CloudRegion1"') - - when(mex.getVariable("bpmnRequest")).thenReturn(req) - when(mex.getVariable("aai.workflowAaiDistributionDelay")).thenReturn("PT5S") - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.preProcessRequest(mex) - - verify(mex).setVariable("cloudRegionId", "CloudRegion1") - verify(mex).setVariable("cloudOwner", "CloudOwner") - } - - @Test - @Ignore - public void preProcessRequest_noVimId() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initPreProcess(mex) - - def req = request - .replace('"mdt1"', '"CloudRegion1_"') - - when(mex.getVariable("bpmnRequest")).thenReturn(req) - when(mex.getVariable("aai.workflowAaiDistributionDelay")).thenReturn("PT5S") - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.preProcessRequest(mex) - - verify(mex).setVariable("cloudRegionId", "CloudRegion1_") - verify(mex).setVariable("cloudOwner", "my-cloud-owner") - - } - - - @Test - // @Ignore - public void preProcessRequest_BpmnError() { - ExecutionEntity mex = setupMock() - initPreProcess(mex) - - when(mex.getVariable("bpmnRequest")).thenThrow(new BpmnError("expected exception")) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - - assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.preProcessRequest(mex) })) - } - - @Test - // @Ignore - public void preProcessRequest_Ex() { - ExecutionEntity mex = setupMock() - initPreProcess(mex) - - when(mex.getVariable("bpmnRequest")).thenThrow(new RuntimeException("expected exception")) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - - assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.preProcessRequest(mex) })) - } - - // ***** sendSyncResponse ***** - - @Test - // @Ignore - public void sendSyncResponse() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initSendSyncResponse(mex) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.sendSyncResponse(mex) - - verify(mex, times(2)).getVariable(DBGFLAG) - - verify(mex).setVariable(processName+"WorkflowResponseSent", "true") - - assertEquals("202", map.get(processName+"ResponseCode")) - assertEquals("Success", map.get(processName+"Status")) - - def resp = map.get(processName+"Response") - - assertTrue(resp.indexOf('"instanceId":"sii"') >= 0) - assertTrue(resp.indexOf('"requestId":"mri"') >= 0) - } - - @Test - // @Ignore - public void sendSyncResponse_Ex() { - ExecutionEntity mex = setupMock() - initSendSyncResponse(mex) - - when(mex.getVariable("serviceInstanceId")).thenThrow(new RuntimeException("expected exception")) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - - assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.sendSyncResponse(mex) })) - } - - - // ***** prepareDecomposeService ***** - - @Test - // @Ignore - public void prepareDecomposeService() { - ExecutionEntity mex = setupMock() - initPrepareDecomposeService(mex) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.prepareDecomposeService(mex) - - verify(mex).getVariable(DBGFLAG) - verify(mex).setVariable("serviceModelInfo", "mi") - } - - @Test - // @Ignore - public void prepareDecomposeService_Ex() { - ExecutionEntity mex = setupMock() - initPrepareDecomposeService(mex) - - when(mex.getVariable("createVcpeServiceRequest")).thenThrow(new RuntimeException("expected exception")) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - - assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.prepareDecomposeService(mex) })) - } - - - // ***** prepareCreateServiceInstance ***** - - @Test - // @Ignore - public void prepareCreateServiceInstance() { - ExecutionEntity mex = setupMock() - initPrepareCreateServiceInstance(mex) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.prepareCreateServiceInstance(mex) - - verify(mex).getVariable(DBGFLAG) - verify(mex).setVariable("serviceInstanceName", "VCPE1") - verify(mex).setVariable("serviceDecompositionString", "mydecomp") - } - - @Test - // @Ignore - public void prepareCreateServiceInstance_Ex() { - ExecutionEntity mex = setupMock() - initPrepareCreateServiceInstance(mex) - - when(mex.getVariable("createVcpeServiceRequest")).thenThrow(new RuntimeException("expected exception")) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - - assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.prepareCreateServiceInstance(mex) })) - } - - - // ***** postProcessServiceInstanceCreate ***** - - @Test - // @Ignore - public void postProcessServiceInstanceCreate() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initPostProcessServiceInstanceCreate(mex) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.postProcessServiceInstanceCreate(mex) - - verify(mex).getVariable(DBGFLAG) - - def reqinfo = map.get(Prefix+"setUpdateDbInstancePayload") - - assertTrue(reqinfo.indexOf("mri= 0) - assertTrue(reqinfo.indexOf("sii= 0) - assertTrue(reqinfo.indexOf("sin= 0) - } - - @Test - // @Ignore - public void postProcessServiceInstanceCreate_BpmnError() { - ExecutionEntity mex = setupMock() - initPostProcessServiceInstanceCreate(mex) - - doThrow(new BpmnError("expected exception")).when(mex).setVariable(endsWith("setUpdateDbInstancePayload"), any()) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - - assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.postProcessServiceInstanceCreate(mex) })) - } - - @Test - // @Ignore - public void postProcessServiceInstanceCreate_Ex() { - ExecutionEntity mex = setupMock() - initPostProcessServiceInstanceCreate(mex) - - doThrow(new RuntimeException("expected exception")).when(mex).setVariable(endsWith("setUpdateDbInstancePayload"), any()) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - - assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.postProcessServiceInstanceCreate(mex) })) - } - - - // ***** processDecomposition ***** - - @Test - // @Ignore - public void processDecomposition() { - ExecutionEntity mex = setupMock() - def svcdecomp = initProcessDecomposition(mex) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.processDecomposition(mex) - - verify(mex).getVariable(DBGFLAG) - - verify(mex).setVariable("vnfList", svcdecomp.getVnfResources()) - verify(mex).setVariable("vnfListString", '[myvnf]') - verify(mex).setVariable(Prefix+"VNFsCount", 1) - - verify(mex).setVariable("vnfModelInfo", "mymodel") - verify(mex).setVariable("vnfModelInfoString", "mymodel") - } - - @Test - // @Ignore - public void processDecomposition_EmptyNet_EmptyVnf() { - ExecutionEntity mex = setupMock() - def svcdecomp = initProcessDecomposition(mex) - - when(svcdecomp.getVnfResources()).thenReturn(new LinkedList()) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.processDecomposition(mex) - - verify(mex).getVariable(DBGFLAG) - - verify(mex).setVariable("vnfList", svcdecomp.getVnfResources()) - verify(mex).setVariable("vnfListString", '[]') - verify(mex).setVariable(Prefix+"VNFsCount", 0) - - verify(mex).setVariable("vnfModelInfo", "") - verify(mex).setVariable("vnfModelInfoString", "") - } - - @Test - // @Ignore - public void processDecomposition_Ex() { - ExecutionEntity mex = setupMock() - def svcdecomp = initProcessDecomposition(mex) - - when(svcdecomp.getVnfResources()).thenThrow(new RuntimeException("expected exception")) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - - assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.processDecomposition(mex) })) - } - - - // ***** filterVnfs ***** - - @Test - // @Ignore - public void filterVnfs() { - ExecutionEntity mex = setupMock() - def svcdecomp = initFilterVnfs(mex) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.processDecomposition(mex) - - verify(mex).setVariable("vnfListString", '[myvnf3, myvnf5]') - } - - @Test - // @Ignore - public void filterVnfs_Null() { - ExecutionEntity mex = setupMock() - def svcdecomp = initFilterVnfs(mex) - - when(svcdecomp.getVnfResources()).thenReturn(null) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.processDecomposition(mex) - - // nothing more to check, as long as it didn't throw an exception - } - - - // ***** prepareCreateAllottedResourceTXC ***** - - @Test - // @Ignore - public void prepareCreateAllottedResourceTXC() { - ExecutionEntity mex = setupMock() - initPrepareCreateAllottedResourceTXC(mex) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.prepareCreateAllottedResourceTXC(mex) - - verify(mex).getVariable(DBGFLAG) - - verify(mex).setVariable("createTXCAR", true) - verify(mex).setVariable("allottedResourceModelInfoTXC", "modelB") - verify(mex).setVariable("allottedResourceRoleTXC", "TXCr") - verify(mex).setVariable("allottedResourceTypeTXC", "Tunnel XConn") - verify(mex).setVariable("parentServiceInstanceIdTXC", "homeB") - } - - @Test - // @Ignore - public void prepareCreateAllottedResourceTXC_NullArList() { - ExecutionEntity mex = setupMock() - def svcdecomp = initPrepareCreateAllottedResourceTXC(mex) - - when(svcdecomp.getAllottedResources()).thenReturn(null) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.prepareCreateAllottedResourceTXC(mex) - - verify(mex).getVariable(DBGFLAG) - - verify(mex, never()).setVariable("createTXCAR", true) - verify(mex, never()).setVariable("allottedResourceModelInfoTXC", "modelB") - verify(mex, never()).setVariable("allottedResourceRoleTXC", "TXCr") - verify(mex, never()).setVariable("allottedResourceTypeTXC", "Tunnel XConn") - verify(mex, never()).setVariable("parentServiceInstanceIdTXC", "homeB") - } - - @Test - // @Ignore - public void prepareCreateAllottedResourceTXC_Ex() { - ExecutionEntity mex = setupMock() - initPrepareCreateAllottedResourceTXC(mex) - - when(mex.getVariable("createVcpeServiceRequest")).thenThrow(new RuntimeException("expected exception")) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - - assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.prepareCreateAllottedResourceTXC(mex) })) - } - - - // ***** prepareCreateAllottedResourceBRG ***** - - @Test - // @Ignore - public void prepareCreateAllottedResourceBRG() { - ExecutionEntity mex = setupMock() - initPrepareCreateAllottedResourceBRG(mex) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.prepareCreateAllottedResourceBRG(mex) - - verify(mex).getVariable(DBGFLAG) - - verify(mex).setVariable("createBRGAR", true) - verify(mex).setVariable("allottedResourceModelInfoBRG", "modelB") - verify(mex).setVariable("allottedResourceRoleBRG", "BRGr") - verify(mex).setVariable("allottedResourceTypeBRG", "BRG") - verify(mex).setVariable("parentServiceInstanceIdBRG", "homeB") - } - - @Test - // @Ignore - public void prepareCreateAllottedResourceBRG_NullArList() { - ExecutionEntity mex = setupMock() - def svcdecomp = initPrepareCreateAllottedResourceBRG(mex) - - when(svcdecomp.getAllottedResources()).thenReturn(null) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.prepareCreateAllottedResourceBRG(mex) - - verify(mex).getVariable(DBGFLAG) - - verify(mex, never()).setVariable("createBRGAR", true) - verify(mex, never()).setVariable("allottedResourceModelInfoBRG", "modelB") - verify(mex, never()).setVariable("allottedResourceRoleBRG", "BRGr") - verify(mex, never()).setVariable("allottedResourceTypeBRG", "BRG") - verify(mex, never()).setVariable("parentServiceInstanceIdBRG", "homeB") - } - - @Test - // @Ignore - public void prepareCreateAllottedResourceBRG_Ex() { - ExecutionEntity mex = setupMock() - initPrepareCreateAllottedResourceBRG(mex) - - when(mex.getVariable("createVcpeServiceRequest")).thenThrow(new RuntimeException("expected exception")) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - - assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.prepareCreateAllottedResourceBRG(mex) })) - } - - - // ***** prepareVnfAndModulesCreate ***** - - @Test - // @Ignore - public void prepareVnfAndModulesCreate() { - ExecutionEntity mex = setupMock() - initPrepareVnfAndModulesCreate(mex) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.prepareVnfAndModulesCreate(mex) - - verify(mex).getVariable(DBGFLAG) - - verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb") - verify(mex).setVariable("lcpCloudRegionId", "mdt1") - verify(mex).setVariable("cloudOwner", "my-cloud-owner") - verify(mex).setVariable("tenantId", "8b1df54faa3b49078e3416e21370a3ba") - } - - @Test - public void prepareVnfAndModulesCreate_noVimId() { - ExecutionEntity mex = setupMock() - initPrepareVnfAndModulesCreate(mex) - - def req = request - .replace('"mdt1"', '"CloudRegion1_"') - - when(mex.getVariable("createVcpeServiceRequest")).thenReturn(req) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.prepareVnfAndModulesCreate(mex) - - verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb") - verify(mex).setVariable("cloudRegionId", "CloudRegion1_") - verify(mex).setVariable("lcpCloudRegionId", "CloudRegion1_") - verify(mex).setVariable("tenantId", "8b1df54faa3b49078e3416e21370a3ba") - } - - @Test - public void prepareVnfAndModulesCreate_vimId() { - ExecutionEntity mex = setupMock() - initPrepareVnfAndModulesCreate(mex) - - def req = request - .replace('"mdt1"', '"CloudOwner_CloudRegion1"') - - when(mex.getVariable("createVcpeServiceRequest")).thenReturn(req) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.prepareVnfAndModulesCreate(mex) - - verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb") - verify(mex).setVariable("cloudOwner", "CloudOwner") - verify(mex).setVariable("cloudRegionId", "CloudRegion1") - verify(mex).setVariable("lcpCloudRegionId", "CloudRegion1") - verify(mex).setVariable("tenantId", "8b1df54faa3b49078e3416e21370a3ba") - } - - @Test - // @Ignore - public void prepareVnfAndModulesCreate_EmptyList() { - ExecutionEntity mex = setupMock() - initPrepareVnfAndModulesCreate(mex) - - when(mex.getVariable("vnfList")).thenReturn(new LinkedList()) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.prepareVnfAndModulesCreate(mex) - - verify(mex).getVariable(DBGFLAG) - - verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb") - verify(mex).setVariable("lcpCloudRegionId", "mdt1") - verify(mex).setVariable("cloudOwner", "my-cloud-owner") - verify(mex).setVariable("tenantId", "8b1df54faa3b49078e3416e21370a3ba") - } - - @Test - // @Ignore - public void prepareVnfAndModulesCreate_NullList() { - ExecutionEntity mex = setupMock() - initPrepareVnfAndModulesCreate(mex) - - when(mex.getVariable("vnfList")).thenReturn(null) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.prepareVnfAndModulesCreate(mex) - - verify(mex).getVariable(DBGFLAG) - - verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb") - verify(mex).setVariable("lcpCloudRegionId", "mdt1") - verify(mex).setVariable("cloudOwner", "my-cloud-owner") - verify(mex).setVariable("tenantId", "8b1df54faa3b49078e3416e21370a3ba") - } - - @Test - // @Ignore - public void prepareVnfAndModulesCreate_Ex() { - ExecutionEntity mex = setupMock() - initPrepareVnfAndModulesCreate(mex) - - when(mex.getVariable("vnfList")).thenThrow(new RuntimeException("expected exception")) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - - assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.prepareVnfAndModulesCreate(mex) })) - } - - - // ***** validateVnfCreate ***** - - @Test - // @Ignore - public void validateVnfCreate() { - ExecutionEntity mex = setupMock() - initValidateVnfCreate(mex) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.validateVnfCreate(mex) - - verify(mex).getVariable(DBGFLAG) - - verify(mex).setVariable(Prefix+"VnfsCreatedCount", 3) - } - - @Test - // @Ignore - public void validateVnfCreate_Ex() { - ExecutionEntity mex = setupMock() - initValidateVnfCreate(mex) - - when(mex.getVariable(Prefix+"VnfsCreatedCount")).thenThrow(new RuntimeException("expected exception")) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - - assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.validateVnfCreate(mex) })) - } - - - // ***** postProcessResponse ***** - - @Test - // @Ignore - public void postProcessResponse() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initPostProcessResponse(mex) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.postProcessResponse(mex) - - verify(mex).getVariable(DBGFLAG) - - verify(mex).setVariable(Prefix+"Success", true) - - def reqinfo = map.get(Prefix+"CompleteMsoProcessRequest") - - assertTrue(reqinfo.indexOf("request-id>mri= 0) - assertTrue(reqinfo.indexOf("source>mysrc= 0) - assertTrue(reqinfo.indexOf("serviceInstanceId>sii= 0) - } - - @Test - // @Ignore - public void postProcessResponse_BpmnError() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initPostProcessResponse(mex) - - when(mex.getVariable("source")).thenThrow(new BpmnError("expected exception")) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - - assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.postProcessResponse(mex) })) - } - - @Test - // @Ignore - public void postProcessResponse_Ex() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initPostProcessResponse(mex) - - when(mex.getVariable("source")).thenThrow(new RuntimeException("expected exception")) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - - assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.postProcessResponse(mex) })) - } - - - // ***** preProcessRollback ***** - - @Test - // @Ignore - public void preProcessRollback() { - ExecutionEntity mex = setupMock() - def wfe = initPreProcessRollback(mex) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.preProcessRollback(mex) - - verify(mex).getVariable(DBGFLAG) - - verify(mex).setVariable("prevWorkflowException", wfe) - } - - @Test - // @Ignore - public void preProcessRollback_NullWfe() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - def wfe = initPreProcessRollback(mex) - - when(mex.getVariable("WorkflowException")).thenReturn(null) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.preProcessRollback(mex) - - verify(mex).getVariable(DBGFLAG) - - assertFalse(map.containsKey("prevWorkflowException")) - } - - @Test - // @Ignore - public void preProcessRollback_BpmnError() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - def wfe = initPreProcessRollback(mex) - - when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception")) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.preProcessRollback(mex) - - verify(mex).getVariable(DBGFLAG) - - assertFalse(map.containsKey("prevWorkflowException")) - } - - @Test - // @Ignore - public void preProcessRollback_Ex() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - def wfe = initPreProcessRollback(mex) - - when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception")) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.preProcessRollback(mex) - - verify(mex).getVariable(DBGFLAG) - - assertFalse(map.containsKey("prevWorkflowException")) - } - - - // ***** postProcessRollback ***** - - @Test - // @Ignore - public void postProcessRollback() { - ExecutionEntity mex = setupMock() - def wfe = initPostProcessRollback(mex) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.postProcessRollback(mex) - - verify(mex).getVariable(DBGFLAG) - - verify(mex).setVariable("WorkflowException", wfe) - } - - @Test - // @Ignore - public void postProcessRollback_NullWfe() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - def wfe = initPostProcessRollback(mex) - - when(mex.getVariable("prevWorkflowException")).thenReturn(null) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.postProcessRollback(mex) - - verify(mex).getVariable(DBGFLAG) - - assertFalse(map.containsKey("WorkflowException")) - } - - @Test - // @Ignore - public void postProcessRollback_BpmnError() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - def wfe = initPostProcessRollback(mex) - - when(mex.getVariable("prevWorkflowException")).thenThrow(new BpmnError("expected exception")) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.postProcessRollback(mex) })) - } - - @Test - // @Ignore - public void postProcessRollback_Ex() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - def wfe = initPostProcessRollback(mex) - - when(mex.getVariable("prevWorkflowException")).thenThrow(new RuntimeException("expected exception")) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.postProcessRollback(mex) - - verify(mex).getVariable(DBGFLAG) - - assertFalse(map.containsKey("WorkflowException")) - } - - - // ***** prepareFalloutRequest ***** - - @Test - // @Ignore - public void prepareFalloutRequest() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initPrepareFalloutRequest(mex) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.prepareFalloutRequest(mex) - - verify(mex, times(2)).getVariable(DBGFLAG) - - def fo = map.get(Prefix+"falloutRequest") - - assertTrue(fo.indexOf("world= 0) - assertTrue(fo.indexOf("ErrorMessage>mymsg= 0) - assertTrue(fo.indexOf("ErrorCode>999= 0) - } - - @Test - // @Ignore - public void prepareFalloutRequest_Ex() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initPrepareFalloutRequest(mex) - - when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception")) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - - assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.prepareFalloutRequest(mex) })) - } - - // ***** sendSyncError ***** - - @Test - // @Ignore - public void sendSyncError() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initSendSyncError(mex) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.sendSyncError(mex) - - verify(mex, times(2)).getVariable(DBGFLAG) - - verify(mex).setVariable(processName+"WorkflowResponseSent", "true") - - assertEquals("500", map.get(processName+"ResponseCode")) - assertEquals("Fail", map.get(processName+"Status")) - - def resp = map.get(processName+"Response") - - assertTrue(resp.indexOf("ErrorMessage>mymsg= 0) - - verify(mex).setVariable("WorkflowResponse", resp) - } - - @Test - // @Ignore - public void sendSyncError_NotWfe() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initSendSyncError(mex) - - when(mex.getVariable("WorkflowException")).thenReturn("not a WFE") - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.sendSyncError(mex) - - verify(mex, times(2)).getVariable(DBGFLAG) - - verify(mex).setVariable(processName+"WorkflowResponseSent", "true") - - assertEquals("500", map.get(processName+"ResponseCode")) - assertEquals("Fail", map.get(processName+"Status")) - - def resp = map.get(processName+"Response") - - assertTrue(resp.indexOf("ErrorMessage>Sending Sync Error.= 0) - - verify(mex).setVariable("WorkflowResponse", resp) - } - - @Test - // @Ignore - public void sendSyncError_NullWfe() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initSendSyncError(mex) - - when(mex.getVariable("WorkflowException")).thenReturn(null) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - CreateVcpeResCustService.sendSyncError(mex) - - verify(mex, times(2)).getVariable(DBGFLAG) - - verify(mex).setVariable(processName+"WorkflowResponseSent", "true") - - assertEquals("500", map.get(processName+"ResponseCode")) - assertEquals("Fail", map.get(processName+"Status")) - - def resp = map.get(processName+"Response") - - assertTrue(resp.indexOf("ErrorMessage>Sending Sync Error.= 0) - - verify(mex).setVariable("WorkflowResponse", resp) - } - - @Test - // @Ignore - public void sendSyncError_Ex() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initSendSyncError(mex) - - when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception")) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - - CreateVcpeResCustService.sendSyncError(mex) - - assertFalse(map.containsKey(processName+"ResponseCode")) - } - - - // ***** processJavaException ***** - - @Test - // @Ignore - public void processJavaException() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initProcessJavaException(mex) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - - assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.processJavaException(mex) })) - - verify(mex, times(2)).getVariable(DBGFLAG) - - verify(mex).setVariable("prefix", Prefix) - - def wfe = map.get("WorkflowException") - - assertEquals("Caught a Java Lang Exception", wfe.getErrorMessage()) - } - - @Test - // @Ignore - public void processJavaException_BpmnError() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initProcessJavaException(mex) - - when(mex.getVariables()).thenThrow(new BpmnError("expected exception")) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - - assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.processJavaException(mex) })) - - assertFalse(map.containsKey("WorkflowException")) - } - - @Test - // @Ignore - public void processJavaException_Ex() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initProcessJavaException(mex) - - when(mex.getVariables()).thenThrow(new RuntimeException("expected exception")) - - CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() - - assertTrue(doBpmnError( { _ -> CreateVcpeResCustService.processJavaException(mex) })) - - def wfe = map.get("WorkflowException") - - assertEquals("Exception in processJavaException method", wfe.getErrorMessage()) - } - - - private void initPreProcess(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("bpmnRequest")).thenReturn(request) - when(mex.getVariable("aai.workflowAaiDistributionDelay")).thenReturn("PT5S") - when(mex.getVariable("mso-request-id")).thenReturn("mri") - when(mex.getVariable("serviceInstanceId")).thenReturn("sii") - when(mex.getVariable("requestAction")).thenReturn("ra") - } - - private initSendSyncResponse(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("mso-request-id")).thenReturn("mri") - when(mex.getVariable("serviceInstanceId")).thenReturn("sii") - } - - private void initPrepareDecomposeService(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("createVcpeServiceRequest")).thenReturn('{"requestDetails":{"modelInfo":"mi"}}') - } - - private void initPrepareCreateServiceInstance(ExecutionEntity mex) { - ServiceDecomposition svcdecomp = mock(ServiceDecomposition.class) - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("createVcpeServiceRequest")).thenReturn(request) - when(mex.getVariable("serviceDecomposition")).thenReturn(svcdecomp) - - when(svcdecomp.toJsonStringNoRootName()).thenReturn("mydecomp") - } - - private void initPostProcessServiceInstanceCreate(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("mso-request-id")).thenReturn("mri") - when(mex.getVariable("serviceInstanceId")).thenReturn("sii") - when(mex.getVariable("serviceInstanceName")).thenReturn("sin") - } - - private ServiceDecomposition initProcessDecomposition(ExecutionEntity mex) { - List vnflst = new LinkedList<>() - vnflst.add(makeVnf("", "")) - vnflst.add(makeVnf("2", "BRG")) - vnflst.add(makeVnf("3", "BRG")) - - ServiceDecomposition svcdecomp = mock(ServiceDecomposition.class) - when(svcdecomp.getVnfResources()).thenReturn(vnflst) - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("serviceDecomposition")).thenReturn(svcdecomp) - when(mex.getVariable("serviceInstanceId")).thenReturn("sii") - when(mex.getVariable("serviceInstanceName")).thenReturn("sin") - - return svcdecomp - } - - private ServiceDecomposition initFilterVnfs(ExecutionEntity mex) { - List vnflst = new LinkedList<>() - vnflst.add(makeVnf("", "BRG")) - vnflst.add(makeVnf("2", "Tunnel XConn")) - vnflst.add(makeVnf("3", "")) - vnflst.add(makeVnf("4", "BRG")) - vnflst.add(makeVnf("5", "other")) - - ServiceDecomposition svcdecomp = mock(ServiceDecomposition.class) - when(svcdecomp.getVnfResources()).thenReturn(vnflst) - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("serviceDecomposition")).thenReturn(svcdecomp) - when(mex.getVariable("serviceInstanceId")).thenReturn("sii") - when(mex.getVariable("serviceInstanceName")).thenReturn("sin") - - return svcdecomp - } - - private initAwaitAaiDistribution(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - } - - private ServiceDecomposition initPrepareCreateAllottedResourceTXC(ExecutionEntity mex) { - ServiceDecomposition svcdecomp = mock(ServiceDecomposition.class) - List arlst = new LinkedList<>() - - arlst.add(makeArBRG("A")) - arlst.add(makeArTXC("B")) - arlst.add(makeArBRG("C")) - - when(svcdecomp.getAllottedResources()).thenReturn(arlst) - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("createVcpeServiceRequest")).thenReturn(request) - when(mex.getVariable("serviceDecomposition")).thenReturn(svcdecomp) - when(mex.getVariable("allottedResourceId")).thenReturn(ARID) - - return svcdecomp - } - - private ServiceDecomposition initPrepareCreateAllottedResourceBRG(ExecutionEntity mex) { - ServiceDecomposition svcdecomp = mock(ServiceDecomposition.class) - List arlst = new LinkedList<>() - - arlst.add(makeArTXC("A")) - arlst.add(makeArBRG("B")) - arlst.add(makeArTXC("C")) - - when(svcdecomp.getAllottedResources()).thenReturn(arlst) - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("createVcpeServiceRequest")).thenReturn(request) - when(mex.getVariable("serviceDecomposition")).thenReturn(svcdecomp) - when(mex.getVariable("allottedResourceId")).thenReturn(ARID) - - return svcdecomp - } - - private AllottedResource makeArTXC(String id) { - AllottedResource ar = mock(AllottedResource.class) - ModelInfo mod = mock(ModelInfo.class) - HomingSolution home = mock(HomingSolution.class) - - when(ar.toJsonStringNoRootName()).thenReturn("json"+id) - when(ar.getAllottedResourceType()).thenReturn("Tunnel XConn") - when(ar.getModelInfo()).thenReturn(mod) - when(ar.getAllottedResourceRole()).thenReturn("TXCr") - when(ar.getHomingSolution()).thenReturn(home) - - when(mod.toJsonStringNoRootName()).thenReturn("model"+id) - - when(home.getServiceInstanceId()).thenReturn("home"+id) - - return ar - } - - private AllottedResource makeArBRG(String id) { - AllottedResource ar = mock(AllottedResource.class) - ModelInfo mod = mock(ModelInfo.class) - HomingSolution home = mock(HomingSolution.class) - - when(ar.toJsonStringNoRootName()).thenReturn("json"+id) - when(ar.getAllottedResourceType()).thenReturn("BRG") - when(ar.getModelInfo()).thenReturn(mod) - when(ar.getAllottedResourceRole()).thenReturn("BRGr") - when(ar.getHomingSolution()).thenReturn(home) - - when(mod.toJsonStringNoRootName()).thenReturn("model"+id) - - when(home.getServiceInstanceId()).thenReturn("home"+id) - - return ar - } - - private initPrepareVnfAndModulesCreate(ExecutionEntity mex) { - - List vnflst = new LinkedList<>() - - vnflst.add(makeVnf("A", "BRG")) - vnflst.add(makeVnf("B", "")) - vnflst.add(makeVnf("C", "")) - vnflst.add(makeVnf("D", "Tunnel XConn")) - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("createVcpeServiceRequest")).thenReturn(request) - when(mex.getVariable("vnfList")).thenReturn(vnflst) - when(mex.getVariable(Prefix+"VnfsCreatedCount")).thenReturn(2) - when(mex.getVariable("vnfModelInfo")).thenReturn("nomodel") - when(mex.getVariable("sdncVersion")).thenReturn("myvers") - } - - private VnfResource makeVnf(String id, String role) { - ModelInfo mod = mock(ModelInfo.class) - VnfResource vnf = mock(VnfResource.class) - - when(mod.toString()).thenReturn('{"modelInfo":"mymodel'+id+'"}') - - when(vnf.toString()).thenReturn("myvnf"+id) - when(vnf.getModelInfo()).thenReturn(mod) - when(vnf.getNfRole()).thenReturn(role) - - return vnf - } - - private initValidateVnfCreate(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable(Prefix+"VnfsCreatedCount")).thenReturn(2) - } - - private initPostProcessResponse(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("source")).thenReturn("mysrc") - when(mex.getVariable("mso-request-id")).thenReturn("mri") - when(mex.getVariable("serviceInstanceId")).thenReturn("sii") - } - - private WorkflowException initPreProcessRollback(ExecutionEntity mex) { - WorkflowException wfe = mock(WorkflowException.class) - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("WorkflowException")).thenReturn(wfe) - - return wfe - } - - private WorkflowException initPostProcessRollback(ExecutionEntity mex) { - WorkflowException wfe = mock(WorkflowException.class) - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("prevWorkflowException")).thenReturn(wfe) - - return wfe - } - - private initPrepareFalloutRequest(ExecutionEntity mex) { - WorkflowException wfe = mock(WorkflowException.class) - - when(wfe.getErrorMessage()).thenReturn("mymsg") - when(wfe.getErrorCode()).thenReturn(999) - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("WorkflowException")).thenReturn(wfe) - when(mex.getVariable(Prefix+"requestInfo")).thenReturn("world") - - return wfe - } - - private initSendSyncError(ExecutionEntity mex) { - WorkflowException wfe = mock(WorkflowException.class) - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("mso-request-id")).thenReturn("mri") - when(mex.getVariable("WorkflowException")).thenReturn(wfe) - - when(wfe.getErrorMessage()).thenReturn("mymsg") - } - - private initProcessJavaException(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - } - + public void init() { + MockitoAnnotations.initMocks(this) + } + + public CreateVcpeResCustServiceTest() { + super("CreateVcpeResCustService") + } + + // ***** preProcessRequest ***** + + @Test + public void preProcessRequest() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + + initPreProcess(mex) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.preProcessRequest(mex) + + verify(mex).getVariable(DBGFLAG) + verify(mex).setVariable("prefix", Prefix) + verify(mex).setVariable("createVcpeServiceRequest", request) + verify(mex).setVariable("msoRequestId", "mri") + assertEquals("sii", map.get("serviceInstanceId")) + verify(mex).setVariable("requestAction", "ra") + verify(mex).setVariable("source", "VID") + verify(mex).setVariable("globalSubscriberId", CUST) + verify(mex).setVariable("globalCustomerId", CUST) + verify(mex).setVariable("subscriptionServiceType", SVC) + verify(mex).setVariable("disableRollback", "false") + verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb") + assertTrue(map.containsKey("subscriberInfo")) + + verify(mex).setVariable("brgWanMacAddress", "brgmac") + verify(mex).setVariable("customerLocation", ["customerLatitude": "32.897480", "customerLongitude": "-97.040443", "customerName": "some_company"]) + verify(mex).setVariable("homingService", "sniro") + assertTrue(map.containsKey("serviceInputParams")) + assertTrue(map.containsKey(Prefix + "requestInfo")) + + def reqinfo = map.get(Prefix + "requestInfo") + assertTrue(reqinfo.indexOf("mri= 0) + assertTrue(reqinfo.indexOf("VID= 0) + + assertTrue(map.containsKey("vfModuleNames")) + } + + @Test + public void preProcessRequest_MissingAaiDistDelay() { + ExecutionEntity mex = setupMock() + setupMap(mex) + initPreProcess(mex) + + when(mex.getVariable("aai.workflowAaiDistributionDelay")).thenReturn(null) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + + assertTrue(doBpmnError({ _ -> CreateVcpeResCustService.preProcessRequest(mex) })) + } + + @Test + public void preProcessRequest_EmptyParts() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initPreProcess(mex) + + def req = request + .replace('"source"', '"sourceXXX"') + .replace('"BRG_WAN_MAC_Address"', '"BRG_WAN_MAC_AddressXXX"') + .replace('"Customer_Location"', '"Customer_LocationXXX"') + + when(mex.getVariable("bpmnRequest")).thenReturn(req) + when(mex.getVariable("serviceInstanceId")).thenReturn(null) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.preProcessRequest(mex) + + verify(mex).getVariable(DBGFLAG) + verify(mex).setVariable("prefix", Prefix) + verify(mex).setVariable("createVcpeServiceRequest", req) + verify(mex).setVariable("msoRequestId", "mri") + assertNotNull(map.get("serviceInstanceId")) + assertFalse(map.get("serviceInstanceId").isEmpty()) + verify(mex).setVariable("requestAction", "ra") + verify(mex).setVariable("source", "VID") + verify(mex).setVariable("globalSubscriberId", CUST) + verify(mex).setVariable("globalCustomerId", CUST) + verify(mex).setVariable("subscriptionServiceType", SVC) + verify(mex).setVariable("disableRollback", "false") + verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb") + assertTrue(map.containsKey("subscriberInfo")) + + assertEquals("", map.get("brgWanMacAddress")) + assertEquals("", map.get("customerLocation")) + assertEquals("sniro", map.get("homingService")) + assertTrue(map.containsKey("serviceInputParams")) + assertTrue(map.containsKey(Prefix + "requestInfo")) + + def reqinfo = map.get(Prefix + "requestInfo") + println reqinfo + assertTrue(reqinfo.indexOf("mri= 0) + assertTrue(reqinfo.indexOf("VID= 0) + } + + @Test + public void preProcessRequest_MissingSubscriberId() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initPreProcess(mex) + + def req = request + .replace('"globalSubscriberId"', '"globalSubscriberIdXXX"') + + when(mex.getVariable("bpmnRequest")).thenReturn(req) + when(mex.getVariable("serviceInstanceId")).thenReturn(null) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + + assertTrue(doBpmnError({ _ -> CreateVcpeResCustService.preProcessRequest(mex) })) + } + + @Test + public void preProcessRequest_vimId() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initPreProcess(mex) + UrnPropertiesReader + + def req = request + .replace('"mdt1"', '"CloudOwner_CloudRegion1"') + + when(mex.getVariable("bpmnRequest")).thenReturn(req) + when(mex.getVariable("aai.workflowAaiDistributionDelay")).thenReturn("PT5S") + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.preProcessRequest(mex) + + verify(mex).setVariable("cloudRegionId", "CloudRegion1") + verify(mex).setVariable("cloudOwner", "CloudOwner") + } + + @Test + public void preProcessRequest_noVimId() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initPreProcess(mex) + + def req = request + .replace('"mdt1"', '"CloudRegion1_"') + + when(mex.getVariable("bpmnRequest")).thenReturn(req) + when(mex.getVariable("aai.workflowAaiDistributionDelay")).thenReturn("PT5S") + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.preProcessRequest(mex) + + verify(mex).setVariable("prefix", Prefix) + verify(mex).setVariable("cloudRegionId", "CloudRegion1_") + verify(mex).setVariable("cloudOwner", "CloudOwner") + + } + + + @Test + public void preProcessRequest_BpmnError() { + ExecutionEntity mex = setupMock() + initPreProcess(mex) + + when(mex.getVariable("bpmnRequest")).thenThrow(new BpmnError("expected exception")) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + + assertTrue(doBpmnError({ _ -> CreateVcpeResCustService.preProcessRequest(mex) })) + } + + @Test + public void preProcessRequest_Ex() { + ExecutionEntity mex = setupMock() + initPreProcess(mex) + + when(mex.getVariable("bpmnRequest")).thenThrow(new RuntimeException("expected exception")) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + + assertTrue(doBpmnError({ _ -> CreateVcpeResCustService.preProcessRequest(mex) })) + } + + // ***** sendSyncResponse ***** + + @Test + public void sendSyncResponse() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initSendSyncResponse(mex) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.sendSyncResponse(mex) + + verify(mex).getVariable(DBGFLAG) + + verify(mex).setVariable(processName + "WorkflowResponseSent", "true") + + assertEquals("202", map.get(processName + "ResponseCode")) + assertEquals("Success", map.get(processName + "Status")) + + def resp = map.get(processName + "Response") + + assertTrue(resp.indexOf('"instanceId":"sii"') >= 0) + assertTrue(resp.indexOf('"requestId":"mri"') >= 0) + } + + @Test + public void sendSyncResponse_Ex() { + ExecutionEntity mex = setupMock() + initSendSyncResponse(mex) + + when(mex.getVariable("serviceInstanceId")).thenThrow(new RuntimeException("expected exception")) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + + assertTrue(doBpmnError({ _ -> CreateVcpeResCustService.sendSyncResponse(mex) })) + } + + // ***** prepareDecomposeService ***** + + @Test + public void prepareDecomposeService() { + ExecutionEntity mex = setupMock() + initPrepareDecomposeService(mex) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.prepareDecomposeService(mex) + + verify(mex).getVariable("createVcpeServiceRequest") + verify(mex).setVariable("serviceModelInfo", "mi") + } + + @Test + public void prepareDecomposeService_Ex() { + ExecutionEntity mex = setupMock() + initPrepareDecomposeService(mex) + + when(mex.getVariable("createVcpeServiceRequest")).thenThrow(new RuntimeException("expected exception")) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + + assertTrue(doBpmnError({ _ -> CreateVcpeResCustService.prepareDecomposeService(mex) })) + } + + // ***** prepareCreateServiceInstance ***** + + @Test + public void prepareCreateServiceInstance() { + ExecutionEntity mex = setupMock() + ServiceDecomposition svcdecomp = initPrepareCreateServiceInstance(mex) + when(svcdecomp.toJsonStringNoRootName()).thenReturn("mydecomp") + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.prepareCreateServiceInstance(mex) + + verify(mex).getVariable("createVcpeServiceRequest") + verify(mex).setVariable("serviceInstanceName", "VCPE1") + verify(mex).setVariable("serviceDecompositionString", "mydecomp") + } + + @Test + public void prepareCreateServiceInstance_Ex() { + ExecutionEntity mex = setupMock() + initPrepareCreateServiceInstance(mex) + + when(mex.getVariable("createVcpeServiceRequest")).thenThrow(new RuntimeException("expected exception")) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + + assertTrue(doBpmnError({ _ -> CreateVcpeResCustService.prepareCreateServiceInstance(mex) })) + } + + // ***** postProcessServiceInstanceCreate ***** + + @Test + public void postProcessServiceInstanceCreate() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initPostProcessServiceInstanceCreate(mex) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.postProcessServiceInstanceCreate(mex) + + verify(mex).getVariable("mso-request-id") + verify(mex).getVariable("serviceInstanceId") + verify(mex).getVariable("serviceInstanceName") + + def reqinfo = map.get(Prefix + "setUpdateDbInstancePayload") + + assertTrue(reqinfo.indexOf("mri= 0) + assertTrue(reqinfo.indexOf("sii= 0) + assertTrue(reqinfo.indexOf("sin= 0) + } + + @Test + public void postProcessServiceInstanceCreate_BpmnError() { + ExecutionEntity mex = setupMock() + initPostProcessServiceInstanceCreate(mex) + + doThrow(new BpmnError("expected exception")).when(mex).setVariable(endsWith("setUpdateDbInstancePayload"), any()) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + + assertTrue(doBpmnError({ _ -> CreateVcpeResCustService.postProcessServiceInstanceCreate(mex) })) + } + + @Test + public void postProcessServiceInstanceCreate_Ex() { + ExecutionEntity mex = setupMock() + initPostProcessServiceInstanceCreate(mex) + + doThrow(new RuntimeException("expected exception")).when(mex).setVariable(endsWith("setUpdateDbInstancePayload"), any()) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + + assertTrue(doBpmnError({ _ -> CreateVcpeResCustService.postProcessServiceInstanceCreate(mex) })) + } + + // ***** processDecomposition ***** + + @Test + public void processDecomposition() { + ExecutionEntity mex = setupMock() + def svcdecomp = initProcessDecomposition(mex) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.processDecomposition(mex) + + verify(mex).getVariable("serviceDecomposition") + + verify(mex).setVariable("vnfList", svcdecomp.getVnfResources()) + verify(mex).setVariable("vnfListString", '[myvnf]') + verify(mex).setVariable(Prefix + "VNFsCount", 1) + + verify(mex).setVariable("vnfModelInfo", "mymodel") + verify(mex).setVariable("vnfModelInfoString", "mymodel") + } + + @Test + public void processDecomposition_EmptyNet_EmptyVnf() { + ExecutionEntity mex = setupMock() + def svcdecomp = initProcessDecomposition(mex) + + when(svcdecomp.getVnfResources()).thenReturn(new LinkedList()) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.processDecomposition(mex) + + verify(mex).getVariable("serviceDecomposition") + + verify(mex).setVariable("vnfList", svcdecomp.getVnfResources()) + verify(mex).setVariable("vnfListString", '[]') + verify(mex).setVariable(Prefix + "VNFsCount", 0) + + verify(mex).setVariable("vnfModelInfo", "") + verify(mex).setVariable("vnfModelInfoString", "") + } + + @Test + public void processDecomposition_Ex() { + ExecutionEntity mex = setupMock() + def svcdecomp = initProcessDecomposition(mex) + + when(svcdecomp.getVnfResources()).thenThrow(new RuntimeException("expected exception")) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + + assertTrue(doBpmnError({ _ -> CreateVcpeResCustService.processDecomposition(mex) })) + } + + // ***** filterVnfs ***** + + @Test + public void filterVnfs() { + ExecutionEntity mex = setupMock() + initFilterVnfs(mex) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.processDecomposition(mex) + + verify(mex).setVariable("vnfListString", '[myvnf3, myvnf5]') + } + + @Test + public void filterVnfs_Null() { + ExecutionEntity mex = setupMock() + def svcdecomp = initFilterVnfs(mex) + + when(svcdecomp.getVnfResources()).thenReturn(null) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.processDecomposition(mex) + + // nothing more to check, as long as it didn't throw an exception + } + + // ***** prepareCreateAllottedResourceTXC ***** + + @Test + public void prepareCreateAllottedResourceTXC() { + ExecutionEntity mex = setupMock() + initPrepareCreateAllottedResourceTXC(mex) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.prepareCreateAllottedResourceTXC(mex) + + verify(mex).getVariable("serviceDecomposition") + + verify(mex).setVariable("createTXCAR", true) + verify(mex).setVariable("allottedResourceModelInfoTXC", "modelB") + verify(mex).setVariable("allottedResourceRoleTXC", "TXCr") + verify(mex).setVariable("allottedResourceTypeTXC", "Tunnel XConn") + verify(mex).setVariable("parentServiceInstanceIdTXC", "homeB") + } + + @Test + public void prepareCreateAllottedResourceTXC_NullArList() { + ExecutionEntity mex = setupMock() + def svcdecomp = initPrepareCreateAllottedResourceTXC(mex) + + when(svcdecomp.getAllottedResources()).thenReturn(null) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.prepareCreateAllottedResourceTXC(mex) + + verify(mex).getVariable("serviceDecomposition") + + verify(mex, never()).setVariable("createTXCAR", true) + verify(mex, never()).setVariable("allottedResourceModelInfoTXC", "modelB") + verify(mex, never()).setVariable("allottedResourceRoleTXC", "TXCr") + verify(mex, never()).setVariable("allottedResourceTypeTXC", "Tunnel XConn") + verify(mex, never()).setVariable("parentServiceInstanceIdTXC", "homeB") + } + + @Test + public void prepareCreateAllottedResourceTXC_Ex() { + ExecutionEntity mex = setupMock() + initPrepareCreateAllottedResourceTXC(mex) + + when(mex.getVariable("serviceDecomposition")).thenThrow(new RuntimeException("expected exception")) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + + assertTrue(doBpmnError({ _ -> CreateVcpeResCustService.prepareCreateAllottedResourceTXC(mex) })) + } + + // ***** prepareCreateAllottedResourceBRG ***** + + @Test + public void prepareCreateAllottedResourceBRG() { + ExecutionEntity mex = setupMock() + initPrepareCreateAllottedResourceBRG(mex) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.prepareCreateAllottedResourceBRG(mex) + + verify(mex).getVariable("serviceDecomposition") + + verify(mex).setVariable("createBRGAR", true) + verify(mex).setVariable("allottedResourceModelInfoBRG", "modelB") + verify(mex).setVariable("allottedResourceRoleBRG", "BRGr") + verify(mex).setVariable("allottedResourceTypeBRG", "BRG") + verify(mex).setVariable("parentServiceInstanceIdBRG", "homeB") + } + + @Test + public void prepareCreateAllottedResourceBRG_NullArList() { + ExecutionEntity mex = setupMock() + def svcdecomp = initPrepareCreateAllottedResourceBRG(mex) + + when(svcdecomp.getAllottedResources()).thenReturn(null) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.prepareCreateAllottedResourceBRG(mex) + + verify(mex).getVariable("serviceDecomposition") + + verify(mex, never()).setVariable("createBRGAR", true) + verify(mex, never()).setVariable("allottedResourceModelInfoBRG", "modelB") + verify(mex, never()).setVariable("allottedResourceRoleBRG", "BRGr") + verify(mex, never()).setVariable("allottedResourceTypeBRG", "BRG") + verify(mex, never()).setVariable("parentServiceInstanceIdBRG", "homeB") + } + + @Test + public void prepareCreateAllottedResourceBRG_Ex() { + ExecutionEntity mex = setupMock() + initPrepareCreateAllottedResourceBRG(mex) + + when(mex.getVariable("serviceDecomposition")).thenThrow(new RuntimeException("expected exception")) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + + assertTrue(doBpmnError({ _ -> CreateVcpeResCustService.prepareCreateAllottedResourceBRG(mex) })) + } + + // ***** prepareVnfAndModulesCreate ***** + + @Test + public void prepareVnfAndModulesCreate() { + ExecutionEntity mex = setupMock() + initPrepareVnfAndModulesCreate(mex) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.prepareVnfAndModulesCreate(mex) + + verify(mex).getVariable("createVcpeServiceRequest") + + verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb") + verify(mex).setVariable("lcpCloudRegionId", "mdt1") + verify(mex).setVariable("cloudOwner", "CloudOwner") + verify(mex).setVariable("tenantId", "8b1df54faa3b49078e3416e21370a3ba") + } + + @Test + public void prepareVnfAndModulesCreate_noVimId() { + ExecutionEntity mex = setupMock() + initPrepareVnfAndModulesCreate(mex) + + def req = request + .replace('"mdt1"', '"CloudRegion1_"') + + when(mex.getVariable("createVcpeServiceRequest")).thenReturn(req) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.prepareVnfAndModulesCreate(mex) + + verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb") + verify(mex).setVariable("cloudRegionId", "CloudRegion1_") + verify(mex).setVariable("lcpCloudRegionId", "CloudRegion1_") + verify(mex).setVariable("tenantId", "8b1df54faa3b49078e3416e21370a3ba") + } + + @Test + public void prepareVnfAndModulesCreate_vimId() { + ExecutionEntity mex = setupMock() + initPrepareVnfAndModulesCreate(mex) + + def req = request + .replace('"mdt1"', '"CloudOwner_CloudRegion1"') + + when(mex.getVariable("createVcpeServiceRequest")).thenReturn(req) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.prepareVnfAndModulesCreate(mex) + + verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb") + verify(mex).setVariable("cloudOwner", "CloudOwner") + verify(mex).setVariable("cloudRegionId", "CloudRegion1") + verify(mex).setVariable("lcpCloudRegionId", "CloudRegion1") + verify(mex).setVariable("tenantId", "8b1df54faa3b49078e3416e21370a3ba") + } + + @Test + public void prepareVnfAndModulesCreate_EmptyList() { + ExecutionEntity mex = setupMock() + initPrepareVnfAndModulesCreate(mex) + + when(mex.getVariable("vnfList")).thenReturn(new LinkedList()) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.prepareVnfAndModulesCreate(mex) + + verify(mex).getVariable("createVcpeServiceRequest") + + verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb") + verify(mex).setVariable("lcpCloudRegionId", "mdt1") + verify(mex).setVariable("cloudOwner", "CloudOwner") + verify(mex).setVariable("tenantId", "8b1df54faa3b49078e3416e21370a3ba") + } + + @Test + public void prepareVnfAndModulesCreate_NullList() { + ExecutionEntity mex = setupMock() + initPrepareVnfAndModulesCreate(mex) + + when(mex.getVariable("vnfList")).thenReturn(null) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.prepareVnfAndModulesCreate(mex) + + verify(mex).getVariable("createVcpeServiceRequest") + + verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb") + verify(mex).setVariable("lcpCloudRegionId", "mdt1") + verify(mex).setVariable("cloudOwner", "CloudOwner") + verify(mex).setVariable("tenantId", "8b1df54faa3b49078e3416e21370a3ba") + } + + @Test + public void prepareVnfAndModulesCreate_Ex() { + ExecutionEntity mex = setupMock() + initPrepareVnfAndModulesCreate(mex) + + when(mex.getVariable("vnfList")).thenThrow(new RuntimeException("expected exception")) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + + assertTrue(doBpmnError({ _ -> CreateVcpeResCustService.prepareVnfAndModulesCreate(mex) })) + } + + // ***** validateVnfCreate ***** + + @Test + public void validateVnfCreate() { + ExecutionEntity mex = setupMock() + initValidateVnfCreate(mex) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.validateVnfCreate(mex) + + verify(mex).getVariable(Prefix + "VnfsCreatedCount") + + verify(mex).setVariable(Prefix + "VnfsCreatedCount", 3) + } + + @Test + public void validateVnfCreate_Ex() { + ExecutionEntity mex = setupMock() + initValidateVnfCreate(mex) + + when(mex.getVariable(Prefix + "VnfsCreatedCount")).thenThrow(new RuntimeException("expected exception")) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + + assertTrue(doBpmnError({ _ -> CreateVcpeResCustService.validateVnfCreate(mex) })) + } + + // ***** postProcessResponse ***** + + @Test + public void postProcessResponse() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initPostProcessResponse(mex) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.postProcessResponse(mex) + + verify(mex).getVariable("source") + verify(mex).getVariable("mso-request-id") + verify(mex).getVariable("serviceInstanceId") + + verify(mex).setVariable(Prefix + "Success", true) + + def reqinfo = map.get(Prefix + "CompleteMsoProcessRequest") + + assertTrue(reqinfo.indexOf("request-id>mri= 0) + assertTrue(reqinfo.indexOf("source>mysrc= 0) + assertTrue(reqinfo.indexOf("serviceInstanceId>sii= 0) + } + + @Test + public void postProcessResponse_BpmnError() { + ExecutionEntity mex = setupMock() + setupMap(mex) + initPostProcessResponse(mex) + + when(mex.getVariable("source")).thenThrow(new BpmnError("expected exception")) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + + assertTrue(doBpmnError({ _ -> CreateVcpeResCustService.postProcessResponse(mex) })) + } + + @Test + public void postProcessResponse_Ex() { + ExecutionEntity mex = setupMock() + setupMap(mex) + initPostProcessResponse(mex) + + when(mex.getVariable("source")).thenThrow(new BpmnError("expected exception")) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + + assertTrue(doBpmnError({ _ -> CreateVcpeResCustService.postProcessResponse(mex) })) + } + + // ***** preProcessRollback ***** + + @Test + public void preProcessRollback() { + ExecutionEntity mex = setupMock() + def wfe = initPreProcessRollback(mex) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.preProcessRollback(mex) + + verify(mex).getVariable("WorkflowException") + + verify(mex).setVariable("prevWorkflowException", wfe) + } + + @Test + public void preProcessRollback_NullWfe() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initPreProcessRollback(mex) + + when(mex.getVariable("WorkflowException")).thenReturn(null) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.preProcessRollback(mex) + + verify(mex).getVariable("WorkflowException") + + assertFalse(map.containsKey("prevWorkflowException")) + } + + @Test + public void preProcessRollback_BpmnError() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initPreProcessRollback(mex) + + when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception")) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.preProcessRollback(mex) + + verify(mex).getVariable("WorkflowException") + + assertFalse(map.containsKey("prevWorkflowException")) + } + + @Test + public void preProcessRollback_Ex() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initPreProcessRollback(mex) + + when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception")) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.preProcessRollback(mex) + + verify(mex).getVariable("WorkflowException") + + assertFalse(map.containsKey("prevWorkflowException")) + } + + // ***** postProcessRollback ***** + + @Test + public void postProcessRollback() { + ExecutionEntity mex = setupMock() + def wfe = initPostProcessRollback(mex) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.postProcessRollback(mex) + + verify(mex).getVariable("prevWorkflowException") + + verify(mex).setVariable("WorkflowException", wfe) + } + + @Test + public void postProcessRollback_NullWfe() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initPostProcessRollback(mex) + + when(mex.getVariable("prevWorkflowException")).thenReturn(null) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.postProcessRollback(mex) + + verify(mex).getVariable("prevWorkflowException") + + assertFalse(map.containsKey("WorkflowException")) + } + + @Test + public void postProcessRollback_BpmnError() { + ExecutionEntity mex = setupMock() + setupMap(mex) + initPostProcessRollback(mex) + + when(mex.getVariable("prevWorkflowException")).thenThrow(new BpmnError("expected exception")) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + assertTrue(doBpmnError({ _ -> CreateVcpeResCustService.postProcessRollback(mex) })) + } + + + @Test + public void postProcessRollback_Ex() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initPostProcessRollback(mex) + + when(mex.getVariable("prevWorkflowException")).thenThrow(new RuntimeException("expected exception")) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.postProcessRollback(mex) + + verify(mex).getVariable("prevWorkflowException") + + assertFalse(map.containsKey("WorkflowException")) + } + + // ***** prepareFalloutRequest ***** + + @Test + public void prepareFalloutRequest() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + WorkflowException wfe = initPrepareFalloutRequest(mex) + when(wfe.getErrorMessage()).thenReturn("mymsg") + when(wfe.getErrorCode()).thenReturn(999) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.prepareFalloutRequest(mex) + + verify(mex, times(4)).getVariable("WorkflowException") + + def fo = map.get(Prefix + "falloutRequest") + + assertTrue(fo.indexOf("world= 0) + assertTrue(fo.indexOf("ErrorMessage>mymsg= 0) + assertTrue(fo.indexOf("ErrorCode>999= 0) + } + + @Test + public void prepareFalloutRequest_Ex() { + ExecutionEntity mex = setupMock() + setupMap(mex) + initPrepareFalloutRequest(mex) + + when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception")) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + + assertTrue(doBpmnError({ _ -> CreateVcpeResCustService.prepareFalloutRequest(mex) })) + } + + // ***** sendSyncError ***** + + @Test + public void sendSyncError() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initSendSyncError(mex) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.sendSyncError(mex) + + verify(mex).getVariable(DBGFLAG) + + verify(mex).setVariable(processName + "WorkflowResponseSent", "true") + + assertEquals("500", map.get(processName + "ResponseCode")) + assertEquals("Fail", map.get(processName + "Status")) + + def resp = map.get(processName + "Response") + + assertTrue(resp.indexOf("ErrorMessage>mymsg= 0) + + verify(mex).setVariable("WorkflowResponse", resp) + } + + @Test + public void sendSyncError_NotWfe() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initSendSyncError(mex) + + when(mex.getVariable("WorkflowException")).thenReturn("not a WFE") + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.sendSyncError(mex) + + verify(mex).getVariable(DBGFLAG) + + verify(mex).setVariable(processName + "WorkflowResponseSent", "true") + + assertEquals("500", map.get(processName + "ResponseCode")) + assertEquals("Fail", map.get(processName + "Status")) + + def resp = map.get(processName + "Response") + + assertTrue(resp.indexOf("ErrorMessage>Sending Sync Error.= 0) + + verify(mex).setVariable("WorkflowResponse", resp) + } + + @Test + public void sendSyncError_NullWfe() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initSendSyncError(mex) + + when(mex.getVariable("WorkflowException")).thenReturn(null) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + CreateVcpeResCustService.sendSyncError(mex) + + verify(mex).getVariable(DBGFLAG) + + verify(mex).setVariable(processName + "WorkflowResponseSent", "true") + + assertEquals("500", map.get(processName + "ResponseCode")) + assertEquals("Fail", map.get(processName + "Status")) + + def resp = map.get(processName + "Response") + + assertTrue(resp.indexOf("ErrorMessage>Sending Sync Error.= 0) + + verify(mex).setVariable("WorkflowResponse", resp) + } + + @Test + public void sendSyncError_Ex() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initSendSyncError(mex) + + when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception")) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + + CreateVcpeResCustService.sendSyncError(mex) + + assertFalse(map.containsKey(processName + "ResponseCode")) + } + + // ***** processJavaException ***** + + @Test + public void processJavaException() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initProcessJavaException(mex) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + + assertTrue(doBpmnError({ _ -> CreateVcpeResCustService.processJavaException(mex) })) + + verify(mex).getVariable("testProcessKey") + + verify(mex).setVariable("prefix", Prefix) + + def wfe = map.get("WorkflowException") + + assertEquals("Caught a Java Lang Exception", wfe.getErrorMessage()) + } + + @Test + public void processJavaException_BpmnError() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initProcessJavaException(mex) + + when(mex.getVariables()).thenThrow(new BpmnError("expected exception")) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + + assertTrue(doBpmnError({ _ -> CreateVcpeResCustService.processJavaException(mex) })) + + assertFalse(map.containsKey("WorkflowException")) + } + + @Test + public void processJavaException_Ex() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initProcessJavaException(mex) + + when(mex.getVariables()).thenThrow(new RuntimeException("expected exception")) + + CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService() + + assertTrue(doBpmnError({ _ -> CreateVcpeResCustService.processJavaException(mex) })) + + def wfe = map.get("WorkflowException") + + assertEquals("Exception in processJavaException method", wfe.getErrorMessage()) + } + + + private void initPreProcess(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("bpmnRequest")).thenReturn(request) + when(mex.getVariable("aai.workflowAaiDistributionDelay")).thenReturn("PT5S") + when(mex.getVariable("mso-request-id")).thenReturn("mri") + when(mex.getVariable("serviceInstanceId")).thenReturn("sii") + when(mex.getVariable("requestAction")).thenReturn("ra") + } + + private initSendSyncResponse(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("mso-request-id")).thenReturn("mri") + when(mex.getVariable("serviceInstanceId")).thenReturn("sii") + } + + private void initPrepareDecomposeService(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("createVcpeServiceRequest")).thenReturn('{"requestDetails":{"modelInfo":"mi"}}') + } + + private ServiceDecomposition initPrepareCreateServiceInstance(ExecutionEntity mex) { + ServiceDecomposition svcdecomp = mock(ServiceDecomposition.class) + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("createVcpeServiceRequest")).thenReturn(request) + when(mex.getVariable("serviceDecomposition")).thenReturn(svcdecomp) + + return svcdecomp + } + + private void initPostProcessServiceInstanceCreate(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("mso-request-id")).thenReturn("mri") + when(mex.getVariable("serviceInstanceId")).thenReturn("sii") + when(mex.getVariable("serviceInstanceName")).thenReturn("sin") + } + + private ServiceDecomposition initProcessDecomposition(ExecutionEntity mex) { + List vnflst = new LinkedList<>() + vnflst.add(makeVnf("", "")) + vnflst.add(makeVnf("2", "BRG")) + vnflst.add(makeVnf("3", "BRG")) + + ServiceDecomposition svcdecomp = mock(ServiceDecomposition.class) + when(svcdecomp.getVnfResources()).thenReturn(vnflst) + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("serviceDecomposition")).thenReturn(svcdecomp) + when(mex.getVariable("serviceInstanceId")).thenReturn("sii") + when(mex.getVariable("serviceInstanceName")).thenReturn("sin") + + return svcdecomp + } + + private ServiceDecomposition initFilterVnfs(ExecutionEntity mex) { + List vnflst = new LinkedList<>() + vnflst.add(makeVnf("", "BRG")) + vnflst.add(makeVnf("2", "Tunnel XConn")) + vnflst.add(makeVnf("3", "")) + vnflst.add(makeVnf("4", "BRG")) + vnflst.add(makeVnf("5", "other")) + + ServiceDecomposition svcdecomp = mock(ServiceDecomposition.class) + when(svcdecomp.getVnfResources()).thenReturn(vnflst) + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("serviceDecomposition")).thenReturn(svcdecomp) + when(mex.getVariable("serviceInstanceId")).thenReturn("sii") + when(mex.getVariable("serviceInstanceName")).thenReturn("sin") + + return svcdecomp + } + + private ServiceDecomposition initPrepareCreateAllottedResourceTXC(ExecutionEntity mex) { + ServiceDecomposition svcdecomp = mock(ServiceDecomposition.class) + List arlst = new LinkedList<>() + + arlst.add(makeArBRG("A")) + arlst.add(makeArTXC("B")) + arlst.add(makeArBRG("C")) + + when(svcdecomp.getAllottedResources()).thenReturn(arlst) + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("createVcpeServiceRequest")).thenReturn(request) + when(mex.getVariable("serviceDecomposition")).thenReturn(svcdecomp) + when(mex.getVariable("allottedResourceId")).thenReturn(ARID) + + return svcdecomp + } + + private ServiceDecomposition initPrepareCreateAllottedResourceBRG(ExecutionEntity mex) { + ServiceDecomposition svcdecomp = mock(ServiceDecomposition.class) + List arlst = new LinkedList<>() + + arlst.add(makeArTXC("A")) + arlst.add(makeArBRG("B")) + arlst.add(makeArTXC("C")) + + when(svcdecomp.getAllottedResources()).thenReturn(arlst) + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("createVcpeServiceRequest")).thenReturn(request) + when(mex.getVariable("serviceDecomposition")).thenReturn(svcdecomp) + when(mex.getVariable("allottedResourceId")).thenReturn(ARID) + + return svcdecomp + } + + private AllottedResource makeArTXC(String id) { + AllottedResource ar = mock(AllottedResource.class) + ModelInfo mod = mock(ModelInfo.class) + HomingSolution home = mock(HomingSolution.class) + + when(ar.toJsonStringNoRootName()).thenReturn("json" + id) + when(ar.getAllottedResourceType()).thenReturn("Tunnel XConn") + when(ar.getModelInfo()).thenReturn(mod) + when(ar.getAllottedResourceRole()).thenReturn("TXCr") + when(ar.getHomingSolution()).thenReturn(home) + + when(mod.toJsonStringNoRootName()).thenReturn("model" + id) + + when(home.getServiceInstanceId()).thenReturn("home" + id) + + return ar + } + + private AllottedResource makeArBRG(String id) { + AllottedResource ar = mock(AllottedResource.class) + ModelInfo mod = mock(ModelInfo.class) + HomingSolution home = mock(HomingSolution.class) + + when(ar.toJsonStringNoRootName()).thenReturn("json" + id) + when(ar.getAllottedResourceType()).thenReturn("BRG") + when(ar.getModelInfo()).thenReturn(mod) + when(ar.getAllottedResourceRole()).thenReturn("BRGr") + when(ar.getHomingSolution()).thenReturn(home) + + when(mod.toJsonStringNoRootName()).thenReturn("model" + id) + + when(home.getServiceInstanceId()).thenReturn("home" + id) + + return ar + } + + private initPrepareVnfAndModulesCreate(ExecutionEntity mex) { + + List vnflst = new LinkedList<>() + + vnflst.add(makeVnf("A", "BRG")) + vnflst.add(makeVnf("B", "")) + vnflst.add(makeVnf("C", "")) + vnflst.add(makeVnf("D", "Tunnel XConn")) + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("createVcpeServiceRequest")).thenReturn(request) + when(mex.getVariable("vnfList")).thenReturn(vnflst) + when(mex.getVariable(Prefix + "VnfsCreatedCount")).thenReturn(2) + when(mex.getVariable("vnfModelInfo")).thenReturn("nomodel") + when(mex.getVariable("sdncVersion")).thenReturn("myvers") + } + + private VnfResource makeVnf(String id, String role) { + ModelInfo mod = mock(ModelInfo.class) + VnfResource vnf = mock(VnfResource.class) + + when(mod.toString()).thenReturn('{"modelInfo":"mymodel' + id + '"}') + + when(vnf.toString()).thenReturn("myvnf" + id) + when(vnf.getModelInfo()).thenReturn(mod) + when(vnf.getNfRole()).thenReturn(role) + + return vnf + } + + private initValidateVnfCreate(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable(Prefix + "VnfsCreatedCount")).thenReturn(2) + } + + private initPostProcessResponse(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("source")).thenReturn("mysrc") + when(mex.getVariable("mso-request-id")).thenReturn("mri") + when(mex.getVariable("serviceInstanceId")).thenReturn("sii") + } + + private WorkflowException initPreProcessRollback(ExecutionEntity mex) { + WorkflowException wfe = mock(WorkflowException.class) + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("WorkflowException")).thenReturn(wfe) + + return wfe + } + + private WorkflowException initPostProcessRollback(ExecutionEntity mex) { + WorkflowException wfe = mock(WorkflowException.class) + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("prevWorkflowException")).thenReturn(wfe) + + return wfe + } + + private initPrepareFalloutRequest(ExecutionEntity mex) { + WorkflowException wfe = mock(WorkflowException.class) + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("WorkflowException")).thenReturn(wfe) + when(mex.getVariable(Prefix + "requestInfo")).thenReturn("world") + + return wfe + } + + private initSendSyncError(ExecutionEntity mex) { + WorkflowException wfe = mock(WorkflowException.class) + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("mso-request-id")).thenReturn("mri") + when(mex.getVariable("WorkflowException")).thenReturn(wfe) + + when(wfe.getErrorMessage()).thenReturn("mymsg") + } + + private initProcessJavaException(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + } + } diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/DeleteVcpeResCustServiceTest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/DeleteVcpeResCustServiceTest.groovy index c2384b63a5..be8f2a2d2e 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/DeleteVcpeResCustServiceTest.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/DeleteVcpeResCustServiceTest.groovy @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,756 +21,543 @@ */ package org.onap.so.bpmn.vcpe.scripts - -import org.camunda.bpm.engine.ProcessEngineServices -import org.camunda.bpm.engine.RepositoryService +import com.github.tomakehurst.wiremock.junit.WireMockRule +import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity -import org.camunda.bpm.engine.repository.ProcessDefinition import org.junit.Before import org.junit.BeforeClass import org.junit.Rule import org.junit.Test -import org.junit.Ignore import org.mockito.MockitoAnnotations -import org.camunda.bpm.engine.delegate.BpmnError import org.onap.so.bpmn.core.WorkflowException import org.onap.so.bpmn.mock.FileUtil -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse -import static com.github.tomakehurst.wiremock.client.WireMock.get -import static com.github.tomakehurst.wiremock.client.WireMock.patch -import static com.github.tomakehurst.wiremock.client.WireMock.put -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor -import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching -import static org.junit.Assert.*; +import static org.junit.Assert.* import static org.mockito.Mockito.* -import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetAllottedResource -import org.onap.so.bpmn.core.domain.ServiceDecomposition -import org.onap.so.bpmn.core.domain.VnfResource -import org.onap.so.bpmn.core.domain.AllottedResource -import org.onap.so.bpmn.core.domain.ModelInfo -import org.onap.so.bpmn.core.RollbackData -import org.onap.so.bpmn.vcpe.scripts.MapGetter -import org.onap.so.bpmn.vcpe.scripts.MapSetter +class DeleteVcpeResCustServiceTest extends GroovyTestBase { -import com.github.tomakehurst.wiremock.junit.WireMockRule + private static String request + + @Rule + public WireMockRule wireMockRule = new WireMockRule(PORT) + + String Prefix = "DVRCS_" + + @BeforeClass + public static void setUpBeforeClass() { + request = FileUtil.readResourceFile("__files/VCPE/DeleteVcpeResCustService/request.json") + } -class DeleteVcpeResCustServiceTest extends GroovyTestBase { - - private static String request - - @Rule - public WireMockRule wireMockRule = new WireMockRule(PORT) - - String Prefix = "DVRCS_" - String RbType = "DCRENI_" - - @BeforeClass - public static void setUpBeforeClass() { - request = FileUtil.readResourceFile("__files/VCPE/DeleteVcpeResCustService/request.json") - } - @Before - public void init() - { - MockitoAnnotations.initMocks(this) - } - - public DeleteVcpeResCustServiceTest() { - super("DeleteVcpeResCustService") - } - - - // ***** preProcessRequest ***** - - @Test -// @Ignore - public void preProcessRequest() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initPreProcess(mex) - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - DeleteVcpeResCustService.preProcessRequest(mex) - - verify(mex).getVariable(DBGFLAG) - - assertEquals(Prefix, map.get("prefix")) - assertEquals(request, map.get("DeleteVcpeResCustServiceRequest")) - assertEquals("mri", map.get("msoRequestId")) - assertEquals("ra", map.get("requestAction")) - assertEquals("VID", map.get("source")) - assertEquals(CUST, map.get("globalSubscriberId")) - assertEquals(CUST, map.get("globalCustomerId")) - assertEquals("false", map.get("disableRollback")) - assertEquals("a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", map.get("productFamilyId")) - assertEquals(SVC, map.get("subscriptionServiceType")) - - assertEquals("mdt1", map.get("lcpCloudRegionId")) - assertEquals("8b1df54faa3b49078e3416e21370a3ba", map.get("tenantId")) - assertEquals("1707", map.get("sdncVersion")) - assertEquals("service-instance", map.get("GENGS_type")) - assertEquals("""{"tenantId":"8b1df54faa3b49078e3416e21370a3ba","lcpCloudRegionId":"mdt1"}""", map.get("cloudConfiguration")) - assertTrue(map.containsKey(Prefix+"requestInfo")) - - def reqinfo = map.get(Prefix+"requestInfo") - assertTrue(reqinfo.indexOf("mri= 0) - assertTrue(reqinfo.indexOf("VID= 0) - } - - @Test -// @Ignore - public void preProcessRequest_EmptyParts() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initPreProcess(mex) - - def req = request - .replace('"source"', '"sourceXXX"') - - when(mex.getVariable("bpmnRequest")).thenReturn(req) - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - DeleteVcpeResCustService.preProcessRequest(mex) - - verify(mex).getVariable(DBGFLAG) - verify(mex).setVariable("prefix", Prefix) - verify(mex).setVariable("DeleteVcpeResCustServiceRequest", req) - verify(mex).setVariable("msoRequestId", "mri") - verify(mex).setVariable("requestAction", "ra") - verify(mex).setVariable("source", "VID") - verify(mex).setVariable("globalSubscriberId", CUST) - verify(mex).setVariable("globalCustomerId", CUST) - verify(mex).setVariable("disableRollback", "false") - verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb") - verify(mex).setVariable("subscriptionServiceType", SVC) - - verify(mex).setVariable("lcpCloudRegionId", "mdt1") - verify(mex).setVariable("cloudOwner", "my-cloud-owner") - verify(mex).setVariable("tenantId", "8b1df54faa3b49078e3416e21370a3ba") - assertEquals("""{"tenantId":"8b1df54faa3b49078e3416e21370a3ba","lcpCloudRegionId":"mdt1"}""", map.get("cloudConfiguration")) - verify(mex).setVariable("sdncVersion", "1707") - verify(mex).setVariable("GENGS_type", "service-instance") - assertTrue(map.containsKey(Prefix+"requestInfo")) - - def reqinfo = map.get(Prefix+"requestInfo") - println reqinfo - assertTrue(reqinfo.indexOf("mri= 0) - assertTrue(reqinfo.indexOf("VID= 0) - } - - @Test -// @Ignore - public void preProcessRequest_MissingServiceInstanceId() { - ExecutionEntity mex = setupMock() - initPreProcess(mex) - - when(mex.getVariable("serviceInstanceId")).thenReturn(null) - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - - assertTrue(doBpmnError( { _ -> DeleteVcpeResCustService.preProcessRequest(mex) })) - } - - @Test -// @Ignore - public void preProcessRequest_BpmnError() { - ExecutionEntity mex = setupMock() - initPreProcess(mex) - - when(mex.getVariable("bpmnRequest")).thenThrow(new BpmnError("expected exception")) - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - - assertTrue(doBpmnError( { _ -> DeleteVcpeResCustService.preProcessRequest(mex) })) - } - - @Test -// @Ignore - public void preProcessRequest_Ex() { - ExecutionEntity mex = setupMock() - initPreProcess(mex) - - when(mex.getVariable("bpmnRequest")).thenThrow(new RuntimeException("expected exception")) - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - - assertTrue(doBpmnError( { _ -> DeleteVcpeResCustService.preProcessRequest(mex) })) - } - - private void initPreProcess(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("bpmnRequest")).thenReturn(request) - when(mex.getVariable("mso-request-id")).thenReturn("mri") - when(mex.getVariable("serviceInstanceId")).thenReturn("sii") - when(mex.getVariable("requestAction")).thenReturn("ra") - } - - // ***** sendSyncResponse ***** - - @Test -// @Ignore - public void sendSyncResponse() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initSendSyncResponse(mex) - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - DeleteVcpeResCustService.sendSyncResponse(mex) - - verify(mex, times(2)).getVariable(DBGFLAG) - - verify(mex).setVariable(processName+"WorkflowResponseSent", "true") - - assertEquals("202", map.get(processName+"ResponseCode")) - assertEquals("Success", map.get(processName+"Status")) - - def resp = map.get(processName+"Response") - - assertTrue(resp.indexOf('"instanceId":"sii"') >= 0) - assertTrue(resp.indexOf('"requestId":"mri"') >= 0) - } - - @Test -// @Ignore - public void sendSyncResponse_Ex() { - ExecutionEntity mex = setupMock() - initSendSyncResponse(mex) - - when(mex.getVariable("serviceInstanceId")).thenThrow(new RuntimeException("expected exception")) - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - - assertTrue(doBpmnError( { _ -> DeleteVcpeResCustService.sendSyncResponse(mex) })) - } - - private initSendSyncResponse(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("mso-request-id")).thenReturn("mri") - when(mex.getVariable("serviceInstanceId")).thenReturn("sii") - } - - // ***** prepareServiceDelete ***** - - @Test -// @Ignore - public void prepareServiceDelete() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initPrepareServiceDelete(mex) - - myMockGetAr("/aai/v11/anytxc", 200, "arGetTXCById.xml"); - myMockGetAr("/aai/v11/anybrg", 200, "arGetBRGById.xml"); - myMockGetAr("/aai/v11/other", 200, "arGetOtherById.xml"); - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - DeleteVcpeResCustService.prepareServiceDelete(mex) - - verify(mex).setVariable(Prefix+"TunnelXConn", true) - assertEquals("ar-txcA", map.get("TXC_allottedResourceId")) - - verify(mex).setVariable(Prefix+"BRG", true) - assertEquals("ar-brgB", map.get("BRG_allottedResourceId")) - - verify(mex).setVariable(Prefix+"vnfsCount", 2) - assertNotNull(map.get(Prefix+"relatedVnfIdList")) - assertEquals("[vnfX, vnfY]", map.get(Prefix+"relatedVnfIdList").toString()) - - verify(mex, never()).setVariable(processName+"WorkflowResponseSent", "true") - } - - @Test -// @Ignore - public void prepareServiceDelete_NotFound() { - ExecutionEntity mex = setupMock() - initPrepareServiceDelete(mex) - - when(mex.getVariable("GENGS_FoundIndicator")).thenReturn(false) - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - - assertTrue(doBpmnError({ _ -> DeleteVcpeResCustService.prepareServiceDelete(mex) })) - - verify(mex, never()).setVariable(processName+"WorkflowResponseSent", "true") - } - - @Test -// @Ignore - public void prepareServiceDelete_Empty() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initPrepareServiceDelete(mex) - - when(mex.getVariable("GENGS_service")).thenReturn("") - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - DeleteVcpeResCustService.prepareServiceDelete(mex) - - verify(mex).getVariable(DBGFLAG) - - verify(mex).setVariable(Prefix+"TunnelXConn", false) - assertNull(map.get("TXC_allottedResourceId")) - - verify(mex).setVariable(Prefix+"BRG", false) - assertNull(map.get("BRG_allottedResourceId")) - - assertEquals(0, map.get(Prefix+"vnfsCount")) - assertFalse(map.containsKey(Prefix+"relatedVnfIdList")) - - verify(mex, never()).setVariable(processName+"WorkflowResponseSent", "true") - } - - @Test -// @Ignore - public void prepareServiceDelete_BpmnError() { - ExecutionEntity mex = setupMock() - initPrepareServiceDelete(mex) - - when(mex.getVariable("GENGS_FoundIndicator")).thenThrow(new BpmnError("expected exception")) - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - - assertTrue(doBpmnError({ _ -> DeleteVcpeResCustService.prepareServiceDelete(mex) })) - - verify(mex, never()).setVariable(processName+"WorkflowResponseSent", "true") - } - - @Test -// @Ignore - public void prepareServiceDelete_Ex() { - ExecutionEntity mex = setupMock() - initPrepareServiceDelete(mex) - - when(mex.getVariable("GENGS_FoundIndicator")).thenThrow(new RuntimeException("expected exception")) - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - - assertTrue(doBpmnError({ _ -> DeleteVcpeResCustService.prepareServiceDelete(mex) })) - - verify(mex).setVariable(processName+"WorkflowResponseSent", "true") - } - - private initPrepareServiceDelete(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("serviceInstanceId")).thenReturn("sii") - when(mex.getVariable("GENGS_FoundIndicator")).thenReturn(true) - when(mex.getVariable("mso-request-id")).thenReturn("mri") - when(mex.getVariable("DeleteVcpeResCustServiceRequest")).thenReturn(request) - when(mex.getVariable("URN_aai_endpoint")).thenReturn(aaiUriPfx) - when(mex.getVariable("GENGS_service")).thenReturn(FileUtil.readResourceFile("__files/VCPE/DeleteVcpeResCustService/serviceToDelete.xml")) - } - - // ***** getAaiAr ***** - - @Test -// @Ignore - public void getAaiAr() { - myMockGetAr("/myurl/ar1", 200, "arGetBRGById.xml"); - - ExecutionEntity mex = setupMock() - initGetAaiAr(mex) - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - def (type, id) = DeleteVcpeResCustService.getAaiAr(mex, "/myurl/ar1") - - assertEquals("BRG", type) - assertEquals("ar-brgB", id) - } - - @Test -// @Ignore - public void getAaiAr_401() { - myMockGetAr("/myurl/ar1", 401, "arGetBRGById.xml"); - - ExecutionEntity mex = setupMock() - initGetAaiAr(mex) - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - def (type, id) = DeleteVcpeResCustService.getAaiAr(mex, "/myurl/ar1") - - assertEquals(null, type) - assertEquals(null, id) - } - - @Test -// @Ignore - public void getAaiAr_EmptyResponse() { - myMockGetAr("/myurl/ar1", 200, "empty.txt"); - - ExecutionEntity mex = setupMock() - initGetAaiAr(mex) - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - def (type, id) = DeleteVcpeResCustService.getAaiAr(mex, "/myurl/ar1") - - assertEquals(null, type) - assertEquals(null, id) - } - - private void initGetAaiAr(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("URN_aai_endpoint")).thenReturn(aaiUriPfx) - } - - // ***** prepareVnfAndModulesDelete ***** - - @Test -// @Ignore - public void prepareVnfAndModulesDelete() { - ExecutionEntity mex = setupMock() - initPrepareVnfAndModulesDelete(mex) - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - DeleteVcpeResCustService.prepareVnfAndModulesDelete(mex) - - verify(mex).getVariable(DBGFLAG) - - verify(mex).setVariable("vnfId", "vnfB") - } - - @Test -// @Ignore - public void prepareVnfAndModulesDelete_Empty() { - ExecutionEntity mex = setupMock() - initPrepareVnfAndModulesDelete(mex) - - when(mex.getVariable(Prefix+"relatedVnfIdList")).thenReturn(new LinkedList()) - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - DeleteVcpeResCustService.prepareVnfAndModulesDelete(mex) - - verify(mex).getVariable(DBGFLAG) - - verify(mex).setVariable("vnfId", "") - } - - @Test -// @Ignore - public void prepareVnfAndModulesDelete_Ex() { - ExecutionEntity mex = setupMock() - initPrepareVnfAndModulesDelete(mex) - - when(mex.getVariable(Prefix+"relatedVnfIdList")).thenThrow(new RuntimeException("expected exception")) - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - - assertTrue(doBpmnError({ _ -> DeleteVcpeResCustService.prepareVnfAndModulesDelete(mex) })) - } - - private initPrepareVnfAndModulesDelete(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable(Prefix+"relatedVnfIdList")).thenReturn(Arrays.asList("vnfA", "vnfB", "vnfC")) - when(mex.getVariable(Prefix+"vnfsDeletedCount")).thenReturn(1) - } - - // ***** validateVnfDelete ***** - - @Test -// @Ignore - public void validateVnfDelete() { - ExecutionEntity mex = setupMock() - initValidateVnfDelete(mex) - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - DeleteVcpeResCustService.validateVnfDelete(mex) - - verify(mex).getVariable(DBGFLAG) - - verify(mex).setVariable(Prefix+"vnfsDeletedCount", 3) - } - - @Test -// @Ignore - public void validateVnfDelete_Ex() { - ExecutionEntity mex = setupMock() - initValidateVnfDelete(mex) - - when(mex.getVariable(Prefix+"vnfsDeletedCount")).thenThrow(new RuntimeException("expected exception")) - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - - assertTrue(doBpmnError({ _ -> DeleteVcpeResCustService.validateVnfDelete(mex) })) - } - - private initValidateVnfDelete(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable(Prefix+"vnfsDeletedCount")).thenReturn(2) - } - - // ***** postProcessResponse ***** - - @Test -// @Ignore - public void postProcessResponse() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initPostProcessResponse(mex) - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - DeleteVcpeResCustService.postProcessResponse(mex) - - verify(mex).getVariable(DBGFLAG) - - assertEquals(true, map.get(Prefix+"Success")) - - def req = map.get(Prefix+"CompleteMsoProcessRequest") - - assertTrue(req.indexOf("mri= 0) - assertTrue(req.indexOf("mysrc= 0) - } - - @Test -// @Ignore - public void postProcessResponse_BpmnError() { - ExecutionEntity mex = setupMock() - initPostProcessResponse(mex) - - when(mex.getVariable("source")).thenThrow(new BpmnError("expected exception")) - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - - assertTrue(doBpmnError( { _ -> DeleteVcpeResCustService.postProcessResponse(mex) })) - } - - @Test -// @Ignore - public void postProcessResponse_Ex() { - ExecutionEntity mex = setupMock() - initPostProcessResponse(mex) - - when(mex.getVariable("source")).thenThrow(new RuntimeException("expected exception")) - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - - assertTrue(doBpmnError( { _ -> DeleteVcpeResCustService.postProcessResponse(mex) })) - } - - private initPostProcessResponse(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("source")).thenReturn("mysrc") - when(mex.getVariable("msoRequestId")).thenReturn("mri") - } - - - // ***** prepareFalloutRequest ***** - - @Test -// @Ignore - public void prepareFalloutRequest() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initPrepareFalloutRequest(mex) - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - DeleteVcpeResCustService.prepareFalloutRequest(mex) - - verify(mex, times(2)).getVariable(DBGFLAG) - - def fo = map.get(Prefix+"falloutRequest") - - assertTrue(fo.indexOf("world= 0) - assertTrue(fo.indexOf("ErrorMessage>mymsg= 0) - assertTrue(fo.indexOf("ErrorCode>999= 0) - } - - @Test -// @Ignore - public void prepareFalloutRequest_Ex() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initPrepareFalloutRequest(mex) - - when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception")) - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - - assertTrue(doBpmnError( { _ -> DeleteVcpeResCustService.prepareFalloutRequest(mex) })) - } - - private initPrepareFalloutRequest(ExecutionEntity mex) { - WorkflowException wfe = mock(WorkflowException.class) - - when(wfe.getErrorMessage()).thenReturn("mymsg") - when(wfe.getErrorCode()).thenReturn(999) - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("WorkflowException")).thenReturn(wfe) - when(mex.getVariable(Prefix+"requestInfo")).thenReturn("world") - - return wfe - } - - // ***** sendSyncError ***** - - @Test -// @Ignore - public void sendSyncError() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initSendSyncError(mex) - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - DeleteVcpeResCustService.sendSyncError(mex) - - verify(mex, times(2)).getVariable(DBGFLAG) - - verify(mex).setVariable(processName+"WorkflowResponseSent", "true") - - assertEquals("500", map.get(processName+"ResponseCode")) - assertEquals("Fail", map.get(processName+"Status")) - - def resp = map.get(processName+"Response") - - assertTrue(resp.indexOf("ErrorMessage>mymsg= 0) - - verify(mex).setVariable("WorkflowResponse", resp) - } - - @Test -// @Ignore - public void sendSyncError_NotWfe() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initSendSyncError(mex) - - when(mex.getVariable("WorkflowException")).thenReturn("not a WFE") - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - DeleteVcpeResCustService.sendSyncError(mex) - - verify(mex, times(2)).getVariable(DBGFLAG) - - verify(mex).setVariable(processName+"WorkflowResponseSent", "true") - - assertEquals("500", map.get(processName+"ResponseCode")) - assertEquals("Fail", map.get(processName+"Status")) - - def resp = map.get(processName+"Response") - - assertTrue(resp.indexOf("ErrorMessage>Sending Sync Error.= 0) - - verify(mex).setVariable("WorkflowResponse", resp) - } - - @Test -// @Ignore - public void sendSyncError_NullWfe() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initSendSyncError(mex) - - when(mex.getVariable("WorkflowException")).thenReturn(null) - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - DeleteVcpeResCustService.sendSyncError(mex) - - verify(mex, times(2)).getVariable(DBGFLAG) - - verify(mex).setVariable(processName+"WorkflowResponseSent", "true") - - assertEquals("500", map.get(processName+"ResponseCode")) - assertEquals("Fail", map.get(processName+"Status")) - - def resp = map.get(processName+"Response") - - assertTrue(resp.indexOf("ErrorMessage>Sending Sync Error.= 0) - - verify(mex).setVariable("WorkflowResponse", resp) - } - - @Test -// @Ignore - public void sendSyncError_Ex() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initSendSyncError(mex) - - when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception")) - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - - DeleteVcpeResCustService.sendSyncError(mex) - - assertFalse(map.containsKey(processName+"ResponseCode")) - } - - private initSendSyncError(ExecutionEntity mex) { - WorkflowException wfe = mock(WorkflowException.class) - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("mso-request-id")).thenReturn("mri") - when(mex.getVariable("WorkflowException")).thenReturn(wfe) - - when(wfe.getErrorMessage()).thenReturn("mymsg") - } - - - // ***** processJavaException ***** - - @Test -// @Ignore - public void processJavaException() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initProcessJavaException(mex) - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - - assertTrue(doBpmnError( { _ -> DeleteVcpeResCustService.processJavaException(mex) })) - - verify(mex, times(2)).getVariable(DBGFLAG) - - verify(mex).setVariable("prefix", Prefix) - - def wfe = map.get("WorkflowException") - - assertEquals("Caught a Java Lang Exception", wfe.getErrorMessage()) - } - - @Test -// @Ignore - public void processJavaException_BpmnError() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initProcessJavaException(mex) - - when(mex.getVariables()).thenThrow(new BpmnError("expected exception")) - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - - assertTrue(doBpmnError( { _ -> DeleteVcpeResCustService.processJavaException(mex) })) - - assertFalse(map.containsKey("WorkflowException")) - } - - @Test -// @Ignore - public void processJavaException_Ex() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initProcessJavaException(mex) - - when(mex.getVariables()).thenThrow(new RuntimeException("expected exception")) - - DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() - - assertTrue(doBpmnError( { _ -> DeleteVcpeResCustService.processJavaException(mex) })) - - def wfe = map.get("WorkflowException") - - assertEquals("Exception in processJavaException method", wfe.getErrorMessage()) - } - - private initProcessJavaException(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - } - - private void myMockGetAr(String url, int status, String fileResp) { - stubFor(get(urlMatching(url)) - .willReturn(aResponse() - .withStatus(status) - .withHeader("Content-Type", "text/xml") - .withBodyFile("VCPE/DeleteVcpeResCustService/" + fileResp))); - } -} + public void init() { + MockitoAnnotations.initMocks(this) + } + + public DeleteVcpeResCustServiceTest() { + super("DeleteVcpeResCustService") + } + + // ***** preProcessRequest ***** + + @Test + public void preProcessRequest() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initPreProcess(mex) + + DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() + DeleteVcpeResCustService.preProcessRequest(mex) + + verify(mex).getVariable(DBGFLAG) + + assertEquals(Prefix, map.get("prefix")) + assertEquals(request, map.get("DeleteVcpeResCustServiceRequest")) + assertEquals("mri", map.get("msoRequestId")) + assertEquals("ra", map.get("requestAction")) + assertEquals("VID", map.get("source")) + assertEquals(CUST, map.get("globalSubscriberId")) + assertEquals(CUST, map.get("globalCustomerId")) + assertEquals("false", map.get("disableRollback")) + assertEquals("a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", map.get("productFamilyId")) + assertEquals(SVC, map.get("subscriptionServiceType")) + + assertEquals("mdt1", map.get("lcpCloudRegionId")) + assertEquals("8b1df54faa3b49078e3416e21370a3ba", map.get("tenantId")) + assertEquals("1707", map.get("sdncVersion")) + assertEquals( + """{"cloudOwner":"CloudOwner","tenantId":"8b1df54faa3b49078e3416e21370a3ba","lcpCloudRegionId":"mdt1"}""", + map.get("cloudConfiguration") + ) + assertTrue(map.containsKey(Prefix + "requestInfo")) + + def reqinfo = map.get(Prefix + "requestInfo") + assertTrue(reqinfo.indexOf("mri= 0) + assertTrue(reqinfo.indexOf("VID= 0) + } + + @Test + public void preProcessRequest_EmptyParts() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initPreProcess(mex) + + def req = request + .replace('"source"', '"sourceXXX"') + + when(mex.getVariable("bpmnRequest")).thenReturn(req) + + DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() + DeleteVcpeResCustService.preProcessRequest(mex) + + verify(mex).getVariable(DBGFLAG) + verify(mex).setVariable("prefix", Prefix) + verify(mex).setVariable("DeleteVcpeResCustServiceRequest", req) + verify(mex).setVariable("msoRequestId", "mri") + verify(mex).setVariable("requestAction", "ra") + verify(mex).setVariable("source", "VID") + verify(mex).setVariable("globalSubscriberId", CUST) + verify(mex).setVariable("globalCustomerId", CUST) + verify(mex).setVariable("disableRollback", "false") + verify(mex).setVariable("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb") + verify(mex).setVariable("subscriptionServiceType", SVC) + + verify(mex).setVariable("lcpCloudRegionId", "mdt1") + verify(mex).setVariable("cloudOwner", "CloudOwner") + verify(mex).setVariable("tenantId", "8b1df54faa3b49078e3416e21370a3ba") + assertEquals( + """{"cloudOwner":"CloudOwner","tenantId":"8b1df54faa3b49078e3416e21370a3ba","lcpCloudRegionId":"mdt1"}""", + map.get("cloudConfiguration") + ) + verify(mex).setVariable("sdncVersion", "1707") + assertTrue(map.containsKey(Prefix + "requestInfo")) + + def reqinfo = map.get(Prefix + "requestInfo") + println reqinfo + assertTrue(reqinfo.indexOf("mri= 0) + assertTrue(reqinfo.indexOf("VID= 0) + } + + @Test + public void preProcessRequest_MissingServiceInstanceId() { + ExecutionEntity mex = setupMock() + initPreProcess(mex) + + when(mex.getVariable("serviceInstanceId")).thenReturn(null) + + DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() + + assertTrue(doBpmnError({ _ -> DeleteVcpeResCustService.preProcessRequest(mex) })) + } + + @Test + public void preProcessRequest_BpmnError() { + ExecutionEntity mex = setupMock() + initPreProcess(mex) + + when(mex.getVariable("bpmnRequest")).thenThrow(new BpmnError("expected exception")) + + DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() + + assertTrue(doBpmnError({ _ -> DeleteVcpeResCustService.preProcessRequest(mex) })) + } + + @Test + public void preProcessRequest_Ex() { + ExecutionEntity mex = setupMock() + initPreProcess(mex) + + when(mex.getVariable("bpmnRequest")).thenThrow(new RuntimeException("expected exception")) + + DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() + + assertTrue(doBpmnError({ _ -> DeleteVcpeResCustService.preProcessRequest(mex) })) + } + + private void initPreProcess(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("bpmnRequest")).thenReturn(request) + when(mex.getVariable("mso-request-id")).thenReturn("mri") + when(mex.getVariable("serviceInstanceId")).thenReturn("sii") + when(mex.getVariable("requestAction")).thenReturn("ra") + } + + // ***** sendSyncResponse ***** + + @Test + public void sendSyncResponse() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initSendSyncResponse(mex) + + DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() + DeleteVcpeResCustService.sendSyncResponse(mex) + + verify(mex, times(2)).getVariable(DBGFLAG) + + verify(mex).setVariable(processName + "WorkflowResponseSent", "true") + + assertEquals("202", map.get(processName + "ResponseCode")) + assertEquals("Success", map.get(processName + "Status")) + + def resp = map.get(processName + "Response") + + assertTrue(resp.indexOf('"instanceId":"sii"') >= 0) + assertTrue(resp.indexOf('"requestId":"mri"') >= 0) + } + + @Test + public void sendSyncResponse_Ex() { + ExecutionEntity mex = setupMock() + initSendSyncResponse(mex) + + when(mex.getVariable("serviceInstanceId")).thenThrow(new RuntimeException("expected exception")) + + DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() + + assertTrue(doBpmnError({ _ -> DeleteVcpeResCustService.sendSyncResponse(mex) })) + } + + private initSendSyncResponse(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("mso-request-id")).thenReturn("mri") + when(mex.getVariable("serviceInstanceId")).thenReturn("sii") + } + + // ***** prepareVnfAndModulesDelete ***** + + @Test + public void prepareVnfAndModulesDelete() { + ExecutionEntity mex = setupMock() + initPrepareVnfAndModulesDelete(mex) + + DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() + DeleteVcpeResCustService.prepareVnfAndModulesDelete(mex) + + verify(mex).getVariable(DBGFLAG) + + verify(mex).setVariable("vnfId", "vnfB") + } + + @Test + public void prepareVnfAndModulesDelete_Empty() { + ExecutionEntity mex = setupMock() + initPrepareVnfAndModulesDelete(mex) + + when(mex.getVariable(Prefix + "relatedVnfIdList")).thenReturn(new LinkedList()) + + DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() + DeleteVcpeResCustService.prepareVnfAndModulesDelete(mex) + + verify(mex).getVariable(DBGFLAG) + + verify(mex).setVariable("vnfId", "") + } + + @Test + public void prepareVnfAndModulesDelete_Ex() { + ExecutionEntity mex = setupMock() + initPrepareVnfAndModulesDelete(mex) + + when(mex.getVariable(Prefix + "relatedVnfIdList")).thenThrow(new RuntimeException("expected exception")) + + DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() + + assertTrue(doBpmnError({ _ -> DeleteVcpeResCustService.prepareVnfAndModulesDelete(mex) })) + } + + private initPrepareVnfAndModulesDelete(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable(Prefix + "relatedVnfIdList")).thenReturn(Arrays.asList("vnfA", "vnfB", "vnfC")) + when(mex.getVariable(Prefix + "vnfsDeletedCount")).thenReturn(1) + } + + // ***** validateVnfDelete ***** + + @Test + public void validateVnfDelete() { + ExecutionEntity mex = setupMock() + initValidateVnfDelete(mex) + + DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() + DeleteVcpeResCustService.validateVnfDelete(mex) + + verify(mex).getVariable(DBGFLAG) + + verify(mex).setVariable(Prefix + "vnfsDeletedCount", 3) + } + + @Test + public void validateVnfDelete_Ex() { + ExecutionEntity mex = setupMock() + initValidateVnfDelete(mex) + + when(mex.getVariable(Prefix + "vnfsDeletedCount")).thenThrow(new RuntimeException("expected exception")) + + DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() + + assertTrue(doBpmnError({ _ -> DeleteVcpeResCustService.validateVnfDelete(mex) })) + } + + private initValidateVnfDelete(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable(Prefix + "vnfsDeletedCount")).thenReturn(2) + } + + // ***** postProcessResponse ***** + + @Test + public void postProcessResponse() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initPostProcessResponse(mex) + + DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() + DeleteVcpeResCustService.postProcessResponse(mex) + + verify(mex).getVariable(DBGFLAG) + + verify(mex).setVariable(Prefix + "Success", true) + + def req = map.get(Prefix + "CompleteMsoProcessRequest") + + assertTrue(req.indexOf("mri= 0) + assertTrue(req.indexOf("mysrc= 0) + } + + @Test + public void postProcessResponse_BpmnError() { + ExecutionEntity mex = setupMock() + initPostProcessResponse(mex) + + when(mex.getVariable("source")).thenThrow(new BpmnError("expected exception")) + + DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() + + assertTrue(doBpmnError({ _ -> DeleteVcpeResCustService.postProcessResponse(mex) })) + } + + @Test + public void postProcessResponse_Ex() { + ExecutionEntity mex = setupMock() + initPostProcessResponse(mex) + + when(mex.getVariable("source")).thenThrow(new RuntimeException("expected exception")) + + DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() + + assertTrue(doBpmnError({ _ -> DeleteVcpeResCustService.postProcessResponse(mex) })) + } + + private initPostProcessResponse(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("source")).thenReturn("mysrc") + when(mex.getVariable("msoRequestId")).thenReturn("mri") + } + + // ***** prepareFalloutRequest ***** + + @Test + public void prepareFalloutRequest() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + WorkflowException wfe = initPrepareFalloutRequest(mex) + when(wfe.getErrorMessage()).thenReturn("mymsg") + when(wfe.getErrorCode()).thenReturn(999) + + DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() + DeleteVcpeResCustService.prepareFalloutRequest(mex) + + verify(mex).getVariable(DBGFLAG) + verify(mex, times(4)).getVariable("WorkflowException") + verify(mex).getVariable(Prefix + "requestInfo") + + def fo = map.get(Prefix + "falloutRequest") + + assertTrue(fo.indexOf("world= 0) + assertTrue(fo.indexOf("ErrorMessage>mymsg= 0) + assertTrue(fo.indexOf("ErrorCode>999= 0) + } + + @Test + public void prepareFalloutRequest_Ex() { + ExecutionEntity mex = setupMock() + setupMap(mex) + initPrepareFalloutRequest(mex) + + when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception")) + + DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() + + assertTrue(doBpmnError({ _ -> DeleteVcpeResCustService.prepareFalloutRequest(mex) })) + } + + private initPrepareFalloutRequest(ExecutionEntity mex) { + WorkflowException wfe = mock(WorkflowException.class) + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("WorkflowException")).thenReturn(wfe) + when(mex.getVariable(Prefix + "requestInfo")).thenReturn("world") + + return wfe + } + + // ***** sendSyncError ***** + + @Test + public void sendSyncError() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initSendSyncError(mex) + + DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() + DeleteVcpeResCustService.sendSyncError(mex) + + verify(mex, times(2)).getVariable(DBGFLAG) + + verify(mex).setVariable(processName + "WorkflowResponseSent", "true") + + assertEquals("500", map.get(processName + "ResponseCode")) + assertEquals("Fail", map.get(processName + "Status")) + + def resp = map.get(processName + "Response") + + assertTrue(resp.indexOf("ErrorMessage>mymsg= 0) + + verify(mex).setVariable("WorkflowResponse", resp) + } + + @Test + public void sendSyncError_NotWfe() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initSendSyncError(mex) + + when(mex.getVariable("WorkflowException")).thenReturn("not a WFE") + + DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() + DeleteVcpeResCustService.sendSyncError(mex) + + verify(mex, times(2)).getVariable(DBGFLAG) + verify(mex, times(2)).getProcessEngineServices() + verify(mex, times(2)).getProcessDefinitionId() + + verify(mex).setVariable(processName + "WorkflowResponseSent", "true") + + assertEquals("500", map.get(processName + "ResponseCode")) + assertEquals("Fail", map.get(processName + "Status")) + + def resp = map.get(processName + "Response") + + assertTrue(resp.indexOf("ErrorMessage>Sending Sync Error.= 0) + + verify(mex).setVariable("WorkflowResponse", resp) + } + + @Test + public void sendSyncError_NullWfe() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initSendSyncError(mex) + + when(mex.getVariable("WorkflowException")).thenReturn(null) + + DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() + DeleteVcpeResCustService.sendSyncError(mex) + + verify(mex, times(2)).getVariable(DBGFLAG) + + verify(mex).setVariable(processName + "WorkflowResponseSent", "true") + + assertEquals("500", map.get(processName + "ResponseCode")) + assertEquals("Fail", map.get(processName + "Status")) + + def resp = map.get(processName + "Response") + + assertTrue(resp.indexOf("ErrorMessage>Sending Sync Error.= 0) + + verify(mex).setVariable("WorkflowResponse", resp) + } + + @Test + public void sendSyncError_Ex() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initSendSyncError(mex) + + when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception")) + + DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() + + DeleteVcpeResCustService.sendSyncError(mex) + + assertFalse(map.containsKey(processName + "ResponseCode")) + } + + private initSendSyncError(ExecutionEntity mex) { + WorkflowException wfe = mock(WorkflowException.class) + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("mso-request-id")).thenReturn("mri") + when(mex.getVariable("WorkflowException")).thenReturn(wfe) + + when(wfe.getErrorMessage()).thenReturn("mymsg") + } + + // ***** processJavaException ***** + + @Test + public void processJavaException() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initProcessJavaException(mex) + + DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() + + assertTrue(doBpmnError({ _ -> DeleteVcpeResCustService.processJavaException(mex) })) + + verify(mex).getVariable(DBGFLAG) + + verify(mex).setVariable("prefix", Prefix) + + def wfe = map.get("WorkflowException") + + assertEquals("Caught a Java Lang Exception", wfe.getErrorMessage()) + } + + @Test + public void processJavaException_BpmnError() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initProcessJavaException(mex) + + when(mex.getVariables()).thenThrow(new BpmnError("expected exception")) + + DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() + + assertTrue(doBpmnError({ _ -> DeleteVcpeResCustService.processJavaException(mex) })) + + assertFalse(map.containsKey("WorkflowException")) + } + + @Test + public void processJavaException_Ex() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initProcessJavaException(mex) + + when(mex.getVariables()).thenThrow(new RuntimeException("expected exception")) + + DeleteVcpeResCustService DeleteVcpeResCustService = new DeleteVcpeResCustService() + + assertTrue(doBpmnError({ _ -> DeleteVcpeResCustService.processJavaException(mex) })) + + def wfe = map.get("WorkflowException") + + assertEquals("Exception in processJavaException method", wfe.getErrorMessage()) + } + + private initProcessJavaException(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + } +} \ No newline at end of file diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/DoCreateAllottedResourceBRGRollbackTest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/DoCreateAllottedResourceBRGRollbackTest.groovy index 7982e4dd4b..41a862e00e 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/DoCreateAllottedResourceBRGRollbackTest.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/DoCreateAllottedResourceBRGRollbackTest.groovy @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -20,635 +22,577 @@ package org.onap.so.bpmn.vcpe.scripts - -import org.camunda.bpm.engine.ProcessEngineServices -import org.camunda.bpm.engine.RepositoryService +import com.github.tomakehurst.wiremock.junit.WireMockRule +import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity -import org.camunda.bpm.engine.repository.ProcessDefinition -import org.camunda.bpm.engine.delegate.DelegateExecution -import org.junit.Before -import org.junit.BeforeClass -import org.junit.Rule -import org.junit.Test -import org.junit.Ignore +import org.junit.* import org.mockito.MockitoAnnotations -import org.camunda.bpm.engine.delegate.BpmnError -import org.onap.so.bpmn.core.WorkflowException -import org.onap.so.bpmn.mock.FileUtil +import org.onap.so.bpmn.core.RollbackData import static com.github.tomakehurst.wiremock.client.WireMock.aResponse import static com.github.tomakehurst.wiremock.client.WireMock.get -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching -import static org.junit.Assert.*; +import static org.junit.Assert.assertTrue import static org.mockito.Mockito.* -import static org.onap.so.bpmn.mock.StubResponseAAI.MockDeleteAllottedResource -import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetAllottedResource -import static org.onap.so.bpmn.mock.StubResponseAAI.MockPatchAllottedResource +import static org.onap.so.bpmn.mock.StubResponseAAI.* -import org.onap.so.bpmn.core.RollbackData +class DoCreateAllottedResourceBRGRollbackTest extends GroovyTestBase { -import com.github.tomakehurst.wiremock.junit.WireMockRule + @Rule + public WireMockRule wireMockRule = new WireMockRule(PORT) + + String Prefix = "DCARBRGRB_" + String RbType = "DCARBRG_" + + @BeforeClass + public static void setUpBeforeClass() { + GroovyTestBase.setUpBeforeClass() + } -class DoCreateAllottedResourceBRGRollbackTest extends GroovyTestBase { - - @Rule - public WireMockRule wireMockRule = new WireMockRule(PORT) - - String Prefix = "DCARBRGRB_" - String RbType = "DCARBRG_" - - @BeforeClass - public static void setUpBeforeClass() { - super.setUpBeforeClass() - } - @Before - public void init() - { - MockitoAnnotations.initMocks(this) - } - - public DoCreateAllottedResourceBRGRollbackTest() { - super("DoCreateAllottedResourceBRGRollback") - } - - - // ***** preProcessRequest ***** - - @Test -// @Ignore - public void preProcessRequest() { - ExecutionEntity mex = setupMock() - initPreProcess(mex) - - DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() - DoCreateAllottedResourceBRGRollback.preProcessRequest(mex) - - ////verify(mex).getVariable(DBGFLAG) - verify(mex).setVariable("prefix", Prefix) - verify(mex).setVariable("serviceInstanceId", "sii") - verify(mex).setVariable("parentServiceInstanceId", "psii") - verify(mex).setVariable("allottedResourceId", "myid") - verify(mex).setVariable("rollbackAAI", true) - verify(mex).setVariable("aaiARPath", "mypath") - verify(mex).setVariable("rollbackSDNC", true) - verify(mex).setVariable("deactivateSdnc", "myactivate") - verify(mex).setVariable("deleteSdnc", "mycreate") - verify(mex).setVariable("unassignSdnc", "true") - verify(mex).setVariable("sdncDeactivateRequest", "activatereq") - verify(mex).setVariable("sdncDeleteRequest", "createreq") - verify(mex).setVariable("sdncUnassignRequest", "assignreq") - - verify(mex, never()).setVariable("skipRollback", true) - } - - @Test -// @Ignore - public void preProcessRequest_RollbackDisabled() { - ExecutionEntity mex = setupMock() - initPreProcess(mex) - - when(mex.getVariable("disableRollback")).thenReturn("true") - - DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() - DoCreateAllottedResourceBRGRollback.preProcessRequest(mex) - - ////verify(mex).getVariable(DBGFLAG) - verify(mex).setVariable("prefix", Prefix) - verify(mex).setVariable("serviceInstanceId", "sii") - verify(mex).setVariable("parentServiceInstanceId", "psii") - verify(mex).setVariable("allottedResourceId", "myid") - verify(mex).setVariable("rollbackAAI", true) - verify(mex).setVariable("aaiARPath", "mypath") - verify(mex).setVariable("rollbackSDNC", true) - verify(mex).setVariable("deactivateSdnc", "myactivate") - verify(mex).setVariable("deleteSdnc", "mycreate") - verify(mex).setVariable("unassignSdnc", "true") - verify(mex).setVariable("sdncDeactivateRequest", "activatereq") - verify(mex).setVariable("sdncDeleteRequest", "createreq") - verify(mex).setVariable("sdncUnassignRequest", "assignreq") - - verify(mex).setVariable("skipRollback", true) - } - - @Test -// @Ignore - public void preProcessRequest_NoAAI() { - ExecutionEntity mex = setupMock() - def data = initPreProcess(mex) - - when(mex.getVariable("rollbackAAI")).thenReturn(false) - data.put(RbType, "rollbackAAI", "false") - - DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() - DoCreateAllottedResourceBRGRollback.preProcessRequest(mex) - - //verify(mex).getVariable(DBGFLAG) - verify(mex).setVariable("prefix", Prefix) - verify(mex).setVariable("serviceInstanceId", "sii") - verify(mex).setVariable("parentServiceInstanceId", "psii") - verify(mex).setVariable("allottedResourceId", "myid") - verify(mex, never()).setVariable("rollbackAAI", true) - verify(mex, never()).setVariable("aaiARPath", "mypath") - verify(mex).setVariable("rollbackSDNC", true) - verify(mex).setVariable("deactivateSdnc", "myactivate") - verify(mex).setVariable("deleteSdnc", "mycreate") - verify(mex).setVariable("unassignSdnc", "true") - verify(mex).setVariable("sdncDeactivateRequest", "activatereq") - verify(mex).setVariable("sdncDeleteRequest", "createreq") - verify(mex).setVariable("sdncUnassignRequest", "assignreq") - - verify(mex, never()).setVariable("skipRollback", true) - } - - @Test -// @Ignore - public void preProcessRequest_NoAssign() { - ExecutionEntity mex = setupMock() - def data = initPreProcess(mex) - - when(mex.getVariable("rollbackSDNC")).thenReturn(false) - data.put(RbType, "rollbackSDNCassign", "false") - - DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() - DoCreateAllottedResourceBRGRollback.preProcessRequest(mex) - - //verify(mex).getVariable(DBGFLAG) - verify(mex).setVariable("prefix", Prefix) - verify(mex).setVariable("serviceInstanceId", "sii") - verify(mex).setVariable("parentServiceInstanceId", "psii") - verify(mex).setVariable("allottedResourceId", "myid") - verify(mex).setVariable("rollbackAAI", true) - verify(mex).setVariable("aaiARPath", "mypath") - verify(mex, never()).setVariable("rollbackSDNC", true) - verify(mex, never()).setVariable("deactivateSdnc", "myactivate") - verify(mex, never()).setVariable("deleteSdnc", "mycreate") - verify(mex, never()).setVariable("unassignSdnc", "true") - verify(mex, never()).setVariable("sdncDeactivateRequest", "activatereq") - verify(mex, never()).setVariable("sdncDeleteRequest", "createreq") - verify(mex, never()).setVariable("sdncUnassignRequest", "assignreq") - - verify(mex, never()).setVariable("skipRollback", true) - } - - @Test -// @Ignore - public void preProcessRequest_NoAAI_NoAssign() { - ExecutionEntity mex = setupMock() - initPreProcess(mex) - - when(mex.getVariable("rollbackAAI")).thenReturn(false) - when(mex.getVariable("rollbackSDNC")).thenReturn(false) - - DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() - DoCreateAllottedResourceBRGRollback.preProcessRequest(mex) - - verify(mex).setVariable("skipRollback", true) - } - - @Test -// @Ignore - public void preProcessRequest_NoRbStructure() { - ExecutionEntity mex = setupMock() - initPreProcess(mex) - - when(mex.getVariable("rollbackData")).thenReturn(new RollbackData()) - - DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() - DoCreateAllottedResourceBRGRollback.preProcessRequest(mex) - - verify(mex).setVariable("skipRollback", true) - } - - @Test -// @Ignore - public void preProcessRequest_NullRb() { - ExecutionEntity mex = setupMock() - initPreProcess(mex) - - when(mex.getVariable("rollbackData")).thenReturn(null) - - DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() - DoCreateAllottedResourceBRGRollback.preProcessRequest(mex) - - verify(mex).setVariable("skipRollback", true) - } - - @Test -// @Ignore - public void preProcessRequest_BpmnError() { - ExecutionEntity mex = setupMock() - initPreProcess(mex) - - when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception")) - - DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() - - assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceBRGRollback.preProcessRequest(mex) })) - } - - @Test -// @Ignore - public void preProcessRequest_Ex() { - ExecutionEntity mex = setupMock() - initPreProcess(mex) - - when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception")) - - DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() - - assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceBRGRollback.preProcessRequest(mex) })) - } - - @Test - @Ignore - public void updateAaiAROrchStatus() { - ExecutionEntity mex = setupMock() - initUpdateAaiAROrchStatus(mex) - - MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRGRollback/arGetById.xml") - MockPatchAllottedResource(CUST, SVC, INST, ARID) - - DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() - DoCreateAllottedResourceBRGRollback.updateAaiAROrchStatus(mex, "success") - } - - @Test -// @Ignore - public void updateAaiAROrchStatus_EmptyResponse() { - ExecutionEntity mex = setupMock() - initUpdateAaiAROrchStatus(mex) - - wireMockRule - .stubFor(get(urlMatching("/aai/v[0-9]+/.*")) - .willReturn(aResponse() - .withStatus(200))) - - DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() - - assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceBRGRollback.updateAaiAROrchStatus(mex, "success") })) - } - - @Test -// @Ignore - public void updateAaiAROrchStatus_NoArPath() { - ExecutionEntity mex = setupMock() - initUpdateAaiAROrchStatus(mex) - - MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRGRollback/arGetById.xml") - MockPatchAllottedResource(CUST, SVC, INST, ARID) - - when(mex.getVariable("aaiARPath")).thenReturn(null) - - DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() - - assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceBRGRollback.updateAaiAROrchStatus(mex, "success") })) - } - - - // ***** validateSDNCResp ***** - - @Test -// @Ignore - public void validateSDNCResp() { - ExecutionEntity mex = setupMock() - initValidateSDNCResp(mex) - def resp = initValidateSDNCResp_Resp() - - when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true) - - DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() - - DoCreateAllottedResourceBRGRollback.validateSDNCResp(mex, resp, "create") - - verify(mex).getVariable("WorkflowException") - verify(mex).getVariable("SDNCA_SuccessIndicator") - } - - @Test -// @Ignore - public void validateSDNCResp_Unsuccessful() { - ExecutionEntity mex = setupMock() - initValidateSDNCResp(mex) - def resp = initValidateSDNCResp_Resp() - - when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(false) - - DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() - - assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceBRGRollback.validateSDNCResp(mex, resp, "create") })) - } - - @Test -// @Ignore - public void validateSDNCResp_BpmnError404() { - ExecutionEntity mex = setupMock() - initValidateSDNCResp(mex) - def resp = initValidateSDNCResp_Resp() - when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true) - - when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("404", "expected exception")) - - DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() - - DoCreateAllottedResourceBRGRollback.validateSDNCResp(mex, resp, "create") - } - - @Test -// @Ignore - public void validateSDNCResp_BpmnError() { - ExecutionEntity mex = setupMock() - initValidateSDNCResp(mex) - def resp = initValidateSDNCResp_Resp() - when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true) - - when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception")) - - DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() - - assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceBRGRollback.validateSDNCResp(mex, resp, "create") })) - } - - @Test -// @Ignore - public void validateSDNCResp_Ex() { - ExecutionEntity mex = setupMock() - initValidateSDNCResp(mex) - def resp = initValidateSDNCResp_Resp() - when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true) - - when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception")) - - DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() - - assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceBRGRollback.validateSDNCResp(mex, resp, "create") })) - } - - @Test - @Ignore - public void deleteAaiAR() { - ExecutionEntity mex = setupMock() - initDeleteAaiAR(mex) - - MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRGRollback/arGetById.xml") - MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) - - DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() - DoCreateAllottedResourceBRGRollback.deleteAaiAR(mex) - } - - @Test -// @Ignore - public void deleteAaiAR_NoArPath() { - ExecutionEntity mex = setupMock() - initDeleteAaiAR(mex) - - MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRGRollback/arGetById.xml") - MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) - - when(mex.getVariable("aaiARPath")).thenReturn("") - - DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() - - assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceBRGRollback.deleteAaiAR(mex) })) - } - - @Test -// @Ignore - public void deleteAaiAR_BpmnError() { - ExecutionEntity mex = setupMock() - initDeleteAaiAR(mex) - - MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRGRollback/arGetById.xml") - MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) - - when(mex.getVariable("aaiARPath")).thenThrow(new BpmnError("expected exception")) - - DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() - - assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceBRGRollback.deleteAaiAR(mex) })) - } - - @Test -// @Ignore - public void deleteAaiAR_Ex() { - ExecutionEntity mex = setupMock() - initDeleteAaiAR(mex) - - MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRGRollback/arGetById.xml") - MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) - - when(mex.getVariable("aaiARPath")).thenThrow(new RuntimeException("expected exception")) - - DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() - - assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceBRGRollback.deleteAaiAR(mex) })) - } - - @Test -// @Ignore - public void postProcessRequest() { - ExecutionEntity mex = setupMock() - initPostProcessRequest(mex) - - DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() - DoCreateAllottedResourceBRGRollback.postProcessRequest(mex) - - //verify(mex).getVariable(DBGFLAG) - verify(mex).setVariable("rollbackData", null) - verify(mex).setVariable("rolledBack", true) - } - - @Test -// @Ignore - public void postProcessRequest_RolledBack() { - ExecutionEntity mex = setupMock() - initPostProcessRequest(mex) - - when(mex.getVariable("skipRollback")).thenReturn(true) - - DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() - DoCreateAllottedResourceBRGRollback.postProcessRequest(mex) - - //verify(mex).getVariable(DBGFLAG) - verify(mex).setVariable("rollbackData", null) - verify(mex, never()).setVariable("rolledBack", true) - } - - @Test -// @Ignore - public void postProcessRequest_BpmnError() { - ExecutionEntity mex = setupMock() - initPostProcessRequest(mex) - - when(mex.getVariable("skipRollback")).thenThrow(new BpmnError("expected exception")) - - DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() - DoCreateAllottedResourceBRGRollback.postProcessRequest(mex) - - //verify(mex).getVariable(DBGFLAG) - verify(mex).setVariable("rollbackData", null) - verify(mex, never()).setVariable("rolledBack", true) - } - - @Test -// @Ignore - public void postProcessRequest_Ex() { - ExecutionEntity mex = setupMock() - initPostProcessRequest(mex) - - when(mex.getVariable("skipRollback")).thenThrow(new RuntimeException("expected exception")) - - DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() - DoCreateAllottedResourceBRGRollback.postProcessRequest(mex) - - //verify(mex).getVariable(DBGFLAG) - verify(mex).setVariable("rollbackData", null) - verify(mex, never()).setVariable("rolledBack", true) - } - - @Test -// @Ignore - public void processRollbackException() { - ExecutionEntity mex = setupMock() - initProcessRollbackException(mex) - - DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() - DoCreateAllottedResourceBRGRollback.processRollbackException(mex) - - //verify(mex).getVariable(DBGFLAG) - verify(mex).setVariable("rollbackData", null) - verify(mex).setVariable("rolledBack", false) - verify(mex).setVariable("rollbackError", "Caught exception in AllottedResource Create Rollback") - verify(mex).setVariable("WorkflowException", null) - } - - @Test -// @Ignore - public void processRollbackException_BpmnError() { - ExecutionEntity mex = setupMock() - initProcessRollbackException(mex) - - doThrow(new BpmnError("expected exception")).when(mex).setVariable("rollbackData", null) - - DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() - DoCreateAllottedResourceBRGRollback.processRollbackException(mex) - } - - @Test -// @Ignore - public void processRollbackException_Ex() { - ExecutionEntity mex = setupMock() - initProcessRollbackException(mex) - - doThrow(new RuntimeException("expected exception")).when(mex).setVariable("rollbackData", null) - - DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() - DoCreateAllottedResourceBRGRollback.processRollbackException(mex) - } - - @Test -// @Ignore - public void processRollbackJavaException() { - ExecutionEntity mex = setupMock() - initProcessRollbackException(mex) - - DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() - DoCreateAllottedResourceBRGRollback.processRollbackJavaException(mex) - - //verify(mex).getVariable(DBGFLAG) - verify(mex).setVariable("rollbackData", null) - verify(mex).setVariable("rolledBack", false) - verify(mex).setVariable("rollbackError", "Caught Java exception in AllottedResource Create Rollback") - verify(mex, never()).setVariable("WorkflowException", null) - } - - @Test -// @Ignore - public void processRollbackJavaException_BpmnError() { - ExecutionEntity mex = setupMock() - initProcessRollbackException(mex) - - doThrow(new BpmnError("expected exception")).when(mex).setVariable("rollbackData", null) - - DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() - DoCreateAllottedResourceBRGRollback.processRollbackJavaException(mex) - } - - @Test -// @Ignore - public void processRollbackJavaException_Ex() { - ExecutionEntity mex = setupMock() - initProcessRollbackException(mex) - - doThrow(new RuntimeException("expected exception")).when(mex).setVariable("rollbackData", null) - - DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() - DoCreateAllottedResourceBRGRollback.processRollbackJavaException(mex) - } - - private RollbackData initPreProcess(ExecutionEntity mex) { - def data = new RollbackData() - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("rollbackData")).thenReturn(data) - when(mex.getVariable("rollbackAAI")).thenReturn(true) - when(mex.getVariable("rollbackSDNC")).thenReturn(true) - when(mex.getVariable("disableRollback")).thenReturn("false") - - data.put("SERVICEINSTANCE", "allottedResourceId", "myid") - - data.put(RbType, "serviceInstanceId", "sii") - data.put(RbType, "parentServiceInstanceId", "psii") - - data.put(RbType, "rollbackAAI", "true") - data.put(RbType, "aaiARPath", "mypath") - - data.put(RbType, "rollbackSDNCassign", "true") - data.put(RbType, "rollbackSDNCactivate", "myactivate") - data.put(RbType, "rollbackSDNCcreate", "mycreate") - data.put(RbType, "sdncActivateRollbackReq", "activatereq") - data.put(RbType, "sdncCreateRollbackReq", "createreq") - data.put(RbType, "sdncAssignRollbackReq", "assignreq") - - return data - } - - private initUpdateAaiAROrchStatus(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("aaiARPath")).thenReturn("/business/customers/customer/"+CUST+"/service-subscriptions/service-subscription/"+SVC+"/service-instances/service-instance/"+INST+"/allotted-resources/allotted-resource/"+ARID) - when(mex.getVariable("aai.endpoint")).thenReturn(aaiUriPfx) - } - - private initValidateSDNCResp(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("prefix")).thenReturn(Prefix) - when(mex.getVariable("SDNCA_SuccessIndicator")).thenReturn(true) - } - - private String initValidateSDNCResp_Resp() { - return "<response-code>200</response-code>" - } - - private initDeleteAaiAR(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("aaiARResourceVersion")).thenReturn(VERS) - when(mex.getVariable("aaiARPath")).thenReturn("/business/customers/customer/"+CUST+"/service-subscriptions/service-subscription/"+SVC+"/service-instances/service-instance/"+INST+"/allotted-resources/allotted-resource/"+ARID) - when(mex.getVariable("aai.endpoint")).thenReturn(aaiUriPfx) - } - - private initPostProcessRequest(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("skipRollback")).thenReturn(false) - } - - private initProcessRollbackException(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - } - - private initProcessRollbackJavaException(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - } - + public void init() { + MockitoAnnotations.initMocks(this) + } + + public DoCreateAllottedResourceBRGRollbackTest() { + super("DoCreateAllottedResourceBRGRollback") + } + + // ***** preProcessRequest ***** + + @Test + public void preProcessRequest() { + ExecutionEntity mex = setupMock() + initPreProcess(mex) + + DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() + DoCreateAllottedResourceBRGRollback.preProcessRequest(mex) + + verify(mex).setVariable("prefix", Prefix) + verify(mex).setVariable("serviceInstanceId", "sii") + verify(mex).setVariable("parentServiceInstanceId", "psii") + verify(mex).setVariable("allottedResourceId", "myid") + verify(mex).setVariable("rollbackAAI", true) + verify(mex).setVariable("aaiARPath", "mypath") + verify(mex).setVariable("rollbackSDNC", true) + verify(mex).setVariable("deactivateSdnc", "myactivate") + verify(mex).setVariable("deleteSdnc", "mycreate") + verify(mex).setVariable("unassignSdnc", "true") + verify(mex).setVariable("sdncDeactivateRequest", "activatereq") + verify(mex).setVariable("sdncDeleteRequest", "createreq") + verify(mex).setVariable("sdncUnassignRequest", "assignreq") + + verify(mex, never()).setVariable("skipRollback", true) + } + + @Test + public void preProcessRequest_RollbackDisabled() { + ExecutionEntity mex = setupMock() + initPreProcess(mex) + + when(mex.getVariable("disableRollback")).thenReturn("true") + + DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() + DoCreateAllottedResourceBRGRollback.preProcessRequest(mex) + + verify(mex).setVariable("prefix", Prefix) + verify(mex).setVariable("serviceInstanceId", "sii") + verify(mex).setVariable("parentServiceInstanceId", "psii") + verify(mex).setVariable("allottedResourceId", "myid") + verify(mex).setVariable("rollbackAAI", true) + verify(mex).setVariable("aaiARPath", "mypath") + verify(mex).setVariable("rollbackSDNC", true) + verify(mex).setVariable("deactivateSdnc", "myactivate") + verify(mex).setVariable("deleteSdnc", "mycreate") + verify(mex).setVariable("unassignSdnc", "true") + verify(mex).setVariable("sdncDeactivateRequest", "activatereq") + verify(mex).setVariable("sdncDeleteRequest", "createreq") + verify(mex).setVariable("sdncUnassignRequest", "assignreq") + + verify(mex).setVariable("skipRollback", true) + } + + @Test + public void preProcessRequest_NoAAI() { + ExecutionEntity mex = setupMock() + def data = initPreProcess(mex) + + when(mex.getVariable("rollbackAAI")).thenReturn(false) + data.put(RbType, "rollbackAAI", "false") + + DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() + DoCreateAllottedResourceBRGRollback.preProcessRequest(mex) + + verify(mex).setVariable("prefix", Prefix) + verify(mex).setVariable("serviceInstanceId", "sii") + verify(mex).setVariable("parentServiceInstanceId", "psii") + verify(mex).setVariable("allottedResourceId", "myid") + verify(mex, never()).setVariable("rollbackAAI", true) + verify(mex, never()).setVariable("aaiARPath", "mypath") + verify(mex).setVariable("rollbackSDNC", true) + verify(mex).setVariable("deactivateSdnc", "myactivate") + verify(mex).setVariable("deleteSdnc", "mycreate") + verify(mex).setVariable("unassignSdnc", "true") + verify(mex).setVariable("sdncDeactivateRequest", "activatereq") + verify(mex).setVariable("sdncDeleteRequest", "createreq") + verify(mex).setVariable("sdncUnassignRequest", "assignreq") + + verify(mex, never()).setVariable("skipRollback", true) + } + + @Test + public void preProcessRequest_NoAssign() { + ExecutionEntity mex = setupMock() + def data = initPreProcess(mex) + + when(mex.getVariable("rollbackSDNC")).thenReturn(false) + data.put(RbType, "rollbackSDNCassign", "false") + + DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() + DoCreateAllottedResourceBRGRollback.preProcessRequest(mex) + + verify(mex).setVariable("prefix", Prefix) + verify(mex).setVariable("serviceInstanceId", "sii") + verify(mex).setVariable("parentServiceInstanceId", "psii") + verify(mex).setVariable("allottedResourceId", "myid") + verify(mex).setVariable("rollbackAAI", true) + verify(mex).setVariable("aaiARPath", "mypath") + verify(mex, never()).setVariable("rollbackSDNC", true) + verify(mex, never()).setVariable("deactivateSdnc", "myactivate") + verify(mex, never()).setVariable("deleteSdnc", "mycreate") + verify(mex, never()).setVariable("unassignSdnc", "true") + verify(mex, never()).setVariable("sdncDeactivateRequest", "activatereq") + verify(mex, never()).setVariable("sdncDeleteRequest", "createreq") + verify(mex, never()).setVariable("sdncUnassignRequest", "assignreq") + + verify(mex, never()).setVariable("skipRollback", true) + } + + @Test + public void preProcessRequest_NoAAI_NoAssign() { + ExecutionEntity mex = setupMock() + initPreProcess(mex) + + when(mex.getVariable("rollbackAAI")).thenReturn(false) + when(mex.getVariable("rollbackSDNC")).thenReturn(false) + + DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() + DoCreateAllottedResourceBRGRollback.preProcessRequest(mex) + + verify(mex).setVariable("skipRollback", true) + } + + @Test + public void preProcessRequest_NoRbStructure() { + ExecutionEntity mex = setupMock() + initPreProcess(mex) + + when(mex.getVariable("rollbackData")).thenReturn(new RollbackData()) + + DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() + DoCreateAllottedResourceBRGRollback.preProcessRequest(mex) + + verify(mex).setVariable("skipRollback", true) + } + + @Test + public void preProcessRequest_NullRb() { + ExecutionEntity mex = setupMock() + initPreProcess(mex) + + when(mex.getVariable("rollbackData")).thenReturn(null) + + DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() + DoCreateAllottedResourceBRGRollback.preProcessRequest(mex) + + verify(mex).setVariable("skipRollback", true) + } + + @Test + public void preProcessRequest_BpmnError() { + ExecutionEntity mex = setupMock() + initPreProcess(mex) + + when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception")) + + DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRGRollback.preProcessRequest(mex) })) + } + + @Test + public void preProcessRequest_Ex() { + ExecutionEntity mex = setupMock() + initPreProcess(mex) + + when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception")) + + DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRGRollback.preProcessRequest(mex) })) + } + + @Test + @Ignore + public void updateAaiAROrchStatus() { + ExecutionEntity mex = setupMock() + initUpdateAaiAROrchStatus(mex) + + MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRGRollback/arGetById.xml") + MockPatchAllottedResource(CUST, SVC, INST, ARID) + + DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() + DoCreateAllottedResourceBRGRollback.updateAaiAROrchStatus(mex, "success") + } + + @Test + public void updateAaiAROrchStatus_EmptyResponse() { + ExecutionEntity mex = setupMock() + initUpdateAaiAROrchStatus(mex) + + wireMockRule + .stubFor(get(urlMatching("/aai/v[0-9]+/.*")) + .willReturn(aResponse() + .withStatus(200))) + + DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRGRollback.updateAaiAROrchStatus(mex, "success") })) + } + + @Test + public void updateAaiAROrchStatus_NoArPath() { + ExecutionEntity mex = setupMock() + initUpdateAaiAROrchStatus(mex) + + MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRGRollback/arGetById.xml") + MockPatchAllottedResource(CUST, SVC, INST, ARID) + + when(mex.getVariable("aaiARPath")).thenReturn(null) + + DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRGRollback.updateAaiAROrchStatus(mex, "success") })) + } + + // ***** validateSDNCResp ***** + + @Test + public void validateSDNCResp() { + ExecutionEntity mex = setupMock() + initValidateSDNCResp(mex) + def resp = initValidateSDNCResp_Resp() + + when(mex.getVariable(Prefix + "sdncResponseSuccess")).thenReturn(true) + + DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() + + DoCreateAllottedResourceBRGRollback.validateSDNCResp(mex, resp, "create") + + verify(mex).getVariable("WorkflowException") + verify(mex).getVariable("SDNCA_SuccessIndicator") + } + + @Test + public void validateSDNCResp_Unsuccessful() { + ExecutionEntity mex = setupMock() + initValidateSDNCResp(mex) + def resp = initValidateSDNCResp_Resp() + + when(mex.getVariable(Prefix + "sdncResponseSuccess")).thenReturn(false) + + DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRGRollback.validateSDNCResp(mex, resp, "create") })) + } + + @Test + public void validateSDNCResp_BpmnError404() { + ExecutionEntity mex = setupMock() + initValidateSDNCResp(mex) + def resp = initValidateSDNCResp_Resp() + when(mex.getVariable(Prefix + "sdncResponseSuccess")).thenReturn(true) + + when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("404", "expected exception")) + + DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() + + DoCreateAllottedResourceBRGRollback.validateSDNCResp(mex, resp, "create") + } + + @Test + public void validateSDNCResp_BpmnError() { + ExecutionEntity mex = setupMock() + initValidateSDNCResp(mex) + def resp = initValidateSDNCResp_Resp() + when(mex.getVariable(Prefix + "sdncResponseSuccess")).thenReturn(true) + + when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception")) + + DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRGRollback.validateSDNCResp(mex, resp, "create") })) + } + + @Test + public void validateSDNCResp_Ex() { + ExecutionEntity mex = setupMock() + initValidateSDNCResp(mex) + def resp = initValidateSDNCResp_Resp() + when(mex.getVariable(Prefix + "sdncResponseSuccess")).thenReturn(true) + + when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception")) + + DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRGRollback.validateSDNCResp(mex, resp, "create") })) + } + + @Test + @Ignore + public void deleteAaiAR() { + ExecutionEntity mex = setupMock() + initDeleteAaiAR(mex) + + MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRGRollback/arGetById.xml") + MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) + + DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() + DoCreateAllottedResourceBRGRollback.deleteAaiAR(mex) + } + + @Test + public void deleteAaiAR_NoArPath() { + ExecutionEntity mex = setupMock() + initDeleteAaiAR(mex) + + MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRGRollback/arGetById.xml") + MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) + + when(mex.getVariable("aaiARPath")).thenReturn("") + + DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRGRollback.deleteAaiAR(mex) })) + } + + @Test + public void deleteAaiAR_BpmnError() { + ExecutionEntity mex = setupMock() + initDeleteAaiAR(mex) + + MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRGRollback/arGetById.xml") + MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) + + when(mex.getVariable("aaiARPath")).thenThrow(new BpmnError("expected exception")) + + DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRGRollback.deleteAaiAR(mex) })) + } + + @Test + public void deleteAaiAR_Ex() { + ExecutionEntity mex = setupMock() + initDeleteAaiAR(mex) + + MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRGRollback/arGetById.xml") + MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) + + when(mex.getVariable("aaiARPath")).thenThrow(new RuntimeException("expected exception")) + + DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRGRollback.deleteAaiAR(mex) })) + } + + @Test + public void postProcessRequest() { + ExecutionEntity mex = setupMock() + initPostProcessRequest(mex) + + DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() + DoCreateAllottedResourceBRGRollback.postProcessRequest(mex) + + verify(mex).setVariable("rollbackData", null) + verify(mex).setVariable("rolledBack", true) + } + + @Test + public void postProcessRequest_RolledBack() { + ExecutionEntity mex = setupMock() + initPostProcessRequest(mex) + + when(mex.getVariable("skipRollback")).thenReturn(true) + + DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() + DoCreateAllottedResourceBRGRollback.postProcessRequest(mex) + + verify(mex).setVariable("rollbackData", null) + verify(mex, never()).setVariable("rolledBack", true) + } + + @Test + public void postProcessRequest_BpmnError() { + ExecutionEntity mex = setupMock() + initPostProcessRequest(mex) + + when(mex.getVariable("skipRollback")).thenThrow(new BpmnError("expected exception")) + + DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() + DoCreateAllottedResourceBRGRollback.postProcessRequest(mex) + + verify(mex).setVariable("rollbackData", null) + verify(mex, never()).setVariable("rolledBack", true) + } + + @Test + public void postProcessRequest_Ex() { + ExecutionEntity mex = setupMock() + initPostProcessRequest(mex) + + when(mex.getVariable("skipRollback")).thenThrow(new RuntimeException("expected exception")) + + DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() + DoCreateAllottedResourceBRGRollback.postProcessRequest(mex) + + verify(mex).setVariable("rollbackData", null) + verify(mex, never()).setVariable("rolledBack", true) + } + + @Test + public void processRollbackException() { + ExecutionEntity mex = setupMock() + initProcessRollbackException(mex) + + DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() + DoCreateAllottedResourceBRGRollback.processRollbackException(mex) + + verify(mex).setVariable("rollbackData", null) + verify(mex).setVariable("rolledBack", false) + verify(mex).setVariable("rollbackError", "Caught exception in AllottedResource Create Rollback") + verify(mex).setVariable("WorkflowException", null) + } + + @Test + public void processRollbackException_BpmnError() { + ExecutionEntity mex = setupMock() + initProcessRollbackException(mex) + + doThrow(new BpmnError("expected exception")).when(mex).setVariable("rollbackData", null) + + DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() + DoCreateAllottedResourceBRGRollback.processRollbackException(mex) + } + + @Test + public void processRollbackException_Ex() { + ExecutionEntity mex = setupMock() + initProcessRollbackException(mex) + + doThrow(new RuntimeException("expected exception")).when(mex).setVariable("rollbackData", null) + + DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() + DoCreateAllottedResourceBRGRollback.processRollbackException(mex) + } + + @Test + public void processRollbackJavaException() { + ExecutionEntity mex = setupMock() + initProcessRollbackException(mex) + + DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() + DoCreateAllottedResourceBRGRollback.processRollbackJavaException(mex) + + verify(mex).setVariable("rollbackData", null) + verify(mex).setVariable("rolledBack", false) + verify(mex).setVariable("rollbackError", "Caught Java exception in AllottedResource Create Rollback") + verify(mex, never()).setVariable("WorkflowException", null) + } + + @Test + public void processRollbackJavaException_BpmnError() { + ExecutionEntity mex = setupMock() + initProcessRollbackException(mex) + + doThrow(new BpmnError("expected exception")).when(mex).setVariable("rollbackData", null) + + DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() + DoCreateAllottedResourceBRGRollback.processRollbackJavaException(mex) + } + + @Test + public void processRollbackJavaException_Ex() { + ExecutionEntity mex = setupMock() + initProcessRollbackException(mex) + + doThrow(new RuntimeException("expected exception")).when(mex).setVariable("rollbackData", null) + + DoCreateAllottedResourceBRGRollback DoCreateAllottedResourceBRGRollback = new DoCreateAllottedResourceBRGRollback() + DoCreateAllottedResourceBRGRollback.processRollbackJavaException(mex) + } + + private RollbackData initPreProcess(ExecutionEntity mex) { + def data = new RollbackData() + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("rollbackData")).thenReturn(data) + when(mex.getVariable("rollbackAAI")).thenReturn(true) + when(mex.getVariable("rollbackSDNC")).thenReturn(true) + when(mex.getVariable("disableRollback")).thenReturn("false") + + data.put("SERVICEINSTANCE", "allottedResourceId", "myid") + + data.put(RbType, "serviceInstanceId", "sii") + data.put(RbType, "parentServiceInstanceId", "psii") + + data.put(RbType, "rollbackAAI", "true") + data.put(RbType, "aaiARPath", "mypath") + + data.put(RbType, "rollbackSDNCassign", "true") + data.put(RbType, "rollbackSDNCactivate", "myactivate") + data.put(RbType, "rollbackSDNCcreate", "mycreate") + data.put(RbType, "sdncActivateRollbackReq", "activatereq") + data.put(RbType, "sdncCreateRollbackReq", "createreq") + data.put(RbType, "sdncAssignRollbackReq", "assignreq") + + return data + } + + private initUpdateAaiAROrchStatus(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("aaiARPath")).thenReturn("/business/customers/customer/" + CUST + "/service-subscriptions/service-subscription/" + SVC + "/service-instances/service-instance/" + INST + "/allotted-resources/allotted-resource/" + ARID) + when(mex.getVariable("aai.endpoint")).thenReturn(aaiUriPfx) + } + + private initValidateSDNCResp(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("prefix")).thenReturn(Prefix) + when(mex.getVariable("SDNCA_SuccessIndicator")).thenReturn(true) + } + + private String initValidateSDNCResp_Resp() { + return "<response-code>200</response-code>" + } + + private initDeleteAaiAR(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("aaiARResourceVersion")).thenReturn(VERS) + when(mex.getVariable("aaiARPath")).thenReturn("/business/customers/customer/" + CUST + "/service-subscriptions/service-subscription/" + SVC + "/service-instances/service-instance/" + INST + "/allotted-resources/allotted-resource/" + ARID) + when(mex.getVariable("aai.endpoint")).thenReturn(aaiUriPfx) + } + + private initPostProcessRequest(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("skipRollback")).thenReturn(false) + } + + private initProcessRollbackException(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + } + + private initProcessRollbackJavaException(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + } + } diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/DoCreateAllottedResourceBRGTest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/DoCreateAllottedResourceBRGTest.groovy index f5e48a02e4..f094ef25fa 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/DoCreateAllottedResourceBRGTest.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/DoCreateAllottedResourceBRGTest.groovy @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -20,15 +22,12 @@ package org.onap.so.bpmn.vcpe.scripts - +import com.github.tomakehurst.wiremock.junit.WireMockRule +import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity -import org.junit.Before -import org.junit.BeforeClass -import org.junit.Rule -import org.junit.Test -import org.junit.Ignore +import org.junit.* import org.mockito.MockitoAnnotations -import org.camunda.bpm.engine.delegate.BpmnError +import org.onap.so.bpmn.core.RollbackData import org.onap.so.bpmn.core.UrnPropertiesReader import org.onap.so.bpmn.core.WorkflowException import org.onap.so.bpmn.mock.FileUtil @@ -41,945 +40,882 @@ import javax.ws.rs.core.UriBuilder import static com.github.tomakehurst.wiremock.client.WireMock.aResponse import static com.github.tomakehurst.wiremock.client.WireMock.put import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching -import static org.junit.Assert.*; +import static org.junit.Assert.* import static org.mockito.Mockito.* -import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetAllottedResource -import static org.onap.so.bpmn.mock.StubResponseAAI.MockPatchAllottedResource -import static org.onap.so.bpmn.mock.StubResponseAAI.MockPutAllottedResource -import static org.onap.so.bpmn.mock.StubResponseAAI.MockPutAllottedResource_500 +import static org.onap.so.bpmn.mock.StubResponseAAI.* -import org.onap.so.bpmn.core.RollbackData +class DoCreateAllottedResourceBRGTest extends GroovyTestBase { -import com.github.tomakehurst.wiremock.junit.WireMockRule + @Rule + public WireMockRule wireMockRule = new WireMockRule(PORT) -class DoCreateAllottedResourceBRGTest extends GroovyTestBase { - - @Rule - public WireMockRule wireMockRule = new WireMockRule(PORT) + String Prefix = "DCARBRG_" - String Prefix = "DCARBRG_" + @BeforeClass + public static void setUpBeforeClass() { + aaiUriPfx = UrnPropertiesReader.getVariable("aai.endpoint") + } - @BeforeClass - public static void setUpBeforeClass() { - aaiUriPfx = UrnPropertiesReader.getVariable("aai.endpoint") - } - @Before - public void init() - { - MockitoAnnotations.initMocks(this) - } - - public DoCreateAllottedResourceBRGTest() { - super("DoCreateAllottedResourceBRG") - } - - - // ***** preProcessRequest ***** - - @Test -// @Ignore - public void preProcessRequest() { - ExecutionEntity mex = setupMock() - initPreProcess(mex) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - DoCreateAllottedResourceBRG.preProcessRequest(mex) - - //verify(mex).getVariable(DBGFLAG) - verify(mex).setVariable("prefix", Prefix) - - assertTrue(checkMissingPreProcessRequest("mso.workflow.sdncadapter.callback")) - assertTrue(checkMissingPreProcessRequest("mso.workflow.sdnc.replication.delay")) - assertTrue(checkMissingPreProcessRequest("serviceInstanceId")) - assertTrue(checkMissingPreProcessRequest("parentServiceInstanceId")) - assertTrue(checkMissingPreProcessRequest("allottedResourceModelInfo")) - assertTrue(checkMissingPreProcessRequest("vni")) - assertTrue(checkMissingPreProcessRequest("vgmuxBearerIP")) - assertTrue(checkMissingPreProcessRequest("brgWanMacAddress")) - assertTrue(checkMissingPreProcessRequest("allottedResourceRole")) - assertTrue(checkMissingPreProcessRequest("allottedResourceType")) - } - - - // ***** getAaiAR ***** - - @Test - @Ignore - public void getAaiAR() { - MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRG/getArBrg.xml") - - ExecutionEntity mex = setupMock() - initGetAaiAR(mex) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - DoCreateAllottedResourceBRG.getAaiAR(mex) - - verify(mex).setVariable("foundActiveAR", true) - } - - @Test -// @Ignore - public void getAaiAR_Duplicate() { - MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRG/getArBrg.xml") - - ExecutionEntity mex = setupMock() - initGetAaiAR(mex) - - // fail if duplicate - when(mex.getVariable("failExists")).thenReturn("true") - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - - assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceBRG.getAaiAR(mex) })) - } - - @Test -// @Ignore - public void getAaiAR_NotActive() { - MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRG/getArBrg.xml") - - ExecutionEntity mex = setupMock() - initGetAaiAR(mex) - - // not active - when(mex.getVariable("aaiAROrchStatus")).thenReturn("not-active") - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - - assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceBRG.getAaiAR(mex) })) - } - - @Test - @Ignore - public void getAaiAR_NoStatus() { - MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRG/getArBrg.xml") - - ExecutionEntity mex = setupMock() - initGetAaiAR(mex) - - when(mex.getVariable("aaiAROrchStatus")).thenReturn(null) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - DoCreateAllottedResourceBRG.getAaiAR(mex) - - verify(mex, never()).setVariable("foundActiveAR", true) - } - - - // ***** createAaiAR ***** - - @Test - public void createAaiAR() { - ExecutionEntity mockExecution = setupMock() - AAIResourcesClient client = mock(AAIResourcesClient.class) - when(mockExecution.getVariable("PSI_resourceLink")).thenReturn(AAIUriFactory.createResourceFromExistingURI(AAIObjectType.SERVICE_INSTANCE,UriBuilder.fromPath( "/aai/v9/business/customers/customer/"+CUST+"/service-subscriptions/service-subscription/"+SVC+"/service-instances/service-instance/"+INST).build())) - when(mockExecution.getVariable("CSI_resourceLink")).thenReturn("/aai/v9/business/customers/customer/"+CUST+"/service-subscriptions/service-subscription/"+SVC+"/service-instances/service-instance/"+INST) - when(mockExecution.getVariable("allottedResourceModelInfo")).thenReturn("{\n" + - " \"modelInvariantUuid\":\"modelInvariantUuid\",\n" + - " \"modelUuid\" : \"modelUuid\"\n" + - "}") - DoCreateAllottedResourceBRG doCreateAllottedResourceBRG = spy(DoCreateAllottedResourceBRG.class) - when(doCreateAllottedResourceBRG.getAAIClient()).thenReturn(client) - doCreateAllottedResourceBRG.createAaiAR(mockExecution) - } - - @Test - @Ignore - public void createAaiAR_NoArid_NoModelUuids() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initCreateAaiAr(mex) - - // no allottedResourceId - will be generated - - when(mex.getVariable("allottedResourceId")).thenReturn(null) - - wireMockRule - .stubFor(put(urlMatching("/aai/.*/allotted-resource/.*")) - .willReturn(aResponse() - .withStatus(200))) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - DoCreateAllottedResourceBRG.createAaiAR(mex) - - def arid = map.get("allottedResourceId") - assertNotNull(arid) - assertFalse(arid.isEmpty()) - - def data = map.get("rollbackData") - assertNotNull(data) - assertTrue(data instanceof RollbackData) - - assertEquals(arid, data.get(Prefix, "allottedResourceId")) - } - - @Test - public void createAaiAR_MissingPsiLink() { - ExecutionEntity mex = setupMock() - initCreateAaiAr(mex) - - when(mex.getVariable("PSI_resourceLink")).thenReturn(null) - - MockPutAllottedResource(CUST, SVC, INST, ARID) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.createAaiAR(mex) })) - } - - @Test - public void createAaiAR_HttpFailed() { - ExecutionEntity mex = setupMock() - initCreateAaiAr(mex) - - MockPutAllottedResource_500(CUST, SVC, INST, ARID) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.createAaiAR(mex) })) - } - - @Test - public void createAaiAR_BpmnError() { - ExecutionEntity mex = setupMock() - initCreateAaiAr(mex) - - when(mex.getVariable("aai.endpoint")).thenThrow(new BpmnError("expected exception")) - - MockPutAllottedResource(CUST, SVC, INST, ARID) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.createAaiAR(mex) })) - } - - @Test - public void createAaiAR_Ex() { - ExecutionEntity mex = setupMock() - initCreateAaiAr(mex) - - when(mex.getVariable("aai.endpoint")).thenThrow(new RuntimeException("expected exception")) - - MockPutAllottedResource(CUST, SVC, INST, ARID) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.createAaiAR(mex) })) - } - - - // ***** buildSDNCRequest ***** - - @Test -// @Ignore - public void buildSDNCRequest() { - ExecutionEntity mex = setupMock() - initBuildSDNCRequest(mex) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - - String result = DoCreateAllottedResourceBRG.buildSDNCRequest(mex, "myact", "myreq") - - assertTrue(result.indexOf("myreq= 0) - assertTrue(result.indexOf("myact= 0) - assertTrue(result.indexOf("ari= 0) - assertTrue(result.indexOf("sii= 0) - assertTrue(result.indexOf("sii= 0) - assertTrue(result.indexOf("psii= 0) - assertTrue(result.indexOf("sst= 0) - assertTrue(result.indexOf("gci= 0) - assertTrue(result.indexOf("scu= 0) - assertTrue(result.indexOf("mri= 0) - assertTrue(result.indexOf("bwma= 0) - assertTrue(result.indexOf("myvni= 0) - assertTrue(result.indexOf("vbi= 0) - assertTrue(result.indexOf("miu= 0) - assertTrue(result.indexOf("mu= 0) - assertTrue(result.indexOf("mcu= 0) - assertTrue(result.indexOf("mv= 0) - assertTrue(result.indexOf("mn= 0) - } - - @Test -// @Ignore - public void buildSDNCRequest_EmptyModelInfo() { - ExecutionEntity mex = setupMock() - initBuildSDNCRequest(mex) - - when(mex.getVariable("allottedResourceModelInfo")).thenReturn("{}") - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - - String result = DoCreateAllottedResourceBRG.buildSDNCRequest(mex, "myact", "myreq") - - assertTrue(result.indexOf("myreq= 0) - assertTrue(result.indexOf("myact= 0) - assertTrue(result.indexOf("ari= 0) - assertTrue(result.indexOf("sii= 0) - assertTrue(result.indexOf("sii= 0) - assertTrue(result.indexOf("psii= 0) - assertTrue(result.indexOf("sst= 0) - assertTrue(result.indexOf("gci= 0) - assertTrue(result.indexOf("scu= 0) - assertTrue(result.indexOf("mri= 0) - assertTrue(result.indexOf("bwma= 0) - assertTrue(result.indexOf("myvni= 0) - assertTrue(result.indexOf("vbi= 0) - assertTrue(result.indexOf("") >= 0) - assertTrue(result.indexOf("") >= 0) - assertTrue(result.indexOf("") >= 0) - assertTrue(result.indexOf("") >= 0) - assertTrue(result.indexOf("") >= 0) - } - - @Test -// @Ignore - public void buildSDNCRequest_Ex() { - ExecutionEntity mex = setupMock() - initBuildSDNCRequest(mex) - - when(mex.getVariable("allottedResourceId")).thenThrow(new RuntimeException("expected exception")) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.buildSDNCRequest(mex, "myact", "myreq") })) - } - - - // ***** preProcessSDNCAssign ***** - - @Test -// @Ignore - public void preProcessSDNCAssign() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - def data = initPreProcessSDNC(mex) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - DoCreateAllottedResourceBRG.preProcessSDNCAssign(mex) - - def req = map.get("sdncAssignRequest") - assertNotNull(req) - - assertEquals(data, map.get("rollbackData")) - - def rbreq = data.get(Prefix, "sdncAssignRollbackReq") - - assertTrue(req.indexOf("assign= 0) - assertTrue(req.indexOf("CreateBRGInstance= 0) - assertTrue(req.indexOf("") >= 0) - - assertTrue(rbreq.indexOf("unassign= 0) - assertTrue(rbreq.indexOf("DeleteBRGInstance= 0) - assertTrue(rbreq.indexOf("") >= 0) - } - - @Test -// @Ignore - public void preProcessSDNCAssign_BpmnError() { - ExecutionEntity mex = setupMock() - initPreProcessSDNC(mex) - - when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception")) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCAssign(mex) })) - } - - @Test -// @Ignore - public void preProcessSDNCAssign_Ex() { - ExecutionEntity mex = setupMock() - initPreProcessSDNC(mex) - - when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception")) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCAssign(mex) })) - } - - - // ***** preProcessSDNCCreate ***** - - @Test -// @Ignore - public void preProcessSDNCCreate() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - def data = initPreProcessSDNC(mex) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - DoCreateAllottedResourceBRG.preProcessSDNCCreate(mex) - - def req = map.get("sdncCreateRequest") - assertNotNull(req) - - assertEquals(data, map.get("rollbackData")) - - def rbreq = data.get(Prefix, "sdncCreateRollbackReq") - - assertTrue(req.indexOf("create= 0) - assertTrue(req.indexOf("CreateBRGInstance= 0) - assertTrue(req.indexOf("") >= 0) - - assertTrue(rbreq.indexOf("delete= 0) - assertTrue(rbreq.indexOf("DeleteBRGInstance= 0) - assertTrue(rbreq.indexOf("") >= 0) - - } - - @Test -// @Ignore - public void preProcessSDNCCreate_BpmnError() { - ExecutionEntity mex = setupMock() - initPreProcessSDNC(mex) - - when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception")) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCCreate(mex) })) - } - - @Test -// @Ignore - public void preProcessSDNCCreate_Ex() { - ExecutionEntity mex = setupMock() - initPreProcessSDNC(mex) - - when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception")) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCCreate(mex) })) - } - - - // ***** preProcessSDNCActivate ***** - - @Test -// @Ignore - public void preProcessSDNCActivate() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - def data = initPreProcessSDNC(mex) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - DoCreateAllottedResourceBRG.preProcessSDNCActivate(mex) - - def req = map.get("sdncActivateRequest") - assertNotNull(req) - - assertEquals(data, map.get("rollbackData")) - - def rbreq = data.get(Prefix, "sdncActivateRollbackReq") - - assertTrue(req.indexOf("activate= 0) - assertTrue(req.indexOf("CreateBRGInstance= 0) - assertTrue(req.indexOf("") >= 0) - - assertTrue(rbreq.indexOf("deactivate= 0) - assertTrue(rbreq.indexOf("DeleteBRGInstance= 0) - assertTrue(rbreq.indexOf("") >= 0) - - } - - @Test -// @Ignore - public void preProcessSDNCActivate_BpmnError() { - ExecutionEntity mex = setupMock() - initPreProcessSDNC(mex) - - when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception")) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCActivate(mex) })) - } - - @Test -// @Ignore - public void preProcessSDNCActivate_Ex() { - ExecutionEntity mex = setupMock() - initPreProcessSDNC(mex) - - when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception")) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCActivate(mex) })) - } - - - // ***** validateSDNCResp ***** - - @Test -// @Ignore - public void validateSDNCResp() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - def data = initValidateSDNCResp(mex) - def resp = initValidateSDNCResp_Resp() - - when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - - DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create") - - verify(mex).getVariable("WorkflowException") - verify(mex).getVariable("SDNCA_SuccessIndicator") - verify(mex).getVariable("rollbackData") - - assertEquals(data, map.get("rollbackData")) - - assertEquals("true", data.get(Prefix, "rollback" + "SDNCcreate")) - - } - - @Test -// @Ignore - public void validateSDNCResp_Get() { - ExecutionEntity mex = setupMock() - def data = initValidateSDNCResp(mex) - def resp = initValidateSDNCResp_Resp() - - when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - - DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "get") - - verify(mex).getVariable("WorkflowException") - verify(mex).getVariable("SDNCA_SuccessIndicator") - - verify(mex, never()).getVariable("rollbackData") - } - - @Test -// @Ignore - public void validateSDNCResp_Unsuccessful() { - ExecutionEntity mex = setupMock() - initValidateSDNCResp(mex) - def resp = initValidateSDNCResp_Resp() - - // unsuccessful - when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(false) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create") })) - } - - @Test -// @Ignore - public void validateSDNCResp_BpmnError() { - ExecutionEntity mex = setupMock() - initValidateSDNCResp(mex) - def resp = initValidateSDNCResp_Resp() - - when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception")) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create") })) - } - - @Test -// @Ignore - public void validateSDNCResp_Ex() { - ExecutionEntity mex = setupMock() - initValidateSDNCResp(mex) - def resp = initValidateSDNCResp_Resp() - - when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception")) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create") })) - } - - - // ***** preProcessSDNCGet ***** - - @Test -// @Ignore - public void preProcessSDNCGet_FoundAR() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initPreProcessSDNCGet(mex) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - DoCreateAllottedResourceBRG.preProcessSDNCGet(mex) - - String req = map.get("sdncGetRequest") - - assertTrue(req.indexOf("") >= 0) - assertTrue(req.indexOf("sii= 0) - assertTrue(req.indexOf("arlink= 0) - assertTrue(req.indexOf("myurl= 0) - - } - - @Test -// @Ignore - public void preProcessSDNCGet_NotFoundAR() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initPreProcessSDNCGet(mex) - - when(mex.getVariable("foundActiveAR")).thenReturn(false) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - DoCreateAllottedResourceBRG.preProcessSDNCGet(mex) - - String req = map.get("sdncGetRequest") - - assertTrue(req.indexOf("") >= 0) - assertTrue(req.indexOf("sii= 0) - assertTrue(req.indexOf("assignlink= 0) - assertTrue(req.indexOf("myurl= 0) - - } - - @Test -// @Ignore - public void preProcessSDNCGet_Ex() { - ExecutionEntity mex = setupMock() - initPreProcessSDNCGet(mex) - - when(mex.getVariable("foundActiveAR")).thenThrow(new RuntimeException("expected exception")) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCGet(mex) })) - } - - - // ***** updateAaiAROrchStatus ***** - - @Test - @Ignore - public void updateAaiAROrchStatus() { - MockPatchAllottedResource(CUST, SVC, INST, ARID) - - ExecutionEntity mex = setupMock() - initUpdateAaiAROrchStatus(mex) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - DoCreateAllottedResourceBRG.updateAaiAROrchStatus(mex, "success") - } - - - // ***** generateOutputs ***** - - @Test -// @Ignore - public void generateOutputs() { - ExecutionEntity mex = setupMock() - def brgtop = FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceBRG/SDNCTopologyQueryCallback.xml") - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("enhancedCallbackRequestData")).thenReturn(brgtop) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - DoCreateAllottedResourceBRG.generateOutputs(mex) - - verify(mex).setVariable("allotedResourceName", "namefromrequest") - - } - - @Test -// @Ignore - public void generateOutputs_BadXml() { - ExecutionEntity mex = setupMock() - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("enhancedCallbackRequestData")).thenReturn("invalid xml") - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - DoCreateAllottedResourceBRG.generateOutputs(mex) - - verify(mex, never()).setVariable(anyString(), anyString()) - - } - - @Test -// @Ignore - public void generateOutputs_BpmnError() { - ExecutionEntity mex = setupMock() - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("enhancedCallbackRequestData")).thenThrow(new BpmnError("expected exception")) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - - DoCreateAllottedResourceBRG.generateOutputs(mex) - verify(mex, never()).setVariable(anyString(), anyString()) - - } - - @Test -// @Ignore - public void generateOutputs_Ex() { - ExecutionEntity mex = setupMock() - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("enhancedCallbackRequestData")).thenThrow(new RuntimeException("expected exception")) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - - DoCreateAllottedResourceBRG.generateOutputs(mex) - verify(mex, never()).setVariable(anyString(), anyString()) - - } - - - // ***** preProcessRollback ***** - - @Test -// @Ignore - public void preProcessRollback() { - ExecutionEntity mex = setupMock() - WorkflowException wfe = mock(WorkflowException.class) - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("WorkflowException")).thenReturn(wfe) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - DoCreateAllottedResourceBRG.preProcessRollback(mex) - - verify(mex).setVariable("prevWorkflowException", wfe) - - } - - @Test -// @Ignore - public void preProcessRollback_NotWFE() { - ExecutionEntity mex = setupMock() - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("WorkflowException")).thenReturn("I'm not a WFE") - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - DoCreateAllottedResourceBRG.preProcessRollback(mex) - -// verify(mex, never()).setVariable("prevWorkflowException", any()) - - } - - @Test -// @Ignore - public void preProcessRollback_BpmnError() { - ExecutionEntity mex = setupMock() - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception")) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - - DoCreateAllottedResourceBRG.preProcessRollback(mex) - - } - - @Test -// @Ignore - public void preProcessRollback_Ex() { - ExecutionEntity mex = setupMock() - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception")) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - - DoCreateAllottedResourceBRG.preProcessRollback(mex) - - } - - - // ***** postProcessRollback ***** - - @Test -// @Ignore - public void postProcessRollback() { - ExecutionEntity mex = setupMock() - WorkflowException wfe = mock(WorkflowException.class) - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("prevWorkflowException")).thenReturn(wfe) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - DoCreateAllottedResourceBRG.postProcessRollback(mex) - - verify(mex).setVariable("WorkflowException", wfe) - verify(mex).setVariable("rollbackData", null) - - } - - @Test -// @Ignore - public void postProcessRollback_NotWFE() { - ExecutionEntity mex = setupMock() - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("prevWorkflowException")).thenReturn("I'm not a WFE") - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - DoCreateAllottedResourceBRG.postProcessRollback(mex) - -// verify(mex, never()).setVariable("WorkflowException", any()) - verify(mex).setVariable("rollbackData", null) - - } - - @Test -// @Ignore - public void postProcessRollback_BpmnError() { - ExecutionEntity mex = setupMock() - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("prevWorkflowException")).thenThrow(new BpmnError("expected exception")) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.postProcessRollback(mex) })) - verify(mex, never()).setVariable("rollbackData", null) - - } - - @Test -// @Ignore - public void postProcessRollback_Ex() { - ExecutionEntity mex = setupMock() - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("prevWorkflowException")).thenThrow(new RuntimeException("expected exception")) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - - DoCreateAllottedResourceBRG.postProcessRollback(mex) - verify(mex, never()).setVariable("rollbackData", null) - - } - - private boolean checkMissingPreProcessRequest(String fieldnm) { - ExecutionEntity mex = setupMock() - initPreProcess(mex) - - DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() - - when(mex.getVariable(fieldnm)).thenReturn("") - - return doBpmnError( { _ -> DoCreateAllottedResourceBRG.preProcessRequest(mex) }) - } - - private void initPreProcess(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("sdncurn") - when(mex.getVariable("mso.workflow.sdnc.replication.delay")).thenReturn("sdncdelay") - when(mex.getVariable("serviceInstanceId")).thenReturn("sii") - when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii") - when(mex.getVariable("allottedResourceModelInfo")).thenReturn("armi") - when(mex.getVariable("vni")).thenReturn("myvni") - when(mex.getVariable("vgmuxBearerIP")).thenReturn("vbi") - when(mex.getVariable("brgWanMacAddress")).thenReturn("bwma") - when(mex.getVariable("allottedResourceRole")).thenReturn("arr") - when(mex.getVariable("allottedResourceType")).thenReturn("art") - } - - private void initGetAaiAR(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("allottedResourceType")).thenReturn("BRGt") - when(mex.getVariable("allottedResourceRole")).thenReturn("BRGr") - when(mex.getVariable("CSI_service")).thenReturn(FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceBRG/getAR.xml")) - when(mex.getVariable("aai.endpoint")).thenReturn(aaiUriPfx) - when(mex.getVariable("aaiAROrchStatus")).thenReturn("Active") - } - - private initCreateAaiAr(ExecutionEntity mex) { - when(mex.getVariable("disableRollback")).thenReturn(45) - when(mex.getVariable("serviceInstanceId")).thenReturn("sii") - when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii") - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("allottedResourceId")).thenReturn(ARID) - when(mex.getVariable("aai.endpoint")).thenReturn(aaiUriPfx) - when(mex.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn(UrnPropertiesReader.getVariable("mso.workflow.global.default.aai.namespace")) - when(mex.getVariable("PSI_resourceLink")).thenReturn(AAIUriFactory.createResourceFromExistingURI(AAIObjectType.SERVICE_INSTANCE, UriBuilder.fromPath( "/business/customers/customer/"+CUST+"/service-subscriptions/service-subscription/"+SVC+"/service-instances/service-instance/"+INST).build())) - when(mex.getVariable("allottedResourceType")).thenReturn("BRGt") - when(mex.getVariable("allottedResourceRole")).thenReturn("BRGr") - when(mex.getVariable("CSI_resourceLink")).thenReturn(aaiUriPfx+"/aai/v9/mycsi") - when(mex.getVariable("allottedResourceModelInfo")).thenReturn(""" - { - "modelInvariantUuid":"modelinvuuid", - "modelUuid":"modeluuid", - "modelCustomizationUuid":"modelcustuuid" - } - """) - } - - private initBuildSDNCRequest(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("allottedResourceId")).thenReturn("ari") - when(mex.getVariable("serviceInstanceId")).thenReturn("sii") - when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii") - when(mex.getVariable("subscriptionServiceType")).thenReturn("sst") - when(mex.getVariable("globalCustomerId")).thenReturn("gci") - when(mex.getVariable("sdncCallbackUrl")).thenReturn("scu") - when(mex.getVariable("msoRequestId")).thenReturn("mri") - when(mex.getVariable("brgWanMacAddress")).thenReturn("bwma") - when(mex.getVariable("vni")).thenReturn("myvni") - when(mex.getVariable("vgmuxBearerIP")).thenReturn("vbi") - when(mex.getVariable("allottedResourceModelInfo")).thenReturn(""" - { - "modelInvariantUuid":"miu", - "modelUuid":"mu", - "modelCustomizationUuid":"mcu", - "modelVersion":"mv", - "modelName":"mn" - } - """) - } - - private RollbackData initPreProcessSDNC(ExecutionEntity mex) { - def data = new RollbackData() - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("rollbackData")).thenReturn(data) - - return data - } - - private initPreProcessSDNCGet(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("sdncCallbackUrl")).thenReturn("myurl") - when(mex.getVariable("foundActiveAR")).thenReturn(true) - when(mex.getVariable("aaiARGetResponse")).thenReturn("arlink") - when(mex.getVariable("sdncAssignResponse")).thenReturn("<object-path>assignlink</object-path>") - when(mex.getVariable("serviceInstanceId")).thenReturn("sii") - when(mex.getVariable("sdncCallbackUrl")).thenReturn("myurl") - } - - private RollbackData initValidateSDNCResp(ExecutionEntity mex) { - def data = new RollbackData() - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("prefix")).thenReturn(Prefix) - when(mex.getVariable("SDNCA_SuccessIndicator")).thenReturn(true) - when(mex.getVariable("rollbackData")).thenReturn(data) - - return data - } - - private String initValidateSDNCResp_Resp() { - return "<response-code>200</response-code>" - } - - private initUpdateAaiAROrchStatus(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("aaiARPath")).thenReturn("/business/customers/customer/"+CUST+"/service-subscriptions/service-subscription/"+SVC+"/service-instances/service-instance/"+INST+"/allotted-resources/allotted-resource/"+ARID) - } - + public void init() { + MockitoAnnotations.initMocks(this) + } + + public DoCreateAllottedResourceBRGTest() { + super("DoCreateAllottedResourceBRG") + } + + // ***** preProcessRequest ***** + + @Test + public void preProcessRequest() { + ExecutionEntity mex = setupMock() + initPreProcess(mex) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + DoCreateAllottedResourceBRG.preProcessRequest(mex) + + verify(mex).setVariable("prefix", Prefix) + + assertTrue(checkMissingPreProcessRequest("mso.workflow.sdncadapter.callback")) + assertTrue(checkMissingPreProcessRequest("mso.workflow.sdnc.replication.delay")) + assertTrue(checkMissingPreProcessRequest("serviceInstanceId")) + assertTrue(checkMissingPreProcessRequest("parentServiceInstanceId")) + assertTrue(checkMissingPreProcessRequest("allottedResourceModelInfo")) + assertTrue(checkMissingPreProcessRequest("vni")) + assertTrue(checkMissingPreProcessRequest("vgmuxBearerIP")) + assertTrue(checkMissingPreProcessRequest("brgWanMacAddress")) + assertTrue(checkMissingPreProcessRequest("allottedResourceRole")) + assertTrue(checkMissingPreProcessRequest("allottedResourceType")) + } + + // ***** getAaiAR ***** + + @Test + @Ignore + public void getAaiAR() { + MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRG/getArBrg.xml") + + ExecutionEntity mex = setupMock() + initGetAaiAR(mex) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + DoCreateAllottedResourceBRG.getAaiAR(mex) + + verify(mex).setVariable("foundActiveAR", true) + } + + @Test + public void getAaiAR_Duplicate() { + MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRG/getArBrg.xml") + + ExecutionEntity mex = setupMock() + initGetAaiAR(mex) + + // fail if duplicate + when(mex.getVariable("failExists")).thenReturn("true") + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.getAaiAR(mex) })) + } + + @Test + public void getAaiAR_NotActive() { + MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRG/getArBrg.xml") + + ExecutionEntity mex = setupMock() + initGetAaiAR(mex) + + // not active + when(mex.getVariable("aaiAROrchStatus")).thenReturn("not-active") + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.getAaiAR(mex) })) + } + + @Test + @Ignore + public void getAaiAR_NoStatus() { + MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRG/getArBrg.xml") + + ExecutionEntity mex = setupMock() + initGetAaiAR(mex) + + when(mex.getVariable("aaiAROrchStatus")).thenReturn(null) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + DoCreateAllottedResourceBRG.getAaiAR(mex) + + verify(mex, never()).setVariable("foundActiveAR", true) + } + + // ***** createAaiAR ***** + + @Test + public void createAaiAR() { + ExecutionEntity mockExecution = setupMock() + AAIResourcesClient client = mock(AAIResourcesClient.class) + when(mockExecution.getVariable("PSI_resourceLink")).thenReturn(AAIUriFactory.createResourceFromExistingURI(AAIObjectType.SERVICE_INSTANCE, UriBuilder.fromPath("/aai/v9/business/customers/customer/" + CUST + "/service-subscriptions/service-subscription/" + SVC + "/service-instances/service-instance/" + INST).build())) + when(mockExecution.getVariable("CSI_resourceLink")).thenReturn("/aai/v9/business/customers/customer/" + CUST + "/service-subscriptions/service-subscription/" + SVC + "/service-instances/service-instance/" + INST) + when(mockExecution.getVariable("allottedResourceModelInfo")).thenReturn("{\n" + + " \"modelInvariantUuid\":\"modelInvariantUuid\",\n" + + " \"modelUuid\" : \"modelUuid\"\n" + + "}") + DoCreateAllottedResourceBRG doCreateAllottedResourceBRG = spy(DoCreateAllottedResourceBRG.class) + when(doCreateAllottedResourceBRG.getAAIClient()).thenReturn(client) + doCreateAllottedResourceBRG.createAaiAR(mockExecution) + } + + @Test + @Ignore + public void createAaiAR_NoArid_NoModelUuids() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initCreateAaiAr(mex) + + // no allottedResourceId - will be generated + + when(mex.getVariable("allottedResourceId")).thenReturn(null) + + wireMockRule + .stubFor(put(urlMatching("/aai/.*/allotted-resource/.*")) + .willReturn(aResponse() + .withStatus(200))) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + DoCreateAllottedResourceBRG.createAaiAR(mex) + + def arid = map.get("allottedResourceId") + assertNotNull(arid) + assertFalse(arid.isEmpty()) + + def data = map.get("rollbackData") + assertNotNull(data) + assertTrue(data instanceof RollbackData) + + assertEquals(arid, data.get(Prefix, "allottedResourceId")) + } + + @Test + public void createAaiAR_MissingPsiLink() { + ExecutionEntity mex = setupMock() + initCreateAaiAr(mex) + + when(mex.getVariable("PSI_resourceLink")).thenReturn(null) + + MockPutAllottedResource(CUST, SVC, INST, ARID) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.createAaiAR(mex) })) + } + + @Test + public void createAaiAR_HttpFailed() { + ExecutionEntity mex = setupMock() + initCreateAaiAr(mex) + + MockPutAllottedResource_500(CUST, SVC, INST, ARID) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.createAaiAR(mex) })) + } + + @Test + public void createAaiAR_BpmnError() { + ExecutionEntity mex = setupMock() + initCreateAaiAr(mex) + + when(mex.getVariable("aai.endpoint")).thenThrow(new BpmnError("expected exception")) + + MockPutAllottedResource(CUST, SVC, INST, ARID) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.createAaiAR(mex) })) + } + + @Test + public void createAaiAR_Ex() { + ExecutionEntity mex = setupMock() + initCreateAaiAr(mex) + + when(mex.getVariable("aai.endpoint")).thenThrow(new RuntimeException("expected exception")) + + MockPutAllottedResource(CUST, SVC, INST, ARID) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.createAaiAR(mex) })) + } + + // ***** buildSDNCRequest ***** + + @Test + public void buildSDNCRequest() { + ExecutionEntity mex = setupMock() + initBuildSDNCRequest(mex) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + + String result = DoCreateAllottedResourceBRG.buildSDNCRequest(mex, "myact", "myreq") + + assertTrue(result.indexOf("myreq= 0) + assertTrue(result.indexOf("myact= 0) + assertTrue(result.indexOf("ari= 0) + assertTrue(result.indexOf("sii= 0) + assertTrue(result.indexOf("sii= 0) + assertTrue(result.indexOf("psii= 0) + assertTrue(result.indexOf("sst= 0) + assertTrue(result.indexOf("gci= 0) + assertTrue(result.indexOf("scu= 0) + assertTrue(result.indexOf("mri= 0) + assertTrue(result.indexOf("bwma= 0) + assertTrue(result.indexOf("myvni= 0) + assertTrue(result.indexOf("vbi= 0) + assertTrue(result.indexOf("miu= 0) + assertTrue(result.indexOf("mu= 0) + assertTrue(result.indexOf("mcu= 0) + assertTrue(result.indexOf("mv= 0) + assertTrue(result.indexOf("mn= 0) + } + + @Test + public void buildSDNCRequest_EmptyModelInfo() { + ExecutionEntity mex = setupMock() + initBuildSDNCRequest(mex) + + when(mex.getVariable("allottedResourceModelInfo")).thenReturn("{}") + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + + String result = DoCreateAllottedResourceBRG.buildSDNCRequest(mex, "myact", "myreq") + + assertTrue(result.indexOf("myreq= 0) + assertTrue(result.indexOf("myact= 0) + assertTrue(result.indexOf("ari= 0) + assertTrue(result.indexOf("sii= 0) + assertTrue(result.indexOf("sii= 0) + assertTrue(result.indexOf("psii= 0) + assertTrue(result.indexOf("sst= 0) + assertTrue(result.indexOf("gci= 0) + assertTrue(result.indexOf("scu= 0) + assertTrue(result.indexOf("mri= 0) + assertTrue(result.indexOf("bwma= 0) + assertTrue(result.indexOf("myvni= 0) + assertTrue(result.indexOf("vbi= 0) + assertTrue(result.indexOf("") >= 0) + assertTrue(result.indexOf("") >= 0) + assertTrue(result.indexOf("") >= 0) + assertTrue(result.indexOf("") >= 0) + assertTrue(result.indexOf("") >= 0) + } + + @Test + public void buildSDNCRequest_Ex() { + ExecutionEntity mex = setupMock() + initBuildSDNCRequest(mex) + + when(mex.getVariable("allottedResourceId")).thenThrow(new RuntimeException("expected exception")) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.buildSDNCRequest(mex, "myact", "myreq") })) + } + + // ***** preProcessSDNCAssign ***** + + @Test + public void preProcessSDNCAssign() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + def data = initPreProcessSDNC(mex) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + DoCreateAllottedResourceBRG.preProcessSDNCAssign(mex) + + def req = map.get("sdncAssignRequest") + assertNotNull(req) + + assertEquals(data, map.get("rollbackData")) + + def rbreq = data.get(Prefix, "sdncAssignRollbackReq") + + assertTrue(req.indexOf("assign= 0) + assertTrue(req.indexOf("CreateBRGInstance= 0) + assertTrue(req.indexOf("") >= 0) + + assertTrue(rbreq.indexOf("unassign= 0) + assertTrue(rbreq.indexOf("DeleteBRGInstance= 0) + assertTrue(rbreq.indexOf("") >= 0) + } + + @Test + public void preProcessSDNCAssign_BpmnError() { + ExecutionEntity mex = setupMock() + initPreProcessSDNC(mex) + + when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception")) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCAssign(mex) })) + } + + @Test + public void preProcessSDNCAssign_Ex() { + ExecutionEntity mex = setupMock() + initPreProcessSDNC(mex) + + when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception")) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCAssign(mex) })) + } + + // ***** preProcessSDNCCreate ***** + + @Test + public void preProcessSDNCCreate() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + def data = initPreProcessSDNC(mex) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + DoCreateAllottedResourceBRG.preProcessSDNCCreate(mex) + + def req = map.get("sdncCreateRequest") + assertNotNull(req) + + assertEquals(data, map.get("rollbackData")) + + def rbreq = data.get(Prefix, "sdncCreateRollbackReq") + + assertTrue(req.indexOf("create= 0) + assertTrue(req.indexOf("CreateBRGInstance= 0) + assertTrue(req.indexOf("") >= 0) + + assertTrue(rbreq.indexOf("delete= 0) + assertTrue(rbreq.indexOf("DeleteBRGInstance= 0) + assertTrue(rbreq.indexOf("") >= 0) + + } + + @Test + public void preProcessSDNCCreate_BpmnError() { + ExecutionEntity mex = setupMock() + initPreProcessSDNC(mex) + + when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception")) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCCreate(mex) })) + } + + @Test + public void preProcessSDNCCreate_Ex() { + ExecutionEntity mex = setupMock() + initPreProcessSDNC(mex) + + when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception")) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCCreate(mex) })) + } + + // ***** preProcessSDNCActivate ***** + + @Test + public void preProcessSDNCActivate() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + def data = initPreProcessSDNC(mex) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + DoCreateAllottedResourceBRG.preProcessSDNCActivate(mex) + + def req = map.get("sdncActivateRequest") + assertNotNull(req) + + assertEquals(data, map.get("rollbackData")) + + def rbreq = data.get(Prefix, "sdncActivateRollbackReq") + + assertTrue(req.indexOf("activate= 0) + assertTrue(req.indexOf("CreateBRGInstance= 0) + assertTrue(req.indexOf("") >= 0) + + assertTrue(rbreq.indexOf("deactivate= 0) + assertTrue(rbreq.indexOf("DeleteBRGInstance= 0) + assertTrue(rbreq.indexOf("") >= 0) + + } + + @Test + public void preProcessSDNCActivate_BpmnError() { + ExecutionEntity mex = setupMock() + initPreProcessSDNC(mex) + + when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception")) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCActivate(mex) })) + } + + @Test + public void preProcessSDNCActivate_Ex() { + ExecutionEntity mex = setupMock() + initPreProcessSDNC(mex) + + when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception")) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCActivate(mex) })) + } + + // ***** validateSDNCResp ***** + + @Test + public void validateSDNCResp() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + def data = initValidateSDNCResp(mex) + def resp = initValidateSDNCResp_Resp() + + when(mex.getVariable(Prefix + "sdncResponseSuccess")).thenReturn(true) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + + DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create") + + verify(mex).getVariable("WorkflowException") + verify(mex).getVariable("SDNCA_SuccessIndicator") + verify(mex).getVariable("rollbackData") + + assertEquals(data, map.get("rollbackData")) + + assertEquals("true", data.get(Prefix, "rollback" + "SDNCcreate")) + + } + + @Test + public void validateSDNCResp_Get() { + ExecutionEntity mex = setupMock() + def data = initValidateSDNCResp(mex) + def resp = initValidateSDNCResp_Resp() + + when(mex.getVariable(Prefix + "sdncResponseSuccess")).thenReturn(true) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + + DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "get") + + verify(mex).getVariable("WorkflowException") + verify(mex).getVariable("SDNCA_SuccessIndicator") + + verify(mex, never()).getVariable("rollbackData") + } + + @Test + public void validateSDNCResp_Unsuccessful() { + ExecutionEntity mex = setupMock() + initValidateSDNCResp(mex) + def resp = initValidateSDNCResp_Resp() + + // unsuccessful + when(mex.getVariable(Prefix + "sdncResponseSuccess")).thenReturn(false) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create") })) + } + + @Test + public void validateSDNCResp_BpmnError() { + ExecutionEntity mex = setupMock() + initValidateSDNCResp(mex) + def resp = initValidateSDNCResp_Resp() + + when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception")) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create") })) + } + + @Test + public void validateSDNCResp_Ex() { + ExecutionEntity mex = setupMock() + initValidateSDNCResp(mex) + def resp = initValidateSDNCResp_Resp() + + when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception")) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create") })) + } + + // ***** preProcessSDNCGet ***** + + @Test + public void preProcessSDNCGet_FoundAR() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initPreProcessSDNCGet(mex) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + DoCreateAllottedResourceBRG.preProcessSDNCGet(mex) + + String req = map.get("sdncGetRequest") + + assertTrue(req.indexOf("") >= 0) + assertTrue(req.indexOf("sii= 0) + assertTrue(req.indexOf("arlink= 0) + assertTrue(req.indexOf("myurl= 0) + + } + + @Test + public void preProcessSDNCGet_NotFoundAR() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initPreProcessSDNCGet(mex) + + when(mex.getVariable("foundActiveAR")).thenReturn(false) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + DoCreateAllottedResourceBRG.preProcessSDNCGet(mex) + + String req = map.get("sdncGetRequest") + + assertTrue(req.indexOf("") >= 0) + assertTrue(req.indexOf("sii= 0) + assertTrue(req.indexOf("assignlink= 0) + assertTrue(req.indexOf("myurl= 0) + + } + + @Test + public void preProcessSDNCGet_Ex() { + ExecutionEntity mex = setupMock() + initPreProcessSDNCGet(mex) + + when(mex.getVariable("foundActiveAR")).thenThrow(new RuntimeException("expected exception")) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCGet(mex) })) + } + + // ***** updateAaiAROrchStatus ***** + + @Test + @Ignore + public void updateAaiAROrchStatus() { + MockPatchAllottedResource(CUST, SVC, INST, ARID) + + ExecutionEntity mex = setupMock() + initUpdateAaiAROrchStatus(mex) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + DoCreateAllottedResourceBRG.updateAaiAROrchStatus(mex, "success") + } + + // ***** generateOutputs ***** + + @Test + public void generateOutputs() { + ExecutionEntity mex = setupMock() + def brgtop = FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceBRG/SDNCTopologyQueryCallback.xml") + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("enhancedCallbackRequestData")).thenReturn(brgtop) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + DoCreateAllottedResourceBRG.generateOutputs(mex) + + verify(mex).setVariable("allotedResourceName", "namefromrequest") + + } + + @Test + public void generateOutputs_BadXml() { + ExecutionEntity mex = setupMock() + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("enhancedCallbackRequestData")).thenReturn("invalid xml") + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + DoCreateAllottedResourceBRG.generateOutputs(mex) + + verify(mex, never()).setVariable(anyString(), anyString()) + + } + + @Test + public void generateOutputs_BpmnError() { + ExecutionEntity mex = setupMock() + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("enhancedCallbackRequestData")).thenThrow(new BpmnError("expected exception")) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + + DoCreateAllottedResourceBRG.generateOutputs(mex) + verify(mex, never()).setVariable(anyString(), anyString()) + + } + + @Test + public void generateOutputs_Ex() { + ExecutionEntity mex = setupMock() + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("enhancedCallbackRequestData")).thenThrow(new RuntimeException("expected exception")) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + + DoCreateAllottedResourceBRG.generateOutputs(mex) + verify(mex, never()).setVariable(anyString(), anyString()) + + } + + // ***** preProcessRollback ***** + + @Test + public void preProcessRollback() { + ExecutionEntity mex = setupMock() + WorkflowException wfe = mock(WorkflowException.class) + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("WorkflowException")).thenReturn(wfe) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + DoCreateAllottedResourceBRG.preProcessRollback(mex) + + verify(mex).setVariable("prevWorkflowException", wfe) + } + + @Test + public void preProcessRollback_NotWFE() { + ExecutionEntity mex = setupMock() + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("WorkflowException")).thenReturn("I'm not a WFE") + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + DoCreateAllottedResourceBRG.preProcessRollback(mex) + } + + @Test + public void preProcessRollback_BpmnError() { + ExecutionEntity mex = setupMock() + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception")) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + + DoCreateAllottedResourceBRG.preProcessRollback(mex) + } + + @Test + public void preProcessRollback_Ex() { + ExecutionEntity mex = setupMock() + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception")) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + + DoCreateAllottedResourceBRG.preProcessRollback(mex) + + } + + // ***** postProcessRollback ***** + + @Test + public void postProcessRollback() { + ExecutionEntity mex = setupMock() + WorkflowException wfe = mock(WorkflowException.class) + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("prevWorkflowException")).thenReturn(wfe) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + DoCreateAllottedResourceBRG.postProcessRollback(mex) + + verify(mex).setVariable("WorkflowException", wfe) + verify(mex).setVariable("rollbackData", null) + + } + + @Test + public void postProcessRollback_NotWFE() { + ExecutionEntity mex = setupMock() + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("prevWorkflowException")).thenReturn("I'm not a WFE") + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + DoCreateAllottedResourceBRG.postProcessRollback(mex) + + verify(mex).setVariable("rollbackData", null) + + } + + @Test + public void postProcessRollback_BpmnError() { + ExecutionEntity mex = setupMock() + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("prevWorkflowException")).thenThrow(new BpmnError("expected exception")) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.postProcessRollback(mex) })) + verify(mex, never()).setVariable("rollbackData", null) + + } + + @Test + public void postProcessRollback_Ex() { + ExecutionEntity mex = setupMock() + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("prevWorkflowException")).thenThrow(new RuntimeException("expected exception")) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + + DoCreateAllottedResourceBRG.postProcessRollback(mex) + verify(mex, never()).setVariable("rollbackData", null) + + } + + private boolean checkMissingPreProcessRequest(String fieldnm) { + ExecutionEntity mex = setupMock() + initPreProcess(mex) + + DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG() + + when(mex.getVariable(fieldnm)).thenReturn("") + + return doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessRequest(mex) }) + } + + private void initPreProcess(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("sdncurn") + when(mex.getVariable("mso.workflow.sdnc.replication.delay")).thenReturn("sdncdelay") + when(mex.getVariable("serviceInstanceId")).thenReturn("sii") + when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii") + when(mex.getVariable("allottedResourceModelInfo")).thenReturn("armi") + when(mex.getVariable("vni")).thenReturn("myvni") + when(mex.getVariable("vgmuxBearerIP")).thenReturn("vbi") + when(mex.getVariable("brgWanMacAddress")).thenReturn("bwma") + when(mex.getVariable("allottedResourceRole")).thenReturn("arr") + when(mex.getVariable("allottedResourceType")).thenReturn("art") + } + + private void initGetAaiAR(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("allottedResourceType")).thenReturn("BRGt") + when(mex.getVariable("allottedResourceRole")).thenReturn("BRGr") + when(mex.getVariable("CSI_service")).thenReturn(FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceBRG/getAR.xml")) + when(mex.getVariable("aai.endpoint")).thenReturn(aaiUriPfx) + when(mex.getVariable("aaiAROrchStatus")).thenReturn("Active") + } + + private initCreateAaiAr(ExecutionEntity mex) { + when(mex.getVariable("disableRollback")).thenReturn(45) + when(mex.getVariable("serviceInstanceId")).thenReturn("sii") + when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii") + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("allottedResourceId")).thenReturn(ARID) + when(mex.getVariable("aai.endpoint")).thenReturn(aaiUriPfx) + when(mex.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn(UrnPropertiesReader.getVariable("mso.workflow.global.default.aai.namespace")) + when(mex.getVariable("PSI_resourceLink")).thenReturn(AAIUriFactory.createResourceFromExistingURI(AAIObjectType.SERVICE_INSTANCE, UriBuilder.fromPath("/business/customers/customer/" + CUST + "/service-subscriptions/service-subscription/" + SVC + "/service-instances/service-instance/" + INST).build())) + when(mex.getVariable("allottedResourceType")).thenReturn("BRGt") + when(mex.getVariable("allottedResourceRole")).thenReturn("BRGr") + when(mex.getVariable("CSI_resourceLink")).thenReturn(aaiUriPfx + "/aai/v9/mycsi") + when(mex.getVariable("allottedResourceModelInfo")).thenReturn(""" + { + "modelInvariantUuid":"modelinvuuid", + "modelUuid":"modeluuid", + "modelCustomizationUuid":"modelcustuuid" + } + """) + } + + private initBuildSDNCRequest(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("allottedResourceId")).thenReturn("ari") + when(mex.getVariable("serviceInstanceId")).thenReturn("sii") + when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii") + when(mex.getVariable("subscriptionServiceType")).thenReturn("sst") + when(mex.getVariable("globalCustomerId")).thenReturn("gci") + when(mex.getVariable("sdncCallbackUrl")).thenReturn("scu") + when(mex.getVariable("msoRequestId")).thenReturn("mri") + when(mex.getVariable("brgWanMacAddress")).thenReturn("bwma") + when(mex.getVariable("vni")).thenReturn("myvni") + when(mex.getVariable("vgmuxBearerIP")).thenReturn("vbi") + when(mex.getVariable("allottedResourceModelInfo")).thenReturn(""" + { + "modelInvariantUuid":"miu", + "modelUuid":"mu", + "modelCustomizationUuid":"mcu", + "modelVersion":"mv", + "modelName":"mn" + } + """) + } + + private RollbackData initPreProcessSDNC(ExecutionEntity mex) { + def data = new RollbackData() + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("rollbackData")).thenReturn(data) + + return data + } + + private initPreProcessSDNCGet(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("sdncCallbackUrl")).thenReturn("myurl") + when(mex.getVariable("foundActiveAR")).thenReturn(true) + when(mex.getVariable("aaiARGetResponse")).thenReturn("arlink") + when(mex.getVariable("sdncAssignResponse")).thenReturn("<object-path>assignlink</object-path>") + when(mex.getVariable("serviceInstanceId")).thenReturn("sii") + when(mex.getVariable("sdncCallbackUrl")).thenReturn("myurl") + } + + private RollbackData initValidateSDNCResp(ExecutionEntity mex) { + def data = new RollbackData() + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("prefix")).thenReturn(Prefix) + when(mex.getVariable("SDNCA_SuccessIndicator")).thenReturn(true) + when(mex.getVariable("rollbackData")).thenReturn(data) + + return data + } + + private String initValidateSDNCResp_Resp() { + return "<response-code>200</response-code>" + } + + private initUpdateAaiAROrchStatus(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("aaiARPath")).thenReturn("/business/customers/customer/" + CUST + "/service-subscriptions/service-subscription/" + SVC + "/service-instances/service-instance/" + INST + "/allotted-resources/allotted-resource/" + ARID) + } + } diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/DoCreateAllottedResourceTXCRollbackTest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/DoCreateAllottedResourceTXCRollbackTest.groovy index 50ce46e4a3..a877ce42e7 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/DoCreateAllottedResourceTXCRollbackTest.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/DoCreateAllottedResourceTXCRollbackTest.groovy @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -20,635 +22,573 @@ package org.onap.so.bpmn.vcpe.scripts - -import org.camunda.bpm.engine.ProcessEngineServices -import org.camunda.bpm.engine.RepositoryService +import com.github.tomakehurst.wiremock.junit.WireMockRule +import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity -import org.camunda.bpm.engine.repository.ProcessDefinition -import org.camunda.bpm.engine.delegate.DelegateExecution -import org.junit.Before -import org.junit.BeforeClass -import org.junit.Rule -import org.junit.Test -import org.junit.Ignore +import org.junit.* import org.mockito.MockitoAnnotations -import org.camunda.bpm.engine.delegate.BpmnError -import org.onap.so.bpmn.core.WorkflowException -import org.onap.so.bpmn.mock.FileUtil +import org.onap.so.bpmn.core.RollbackData import static com.github.tomakehurst.wiremock.client.WireMock.aResponse import static com.github.tomakehurst.wiremock.client.WireMock.get -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching -import static org.junit.Assert.*; +import static org.junit.Assert.assertTrue import static org.mockito.Mockito.* -import static org.onap.so.bpmn.mock.StubResponseAAI.MockDeleteAllottedResource -import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetAllottedResource -import static org.onap.so.bpmn.mock.StubResponseAAI.MockPatchAllottedResource +import static org.onap.so.bpmn.mock.StubResponseAAI.* -import org.onap.so.bpmn.core.RollbackData +class DoCreateAllottedResourceTXCRollbackTest extends GroovyTestBase { -import com.github.tomakehurst.wiremock.junit.WireMockRule + @Rule + public WireMockRule wireMockRule = new WireMockRule(PORT) + + String Prefix = "DCARTXCRB_" + String RbType = "DCARTXC_" + + @BeforeClass + public static void setUpBeforeClass() { + GroovyTestBase.setUpBeforeClass() + } -class DoCreateAllottedResourceTXCRollbackTest extends GroovyTestBase { - - @Rule - public WireMockRule wireMockRule = new WireMockRule(PORT) - - String Prefix = "DCARTXCRB_" - String RbType = "DCARTXC_" - - @BeforeClass - public static void setUpBeforeClass() { - super.setUpBeforeClass() - } - @Before - public void init() - { - MockitoAnnotations.initMocks(this) - } - - public DoCreateAllottedResourceTXCRollbackTest() { - super("DoCreateAllottedResourceTXCRollback") - } - - - // ***** preProcessRequest ***** - - @Test -// @Ignore - public void preProcessRequest() { - ExecutionEntity mex = setupMock() - initPreProcess(mex) - - DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() - DoCreateAllottedResourceTXCRollback.preProcessRequest(mex) - - //verify(mex).getVariable(DBGFLAG) - verify(mex).setVariable("prefix", Prefix) - verify(mex).setVariable("serviceInstanceId", "sii") - verify(mex).setVariable("parentServiceInstanceId", "psii") - verify(mex).setVariable("allottedResourceId", "myid") - verify(mex).setVariable("rollbackAAI", true) - verify(mex).setVariable("aaiARPath", "mypath") - verify(mex).setVariable("rollbackSDNC", true) - verify(mex).setVariable("deactivateSdnc", "myactivate") - verify(mex).setVariable("deleteSdnc", "mycreate") - verify(mex).setVariable("unassignSdnc", "true") - verify(mex).setVariable("sdncDeactivateRequest", "activatereq") - verify(mex).setVariable("sdncDeleteRequest", "createreq") - verify(mex).setVariable("sdncUnassignRequest", "assignreq") - - verify(mex, never()).setVariable("skipRollback", true) - } - - @Test -// @Ignore - public void preProcessRequest_RollbackDisabled() { - ExecutionEntity mex = setupMock() - initPreProcess(mex) - - when(mex.getVariable("disableRollback")).thenReturn("true") - - DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() - DoCreateAllottedResourceTXCRollback.preProcessRequest(mex) - - //verify(mex).getVariable(DBGFLAG) - verify(mex).setVariable("prefix", Prefix) - verify(mex).setVariable("serviceInstanceId", "sii") - verify(mex).setVariable("parentServiceInstanceId", "psii") - verify(mex).setVariable("allottedResourceId", "myid") - verify(mex).setVariable("rollbackAAI", true) - verify(mex).setVariable("aaiARPath", "mypath") - verify(mex).setVariable("rollbackSDNC", true) - verify(mex).setVariable("deactivateSdnc", "myactivate") - verify(mex).setVariable("deleteSdnc", "mycreate") - verify(mex).setVariable("unassignSdnc", "true") - verify(mex).setVariable("sdncDeactivateRequest", "activatereq") - verify(mex).setVariable("sdncDeleteRequest", "createreq") - verify(mex).setVariable("sdncUnassignRequest", "assignreq") - - verify(mex).setVariable("skipRollback", true) - } - - @Test -// @Ignore - public void preProcessRequest_NoAAI() { - ExecutionEntity mex = setupMock() - def data = initPreProcess(mex) - - when(mex.getVariable("rollbackAAI")).thenReturn(false) - data.put(RbType, "rollbackAAI", "false") - - DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() - DoCreateAllottedResourceTXCRollback.preProcessRequest(mex) - - //verify(mex).getVariable(DBGFLAG) - verify(mex).setVariable("prefix", Prefix) - verify(mex).setVariable("serviceInstanceId", "sii") - verify(mex).setVariable("parentServiceInstanceId", "psii") - verify(mex).setVariable("allottedResourceId", "myid") - verify(mex, never()).setVariable("rollbackAAI", true) - verify(mex, never()).setVariable("aaiARPath", "mypath") - verify(mex).setVariable("rollbackSDNC", true) - verify(mex).setVariable("deactivateSdnc", "myactivate") - verify(mex).setVariable("deleteSdnc", "mycreate") - verify(mex).setVariable("unassignSdnc", "true") - verify(mex).setVariable("sdncDeactivateRequest", "activatereq") - verify(mex).setVariable("sdncDeleteRequest", "createreq") - verify(mex).setVariable("sdncUnassignRequest", "assignreq") - - verify(mex, never()).setVariable("skipRollback", true) - } - - @Test -// @Ignore - public void preProcessRequest_NoAssign() { - ExecutionEntity mex = setupMock() - def data = initPreProcess(mex) - - when(mex.getVariable("rollbackSDNC")).thenReturn(false) - data.put(RbType, "rollbackSDNCassign", "false") - - DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() - DoCreateAllottedResourceTXCRollback.preProcessRequest(mex) - - //verify(mex).getVariable(DBGFLAG) - verify(mex).setVariable("prefix", Prefix) - verify(mex).setVariable("serviceInstanceId", "sii") - verify(mex).setVariable("parentServiceInstanceId", "psii") - verify(mex).setVariable("allottedResourceId", "myid") - verify(mex).setVariable("rollbackAAI", true) - verify(mex).setVariable("aaiARPath", "mypath") - verify(mex, never()).setVariable("rollbackSDNC", true) - verify(mex, never()).setVariable("deactivateSdnc", "myactivate") - verify(mex, never()).setVariable("deleteSdnc", "mycreate") - verify(mex, never()).setVariable("unassignSdnc", "true") - verify(mex, never()).setVariable("sdncDeactivateRequest", "activatereq") - verify(mex, never()).setVariable("sdncDeleteRequest", "createreq") - verify(mex, never()).setVariable("sdncUnassignRequest", "assignreq") - - verify(mex, never()).setVariable("skipRollback", true) - } - - @Test -// @Ignore - public void preProcessRequest_NoAAI_NoAssign() { - ExecutionEntity mex = setupMock() - initPreProcess(mex) - - when(mex.getVariable("rollbackAAI")).thenReturn(false) - when(mex.getVariable("rollbackSDNC")).thenReturn(false) - - DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() - DoCreateAllottedResourceTXCRollback.preProcessRequest(mex) - - verify(mex).setVariable("skipRollback", true) - } - - @Test -// @Ignore - public void preProcessRequest_NoRbStructure() { - ExecutionEntity mex = setupMock() - initPreProcess(mex) - - when(mex.getVariable("rollbackData")).thenReturn(new RollbackData()) - - DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() - DoCreateAllottedResourceTXCRollback.preProcessRequest(mex) - - verify(mex).setVariable("skipRollback", true) - } - - @Test -// @Ignore - public void preProcessRequest_NullRb() { - ExecutionEntity mex = setupMock() - initPreProcess(mex) - - when(mex.getVariable("rollbackData")).thenReturn(null) - - DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() - DoCreateAllottedResourceTXCRollback.preProcessRequest(mex) - - verify(mex).setVariable("skipRollback", true) - } - - @Test -// @Ignore - public void preProcessRequest_BpmnError() { - ExecutionEntity mex = setupMock() - initPreProcess(mex) - - when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception")) - - DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() - - assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceTXCRollback.preProcessRequest(mex) })) - } - - @Test -// @Ignore - public void preProcessRequest_Ex() { - ExecutionEntity mex = setupMock() - initPreProcess(mex) - - when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception")) - - DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() - - assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceTXCRollback.preProcessRequest(mex) })) - } - - @Test - @Ignore - public void updateAaiAROrchStatus() { - ExecutionEntity mex = setupMock() - initUpdateAaiAROrchStatus(mex) - - MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXCRollback/arGetById.xml") - MockPatchAllottedResource(CUST, SVC, INST, ARID) - - DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() - DoCreateAllottedResourceTXCRollback.updateAaiAROrchStatus(mex, "success") - } - - @Test -// @Ignore - public void updateAaiAROrchStatus_EmptyResponse() { - ExecutionEntity mex = setupMock() - initUpdateAaiAROrchStatus(mex) - - wireMockRule - .stubFor(get(urlMatching("/aai/v[0-9]+/.*")) - .willReturn(aResponse() - .withStatus(200))) - - DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() - - assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceTXCRollback.updateAaiAROrchStatus(mex, "success") })) - } - - @Test -// @Ignore - public void updateAaiAROrchStatus_NoArPath() { - ExecutionEntity mex = setupMock() - initUpdateAaiAROrchStatus(mex) - - MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXCRollback/arGetById.xml") - MockPatchAllottedResource(CUST, SVC, INST, ARID) - - when(mex.getVariable("aaiARPath")).thenReturn(null) - - DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() - - assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceTXCRollback.updateAaiAROrchStatus(mex, "success") })) - } - - - // ***** validateSDNCResp ***** - - @Test -// @Ignore - public void validateSDNCResp() { - ExecutionEntity mex = setupMock() - initValidateSDNCResp(mex) - def resp = initValidateSDNCResp_Resp() - - when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true) - - DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() - - DoCreateAllottedResourceTXCRollback.validateSDNCResp(mex, resp, "create") - - verify(mex).getVariable("WorkflowException") - verify(mex).getVariable("SDNCA_SuccessIndicator") - } - - @Test -// @Ignore - public void validateSDNCResp_Unsuccessful() { - ExecutionEntity mex = setupMock() - initValidateSDNCResp(mex) - def resp = initValidateSDNCResp_Resp() - - when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(false) - - DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() - - assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceTXCRollback.validateSDNCResp(mex, resp, "create") })) - } - - @Test -// @Ignore - public void validateSDNCResp_BpmnError404() { - ExecutionEntity mex = setupMock() - initValidateSDNCResp(mex) - def resp = initValidateSDNCResp_Resp() - when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true) - - when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("404", "expected exception")) - - DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() - - DoCreateAllottedResourceTXCRollback.validateSDNCResp(mex, resp, "create") - } - - @Test -// @Ignore - public void validateSDNCResp_BpmnError() { - ExecutionEntity mex = setupMock() - initValidateSDNCResp(mex) - def resp = initValidateSDNCResp_Resp() - when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true) - - when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception")) - - DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() - - assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceTXCRollback.validateSDNCResp(mex, resp, "create") })) - } - - @Test -// @Ignore - public void validateSDNCResp_Ex() { - ExecutionEntity mex = setupMock() - initValidateSDNCResp(mex) - def resp = initValidateSDNCResp_Resp() - when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true) - - when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception")) - - DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() - - assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceTXCRollback.validateSDNCResp(mex, resp, "create") })) - } - - @Test - @Ignore - public void deleteAaiAR() { - ExecutionEntity mex = setupMock() - initDeleteAaiAR(mex) - - MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXCRollback/arGetById.xml") - MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) - - DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() - DoCreateAllottedResourceTXCRollback.deleteAaiAR(mex) - } - - @Test -// @Ignore - public void deleteAaiAR_NoArPath() { - ExecutionEntity mex = setupMock() - initDeleteAaiAR(mex) - - MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXCRollback/arGetById.xml") - MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) - - when(mex.getVariable("aaiARPath")).thenReturn("") - - DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() - - assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceTXCRollback.deleteAaiAR(mex) })) - } - - @Test -// @Ignore - public void deleteAaiAR_BpmnError() { - ExecutionEntity mex = setupMock() - initDeleteAaiAR(mex) - - MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXCRollback/arGetById.xml") - MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) - - when(mex.getVariable("aaiARPath")).thenThrow(new BpmnError("expected exception")) - - DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() - - assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceTXCRollback.deleteAaiAR(mex) })) - } - - @Test -// @Ignore - public void deleteAaiAR_Ex() { - ExecutionEntity mex = setupMock() - initDeleteAaiAR(mex) - - MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXCRollback/arGetById.xml") - MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) - - when(mex.getVariable("aaiARPath")).thenThrow(new RuntimeException("expected exception")) - - DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() - - assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceTXCRollback.deleteAaiAR(mex) })) - } - - @Test -// @Ignore - public void postProcessRequest() { - ExecutionEntity mex = setupMock() - initPostProcessRequest(mex) - - DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() - DoCreateAllottedResourceTXCRollback.postProcessRequest(mex) - - //verify(mex).getVariable(DBGFLAG) - verify(mex).setVariable("rollbackData", null) - verify(mex).setVariable("rolledBack", true) - } - - @Test -// @Ignore - public void postProcessRequest_RolledBack() { - ExecutionEntity mex = setupMock() - initPostProcessRequest(mex) - - when(mex.getVariable("skipRollback")).thenReturn(true) - - DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() - DoCreateAllottedResourceTXCRollback.postProcessRequest(mex) - - //verify(mex).getVariable(DBGFLAG) - verify(mex).setVariable("rollbackData", null) - verify(mex, never()).setVariable("rolledBack", true) - } - - @Test -// @Ignore - public void postProcessRequest_BpmnError() { - ExecutionEntity mex = setupMock() - initPostProcessRequest(mex) - - when(mex.getVariable("skipRollback")).thenThrow(new BpmnError("expected exception")) - - DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() - DoCreateAllottedResourceTXCRollback.postProcessRequest(mex) - - //verify(mex).getVariable(DBGFLAG) - verify(mex).setVariable("rollbackData", null) - verify(mex, never()).setVariable("rolledBack", true) - } - - @Test -// @Ignore - public void postProcessRequest_Ex() { - ExecutionEntity mex = setupMock() - initPostProcessRequest(mex) - - when(mex.getVariable("skipRollback")).thenThrow(new RuntimeException("expected exception")) - - DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() - DoCreateAllottedResourceTXCRollback.postProcessRequest(mex) - - //verify(mex).getVariable(DBGFLAG) - verify(mex).setVariable("rollbackData", null) - verify(mex, never()).setVariable("rolledBack", true) - } - - @Test -// @Ignore - public void processRollbackException() { - ExecutionEntity mex = setupMock() - initProcessRollbackException(mex) - - DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() - DoCreateAllottedResourceTXCRollback.processRollbackException(mex) - - //verify(mex).getVariable(DBGFLAG) - verify(mex).setVariable("rollbackData", null) - verify(mex).setVariable("rolledBack", false) - verify(mex).setVariable("rollbackError", "Caught exception in AllottedResource Create Rollback") - verify(mex).setVariable("WorkflowException", null) - } - - @Test -// @Ignore - public void processRollbackException_BpmnError() { - ExecutionEntity mex = setupMock() - initProcessRollbackException(mex) - - doThrow(new BpmnError("expected exception")).when(mex).setVariable("rollbackData", null) - - DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() - DoCreateAllottedResourceTXCRollback.processRollbackException(mex) - } - - @Test -// @Ignore - public void processRollbackException_Ex() { - ExecutionEntity mex = setupMock() - initProcessRollbackException(mex) - - doThrow(new RuntimeException("expected exception")).when(mex).setVariable("rollbackData", null) - - DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() - DoCreateAllottedResourceTXCRollback.processRollbackException(mex) - } - - @Test -// @Ignore - public void processRollbackJavaException() { - ExecutionEntity mex = setupMock() - initProcessRollbackException(mex) - - DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() - DoCreateAllottedResourceTXCRollback.processRollbackJavaException(mex) - - //verify(mex).getVariable(DBGFLAG) - verify(mex).setVariable("rollbackData", null) - verify(mex).setVariable("rolledBack", false) - verify(mex).setVariable("rollbackError", "Caught Java exception in AllottedResource Create Rollback") - verify(mex, never()).setVariable("WorkflowException", null) - } - - @Test -// @Ignore - public void processRollbackJavaException_BpmnError() { - ExecutionEntity mex = setupMock() - initProcessRollbackException(mex) - - doThrow(new BpmnError("expected exception")).when(mex).setVariable("rollbackData", null) - - DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() - DoCreateAllottedResourceTXCRollback.processRollbackJavaException(mex) - } - - @Test -// @Ignore - public void processRollbackJavaException_Ex() { - ExecutionEntity mex = setupMock() - initProcessRollbackException(mex) - - doThrow(new RuntimeException("expected exception")).when(mex).setVariable("rollbackData", null) - - DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() - DoCreateAllottedResourceTXCRollback.processRollbackJavaException(mex) - } - - private RollbackData initPreProcess(ExecutionEntity mex) { - def data = new RollbackData() - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("rollbackData")).thenReturn(data) - when(mex.getVariable("rollbackAAI")).thenReturn(true) - when(mex.getVariable("rollbackSDNC")).thenReturn(true) - when(mex.getVariable("disableRollback")).thenReturn("false") - - data.put("SERVICEINSTANCE", "allottedResourceId", "myid") - - data.put(RbType, "serviceInstanceId", "sii") - data.put(RbType, "parentServiceInstanceId", "psii") - - data.put(RbType, "rollbackAAI", "true") - data.put(RbType, "aaiARPath", "mypath") - - data.put(RbType, "rollbackSDNCassign", "true") - data.put(RbType, "rollbackSDNCactivate", "myactivate") - data.put(RbType, "rollbackSDNCcreate", "mycreate") - data.put(RbType, "sdncActivateRollbackReq", "activatereq") - data.put(RbType, "sdncCreateRollbackReq", "createreq") - data.put(RbType, "sdncAssignRollbackReq", "assignreq") - - return data - } - - private initUpdateAaiAROrchStatus(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("aaiARPath")).thenReturn("/business/customers/customer/"+CUST+"/service-subscriptions/service-subscription/"+SVC+"/service-instances/service-instance/"+INST+"/allotted-resources/allotted-resource/"+ARID) - when(mex.getVariable("aai.endpoint")).thenReturn(aaiUriPfx) - } - - private initValidateSDNCResp(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("prefix")).thenReturn(Prefix) - when(mex.getVariable("SDNCA_SuccessIndicator")).thenReturn(true) - } - - private String initValidateSDNCResp_Resp() { - return "<response-code>200</response-code>" - } - - private initDeleteAaiAR(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("aaiARResourceVersion")).thenReturn(VERS) - when(mex.getVariable("aaiARPath")).thenReturn("/business/customers/customer/"+CUST+"/service-subscriptions/service-subscription/"+SVC+"/service-instances/service-instance/"+INST+"/allotted-resources/allotted-resource/"+ARID) - when(mex.getVariable("aai.endpoint")).thenReturn(aaiUriPfx) - } - - private initPostProcessRequest(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("skipRollback")).thenReturn(false) - } - - private initProcessRollbackException(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - } - - private initProcessRollbackJavaException(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - } - + public void init() { + MockitoAnnotations.initMocks(this) + } + + public DoCreateAllottedResourceTXCRollbackTest() { + super("DoCreateAllottedResourceTXCRollback") + } + + // ***** preProcessRequest ***** + + @Test + public void preProcessRequest() { + ExecutionEntity mex = setupMock() + initPreProcess(mex) + + DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() + DoCreateAllottedResourceTXCRollback.preProcessRequest(mex) + + verify(mex).setVariable("prefix", Prefix) + verify(mex).setVariable("serviceInstanceId", "sii") + verify(mex).setVariable("parentServiceInstanceId", "psii") + verify(mex).setVariable("allottedResourceId", "myid") + verify(mex).setVariable("rollbackAAI", true) + verify(mex).setVariable("aaiARPath", "mypath") + verify(mex).setVariable("rollbackSDNC", true) + verify(mex).setVariable("deactivateSdnc", "myactivate") + verify(mex).setVariable("deleteSdnc", "mycreate") + verify(mex).setVariable("unassignSdnc", "true") + verify(mex).setVariable("sdncDeactivateRequest", "activatereq") + verify(mex).setVariable("sdncDeleteRequest", "createreq") + verify(mex).setVariable("sdncUnassignRequest", "assignreq") + + verify(mex, never()).setVariable("skipRollback", true) + } + + @Test + public void preProcessRequest_RollbackDisabled() { + ExecutionEntity mex = setupMock() + initPreProcess(mex) + + when(mex.getVariable("disableRollback")).thenReturn("true") + + DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() + DoCreateAllottedResourceTXCRollback.preProcessRequest(mex) + + verify(mex).setVariable("prefix", Prefix) + verify(mex).setVariable("serviceInstanceId", "sii") + verify(mex).setVariable("parentServiceInstanceId", "psii") + verify(mex).setVariable("allottedResourceId", "myid") + verify(mex).setVariable("rollbackAAI", true) + verify(mex).setVariable("aaiARPath", "mypath") + verify(mex).setVariable("rollbackSDNC", true) + verify(mex).setVariable("deactivateSdnc", "myactivate") + verify(mex).setVariable("deleteSdnc", "mycreate") + verify(mex).setVariable("unassignSdnc", "true") + verify(mex).setVariable("sdncDeactivateRequest", "activatereq") + verify(mex).setVariable("sdncDeleteRequest", "createreq") + verify(mex).setVariable("sdncUnassignRequest", "assignreq") + + verify(mex).setVariable("skipRollback", true) + } + + @Test + public void preProcessRequest_NoAAI() { + ExecutionEntity mex = setupMock() + def data = initPreProcess(mex) + + when(mex.getVariable("rollbackAAI")).thenReturn(false) + data.put(RbType, "rollbackAAI", "false") + + DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() + DoCreateAllottedResourceTXCRollback.preProcessRequest(mex) + + verify(mex).setVariable("prefix", Prefix) + verify(mex).setVariable("serviceInstanceId", "sii") + verify(mex).setVariable("parentServiceInstanceId", "psii") + verify(mex).setVariable("allottedResourceId", "myid") + verify(mex, never()).setVariable("rollbackAAI", true) + verify(mex, never()).setVariable("aaiARPath", "mypath") + verify(mex).setVariable("rollbackSDNC", true) + verify(mex).setVariable("deactivateSdnc", "myactivate") + verify(mex).setVariable("deleteSdnc", "mycreate") + verify(mex).setVariable("unassignSdnc", "true") + verify(mex).setVariable("sdncDeactivateRequest", "activatereq") + verify(mex).setVariable("sdncDeleteRequest", "createreq") + verify(mex).setVariable("sdncUnassignRequest", "assignreq") + + verify(mex, never()).setVariable("skipRollback", true) + } + + @Test + public void preProcessRequest_NoAssign() { + ExecutionEntity mex = setupMock() + def data = initPreProcess(mex) + + when(mex.getVariable("rollbackSDNC")).thenReturn(false) + data.put(RbType, "rollbackSDNCassign", "false") + + DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() + DoCreateAllottedResourceTXCRollback.preProcessRequest(mex) + + verify(mex).setVariable("prefix", Prefix) + verify(mex).setVariable("serviceInstanceId", "sii") + verify(mex).setVariable("parentServiceInstanceId", "psii") + verify(mex).setVariable("allottedResourceId", "myid") + verify(mex).setVariable("rollbackAAI", true) + verify(mex).setVariable("aaiARPath", "mypath") + verify(mex, never()).setVariable("rollbackSDNC", true) + verify(mex, never()).setVariable("deactivateSdnc", "myactivate") + verify(mex, never()).setVariable("deleteSdnc", "mycreate") + verify(mex, never()).setVariable("unassignSdnc", "true") + verify(mex, never()).setVariable("sdncDeactivateRequest", "activatereq") + verify(mex, never()).setVariable("sdncDeleteRequest", "createreq") + verify(mex, never()).setVariable("sdncUnassignRequest", "assignreq") + + verify(mex, never()).setVariable("skipRollback", true) + } + + @Test + public void preProcessRequest_NoAAI_NoAssign() { + ExecutionEntity mex = setupMock() + initPreProcess(mex) + + when(mex.getVariable("rollbackAAI")).thenReturn(false) + when(mex.getVariable("rollbackSDNC")).thenReturn(false) + + DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() + DoCreateAllottedResourceTXCRollback.preProcessRequest(mex) + + verify(mex).setVariable("skipRollback", true) + } + + @Test + public void preProcessRequest_NoRbStructure() { + ExecutionEntity mex = setupMock() + initPreProcess(mex) + + when(mex.getVariable("rollbackData")).thenReturn(new RollbackData()) + + DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() + DoCreateAllottedResourceTXCRollback.preProcessRequest(mex) + + verify(mex).setVariable("skipRollback", true) + } + + @Test + public void preProcessRequest_NullRb() { + ExecutionEntity mex = setupMock() + initPreProcess(mex) + + when(mex.getVariable("rollbackData")).thenReturn(null) + + DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() + DoCreateAllottedResourceTXCRollback.preProcessRequest(mex) + + verify(mex).setVariable("skipRollback", true) + } + + @Test + public void preProcessRequest_BpmnError() { + ExecutionEntity mex = setupMock() + initPreProcess(mex) + + when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception")) + + DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXCRollback.preProcessRequest(mex) })) + } + + @Test + public void preProcessRequest_Ex() { + ExecutionEntity mex = setupMock() + initPreProcess(mex) + + when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception")) + + DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXCRollback.preProcessRequest(mex) })) + } + + @Test + @Ignore + public void updateAaiAROrchStatus() { + ExecutionEntity mex = setupMock() + initUpdateAaiAROrchStatus(mex) + + MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXCRollback/arGetById.xml") + MockPatchAllottedResource(CUST, SVC, INST, ARID) + + DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() + DoCreateAllottedResourceTXCRollback.updateAaiAROrchStatus(mex, "success") + } + + @Test + public void updateAaiAROrchStatus_EmptyResponse() { + ExecutionEntity mex = setupMock() + initUpdateAaiAROrchStatus(mex) + + wireMockRule + .stubFor(get(urlMatching("/aai/v[0-9]+/.*")) + .willReturn(aResponse() + .withStatus(200))) + + DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXCRollback.updateAaiAROrchStatus(mex, "success") })) + } + + @Test + public void updateAaiAROrchStatus_NoArPath() { + ExecutionEntity mex = setupMock() + initUpdateAaiAROrchStatus(mex) + + MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXCRollback/arGetById.xml") + MockPatchAllottedResource(CUST, SVC, INST, ARID) + + when(mex.getVariable("aaiARPath")).thenReturn(null) + + DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXCRollback.updateAaiAROrchStatus(mex, "success") })) + } + + // ***** validateSDNCResp ***** + + @Test + public void validateSDNCResp() { + ExecutionEntity mex = setupMock() + initValidateSDNCResp(mex) + def resp = initValidateSDNCResp_Resp() + + when(mex.getVariable(Prefix + "sdncResponseSuccess")).thenReturn(true) + + DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() + + DoCreateAllottedResourceTXCRollback.validateSDNCResp(mex, resp, "create") + + verify(mex).getVariable("WorkflowException") + verify(mex).getVariable("SDNCA_SuccessIndicator") + } + + @Test + public void validateSDNCResp_Unsuccessful() { + ExecutionEntity mex = setupMock() + initValidateSDNCResp(mex) + def resp = initValidateSDNCResp_Resp() + + when(mex.getVariable(Prefix + "sdncResponseSuccess")).thenReturn(false) + + DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXCRollback.validateSDNCResp(mex, resp, "create") })) + } + + @Test + public void validateSDNCResp_BpmnError404() { + ExecutionEntity mex = setupMock() + initValidateSDNCResp(mex) + def resp = initValidateSDNCResp_Resp() + when(mex.getVariable(Prefix + "sdncResponseSuccess")).thenReturn(true) + + when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("404", "expected exception")) + + DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() + + DoCreateAllottedResourceTXCRollback.validateSDNCResp(mex, resp, "create") + } + + @Test + public void validateSDNCResp_BpmnError() { + ExecutionEntity mex = setupMock() + initValidateSDNCResp(mex) + def resp = initValidateSDNCResp_Resp() + when(mex.getVariable(Prefix + "sdncResponseSuccess")).thenReturn(true) + + when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception")) + + DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXCRollback.validateSDNCResp(mex, resp, "create") })) + } + + @Test + public void validateSDNCResp_Ex() { + ExecutionEntity mex = setupMock() + initValidateSDNCResp(mex) + def resp = initValidateSDNCResp_Resp() + when(mex.getVariable(Prefix + "sdncResponseSuccess")).thenReturn(true) + + when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception")) + + DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXCRollback.validateSDNCResp(mex, resp, "create") })) + } + + @Test + @Ignore + public void deleteAaiAR() { + ExecutionEntity mex = setupMock() + initDeleteAaiAR(mex) + + MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXCRollback/arGetById.xml") + MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) + + DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() + DoCreateAllottedResourceTXCRollback.deleteAaiAR(mex) + } + + @Test + public void deleteAaiAR_NoArPath() { + ExecutionEntity mex = setupMock() + initDeleteAaiAR(mex) + + MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXCRollback/arGetById.xml") + MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) + + when(mex.getVariable("aaiARPath")).thenReturn("") + + DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXCRollback.deleteAaiAR(mex) })) + } + + @Test + public void deleteAaiAR_BpmnError() { + ExecutionEntity mex = setupMock() + initDeleteAaiAR(mex) + + MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXCRollback/arGetById.xml") + MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) + + when(mex.getVariable("aaiARPath")).thenThrow(new BpmnError("expected exception")) + + DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXCRollback.deleteAaiAR(mex) })) + } + + @Test + public void deleteAaiAR_Ex() { + ExecutionEntity mex = setupMock() + initDeleteAaiAR(mex) + + MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXCRollback/arGetById.xml") + MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) + + when(mex.getVariable("aaiARPath")).thenThrow(new RuntimeException("expected exception")) + + DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXCRollback.deleteAaiAR(mex) })) + } + + @Test + public void postProcessRequest() { + ExecutionEntity mex = setupMock() + initPostProcessRequest(mex) + + DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() + DoCreateAllottedResourceTXCRollback.postProcessRequest(mex) + + verify(mex).setVariable("rollbackData", null) + verify(mex).setVariable("rolledBack", true) + } + + @Test + public void postProcessRequest_RolledBack() { + ExecutionEntity mex = setupMock() + initPostProcessRequest(mex) + + when(mex.getVariable("skipRollback")).thenReturn(true) + + DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() + DoCreateAllottedResourceTXCRollback.postProcessRequest(mex) + + verify(mex).setVariable("rollbackData", null) + verify(mex, never()).setVariable("rolledBack", true) + } + + @Test + public void postProcessRequest_BpmnError() { + ExecutionEntity mex = setupMock() + initPostProcessRequest(mex) + + when(mex.getVariable("skipRollback")).thenThrow(new BpmnError("expected exception")) + + DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() + DoCreateAllottedResourceTXCRollback.postProcessRequest(mex) + + verify(mex).setVariable("rollbackData", null) + verify(mex, never()).setVariable("rolledBack", true) + } + + @Test + public void postProcessRequest_Ex() { + ExecutionEntity mex = setupMock() + initPostProcessRequest(mex) + + when(mex.getVariable("skipRollback")).thenThrow(new RuntimeException("expected exception")) + + DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() + DoCreateAllottedResourceTXCRollback.postProcessRequest(mex) + + verify(mex).setVariable("rollbackData", null) + verify(mex, never()).setVariable("rolledBack", true) + } + + @Test + public void processRollbackException() { + ExecutionEntity mex = setupMock() + initProcessRollbackException(mex) + + DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() + DoCreateAllottedResourceTXCRollback.processRollbackException(mex) + + verify(mex).setVariable("rollbackData", null) + verify(mex).setVariable("rolledBack", false) + verify(mex).setVariable("rollbackError", "Caught exception in AllottedResource Create Rollback") + verify(mex).setVariable("WorkflowException", null) + } + + @Test + public void processRollbackException_BpmnError() { + ExecutionEntity mex = setupMock() + initProcessRollbackException(mex) + + doThrow(new BpmnError("expected exception")).when(mex).setVariable("rollbackData", null) + + DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() + DoCreateAllottedResourceTXCRollback.processRollbackException(mex) + } + + @Test + public void processRollbackException_Ex() { + ExecutionEntity mex = setupMock() + initProcessRollbackException(mex) + + doThrow(new RuntimeException("expected exception")).when(mex).setVariable("rollbackData", null) + + DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() + DoCreateAllottedResourceTXCRollback.processRollbackException(mex) + } + + @Test + public void processRollbackJavaException() { + ExecutionEntity mex = setupMock() + initProcessRollbackException(mex) + + DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() + DoCreateAllottedResourceTXCRollback.processRollbackJavaException(mex) + + verify(mex).setVariable("rollbackData", null) + verify(mex).setVariable("rolledBack", false) + verify(mex).setVariable("rollbackError", "Caught Java exception in AllottedResource Create Rollback") + verify(mex, never()).setVariable("WorkflowException", null) + } + + @Test + public void processRollbackJavaException_BpmnError() { + ExecutionEntity mex = setupMock() + initProcessRollbackException(mex) + + doThrow(new BpmnError("expected exception")).when(mex).setVariable("rollbackData", null) + + DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() + DoCreateAllottedResourceTXCRollback.processRollbackJavaException(mex) + } + + @Test + public void processRollbackJavaException_Ex() { + ExecutionEntity mex = setupMock() + initProcessRollbackException(mex) + + doThrow(new RuntimeException("expected exception")).when(mex).setVariable("rollbackData", null) + + DoCreateAllottedResourceTXCRollback DoCreateAllottedResourceTXCRollback = new DoCreateAllottedResourceTXCRollback() + DoCreateAllottedResourceTXCRollback.processRollbackJavaException(mex) + } + + private RollbackData initPreProcess(ExecutionEntity mex) { + def data = new RollbackData() + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("rollbackData")).thenReturn(data) + when(mex.getVariable("rollbackAAI")).thenReturn(true) + when(mex.getVariable("rollbackSDNC")).thenReturn(true) + when(mex.getVariable("disableRollback")).thenReturn("false") + + data.put("SERVICEINSTANCE", "allottedResourceId", "myid") + + data.put(RbType, "serviceInstanceId", "sii") + data.put(RbType, "parentServiceInstanceId", "psii") + + data.put(RbType, "rollbackAAI", "true") + data.put(RbType, "aaiARPath", "mypath") + + data.put(RbType, "rollbackSDNCassign", "true") + data.put(RbType, "rollbackSDNCactivate", "myactivate") + data.put(RbType, "rollbackSDNCcreate", "mycreate") + data.put(RbType, "sdncActivateRollbackReq", "activatereq") + data.put(RbType, "sdncCreateRollbackReq", "createreq") + data.put(RbType, "sdncAssignRollbackReq", "assignreq") + + return data + } + + private initUpdateAaiAROrchStatus(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("aaiARPath")).thenReturn("/business/customers/customer/" + CUST + "/service-subscriptions/service-subscription/" + SVC + "/service-instances/service-instance/" + INST + "/allotted-resources/allotted-resource/" + ARID) + when(mex.getVariable("aai.endpoint")).thenReturn(aaiUriPfx) + } + + private initValidateSDNCResp(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("prefix")).thenReturn(Prefix) + when(mex.getVariable("SDNCA_SuccessIndicator")).thenReturn(true) + } + + private String initValidateSDNCResp_Resp() { + return "<response-code>200</response-code>" + } + + private initDeleteAaiAR(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("aaiARResourceVersion")).thenReturn(VERS) + when(mex.getVariable("aaiARPath")).thenReturn("/business/customers/customer/" + CUST + "/service-subscriptions/service-subscription/" + SVC + "/service-instances/service-instance/" + INST + "/allotted-resources/allotted-resource/" + ARID) + when(mex.getVariable("aai.endpoint")).thenReturn(aaiUriPfx) + } + + private initPostProcessRequest(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("skipRollback")).thenReturn(false) + } + + private initProcessRollbackException(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + } + } diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/DoCreateAllottedResourceTXCTest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/DoCreateAllottedResourceTXCTest.groovy index b759ca1c20..b53e5fce21 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/DoCreateAllottedResourceTXCTest.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/DoCreateAllottedResourceTXCTest.groovy @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -20,15 +22,10 @@ package org.onap.so.bpmn.vcpe.scripts - +import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity -import org.junit.Before -import org.junit.BeforeClass -import org.junit.Rule -import org.junit.Test -import org.junit.Ignore +import org.junit.* import org.mockito.MockitoAnnotations -import org.camunda.bpm.engine.delegate.BpmnError import org.onap.so.bpmn.core.UrnPropertiesReader import org.onap.so.bpmn.core.WorkflowException import org.onap.so.bpmn.mock.FileUtil @@ -38,7 +35,7 @@ import org.onap.so.client.aai.entities.uri.AAIUriFactory import javax.ws.rs.core.UriBuilder -import static org.junit.Assert.*; +import static org.junit.Assert.* import static org.mockito.Mockito.* import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetAllottedResource import static org.onap.so.bpmn.mock.StubResponseAAI.MockPatchAllottedResource @@ -50,860 +47,808 @@ import org.onap.so.bpmn.core.RollbackData import com.github.tomakehurst.wiremock.junit.WireMockRule class DoCreateAllottedResourceTXCTest extends GroovyTestBase { - - @Rule - public WireMockRule wireMockRule = new WireMockRule(PORT) - String Prefix = "DCARTXC_" + @Rule + public WireMockRule wireMockRule = new WireMockRule(PORT) + + String Prefix = "DCARTXC_" + + @BeforeClass + public static void setUpBeforeClass() { + aaiUriPfx = UrnPropertiesReader.getVariable("aai.endpoint") + } - @BeforeClass - public static void setUpBeforeClass() { - aaiUriPfx = UrnPropertiesReader.getVariable("aai.endpoint") - } - @Before - public void init() - { - MockitoAnnotations.initMocks(this) - } - - public DoCreateAllottedResourceTXCTest() { - super("DoCreateAllottedResourceTXC") - } - - - // ***** preProcessRequest ***** - - @Test - - public void preProcessRequest() { - ExecutionEntity mex = setupMock() - initPreProcess(mex) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - DoCreateAllottedResourceTXC.preProcessRequest(mex) - - //verify(mex).getVariable(DBGFLAG) - verify(mex).setVariable("prefix", Prefix) - - assertTrue(checkMissingPreProcessRequest("mso.workflow.sdncadapter.callback")) - assertTrue(checkMissingPreProcessRequest("mso.workflow.sdnc.replication.delay")) - assertTrue(checkMissingPreProcessRequest("serviceInstanceId")) - assertTrue(checkMissingPreProcessRequest("parentServiceInstanceId")) - assertTrue(checkMissingPreProcessRequest("allottedResourceModelInfo")) - assertTrue(checkMissingPreProcessRequest("brgWanMacAddress")) - assertTrue(checkMissingPreProcessRequest("allottedResourceRole")) - assertTrue(checkMissingPreProcessRequest("allottedResourceType")) - } - - - // ***** getAaiAR ***** - - @Test - @Ignore - public void getAaiAR() { - MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXC/getArTxc.xml") - - ExecutionEntity mex = setupMock() - initGetAaiAR(mex) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - DoCreateAllottedResourceTXC.getAaiAR(mex) - - verify(mex).setVariable("foundActiveAR", true) - } - - @Test - - public void getAaiAR_Duplicate() { - MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXC/getArTxc.xml") - - ExecutionEntity mex = setupMock() - initGetAaiAR(mex) - - // fail if duplicate - when(mex.getVariable("failExists")).thenReturn("true") - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - - assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceTXC.getAaiAR(mex) })) - } - - @Test - - public void getAaiAR_NotActive() { - MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXC/getArTxc.xml") - - ExecutionEntity mex = setupMock() - initGetAaiAR(mex) - - // not active - when(mex.getVariable("aaiAROrchStatus")).thenReturn("not-active") - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - - assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceTXC.getAaiAR(mex) })) - } - - @Test - @Ignore - public void getAaiAR_NoStatus() { - MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXC/getArTxc.xml") - - ExecutionEntity mex = setupMock() - initGetAaiAR(mex) - - when(mex.getVariable("aaiAROrchStatus")).thenReturn(null) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - DoCreateAllottedResourceTXC.getAaiAR(mex) - - verify(mex, never()).setVariable("foundActiveAR", true) - } - - - // ***** createAaiAR ***** - - @Test - public void createAaiAR() { - ExecutionEntity mex = setupMock() - initCreateAaiAr(mex) - when(mex.getVariable("PSI_resourceLink")).thenReturn(AAIUriFactory.createResourceFromExistingURI(AAIObjectType.SERVICE_INSTANCE, UriBuilder.fromPath( "/aai/v9/business/customers/customer/"+CUST+"/service-subscriptions/service-subscription/"+SVC+"/service-instances/service-instance/"+INST).build())) - when(mex.getVariable("CSI_resourceLink")).thenReturn("/aai/v9/business/customers/customer/"+CUST+"/service-subscriptions/service-subscription/"+SVC+"/service-instances/service-instance/"+INST) - when(mex.getVariable("allottedResourceModelInfo")).thenReturn("{\n" + - " \"modelInvariantUuid\":\"modelInvariantUuid\",\n" + - " \"modelUuid\" : \"modelUuid\"\n" + - "}") - AAIResourcesClient client = mock(AAIResourcesClient.class) - DoCreateAllottedResourceTXC doCreateAllottedResourceTXC = spy(DoCreateAllottedResourceTXC.class) - when(doCreateAllottedResourceTXC.getAAIClient()).thenReturn(client) - doCreateAllottedResourceTXC.createAaiAR(mex) - } - - - @Test - public void createAaiAR_MissingPsiLink() { - ExecutionEntity mex = setupMock() - initCreateAaiAr(mex) - - when(mex.getVariable("PSI_resourceLink")).thenReturn(null) - - MockPutAllottedResource(CUST, SVC, INST, ARID) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.createAaiAR(mex) })) - } - - @Test - - public void createAaiAR_HttpFailed() { - ExecutionEntity mex = setupMock() - initCreateAaiAr(mex) - - MockPutAllottedResource_500(CUST, SVC, INST, ARID) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.createAaiAR(mex) })) - } - - @Test - - public void createAaiAR_BpmnError() { - ExecutionEntity mex = setupMock() - initCreateAaiAr(mex) - - when(mex.getVariable("aai.endpoint")).thenThrow(new BpmnError("expected exception")) - - MockPutAllottedResource(CUST, SVC, INST, ARID) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.createAaiAR(mex) })) - } - - @Test - - public void createAaiAR_Ex() { - ExecutionEntity mex = setupMock() - initCreateAaiAr(mex) - - when(mex.getVariable("aai.endpoint")).thenThrow(new RuntimeException("expected exception")) - - MockPutAllottedResource(CUST, SVC, INST, ARID) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.createAaiAR(mex) })) - } - - - // ***** buildSDNCRequest ***** - - @Test - - public void buildSDNCRequest() { - ExecutionEntity mex = setupMock() - initBuildSDNCRequest(mex) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - - String result = DoCreateAllottedResourceTXC.buildSDNCRequest(mex, "myact", "myreq") - - assertTrue(result.indexOf("myreq= 0) - assertTrue(result.indexOf("myact= 0) - assertTrue(result.indexOf("ari= 0) - assertTrue(result.indexOf("sii= 0) - assertTrue(result.indexOf("sii= 0) - assertTrue(result.indexOf("psii= 0) - assertTrue(result.indexOf("sst= 0) - assertTrue(result.indexOf("gci= 0) - assertTrue(result.indexOf("scu= 0) - assertTrue(result.indexOf("mri= 0) - assertTrue(result.indexOf("") >= 0) - assertTrue(result.indexOf("") >= 0) - assertTrue(result.indexOf("") >= 0) - assertTrue(result.indexOf("") >= 0) - assertTrue(result.indexOf("") >= 0) - } - - @Test - - public void buildSDNCRequest_Ex() { - ExecutionEntity mex = setupMock() - initBuildSDNCRequest(mex) - - when(mex.getVariable("allottedResourceId")).thenThrow(new RuntimeException("expected exception")) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.buildSDNCRequest(mex, "myact", "myreq") })) - } - - - // ***** preProcessSDNCAssign ***** - - @Test - - public void preProcessSDNCAssign() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - def data = initPreProcessSDNC(mex) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - DoCreateAllottedResourceTXC.preProcessSDNCAssign(mex) - - def req = map.get("sdncAssignRequest") - assertNotNull(req) - - assertEquals(data, map.get("rollbackData")) - - def rbreq = data.get(Prefix, "sdncAssignRollbackReq") - - assertTrue(req.indexOf("assign= 0) - assertTrue(req.indexOf("CreateTunnelXConnInstance= 0) - assertTrue(req.indexOf("") >= 0) - - assertTrue(rbreq.indexOf("unassign= 0) - assertTrue(rbreq.indexOf("DeleteTunnelXConnInstance= 0) - assertTrue(rbreq.indexOf("") >= 0) - } - - @Test - - public void preProcessSDNCAssign_BpmnError() { - ExecutionEntity mex = setupMock() - initPreProcessSDNC(mex) - - when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception")) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCAssign(mex) })) - } - - @Test - - public void preProcessSDNCAssign_Ex() { - ExecutionEntity mex = setupMock() - initPreProcessSDNC(mex) - - when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception")) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCAssign(mex) })) - } - - - // ***** preProcessSDNCCreate ***** - - @Test - - public void preProcessSDNCCreate() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - def data = initPreProcessSDNC(mex) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - DoCreateAllottedResourceTXC.preProcessSDNCCreate(mex) - - def req = map.get("sdncCreateRequest") - assertNotNull(req) - - assertEquals(data, map.get("rollbackData")) - - def rbreq = data.get(Prefix, "sdncCreateRollbackReq") - - assertTrue(req.indexOf("create= 0) - assertTrue(req.indexOf("CreateTunnelXConnInstance= 0) - assertTrue(req.indexOf("") >= 0) - - assertTrue(rbreq.indexOf("delete= 0) - assertTrue(rbreq.indexOf("DeleteTunnelXConnInstance= 0) - assertTrue(rbreq.indexOf("") >= 0) - - } - - @Test - - public void preProcessSDNCCreate_BpmnError() { - ExecutionEntity mex = setupMock() - initPreProcessSDNC(mex) - - when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception")) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCCreate(mex) })) - } - - @Test - - public void preProcessSDNCCreate_Ex() { - ExecutionEntity mex = setupMock() - initPreProcessSDNC(mex) - - when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception")) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCCreate(mex) })) - } - - - // ***** preProcessSDNCActivate ***** - - @Test - - public void preProcessSDNCActivate() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - def data = initPreProcessSDNC(mex) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - DoCreateAllottedResourceTXC.preProcessSDNCActivate(mex) - - def req = map.get("sdncActivateRequest") - assertNotNull(req) - - assertEquals(data, map.get("rollbackData")) - - def rbreq = data.get(Prefix, "sdncActivateRollbackReq") - - assertTrue(req.indexOf("activate= 0) - assertTrue(req.indexOf("CreateTunnelXConnInstance= 0) - assertTrue(req.indexOf("") >= 0) - - assertTrue(rbreq.indexOf("deactivate= 0) - assertTrue(rbreq.indexOf("DeleteTunnelXConnInstance= 0) - assertTrue(rbreq.indexOf("") >= 0) - - } - - @Test - - public void preProcessSDNCActivate_BpmnError() { - ExecutionEntity mex = setupMock() - initPreProcessSDNC(mex) - - when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception")) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCActivate(mex) })) - } - - @Test - - public void preProcessSDNCActivate_Ex() { - ExecutionEntity mex = setupMock() - initPreProcessSDNC(mex) - - when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception")) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCActivate(mex) })) - } - - - // ***** validateSDNCResp ***** - - @Test - - public void validateSDNCResp() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - def data = initValidateSDNCResp(mex) - def resp = initValidateSDNCResp_Resp() - - when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - - DoCreateAllottedResourceTXC.validateSDNCResp(mex, resp, "create") - - verify(mex).getVariable("WorkflowException") - verify(mex).getVariable("SDNCA_SuccessIndicator") - verify(mex).getVariable("rollbackData") - - assertEquals(data, map.get("rollbackData")) - - assertEquals("true", data.get(Prefix, "rollback" + "SDNCcreate")) - - } - - @Test - - public void validateSDNCResp_Get() { - ExecutionEntity mex = setupMock() - def data = initValidateSDNCResp(mex) - def resp = initValidateSDNCResp_Resp() - - when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - - DoCreateAllottedResourceTXC.validateSDNCResp(mex, resp, "get") - - verify(mex).getVariable("WorkflowException") - verify(mex).getVariable("SDNCA_SuccessIndicator") - - verify(mex, never()).getVariable("rollbackData") - } - - @Test - - public void validateSDNCResp_Unsuccessful() { - ExecutionEntity mex = setupMock() - initValidateSDNCResp(mex) - def resp = initValidateSDNCResp_Resp() - - // unsuccessful - when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(false) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.validateSDNCResp(mex, resp, "create") })) - } - - @Test - - public void validateSDNCResp_BpmnError() { - ExecutionEntity mex = setupMock() - initValidateSDNCResp(mex) - def resp = initValidateSDNCResp_Resp() - - when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception")) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.validateSDNCResp(mex, resp, "create") })) - } - - @Test - - public void validateSDNCResp_Ex() { - ExecutionEntity mex = setupMock() - initValidateSDNCResp(mex) - def resp = initValidateSDNCResp_Resp() - - when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception")) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.validateSDNCResp(mex, resp, "create") })) - } - - - // ***** preProcessSDNCGet ***** - - @Test - - public void preProcessSDNCGet_FoundAR() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initPreProcessSDNCGet(mex) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - DoCreateAllottedResourceTXC.preProcessSDNCGet(mex) - - String req = map.get("sdncGetRequest") - - assertTrue(req.indexOf("") >= 0) - assertTrue(req.indexOf("sii= 0) - assertTrue(req.indexOf("arlink= 0) - assertTrue(req.indexOf("myurl= 0) - - } - - @Test - - public void preProcessSDNCGet_NotFoundAR() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initPreProcessSDNCGet(mex) - - when(mex.getVariable("foundActiveAR")).thenReturn(false) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - DoCreateAllottedResourceTXC.preProcessSDNCGet(mex) - - String req = map.get("sdncGetRequest") - - assertTrue(req.indexOf("") >= 0) - assertTrue(req.indexOf("sii= 0) - assertTrue(req.indexOf("assignlink= 0) - assertTrue(req.indexOf("myurl= 0) - - } - - @Test - - public void preProcessSDNCGet_Ex() { - ExecutionEntity mex = setupMock() - initPreProcessSDNCGet(mex) - - when(mex.getVariable("foundActiveAR")).thenThrow(new RuntimeException("expected exception")) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCGet(mex) })) - } - - - // ***** updateAaiAROrchStatus ***** - - @Test - @Ignore - public void updateAaiAROrchStatus() { - MockPatchAllottedResource(CUST, SVC, INST, ARID) - - ExecutionEntity mex = setupMock() - initUpdateAaiAROrchStatus(mex) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - DoCreateAllottedResourceTXC.updateAaiAROrchStatus(mex, "success") - } - - - // ***** generateOutputs ***** - - @Test - - public void generateOutputs() { - ExecutionEntity mex = setupMock() - def txctop = FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceTXC/SDNCTopologyQueryCallback.xml") - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("enhancedCallbackRequestData")).thenReturn(txctop) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - DoCreateAllottedResourceTXC.generateOutputs(mex) - - verify(mex).setVariable("allotedResourceName", "namefromrequest") - verify(mex).setVariable("vni", "my-vni") - verify(mex).setVariable("vgmuxBearerIP", "my-bearer-ip") - verify(mex).setVariable("vgmuxLanIP", "my-lan-ip") - - } - - @Test - - public void generateOutputs_BadXml() { - ExecutionEntity mex = setupMock() - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("enhancedCallbackRequestData")).thenReturn("invalid xml") - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - DoCreateAllottedResourceTXC.generateOutputs(mex) - - verify(mex, never()).setVariable(anyString(), anyString()) - - } - - @Test - - public void generateOutputs_BpmnError() { - ExecutionEntity mex = setupMock() - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("enhancedCallbackRequestData")).thenThrow(new BpmnError("expected exception")) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - - DoCreateAllottedResourceTXC.generateOutputs(mex) - verify(mex, never()).setVariable(anyString(), anyString()) - - } - - @Test - - public void generateOutputs_Ex() { - ExecutionEntity mex = setupMock() - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("enhancedCallbackRequestData")).thenThrow(new RuntimeException("expected exception")) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - - DoCreateAllottedResourceTXC.generateOutputs(mex) - verify(mex, never()).setVariable(anyString(), anyString()) - - } - - - // ***** preProcessRollback ***** - - @Test - - public void preProcessRollback() { - ExecutionEntity mex = setupMock() - WorkflowException wfe = mock(WorkflowException.class) - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("WorkflowException")).thenReturn(wfe) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - DoCreateAllottedResourceTXC.preProcessRollback(mex) - - verify(mex).setVariable("prevWorkflowException", wfe) - - } - - @Test - - public void preProcessRollback_NotWFE() { - ExecutionEntity mex = setupMock() - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("WorkflowException")).thenReturn("I'm not a WFE") - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - DoCreateAllottedResourceTXC.preProcessRollback(mex) - -// verify(mex, never()).setVariable("prevWorkflowException", any()) - - } - - @Test - - public void preProcessRollback_BpmnError() { - ExecutionEntity mex = setupMock() - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception")) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - - DoCreateAllottedResourceTXC.preProcessRollback(mex) - - } - - @Test - - public void preProcessRollback_Ex() { - ExecutionEntity mex = setupMock() - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception")) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - - DoCreateAllottedResourceTXC.preProcessRollback(mex) - - } - - - // ***** postProcessRollback ***** - - @Test - - public void postProcessRollback() { - ExecutionEntity mex = setupMock() - WorkflowException wfe = mock(WorkflowException.class) - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("prevWorkflowException")).thenReturn(wfe) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - DoCreateAllottedResourceTXC.postProcessRollback(mex) - - verify(mex).setVariable("WorkflowException", wfe) - verify(mex).setVariable("rollbackData", null) - - } - - @Test - - public void postProcessRollback_NotWFE() { - ExecutionEntity mex = setupMock() - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("prevWorkflowException")).thenReturn("I'm not a WFE") - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - DoCreateAllottedResourceTXC.postProcessRollback(mex) - -// verify(mex, never()).setVariable("WorkflowException", any()) - verify(mex).setVariable("rollbackData", null) - - } - - @Test - - public void postProcessRollback_BpmnError() { - ExecutionEntity mex = setupMock() - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("prevWorkflowException")).thenThrow(new BpmnError("expected exception")) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - - assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.postProcessRollback(mex) })) - verify(mex, never()).setVariable("rollbackData", null) - - } - - @Test - - public void postProcessRollback_Ex() { - ExecutionEntity mex = setupMock() - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("prevWorkflowException")).thenThrow(new RuntimeException("expected exception")) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - - DoCreateAllottedResourceTXC.postProcessRollback(mex) - verify(mex, never()).setVariable("rollbackData", null) - - } - - private boolean checkMissingPreProcessRequest(String fieldnm) { - ExecutionEntity mex = setupMock() - initPreProcess(mex) - - DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() - - when(mex.getVariable(fieldnm)).thenReturn("") - - return doBpmnError( { _ -> DoCreateAllottedResourceTXC.preProcessRequest(mex) }) - } - - private void initPreProcess(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("sdncurn") - when(mex.getVariable("mso.workflow.sdnc.replication.delay")).thenReturn("sdncdelay") - when(mex.getVariable("serviceInstanceId")).thenReturn("sii") - when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii") - when(mex.getVariable("allottedResourceModelInfo")).thenReturn("armi") - when(mex.getVariable("brgWanMacAddress")).thenReturn("bwma") - when(mex.getVariable("allottedResourceRole")).thenReturn("arr") - when(mex.getVariable("allottedResourceType")).thenReturn("art") - } - - private void initGetAaiAR(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("allottedResourceType")).thenReturn("TXCt") - when(mex.getVariable("allottedResourceRole")).thenReturn("TXCr") - when(mex.getVariable("CSI_service")).thenReturn(FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceTXC/getAR.xml")) - when(mex.getVariable("aai.endpoint")).thenReturn(aaiUriPfx) - when(mex.getVariable("aaiAROrchStatus")).thenReturn("Active") - } - - private initCreateAaiAr(ExecutionEntity mex) { - when(mex.getVariable("disableRollback")).thenReturn(45) - when(mex.getVariable("serviceInstanceId")).thenReturn("sii") - when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii") - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("allottedResourceId")).thenReturn(ARID) - when(mex.getVariable("aai.endpoint")).thenReturn(aaiUriPfx) - when(mex.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn(UrnPropertiesReader.getVariable("mso.workflow.global.default.aai.namespace")) - when(mex.getVariable("PSI_resourceLink")).thenReturn(AAIUriFactory.createResourceFromExistingURI(AAIObjectType.SERVICE_INSTANCE, UriBuilder.fromPath( "/business/customers/customer/"+CUST+"/service-subscriptions/service-subscription/"+SVC+"/service-instances/service-instance/"+INST).build())) - when(mex.getVariable("allottedResourceType")).thenReturn("TXCt") - when(mex.getVariable("allottedResourceRole")).thenReturn("TXCr") - when(mex.getVariable("CSI_resourceLink")).thenReturn(aaiUriPfx+"/aai/v9/mycsi") - when(mex.getVariable("allottedResourceModelInfo")).thenReturn(""" - { - "modelInvariantUuid":"modelinvuuid", - "modelUuid":"modeluuid", - "modelCustomizationUuid":"modelcustuuid" - } - """) - } - - private initBuildSDNCRequest(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("allottedResourceId")).thenReturn("ari") - when(mex.getVariable("serviceInstanceId")).thenReturn("sii") - when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii") - when(mex.getVariable("subscriptionServiceType")).thenReturn("sst") - when(mex.getVariable("globalCustomerId")).thenReturn("gci") - when(mex.getVariable("sdncCallbackUrl")).thenReturn("scu") - when(mex.getVariable("msoRequestId")).thenReturn("mri") - } - - private RollbackData initPreProcessSDNC(ExecutionEntity mex) { - def data = new RollbackData() - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("rollbackData")).thenReturn(data) - - return data - } - - private initPreProcessSDNCGet(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("sdncCallbackUrl")).thenReturn("myurl") - when(mex.getVariable("foundActiveAR")).thenReturn(true) - when(mex.getVariable("aaiARGetResponse")).thenReturn("arlink") - when(mex.getVariable("sdncAssignResponse")).thenReturn("<object-path>assignlink</object-path>") - when(mex.getVariable("serviceInstanceId")).thenReturn("sii") - when(mex.getVariable("sdncCallbackUrl")).thenReturn("myurl") - } - - private RollbackData initValidateSDNCResp(ExecutionEntity mex) { - def data = new RollbackData() - - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("prefix")).thenReturn(Prefix) - when(mex.getVariable("SDNCA_SuccessIndicator")).thenReturn(true) - when(mex.getVariable("rollbackData")).thenReturn(data) - - return data - } - - private String initValidateSDNCResp_Resp() { - return "<response-code>200</response-code>" - } - - private initUpdateAaiAROrchStatus(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("aaiARPath")).thenReturn("/business/customers/customer/"+CUST+"/service-subscriptions/service-subscription/"+SVC+"/service-instances/service-instance/"+INST+"/allotted-resources/allotted-resource/"+ARID) - } - + public void init() { + MockitoAnnotations.initMocks(this) + } + + public DoCreateAllottedResourceTXCTest() { + super("DoCreateAllottedResourceTXC") + } + + // ***** preProcessRequest ***** + @Test + public void preProcessRequest() { + ExecutionEntity mex = setupMock() + initPreProcess(mex) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + DoCreateAllottedResourceTXC.preProcessRequest(mex) + + verify(mex).setVariable("prefix", Prefix) + + assertTrue(checkMissingPreProcessRequest("mso.workflow.sdncadapter.callback")) + assertTrue(checkMissingPreProcessRequest("mso.workflow.sdnc.replication.delay")) + assertTrue(checkMissingPreProcessRequest("serviceInstanceId")) + assertTrue(checkMissingPreProcessRequest("parentServiceInstanceId")) + assertTrue(checkMissingPreProcessRequest("allottedResourceModelInfo")) + assertTrue(checkMissingPreProcessRequest("brgWanMacAddress")) + assertTrue(checkMissingPreProcessRequest("allottedResourceRole")) + assertTrue(checkMissingPreProcessRequest("allottedResourceType")) + } + + // ***** getAaiAR ***** + + @Test + @Ignore + public void getAaiAR() { + MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXC/getArTxc.xml") + + ExecutionEntity mex = setupMock() + initGetAaiAR(mex) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + DoCreateAllottedResourceTXC.getAaiAR(mex) + + verify(mex).setVariable("foundActiveAR", true) + } + + @Test + + public void getAaiAR_Duplicate() { + MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXC/getArTxc.xml") + + ExecutionEntity mex = setupMock() + initGetAaiAR(mex) + + // fail if duplicate + when(mex.getVariable("failExists")).thenReturn("true") + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.getAaiAR(mex) })) + } + + @Test + public void getAaiAR_NotActive() { + MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXC/getArTxc.xml") + + ExecutionEntity mex = setupMock() + initGetAaiAR(mex) + + // not active + when(mex.getVariable("aaiAROrchStatus")).thenReturn("not-active") + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.getAaiAR(mex) })) + } + + @Test + @Ignore + public void getAaiAR_NoStatus() { + MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXC/getArTxc.xml") + + ExecutionEntity mex = setupMock() + initGetAaiAR(mex) + + when(mex.getVariable("aaiAROrchStatus")).thenReturn(null) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + DoCreateAllottedResourceTXC.getAaiAR(mex) + + verify(mex, never()).setVariable("foundActiveAR", true) + } + + // ***** createAaiAR ***** + + @Test + public void createAaiAR() { + ExecutionEntity mex = setupMock() + initCreateAaiAr(mex) + when(mex.getVariable("PSI_resourceLink")).thenReturn(AAIUriFactory.createResourceFromExistingURI(AAIObjectType.SERVICE_INSTANCE, UriBuilder.fromPath("/aai/v9/business/customers/customer/" + CUST + "/service-subscriptions/service-subscription/" + SVC + "/service-instances/service-instance/" + INST).build())) + when(mex.getVariable("CSI_resourceLink")).thenReturn("/aai/v9/business/customers/customer/" + CUST + "/service-subscriptions/service-subscription/" + SVC + "/service-instances/service-instance/" + INST) + when(mex.getVariable("allottedResourceModelInfo")).thenReturn("{\n" + + " \"modelInvariantUuid\":\"modelInvariantUuid\",\n" + + " \"modelUuid\" : \"modelUuid\"\n" + + "}") + AAIResourcesClient client = mock(AAIResourcesClient.class) + DoCreateAllottedResourceTXC doCreateAllottedResourceTXC = spy(DoCreateAllottedResourceTXC.class) + when(doCreateAllottedResourceTXC.getAAIClient()).thenReturn(client) + doCreateAllottedResourceTXC.createAaiAR(mex) + } + + + @Test + public void createAaiAR_MissingPsiLink() { + ExecutionEntity mex = setupMock() + initCreateAaiAr(mex) + + when(mex.getVariable("PSI_resourceLink")).thenReturn(null) + + MockPutAllottedResource(CUST, SVC, INST, ARID) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.createAaiAR(mex) })) + } + + @Test + public void createAaiAR_HttpFailed() { + ExecutionEntity mex = setupMock() + initCreateAaiAr(mex) + + MockPutAllottedResource_500(CUST, SVC, INST, ARID) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.createAaiAR(mex) })) + } + + @Test + public void createAaiAR_BpmnError() { + ExecutionEntity mex = setupMock() + initCreateAaiAr(mex) + + when(mex.getVariable("aai.endpoint")).thenThrow(new BpmnError("expected exception")) + + MockPutAllottedResource(CUST, SVC, INST, ARID) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.createAaiAR(mex) })) + } + + @Test + public void createAaiAR_Ex() { + ExecutionEntity mex = setupMock() + initCreateAaiAr(mex) + + when(mex.getVariable("aai.endpoint")).thenThrow(new RuntimeException("expected exception")) + + MockPutAllottedResource(CUST, SVC, INST, ARID) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.createAaiAR(mex) })) + } + + // ***** buildSDNCRequest ***** + + @Test + public void buildSDNCRequest() { + ExecutionEntity mex = setupMock() + initBuildSDNCRequest(mex) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + + String result = DoCreateAllottedResourceTXC.buildSDNCRequest(mex, "myact", "myreq") + + assertTrue(result.indexOf("myreq= 0) + assertTrue(result.indexOf("myact= 0) + assertTrue(result.indexOf("ari= 0) + assertTrue(result.indexOf("sii= 0) + assertTrue(result.indexOf("sii= 0) + assertTrue(result.indexOf("psii= 0) + assertTrue(result.indexOf("sst= 0) + assertTrue(result.indexOf("gci= 0) + assertTrue(result.indexOf("scu= 0) + assertTrue(result.indexOf("mri= 0) + assertTrue(result.indexOf("") >= 0) + assertTrue(result.indexOf("") >= 0) + assertTrue(result.indexOf("") >= 0) + assertTrue(result.indexOf("") >= 0) + assertTrue(result.indexOf("") >= 0) + } + + @Test + public void buildSDNCRequest_Ex() { + ExecutionEntity mex = setupMock() + initBuildSDNCRequest(mex) + + when(mex.getVariable("allottedResourceId")).thenThrow(new RuntimeException("expected exception")) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.buildSDNCRequest(mex, "myact", "myreq") })) + } + + // ***** preProcessSDNCAssign ***** + + @Test + public void preProcessSDNCAssign() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + def data = initPreProcessSDNC(mex) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + DoCreateAllottedResourceTXC.preProcessSDNCAssign(mex) + + def req = map.get("sdncAssignRequest") + assertNotNull(req) + + assertEquals(data, map.get("rollbackData")) + + def rbreq = data.get(Prefix, "sdncAssignRollbackReq") + + assertTrue(req.indexOf("assign= 0) + assertTrue(req.indexOf("CreateTunnelXConnInstance= 0) + assertTrue(req.indexOf("") >= 0) + + assertTrue(rbreq.indexOf("unassign= 0) + assertTrue(rbreq.indexOf("DeleteTunnelXConnInstance= 0) + assertTrue(rbreq.indexOf("") >= 0) + } + + @Test + public void preProcessSDNCAssign_BpmnError() { + ExecutionEntity mex = setupMock() + initPreProcessSDNC(mex) + + when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception")) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCAssign(mex) })) + } + + @Test + public void preProcessSDNCAssign_Ex() { + ExecutionEntity mex = setupMock() + initPreProcessSDNC(mex) + + when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception")) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCAssign(mex) })) + } + + // ***** preProcessSDNCCreate ***** + + @Test + public void preProcessSDNCCreate() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + def data = initPreProcessSDNC(mex) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + DoCreateAllottedResourceTXC.preProcessSDNCCreate(mex) + + def req = map.get("sdncCreateRequest") + assertNotNull(req) + + assertEquals(data, map.get("rollbackData")) + + def rbreq = data.get(Prefix, "sdncCreateRollbackReq") + + assertTrue(req.indexOf("create= 0) + assertTrue(req.indexOf("CreateTunnelXConnInstance= 0) + assertTrue(req.indexOf("") >= 0) + + assertTrue(rbreq.indexOf("delete= 0) + assertTrue(rbreq.indexOf("DeleteTunnelXConnInstance= 0) + assertTrue(rbreq.indexOf("") >= 0) + + } + + @Test + public void preProcessSDNCCreate_BpmnError() { + ExecutionEntity mex = setupMock() + initPreProcessSDNC(mex) + + when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception")) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCCreate(mex) })) + } + + @Test + public void preProcessSDNCCreate_Ex() { + ExecutionEntity mex = setupMock() + initPreProcessSDNC(mex) + + when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception")) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCCreate(mex) })) + } + + // ***** preProcessSDNCActivate ***** + + @Test + public void preProcessSDNCActivate() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + def data = initPreProcessSDNC(mex) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + DoCreateAllottedResourceTXC.preProcessSDNCActivate(mex) + + def req = map.get("sdncActivateRequest") + assertNotNull(req) + + assertEquals(data, map.get("rollbackData")) + + def rbreq = data.get(Prefix, "sdncActivateRollbackReq") + + assertTrue(req.indexOf("activate= 0) + assertTrue(req.indexOf("CreateTunnelXConnInstance= 0) + assertTrue(req.indexOf("") >= 0) + + assertTrue(rbreq.indexOf("deactivate= 0) + assertTrue(rbreq.indexOf("DeleteTunnelXConnInstance= 0) + assertTrue(rbreq.indexOf("") >= 0) + + } + + @Test + public void preProcessSDNCActivate_BpmnError() { + ExecutionEntity mex = setupMock() + initPreProcessSDNC(mex) + + when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception")) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCActivate(mex) })) + } + + @Test + public void preProcessSDNCActivate_Ex() { + ExecutionEntity mex = setupMock() + initPreProcessSDNC(mex) + + when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception")) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCActivate(mex) })) + } + + // ***** validateSDNCResp ***** + + @Test + public void validateSDNCResp() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + def data = initValidateSDNCResp(mex) + def resp = initValidateSDNCResp_Resp() + + when(mex.getVariable(Prefix + "sdncResponseSuccess")).thenReturn(true) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + + DoCreateAllottedResourceTXC.validateSDNCResp(mex, resp, "create") + + verify(mex).getVariable("WorkflowException") + verify(mex).getVariable("SDNCA_SuccessIndicator") + verify(mex).getVariable("rollbackData") + + assertEquals(data, map.get("rollbackData")) + + assertEquals("true", data.get(Prefix, "rollback" + "SDNCcreate")) + + } + + @Test + public void validateSDNCResp_Get() { + ExecutionEntity mex = setupMock() + initValidateSDNCResp(mex) + def resp = initValidateSDNCResp_Resp() + + when(mex.getVariable(Prefix + "sdncResponseSuccess")).thenReturn(true) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + + DoCreateAllottedResourceTXC.validateSDNCResp(mex, resp, "get") + + verify(mex).getVariable("WorkflowException") + verify(mex).getVariable("SDNCA_SuccessIndicator") + + verify(mex, never()).getVariable("rollbackData") + } + + @Test + public void validateSDNCResp_Unsuccessful() { + ExecutionEntity mex = setupMock() + initValidateSDNCResp(mex) + def resp = initValidateSDNCResp_Resp() + + // unsuccessful + when(mex.getVariable(Prefix + "sdncResponseSuccess")).thenReturn(false) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.validateSDNCResp(mex, resp, "create") })) + } + + @Test + public void validateSDNCResp_BpmnError() { + ExecutionEntity mex = setupMock() + initValidateSDNCResp(mex) + def resp = initValidateSDNCResp_Resp() + + when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception")) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.validateSDNCResp(mex, resp, "create") })) + } + + @Test + public void validateSDNCResp_Ex() { + ExecutionEntity mex = setupMock() + initValidateSDNCResp(mex) + def resp = initValidateSDNCResp_Resp() + + when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception")) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.validateSDNCResp(mex, resp, "create") })) + } + + // ***** preProcessSDNCGet ***** + + @Test + public void preProcessSDNCGet_FoundAR() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initPreProcessSDNCGet(mex) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + DoCreateAllottedResourceTXC.preProcessSDNCGet(mex) + + String req = map.get("sdncGetRequest") + + assertTrue(req.indexOf("") >= 0) + assertTrue(req.indexOf("sii= 0) + assertTrue(req.indexOf("arlink= 0) + assertTrue(req.indexOf("myurl= 0) + + } + + @Test + public void preProcessSDNCGet_NotFoundAR() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initPreProcessSDNCGet(mex) + + when(mex.getVariable("foundActiveAR")).thenReturn(false) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + DoCreateAllottedResourceTXC.preProcessSDNCGet(mex) + + String req = map.get("sdncGetRequest") + + assertTrue(req.indexOf("") >= 0) + assertTrue(req.indexOf("sii= 0) + assertTrue(req.indexOf("assignlink= 0) + assertTrue(req.indexOf("myurl= 0) + + } + + @Test + public void preProcessSDNCGet_Ex() { + ExecutionEntity mex = setupMock() + initPreProcessSDNCGet(mex) + + when(mex.getVariable("foundActiveAR")).thenThrow(new RuntimeException("expected exception")) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCGet(mex) })) + } + + // ***** updateAaiAROrchStatus ***** + + @Test + @Ignore + public void updateAaiAROrchStatus() { + MockPatchAllottedResource(CUST, SVC, INST, ARID) + + ExecutionEntity mex = setupMock() + initUpdateAaiAROrchStatus(mex) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + DoCreateAllottedResourceTXC.updateAaiAROrchStatus(mex, "success") + } + + // ***** generateOutputs ***** + + @Test + public void generateOutputs() { + ExecutionEntity mex = setupMock() + def txctop = FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceTXC/SDNCTopologyQueryCallback.xml") + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("enhancedCallbackRequestData")).thenReturn(txctop) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + DoCreateAllottedResourceTXC.generateOutputs(mex) + + verify(mex).setVariable("allotedResourceName", "namefromrequest") + verify(mex).setVariable("vni", "my-vni") + verify(mex).setVariable("vgmuxBearerIP", "my-bearer-ip") + verify(mex).setVariable("vgmuxLanIP", "my-lan-ip") + + } + + @Test + public void generateOutputs_BadXml() { + ExecutionEntity mex = setupMock() + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("enhancedCallbackRequestData")).thenReturn("invalid xml") + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + DoCreateAllottedResourceTXC.generateOutputs(mex) + + verify(mex, never()).setVariable(anyString(), anyString()) + + } + + @Test + public void generateOutputs_BpmnError() { + ExecutionEntity mex = setupMock() + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("enhancedCallbackRequestData")).thenThrow(new BpmnError("expected exception")) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + + DoCreateAllottedResourceTXC.generateOutputs(mex) + verify(mex, never()).setVariable(anyString(), anyString()) + + } + + @Test + public void generateOutputs_Ex() { + ExecutionEntity mex = setupMock() + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("enhancedCallbackRequestData")).thenThrow(new RuntimeException("expected exception")) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + + DoCreateAllottedResourceTXC.generateOutputs(mex) + verify(mex, never()).setVariable(anyString(), anyString()) + + } + + // ***** preProcessRollback ***** + + @Test + public void preProcessRollback() { + ExecutionEntity mex = setupMock() + WorkflowException wfe = mock(WorkflowException.class) + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("WorkflowException")).thenReturn(wfe) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + DoCreateAllottedResourceTXC.preProcessRollback(mex) + + verify(mex).setVariable("prevWorkflowException", wfe) + + } + + @Test + public void preProcessRollback_NotWFE() { + ExecutionEntity mex = setupMock() + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("WorkflowException")).thenReturn("I'm not a WFE") + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + DoCreateAllottedResourceTXC.preProcessRollback(mex) + + verify(mex, never()).setVariable(eq("prevWorkflowException"), any()) + + } + + @Test + public void preProcessRollback_BpmnError() { + ExecutionEntity mex = setupMock() + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception")) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + + DoCreateAllottedResourceTXC.preProcessRollback(mex) + + } + + @Test + public void preProcessRollback_Ex() { + ExecutionEntity mex = setupMock() + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception")) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + + DoCreateAllottedResourceTXC.preProcessRollback(mex) + + } + + // ***** postProcessRollback ***** + + @Test + public void postProcessRollback() { + ExecutionEntity mex = setupMock() + WorkflowException wfe = mock(WorkflowException.class) + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("prevWorkflowException")).thenReturn(wfe) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + DoCreateAllottedResourceTXC.postProcessRollback(mex) + + verify(mex).setVariable("WorkflowException", wfe) + verify(mex).setVariable("rollbackData", null) + + } + + @Test + public void postProcessRollback_NotWFE() { + ExecutionEntity mex = setupMock() + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("prevWorkflowException")).thenReturn("I'm not a WFE") + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + DoCreateAllottedResourceTXC.postProcessRollback(mex) + + verify(mex, never()).setVariable(eq("WorkflowException"), any()) + verify(mex).setVariable("rollbackData", null) + + } + + @Test + public void postProcessRollback_BpmnError() { + ExecutionEntity mex = setupMock() + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("prevWorkflowException")).thenThrow(new BpmnError("expected exception")) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.postProcessRollback(mex) })) + verify(mex, never()).setVariable("rollbackData", null) + + } + + @Test + public void postProcessRollback_Ex() { + ExecutionEntity mex = setupMock() + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("prevWorkflowException")).thenThrow(new RuntimeException("expected exception")) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + + DoCreateAllottedResourceTXC.postProcessRollback(mex) + verify(mex, never()).setVariable("rollbackData", null) + + } + + private boolean checkMissingPreProcessRequest(String fieldnm) { + ExecutionEntity mex = setupMock() + initPreProcess(mex) + + DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC() + + when(mex.getVariable(fieldnm)).thenReturn("") + + return doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessRequest(mex) }) + } + + private void initPreProcess(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("sdncurn") + when(mex.getVariable("mso.workflow.sdnc.replication.delay")).thenReturn("sdncdelay") + when(mex.getVariable("serviceInstanceId")).thenReturn("sii") + when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii") + when(mex.getVariable("allottedResourceModelInfo")).thenReturn("armi") + when(mex.getVariable("brgWanMacAddress")).thenReturn("bwma") + when(mex.getVariable("allottedResourceRole")).thenReturn("arr") + when(mex.getVariable("allottedResourceType")).thenReturn("art") + } + + private void initGetAaiAR(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("allottedResourceType")).thenReturn("TXCt") + when(mex.getVariable("allottedResourceRole")).thenReturn("TXCr") + when(mex.getVariable("CSI_service")).thenReturn(FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceTXC/getAR.xml")) + when(mex.getVariable("aai.endpoint")).thenReturn(aaiUriPfx) + when(mex.getVariable("aaiAROrchStatus")).thenReturn("Active") + } + + private initCreateAaiAr(ExecutionEntity mex) { + when(mex.getVariable("disableRollback")).thenReturn(45) + when(mex.getVariable("serviceInstanceId")).thenReturn("sii") + when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii") + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("allottedResourceId")).thenReturn(ARID) + when(mex.getVariable("aai.endpoint")).thenReturn(aaiUriPfx) + when(mex.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn(UrnPropertiesReader.getVariable("mso.workflow.global.default.aai.namespace")) + when(mex.getVariable("PSI_resourceLink")).thenReturn(AAIUriFactory.createResourceFromExistingURI(AAIObjectType.SERVICE_INSTANCE, UriBuilder.fromPath("/business/customers/customer/" + CUST + "/service-subscriptions/service-subscription/" + SVC + "/service-instances/service-instance/" + INST).build())) + when(mex.getVariable("allottedResourceType")).thenReturn("TXCt") + when(mex.getVariable("allottedResourceRole")).thenReturn("TXCr") + when(mex.getVariable("CSI_resourceLink")).thenReturn(aaiUriPfx + "/aai/v9/mycsi") + when(mex.getVariable("allottedResourceModelInfo")).thenReturn(""" + { + "modelInvariantUuid":"modelinvuuid", + "modelUuid":"modeluuid", + "modelCustomizationUuid":"modelcustuuid" + } + """) + } + + private initBuildSDNCRequest(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("allottedResourceId")).thenReturn("ari") + when(mex.getVariable("serviceInstanceId")).thenReturn("sii") + when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii") + when(mex.getVariable("subscriptionServiceType")).thenReturn("sst") + when(mex.getVariable("globalCustomerId")).thenReturn("gci") + when(mex.getVariable("sdncCallbackUrl")).thenReturn("scu") + when(mex.getVariable("msoRequestId")).thenReturn("mri") + } + + private RollbackData initPreProcessSDNC(ExecutionEntity mex) { + def data = new RollbackData() + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("rollbackData")).thenReturn(data) + + return data + } + + private initPreProcessSDNCGet(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("sdncCallbackUrl")).thenReturn("myurl") + when(mex.getVariable("foundActiveAR")).thenReturn(true) + when(mex.getVariable("aaiARGetResponse")).thenReturn("arlink") + when(mex.getVariable("sdncAssignResponse")).thenReturn("<object-path>assignlink</object-path>") + when(mex.getVariable("serviceInstanceId")).thenReturn("sii") + when(mex.getVariable("sdncCallbackUrl")).thenReturn("myurl") + } + + private RollbackData initValidateSDNCResp(ExecutionEntity mex) { + def data = new RollbackData() + + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("prefix")).thenReturn(Prefix) + when(mex.getVariable("SDNCA_SuccessIndicator")).thenReturn(true) + when(mex.getVariable("rollbackData")).thenReturn(data) + + return data + } + + private String initValidateSDNCResp_Resp() { + return "<response-code>200</response-code>" + } + + private initUpdateAaiAROrchStatus(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("aaiARPath")).thenReturn("/business/customers/customer/" + CUST + "/service-subscriptions/service-subscription/" + SVC + "/service-instances/service-instance/" + INST + "/allotted-resources/allotted-resource/" + ARID) + } + } diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/DoDeleteAllottedResourceBRGTest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/DoDeleteAllottedResourceBRGTest.groovy index 0528529819..e77c1dd9ed 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/DoDeleteAllottedResourceBRGTest.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/DoDeleteAllottedResourceBRGTest.groovy @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -20,19 +22,15 @@ package org.onap.so.bpmn.vcpe.scripts +import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity -import org.junit.Before -import org.junit.BeforeClass -import org.junit.Rule -import org.junit.Test -import org.junit.Ignore +import org.junit.* import org.mockito.MockitoAnnotations -import org.camunda.bpm.engine.delegate.BpmnError import org.mockito.Spy import org.onap.so.bpmn.core.UrnPropertiesReader -import org.onap.so.bpmn.mock.FileUtil -import org.onap.so.client.aai.entities.uri.AAIResourceUri -import static org.junit.Assert.*; + +import static org.junit.Assert.assertTrue +import static org.mockito.ArgumentMatchers.eq import static org.mockito.Mockito.* import static org.onap.so.bpmn.mock.StubResponseAAI.MockDeleteAllottedResource import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetAllottedResource @@ -41,533 +39,497 @@ import com.github.tomakehurst.wiremock.junit.WireMockRule class DoDeleteAllottedResourceBRGTest extends GroovyTestBase { - @Rule - public WireMockRule wireMockRule = new WireMockRule(PORT) + @Rule + public WireMockRule wireMockRule = new WireMockRule(PORT) + + String Prefix = "DDARBRG_" - String Prefix = "DDARBRG_" + @BeforeClass + public static void setUpBeforeClass() { + GroovyTestBase.setUpBeforeClass() + } - @BeforeClass - public static void setUpBeforeClass() { - super.setUpBeforeClass() - } + @Spy + DoDeleteAllottedResourceBRG doDeleteAllottedResourceBRG - @Spy - DoDeleteAllottedResourceBRG doDeleteAllottedResourceBRG - @Before - public void init() - { - MockitoAnnotations.initMocks(this) - super.init() - when(doDeleteAllottedResourceBRG.getAllottedResourceUtils()).thenReturn(allottedResourceUtils_MOCK) - } - - public DoDeleteAllottedResourceBRGTest() { - super("DoDeleteAllottedResourceBRG") - } - - - // ***** preProcessRequest ***** - - @Test -// @Ignore - public void preProcessRequest() { - ExecutionEntity mex = setupMock() - initPreProcess(mex) - - DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() - DoDeleteAllottedResourceBRG.preProcessRequest(mex) - - //verify(mex).getVariable(DBGFLAG) - verify(mex).setVariable("prefix", Prefix) - verify(mex).setVariable("sdncCallbackUrl", "sdncurn") - - assertTrue(checkMissingPreProcessRequest("mso.workflow.sdncadapter.callback")) - assertTrue(checkMissingPreProcessRequest("serviceInstanceId")) - assertTrue(checkMissingPreProcessRequest("allottedResourceId")) - } - - @Test -// @Ignore - public void preProcessRequest_BpmnError() { - ExecutionEntity mex = setupMock() - initPreProcess(mex) - - when(mex.getVariable("serviceInstanceId")).thenThrow(new BpmnError("expected exception")) - - DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() - - assertTrue(doBpmnError( { _ -> DoDeleteAllottedResourceBRG.preProcessRequest(mex) })) - } - - @Test -// @Ignore - public void preProcessRequest_Ex() { - ExecutionEntity mex = setupMock() - initPreProcess(mex) - - when(mex.getVariable("serviceInstanceId")).thenThrow(new RuntimeException("expected exception")) - - DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() - - assertTrue(doBpmnError( { _ -> DoDeleteAllottedResourceBRG.preProcessRequest(mex) })) - } - - - // ***** getAaiAR ***** - - @Test + public void init() { + MockitoAnnotations.initMocks(this) + initAllottedResourceMock() + } + + public DoDeleteAllottedResourceBRGTest() { + super("DoDeleteAllottedResourceBRG") + } + + // ***** preProcessRequest ***** + + @Test + public void preProcessRequest() { + ExecutionEntity mex = setupMock() + initPreProcess(mex) + + DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() + DoDeleteAllottedResourceBRG.preProcessRequest(mex) + + verify(mex).setVariable("prefix", Prefix) + verify(mex).setVariable("sdncCallbackUrl", "sdncurn") + + assertTrue(checkMissingPreProcessRequest("mso.workflow.sdncadapter.callback")) + assertTrue(checkMissingPreProcessRequest("serviceInstanceId")) + assertTrue(checkMissingPreProcessRequest("allottedResourceId")) + } + + @Test + public void preProcessRequest_BpmnError() { + ExecutionEntity mex = setupMock() + initPreProcess(mex) + + when(mex.getVariable("serviceInstanceId")).thenThrow(new BpmnError("expected exception")) + + DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceBRG.preProcessRequest(mex) })) + } + + @Test + public void preProcessRequest_Ex() { + ExecutionEntity mex = setupMock() + initPreProcess(mex) + + when(mex.getVariable("serviceInstanceId")).thenThrow(new RuntimeException("expected exception")) + + DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceBRG.preProcessRequest(mex) })) + } + + // ***** getAaiAR ***** + + @Test + public void getAaiAR() { + ExecutionEntity mex = setupMock() + initGetAaiAR(mex) + when(doDeleteAllottedResourceBRG.getAllottedResourceUtils()).thenReturn(allottedResourceUtils_MOCK) + doReturn(true).when(allottedResourceUtils_MOCK).ifExistsAR(eq(mex), eq(ARID)) + doDeleteAllottedResourceBRG.getAaiAR(mex) + verify(mex).setVariable("parentServiceInstanceId", INST) + } + + @Test + public void getAaiAR_EmptyResponse() { + ExecutionEntity mex = setupMock() + initGetAaiAR(mex) + doReturn(false).when(allottedResourceUtils_MOCK).ifExistsAR(eq(mex), eq(ARID)) + assertTrue(doBpmnError({ _ -> doDeleteAllottedResourceBRG.getAaiAR(mex) })) + } + + // ***** updateAaiAROrchStatus ***** + + @Test @Ignore - public void getAaiAR() { - ExecutionEntity mex = setupMock() - initGetAaiAR(mex) - when(client_MOCK.exists(any(AAIResourceUri.class))).thenReturn(true) - doDeleteAllottedResourceBRG.getAaiAR(mex) - verify(mex).setVariable("parentServiceInstanceId", INST) - } - - @Test - public void getAaiAR_EmptyResponse() { - ExecutionEntity mex = setupMock() - initGetAaiAR(mex) - when(client_MOCK.exists(any(AAIResourceUri.class))).thenReturn(false) - assertTrue(doBpmnError( { _ -> doDeleteAllottedResourceBRG.getAaiAR(mex) })) - } - - - // ***** updateAaiAROrchStatus ***** - - @Test - @Ignore - public void updateAaiAROrchStatus() { - ExecutionEntity mex = setupMock() - initUpdateAaiAROrchStatus(mex) - - MockPatchAllottedResource(CUST, SVC, INST, ARID) - - DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() - DoDeleteAllottedResourceBRG.updateAaiAROrchStatus(mex, "success") - } - - - // ***** buildSDNCRequest ***** - - @Test -// @Ignore - public void buildSDNCRequest() { - ExecutionEntity mex = setupMock() - initBuildSDNCRequest(mex) - - DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() - - String result = DoDeleteAllottedResourceBRG.buildSDNCRequest(mex, "myact", "myreq") - - assertTrue(result.indexOf("myreq= 0) - assertTrue(result.indexOf("myact= 0) - assertTrue(result.indexOf("ari= 0) - assertTrue(result.indexOf("sii= 0) - assertTrue(result.indexOf("sii= 0) - assertTrue(result.indexOf("psii= 0) - assertTrue(result.indexOf("sst= 0) - assertTrue(result.indexOf("gci= 0) - assertTrue(result.indexOf("scu= 0) - assertTrue(result.indexOf("mri= 0) - assertTrue(result.indexOf("") >= 0) - assertTrue(result.indexOf("") >= 0) - assertTrue(result.indexOf("") >= 0) - assertTrue(result.indexOf("") >= 0) - assertTrue(result.indexOf("") >= 0) - } - - @Test -// @Ignore - public void buildSDNCRequest_Ex() { - ExecutionEntity mex = setupMock() - initBuildSDNCRequest(mex) - - when(mex.getVariable("allottedResourceId")).thenThrow(new RuntimeException("expected exception")) - - DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() - - assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceBRG.buildSDNCRequest(mex, "myact", "myreq") })) - } - - - // ***** preProcessSDNCUnassign ***** - - @Test -// @Ignore - public void preProcessSDNCUnassign() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initPreProcessSDNC(mex) - - DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() - DoDeleteAllottedResourceBRG.preProcessSDNCUnassign(mex) - - def req = map.get("sdncUnassignRequest") - - assertTrue(req.indexOf("unassign= 0) - assertTrue(req.indexOf("DeleteBRGInstance= 0) - assertTrue(req.indexOf("") >= 0) - } - - @Test -// @Ignore - public void preProcessSDNCUnassign_BpmnError() { - ExecutionEntity mex = setupMock() - initPreProcessSDNC(mex) - - when(mex.getVariable("allottedResourceId")).thenThrow(new BpmnError("expected exception")) - - DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() - - assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceBRG.preProcessSDNCUnassign(mex) })) - } - - @Test -// @Ignore - public void preProcessSDNCUnassign_Ex() { - ExecutionEntity mex = setupMock() - initPreProcessSDNC(mex) - - when(mex.getVariable("allottedResourceId")).thenThrow(new RuntimeException("expected exception")) - - DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() - - assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceBRG.preProcessSDNCUnassign(mex) })) - } - - - // ***** preProcessSDNCDelete ***** - - @Test -// @Ignore - public void preProcessSDNCDelete() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initPreProcessSDNC(mex) - - DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() - DoDeleteAllottedResourceBRG.preProcessSDNCDelete(mex) - - def req = map.get("sdncDeleteRequest") - - assertTrue(req.indexOf("delete= 0) - assertTrue(req.indexOf("DeleteBRGInstance= 0) - assertTrue(req.indexOf("") >= 0) - } - - @Test -// @Ignore - public void preProcessSDNCDelete_BpmnError() { - ExecutionEntity mex = setupMock() - initPreProcessSDNC(mex) - - when(mex.getVariable("allottedResourceId")).thenThrow(new BpmnError("expected exception")) - - DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() - - assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceBRG.preProcessSDNCDelete(mex) })) - } - - @Test -// @Ignore - public void preProcessSDNCDelete_Ex() { - ExecutionEntity mex = setupMock() - initPreProcessSDNC(mex) - - when(mex.getVariable("allottedResourceId")).thenThrow(new RuntimeException("expected exception")) - - DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() - - assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceBRG.preProcessSDNCDelete(mex) })) - } - - - // ***** preProcessSDNCDeactivate ***** - - @Test -// @Ignore - public void preProcessSDNCDeactivate() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initPreProcessSDNC(mex) - - DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() - DoDeleteAllottedResourceBRG.preProcessSDNCDeactivate(mex) - - def req = map.get("sdncDeactivateRequest") - - assertTrue(req.indexOf("deactivate= 0) - assertTrue(req.indexOf("DeleteBRGInstance= 0) - assertTrue(req.indexOf("") >= 0) - } - - @Test -// @Ignore - public void preProcessSDNCDeactivate_BpmnError() { - ExecutionEntity mex = setupMock() - initPreProcessSDNC(mex) - - when(mex.getVariable("allottedResourceId")).thenThrow(new BpmnError("expected exception")) - - DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() - - assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceBRG.preProcessSDNCDeactivate(mex) })) - } - - @Test -// @Ignore - public void preProcessSDNCDeactivate_Ex() { - ExecutionEntity mex = setupMock() - initPreProcessSDNC(mex) - - when(mex.getVariable("allottedResourceId")).thenThrow(new RuntimeException("expected exception")) - - DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() - - assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceBRG.preProcessSDNCDeactivate(mex) })) - } - - - // ***** validateSDNCResp ***** - - @Test -// @Ignore - public void validateSDNCResp() { - ExecutionEntity mex = setupMock() - def data = initValidateSDNCResp(mex) - def resp = initValidateSDNCResp_Resp(200) - - when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true) - - DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() - - DoDeleteAllottedResourceBRG.validateSDNCResp(mex, resp, "create") - - verify(mex).getVariable("WorkflowException") - verify(mex).getVariable("SDNCA_SuccessIndicator") - verify(mex).getVariable(Prefix+"sdncResponseSuccess") - - verify(mex, never()).getVariable(Prefix + "sdncRequestDataResponseCode") - verify(mex, never()).setVariable("wasDeleted", false) - } - - @Test -// @Ignore - public void validateSDNCResp_Fail404_Deactivate_FailNotFound() { - ExecutionEntity mex = setupMock() - def data = initValidateSDNCResp(mex) - - def resp = initValidateSDNCResp_Resp(404) - when(mex.getVariable(Prefix+"sdncRequestDataResponseCode")).thenReturn("404") - when(mex.getVariable("failNotFound")).thenReturn("true") - - DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() - - assertTrue(doBpmnError( { _ -> DoDeleteAllottedResourceBRG.validateSDNCResp(mex, resp, "deactivate")})) - } - - @Test -// @Ignore - public void validateSDNCResp_Fail404_Deactivate() { - ExecutionEntity mex = setupMock() - def data = initValidateSDNCResp(mex) - - def resp = initValidateSDNCResp_Resp(404) - when(mex.getVariable(Prefix+"sdncRequestDataResponseCode")).thenReturn("404") - - DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() - - DoDeleteAllottedResourceBRG.validateSDNCResp(mex, resp, "deactivate") - - verify(mex).setVariable("ARNotFoundInSDNC", true) - verify(mex).setVariable("wasDeleted", false) - } - - @Test -// @Ignore - public void validateSDNCResp_Fail404() { - ExecutionEntity mex = setupMock() - def data = initValidateSDNCResp(mex) - - def resp = initValidateSDNCResp_Resp(404) - when(mex.getVariable(Prefix+"sdncRequestDataResponseCode")).thenReturn("404") - - DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() - - assertTrue(doBpmnError( { _ -> DoDeleteAllottedResourceBRG.validateSDNCResp(mex, resp, "create")})) - } - - @Test -// @Ignore - public void validateSDNCResp_Deactivate() { - ExecutionEntity mex = setupMock() - def data = initValidateSDNCResp(mex) - def resp = initValidateSDNCResp_Resp(200) - - DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() - - assertTrue(doBpmnError( { _ -> DoDeleteAllottedResourceBRG.validateSDNCResp(mex, resp, "deactivate")})) - } - - @Test -// @Ignore - public void validateSDNCResp_BpmnError() { - ExecutionEntity mex = setupMock() - initValidateSDNCResp(mex) - def resp = initValidateSDNCResp_Resp(200) - - when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception")) - - DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() - - assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceBRG.validateSDNCResp(mex, resp, "create") })) - } - - @Test -// @Ignore - public void validateSDNCResp_Ex() { - ExecutionEntity mex = setupMock() - initValidateSDNCResp(mex) - def resp = initValidateSDNCResp_Resp(200) - - when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception")) - - DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() - - assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceBRG.validateSDNCResp(mex, resp, "create") })) - } - - @Test - @Ignore - public void deleteAaiAR() { - ExecutionEntity mex = setupMock() - initDeleteAaiAR(mex) - - MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoDeleteAllottedResourceBRG/arGetById.xml") - MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) - - DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() - DoDeleteAllottedResourceBRG.deleteAaiAR(mex) - } - - @Test -// @Ignore - public void deleteAaiAR_NoArPath() { - ExecutionEntity mex = setupMock() - initDeleteAaiAR(mex) - - MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoDeleteAllottedResourceBRG/arGetById.xml") - MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) - - when(mex.getVariable("aaiARPath")).thenReturn("") - - DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() - - assertTrue(doBpmnError( { _ -> DoDeleteAllottedResourceBRG.deleteAaiAR(mex) })) - } - - @Test -// @Ignore - public void deleteAaiAR_BpmnError() { - ExecutionEntity mex = setupMock() - initDeleteAaiAR(mex) - - MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoDeleteAllottedResourceBRG/arGetById.xml") - MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) - - when(mex.getVariable("aaiARPath")).thenThrow(new BpmnError("expected exception")) - - DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() - - assertTrue(doBpmnError( { _ -> DoDeleteAllottedResourceBRG.deleteAaiAR(mex) })) - } - - @Test -// @Ignore - public void deleteAaiAR_Ex() { - ExecutionEntity mex = setupMock() - initDeleteAaiAR(mex) - - MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoDeleteAllottedResourceBRG/arGetById.xml") - MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) - - when(mex.getVariable("aaiARPath")).thenThrow(new RuntimeException("expected exception")) - - DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() - - assertTrue(doBpmnError( { _ -> DoDeleteAllottedResourceBRG.deleteAaiAR(mex) })) - } - - private boolean checkMissingPreProcessRequest(String fieldnm) { - ExecutionEntity mex = setupMock() - initPreProcess(mex) - - DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() - - when(mex.getVariable(fieldnm)).thenReturn("") - - return doBpmnError( { _ -> DoDeleteAllottedResourceBRG.preProcessRequest(mex) }) - } - - private void initPreProcess(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("sdncurn") - when(mex.getVariable("serviceInstanceId")).thenReturn("sii") - when(mex.getVariable("allottedResourceId")).thenReturn("ari") - } - - private void initGetAaiAR(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("allottedResourceType")).thenReturn("BRG") - when(mex.getVariable("allottedResourceRole")).thenReturn("BRG") - when(mex.getVariable("allottedResourceId")).thenReturn(ARID) - when(mex.getVariable("CSI_service")).thenReturn(FileUtil.readResourceFile("__files/VCPE/DoDeleteAllottedResourceBRG/getAR.xml")) - when(mex.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn(UrnPropertiesReader.getVariable("mso.workflow.global.default.aai.namespace")) - when(mex.getVariable("mso.workflow.global.default.aai.version")).thenReturn(UrnPropertiesReader.getVariable("mso.workflow.global.default.aai.version")) - when(mex.getVariable("mso.workflow.default.aai.v8.nodes.query.uri")).thenReturn(UrnPropertiesReader.getVariable("mso.workflow.default.aai.v8.nodes-query.uri")) - when(mex.getVariable("aai.endpoint")).thenReturn(aaiUriPfx) - when(mex.getVariable("aaiARPath")).thenReturn("/business/customers/customer/"+CUST+"/service-subscriptions/service-subscription/"+SVC+"/service-instances/service-instance/"+INST+"/allotted-resources/allotted-resource/"+ARID) - when(mex.getVariable("aaiAROrchStatus")).thenReturn("Active") - } - - private initUpdateAaiAROrchStatus(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("aaiARPath")).thenReturn("/business/customers/customer/"+CUST+"/service-subscriptions/service-subscription/"+SVC+"/service-instances/service-instance/"+INST+"/allotted-resources/allotted-resource/"+ARID) - } - - private initBuildSDNCRequest(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("allottedResourceId")).thenReturn("ari") - when(mex.getVariable("serviceInstanceId")).thenReturn("sii") - when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii") - when(mex.getVariable("subscriptionServiceType")).thenReturn("sst") - when(mex.getVariable("globalCustomerId")).thenReturn("gci") - when(mex.getVariable("sdncCallbackUrl")).thenReturn("scu") - when(mex.getVariable("msoRequestId")).thenReturn("mri") - } - - private initPreProcessSDNC(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - } - - private initValidateSDNCResp(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("prefix")).thenReturn(Prefix) - when(mex.getVariable("SDNCA_SuccessIndicator")).thenReturn(true) - } - - private String initValidateSDNCResp_Resp(int code) { - return "<response-code>${code}</response-code>" - } - - private initDeleteAaiAR(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("aaiARPath")).thenReturn("/business/customers/customer/"+CUST+"/service-subscriptions/service-subscription/"+SVC+"/service-instances/service-instance/"+INST+"/allotted-resources/allotted-resource/"+ARID) - when(mex.getVariable("aaiARResourceVersion")).thenReturn("myvers") - when(mex.getVariable("aai.endpoint")).thenReturn(aaiUriPfx) - } - + public void updateAaiAROrchStatus() { + ExecutionEntity mex = setupMock() + initUpdateAaiAROrchStatus(mex) + + MockPatchAllottedResource(CUST, SVC, INST, ARID) + + DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() + DoDeleteAllottedResourceBRG.updateAaiAROrchStatus(mex, "success") + } + + // ***** buildSDNCRequest ***** + + @Test + public void buildSDNCRequest() { + ExecutionEntity mex = setupMock() + initBuildSDNCRequest(mex) + + DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() + + String result = DoDeleteAllottedResourceBRG.buildSDNCRequest(mex, "myact", "myreq") + + assertTrue(result.indexOf("myreq= 0) + assertTrue(result.indexOf("myact= 0) + assertTrue(result.indexOf("ari= 0) + assertTrue(result.indexOf("sii= 0) + assertTrue(result.indexOf("sii= 0) + assertTrue(result.indexOf("psii= 0) + assertTrue(result.indexOf("sst= 0) + assertTrue(result.indexOf("gci= 0) + assertTrue(result.indexOf("scu= 0) + assertTrue(result.indexOf("mri= 0) + assertTrue(result.indexOf("") >= 0) + assertTrue(result.indexOf("") >= 0) + assertTrue(result.indexOf("") >= 0) + assertTrue(result.indexOf("") >= 0) + assertTrue(result.indexOf("") >= 0) + } + + @Test + public void buildSDNCRequest_Ex() { + ExecutionEntity mex = setupMock() + initBuildSDNCRequest(mex) + + when(mex.getVariable("allottedResourceId")).thenThrow(new RuntimeException("expected exception")) + + DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceBRG.buildSDNCRequest(mex, "myact", "myreq") })) + } + + // ***** preProcessSDNCUnassign ***** + + @Test + public void preProcessSDNCUnassign() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initPreProcessSDNC(mex) + + DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() + DoDeleteAllottedResourceBRG.preProcessSDNCUnassign(mex) + + def req = map.get("sdncUnassignRequest") + + assertTrue(req.indexOf("unassign= 0) + assertTrue(req.indexOf("DeleteBRGInstance= 0) + assertTrue(req.indexOf("") >= 0) + } + + @Test + public void preProcessSDNCUnassign_BpmnError() { + ExecutionEntity mex = setupMock() + initPreProcessSDNC(mex) + + when(mex.getVariable("allottedResourceId")).thenThrow(new BpmnError("expected exception")) + + DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceBRG.preProcessSDNCUnassign(mex) })) + } + + @Test + public void preProcessSDNCUnassign_Ex() { + ExecutionEntity mex = setupMock() + initPreProcessSDNC(mex) + + when(mex.getVariable("allottedResourceId")).thenThrow(new RuntimeException("expected exception")) + + DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceBRG.preProcessSDNCUnassign(mex) })) + } + + // ***** preProcessSDNCDelete ***** + + @Test + public void preProcessSDNCDelete() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initPreProcessSDNC(mex) + + DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() + DoDeleteAllottedResourceBRG.preProcessSDNCDelete(mex) + + def req = map.get("sdncDeleteRequest") + + assertTrue(req.indexOf("delete= 0) + assertTrue(req.indexOf("DeleteBRGInstance= 0) + assertTrue(req.indexOf("") >= 0) + } + + @Test + public void preProcessSDNCDelete_BpmnError() { + ExecutionEntity mex = setupMock() + initPreProcessSDNC(mex) + + when(mex.getVariable("allottedResourceId")).thenThrow(new BpmnError("expected exception")) + + DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceBRG.preProcessSDNCDelete(mex) })) + } + + @Test + public void preProcessSDNCDelete_Ex() { + ExecutionEntity mex = setupMock() + initPreProcessSDNC(mex) + + when(mex.getVariable("allottedResourceId")).thenThrow(new RuntimeException("expected exception")) + + DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceBRG.preProcessSDNCDelete(mex) })) + } + + // ***** preProcessSDNCDeactivate ***** + + @Test + public void preProcessSDNCDeactivate() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initPreProcessSDNC(mex) + + DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() + DoDeleteAllottedResourceBRG.preProcessSDNCDeactivate(mex) + + def req = map.get("sdncDeactivateRequest") + + assertTrue(req.indexOf("deactivate= 0) + assertTrue(req.indexOf("DeleteBRGInstance= 0) + assertTrue(req.indexOf("") >= 0) + } + + @Test + public void preProcessSDNCDeactivate_BpmnError() { + ExecutionEntity mex = setupMock() + initPreProcessSDNC(mex) + + when(mex.getVariable("allottedResourceId")).thenThrow(new BpmnError("expected exception")) + + DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceBRG.preProcessSDNCDeactivate(mex) })) + } + + @Test + public void preProcessSDNCDeactivate_Ex() { + ExecutionEntity mex = setupMock() + initPreProcessSDNC(mex) + + when(mex.getVariable("allottedResourceId")).thenThrow(new RuntimeException("expected exception")) + + DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceBRG.preProcessSDNCDeactivate(mex) })) + } + + // ***** validateSDNCResp ***** + + @Test + public void validateSDNCResp() { + ExecutionEntity mex = setupMock() + initValidateSDNCResp(mex) + def resp = initValidateSDNCResp_Resp(200) + + when(mex.getVariable(Prefix + "sdncResponseSuccess")).thenReturn(true) + + DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() + + DoDeleteAllottedResourceBRG.validateSDNCResp(mex, resp, "create") + + verify(mex).getVariable("WorkflowException") + verify(mex).getVariable("SDNCA_SuccessIndicator") + verify(mex).getVariable(Prefix + "sdncResponseSuccess") + + verify(mex, never()).getVariable(Prefix + "sdncRequestDataResponseCode") + verify(mex, never()).setVariable("wasDeleted", false) + } + + @Test + public void validateSDNCResp_Fail404_Deactivate_FailNotFound() { + ExecutionEntity mex = setupMock() + initValidateSDNCResp(mex) + + def resp = initValidateSDNCResp_Resp(404) + when(mex.getVariable(Prefix + "sdncRequestDataResponseCode")).thenReturn("404") + when(mex.getVariable("failNotFound")).thenReturn("true") + + DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceBRG.validateSDNCResp(mex, resp, "deactivate") })) + } + + @Test + public void validateSDNCResp_Fail404_Deactivate() { + ExecutionEntity mex = setupMock() + initValidateSDNCResp(mex) + + def resp = initValidateSDNCResp_Resp(404) + when(mex.getVariable(Prefix + "sdncRequestDataResponseCode")).thenReturn("404") + + DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() + + DoDeleteAllottedResourceBRG.validateSDNCResp(mex, resp, "deactivate") + + verify(mex).setVariable("ARNotFoundInSDNC", true) + verify(mex).setVariable("wasDeleted", false) + } + + @Test + public void validateSDNCResp_Fail404() { + ExecutionEntity mex = setupMock() + initValidateSDNCResp(mex) + + def resp = initValidateSDNCResp_Resp(404) + when(mex.getVariable(Prefix + "sdncRequestDataResponseCode")).thenReturn("404") + + DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceBRG.validateSDNCResp(mex, resp, "create") })) + } + + @Test + public void validateSDNCResp_Deactivate() { + ExecutionEntity mex = setupMock() + def data = initValidateSDNCResp(mex) + def resp = initValidateSDNCResp_Resp(200) + + DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceBRG.validateSDNCResp(mex, resp, "deactivate") })) + } + + @Test + public void validateSDNCResp_BpmnError() { + ExecutionEntity mex = setupMock() + initValidateSDNCResp(mex) + def resp = initValidateSDNCResp_Resp(200) + + when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception")) + + DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceBRG.validateSDNCResp(mex, resp, "create") })) + } + + @Test + public void validateSDNCResp_Ex() { + ExecutionEntity mex = setupMock() + initValidateSDNCResp(mex) + def resp = initValidateSDNCResp_Resp(200) + + when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception")) + + DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceBRG.validateSDNCResp(mex, resp, "create") })) + } + + @Test + @Ignore + public void deleteAaiAR() { + ExecutionEntity mex = setupMock() + initDeleteAaiAR(mex) + + MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoDeleteAllottedResourceBRG/arGetById.xml") + MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) + + DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() + DoDeleteAllottedResourceBRG.deleteAaiAR(mex) + } + + @Test + public void deleteAaiAR_NoArPath() { + ExecutionEntity mex = setupMock() + initDeleteAaiAR(mex) + + MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoDeleteAllottedResourceBRG/arGetById.xml") + MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) + + when(mex.getVariable("aaiARPath")).thenReturn("") + + DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceBRG.deleteAaiAR(mex) })) + } + + @Test + public void deleteAaiAR_BpmnError() { + ExecutionEntity mex = setupMock() + initDeleteAaiAR(mex) + + MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoDeleteAllottedResourceBRG/arGetById.xml") + MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) + + when(mex.getVariable("aaiARPath")).thenThrow(new BpmnError("expected exception")) + + DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceBRG.deleteAaiAR(mex) })) + } + + @Test + public void deleteAaiAR_Ex() { + ExecutionEntity mex = setupMock() + initDeleteAaiAR(mex) + + MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoDeleteAllottedResourceBRG/arGetById.xml") + MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) + + when(mex.getVariable("aaiARPath")).thenThrow(new RuntimeException("expected exception")) + + DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceBRG.deleteAaiAR(mex) })) + } + + private boolean checkMissingPreProcessRequest(String fieldnm) { + ExecutionEntity mex = setupMock() + initPreProcess(mex) + + DoDeleteAllottedResourceBRG DoDeleteAllottedResourceBRG = new DoDeleteAllottedResourceBRG() + + when(mex.getVariable(fieldnm)).thenReturn("") + + return doBpmnError({ _ -> DoDeleteAllottedResourceBRG.preProcessRequest(mex) }) + } + + private void initPreProcess(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("sdncurn") + when(mex.getVariable("serviceInstanceId")).thenReturn("sii") + when(mex.getVariable("allottedResourceId")).thenReturn("ari") + } + + private void initGetAaiAR(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("allottedResourceType")).thenReturn("BRG") + when(mex.getVariable("allottedResourceRole")).thenReturn("BRG") + when(mex.getVariable("allottedResourceId")).thenReturn(ARID) + when(mex.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn(UrnPropertiesReader.getVariable("mso.workflow.global.default.aai.namespace")) + when(mex.getVariable("mso.workflow.global.default.aai.version")).thenReturn(UrnPropertiesReader.getVariable("mso.workflow.global.default.aai.version")) + when(mex.getVariable("mso.workflow.default.aai.v8.nodes.query.uri")).thenReturn(UrnPropertiesReader.getVariable("mso.workflow.default.aai.v8.nodes-query.uri")) + when(mex.getVariable("aai.endpoint")).thenReturn(aaiUriPfx) + when(mex.getVariable("aaiARPath")).thenReturn("/business/customers/customer/" + CUST + "/service-subscriptions/service-subscription/" + SVC + "/service-instances/service-instance/" + INST + "/allotted-resources/allotted-resource/" + ARID) + when(mex.getVariable("aaiAROrchStatus")).thenReturn("Active") + } + + private initUpdateAaiAROrchStatus(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("aaiARPath")).thenReturn("/business/customers/customer/" + CUST + "/service-subscriptions/service-subscription/" + SVC + "/service-instances/service-instance/" + INST + "/allotted-resources/allotted-resource/" + ARID) + } + + private initBuildSDNCRequest(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("allottedResourceId")).thenReturn("ari") + when(mex.getVariable("serviceInstanceId")).thenReturn("sii") + when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii") + when(mex.getVariable("subscriptionServiceType")).thenReturn("sst") + when(mex.getVariable("globalCustomerId")).thenReturn("gci") + when(mex.getVariable("sdncCallbackUrl")).thenReturn("scu") + when(mex.getVariable("msoRequestId")).thenReturn("mri") + } + + private initPreProcessSDNC(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + } + + private initValidateSDNCResp(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("prefix")).thenReturn(Prefix) + when(mex.getVariable("SDNCA_SuccessIndicator")).thenReturn(true) + } + + private String initValidateSDNCResp_Resp(int code) { + return "<response-code>${code}</response-code>" + } + + private initDeleteAaiAR(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("aaiARPath")).thenReturn("/business/customers/customer/" + CUST + "/service-subscriptions/service-subscription/" + SVC + "/service-instances/service-instance/" + INST + "/allotted-resources/allotted-resource/" + ARID) + when(mex.getVariable("aaiARResourceVersion")).thenReturn("myvers") + when(mex.getVariable("aai.endpoint")).thenReturn(aaiUriPfx) + } + } diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/DoDeleteAllottedResourceTXCTest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/DoDeleteAllottedResourceTXCTest.groovy index ad9b3d4f88..23115874a2 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/DoDeleteAllottedResourceTXCTest.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/DoDeleteAllottedResourceTXCTest.groovy @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -20,19 +22,15 @@ package org.onap.so.bpmn.vcpe.scripts +import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity -import org.junit.Before -import org.junit.BeforeClass -import org.junit.Rule -import org.junit.Test -import org.junit.Ignore +import org.junit.* import org.mockito.MockitoAnnotations -import org.camunda.bpm.engine.delegate.BpmnError import org.mockito.Spy import org.onap.so.bpmn.core.UrnPropertiesReader -import org.onap.so.bpmn.mock.FileUtil -import org.onap.so.client.aai.entities.uri.AAIResourceUri -import static org.junit.Assert.*; + +import static org.junit.Assert.assertTrue +import static org.mockito.ArgumentMatchers.eq import static org.mockito.Mockito.* import static org.onap.so.bpmn.mock.StubResponseAAI.MockDeleteAllottedResource import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetAllottedResource @@ -40,534 +38,498 @@ import static org.onap.so.bpmn.mock.StubResponseAAI.MockPatchAllottedResource import com.github.tomakehurst.wiremock.junit.WireMockRule class DoDeleteAllottedResourceTXCTest extends GroovyTestBase { - - @Rule - public WireMockRule wireMockRule = new WireMockRule(PORT) - String Prefix = "DDARTXC_" + @Rule + public WireMockRule wireMockRule = new WireMockRule(PORT) + + String Prefix = "DDARTXC_" @Spy DoDeleteAllottedResourceTXC doDeleteAllottedResourceTXC - @BeforeClass - public static void setUpBeforeClass() { - super.setUpBeforeClass() - } - + @BeforeClass + public static void setUpBeforeClass() { + GroovyTestBase.setUpBeforeClass() + } + @Before - public void init() - { + public void init() { MockitoAnnotations.initMocks(this) - super.init() + initAllottedResourceMock() + } + + public DoDeleteAllottedResourceTXCTest() { + super("DoDeleteAllottedResourceTXC") + } + + // ***** preProcessRequest ***** + + @Test + public void preProcessRequest() { + ExecutionEntity mex = setupMock() + initPreProcess(mex) + + DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() + DoDeleteAllottedResourceTXC.preProcessRequest(mex) + + verify(mex).setVariable("prefix", Prefix) + verify(mex).setVariable("sdncCallbackUrl", "sdncurn") + + assertTrue(checkMissingPreProcessRequest("mso.workflow.sdncadapter.callback")) + assertTrue(checkMissingPreProcessRequest("serviceInstanceId")) + assertTrue(checkMissingPreProcessRequest("allottedResourceId")) + } + + @Test + public void preProcessRequest_BpmnError() { + ExecutionEntity mex = setupMock() + initPreProcess(mex) + + when(mex.getVariable("serviceInstanceId")).thenThrow(new BpmnError("expected exception")) + + DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceTXC.preProcessRequest(mex) })) + } + + @Test + public void preProcessRequest_Ex() { + ExecutionEntity mex = setupMock() + initPreProcess(mex) + + when(mex.getVariable("serviceInstanceId")).thenThrow(new RuntimeException("expected exception")) + + DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceTXC.preProcessRequest(mex) })) + } + + // ***** getAaiAR ***** + @Test + public void getAaiAR() { + + ExecutionEntity mex = setupMock() + initGetAaiAR(mex) when(doDeleteAllottedResourceTXC.getAllottedResourceUtils()).thenReturn(allottedResourceUtils_MOCK) - } - - public DoDeleteAllottedResourceTXCTest() { - super("DoDeleteAllottedResourceTXC") - } - - - // ***** preProcessRequest ***** - - @Test -// @Ignore - public void preProcessRequest() { - ExecutionEntity mex = setupMock() - initPreProcess(mex) - - DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() - DoDeleteAllottedResourceTXC.preProcessRequest(mex) - - //verify(mex).getVariable(DBGFLAG) - verify(mex).setVariable("prefix", Prefix) - verify(mex).setVariable("sdncCallbackUrl", "sdncurn") - - assertTrue(checkMissingPreProcessRequest("mso.workflow.sdncadapter.callback")) - assertTrue(checkMissingPreProcessRequest("serviceInstanceId")) - assertTrue(checkMissingPreProcessRequest("allottedResourceId")) - } - - @Test -// @Ignore - public void preProcessRequest_BpmnError() { - ExecutionEntity mex = setupMock() - initPreProcess(mex) - - when(mex.getVariable("serviceInstanceId")).thenThrow(new BpmnError("expected exception")) - - DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() - - assertTrue(doBpmnError( { _ -> DoDeleteAllottedResourceTXC.preProcessRequest(mex) })) - } - - @Test -// @Ignore - public void preProcessRequest_Ex() { - ExecutionEntity mex = setupMock() - initPreProcess(mex) - - when(mex.getVariable("serviceInstanceId")).thenThrow(new RuntimeException("expected exception")) - - DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() - - assertTrue(doBpmnError( { _ -> DoDeleteAllottedResourceTXC.preProcessRequest(mex) })) - } - - - // ***** getAaiAR ***** - @Test + doReturn(true).when(allottedResourceUtils_MOCK).ifExistsAR(eq(mex), eq(ARID)) + doDeleteAllottedResourceTXC.getAaiAR(mex) + verify(mex).setVariable("parentServiceInstanceId", INST) + } + + @Test + public void getAaiAR_EmptyResponse() { + ExecutionEntity mex = setupMock() + initGetAaiAR(mex) + doReturn(false).when(allottedResourceUtils_MOCK).ifExistsAR(eq(mex), eq(ARID)) + assertTrue(doBpmnError({ _ -> doDeleteAllottedResourceTXC.getAaiAR(mex) })) + } + + // ***** updateAaiAROrchStatus ***** + + @Test @Ignore - public void getAaiAR() { + public void updateAaiAROrchStatus() { + ExecutionEntity mex = setupMock() + initUpdateAaiAROrchStatus(mex) + + MockPatchAllottedResource(CUST, SVC, INST, ARID) + + DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() + DoDeleteAllottedResourceTXC.updateAaiAROrchStatus(mex, "success") + } + + // ***** buildSDNCRequest ***** + + @Test + public void buildSDNCRequest() { + ExecutionEntity mex = setupMock() + initBuildSDNCRequest(mex) + + DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() + + String result = DoDeleteAllottedResourceTXC.buildSDNCRequest(mex, "myact", "myreq") + + assertTrue(result.indexOf("myreq= 0) + assertTrue(result.indexOf("myact= 0) + assertTrue(result.indexOf("ari= 0) + assertTrue(result.indexOf("sii= 0) + assertTrue(result.indexOf("sii= 0) + assertTrue(result.indexOf("psii= 0) + assertTrue(result.indexOf("sst= 0) + assertTrue(result.indexOf("gci= 0) + assertTrue(result.indexOf("scu= 0) + assertTrue(result.indexOf("mri= 0) + assertTrue(result.indexOf("") >= 0) + assertTrue(result.indexOf("") >= 0) + assertTrue(result.indexOf("") >= 0) + assertTrue(result.indexOf("") >= 0) + assertTrue(result.indexOf("") >= 0) + } + + @Test + public void buildSDNCRequest_Ex() { + ExecutionEntity mex = setupMock() + initBuildSDNCRequest(mex) + + when(mex.getVariable("allottedResourceId")).thenThrow(new RuntimeException("expected exception")) + + DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceTXC.buildSDNCRequest(mex, "myact", "myreq") })) + } + + // ***** preProcessSDNCUnassign ***** + + @Test + public void preProcessSDNCUnassign() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initPreProcessSDNC(mex) + + DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() + DoDeleteAllottedResourceTXC.preProcessSDNCUnassign(mex) + + def req = map.get("sdncUnassignRequest") + + assertTrue(req.indexOf("unassign= 0) + assertTrue(req.indexOf("DeleteTunnelXConnInstance= 0) + assertTrue(req.indexOf("") >= 0) + } + + @Test + public void preProcessSDNCUnassign_BpmnError() { + ExecutionEntity mex = setupMock() + initPreProcessSDNC(mex) + + when(mex.getVariable("allottedResourceId")).thenThrow(new BpmnError("expected exception")) + + DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceTXC.preProcessSDNCUnassign(mex) })) + } + + @Test + public void preProcessSDNCUnassign_Ex() { + ExecutionEntity mex = setupMock() + initPreProcessSDNC(mex) + + when(mex.getVariable("allottedResourceId")).thenThrow(new RuntimeException("expected exception")) + + DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceTXC.preProcessSDNCUnassign(mex) })) + } + + // ***** preProcessSDNCDelete ***** + + @Test + public void preProcessSDNCDelete() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initPreProcessSDNC(mex) + + DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() + DoDeleteAllottedResourceTXC.preProcessSDNCDelete(mex) + + def req = map.get("sdncDeleteRequest") + + assertTrue(req.indexOf("delete= 0) + assertTrue(req.indexOf("DeleteTunnelXConnInstance= 0) + assertTrue(req.indexOf("") >= 0) + } + + @Test + public void preProcessSDNCDelete_BpmnError() { + ExecutionEntity mex = setupMock() + initPreProcessSDNC(mex) + + when(mex.getVariable("allottedResourceId")).thenThrow(new BpmnError("expected exception")) + + DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceTXC.preProcessSDNCDelete(mex) })) + } + + @Test + public void preProcessSDNCDelete_Ex() { + ExecutionEntity mex = setupMock() + initPreProcessSDNC(mex) + + when(mex.getVariable("allottedResourceId")).thenThrow(new RuntimeException("expected exception")) + + DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceTXC.preProcessSDNCDelete(mex) })) + } + + // ***** preProcessSDNCDeactivate ***** + + @Test + public void preProcessSDNCDeactivate() { + ExecutionEntity mex = setupMock() + def map = setupMap(mex) + initPreProcessSDNC(mex) + + DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() + DoDeleteAllottedResourceTXC.preProcessSDNCDeactivate(mex) + + def req = map.get("sdncDeactivateRequest") + + assertTrue(req.indexOf("deactivate= 0) + assertTrue(req.indexOf("DeleteTunnelXConnInstance= 0) + assertTrue(req.indexOf("") >= 0) + } + + @Test + public void preProcessSDNCDeactivate_BpmnError() { + ExecutionEntity mex = setupMock() + initPreProcessSDNC(mex) + + when(mex.getVariable("allottedResourceId")).thenThrow(new BpmnError("expected exception")) + + DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceTXC.preProcessSDNCDeactivate(mex) })) + } + + @Test + public void preProcessSDNCDeactivate_Ex() { + ExecutionEntity mex = setupMock() + initPreProcessSDNC(mex) + + when(mex.getVariable("allottedResourceId")).thenThrow(new RuntimeException("expected exception")) + + DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceTXC.preProcessSDNCDeactivate(mex) })) + } + + // ***** validateSDNCResp ***** + + @Test + public void validateSDNCResp() { + ExecutionEntity mex = setupMock() + initValidateSDNCResp(mex) + def resp = initValidateSDNCResp_Resp(200) + + when(mex.getVariable(Prefix + "sdncResponseSuccess")).thenReturn(true) + + DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() + + DoDeleteAllottedResourceTXC.validateSDNCResp(mex, resp, "create") + + verify(mex).getVariable("WorkflowException") + verify(mex).getVariable("SDNCA_SuccessIndicator") + verify(mex).getVariable(Prefix + "sdncResponseSuccess") + + verify(mex, never()).getVariable(Prefix + "sdncRequestDataResponseCode") + verify(mex, never()).setVariable("wasDeleted", false) + } + + @Test + public void validateSDNCResp_Fail404_Deactivate_FailNotFound() { + ExecutionEntity mex = setupMock() + initValidateSDNCResp(mex) + + def resp = initValidateSDNCResp_Resp(404) + when(mex.getVariable(Prefix + "sdncRequestDataResponseCode")).thenReturn("404") + when(mex.getVariable("failNotFound")).thenReturn("true") + + DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceTXC.validateSDNCResp(mex, resp, "deactivate") })) + } + + @Test + public void validateSDNCResp_Fail404_Deactivate() { + ExecutionEntity mex = setupMock() + initValidateSDNCResp(mex) + + def resp = initValidateSDNCResp_Resp(404) + when(mex.getVariable(Prefix + "sdncRequestDataResponseCode")).thenReturn("404") + + DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() + + DoDeleteAllottedResourceTXC.validateSDNCResp(mex, resp, "deactivate") + + verify(mex).setVariable("ARNotFoundInSDNC", true) + verify(mex).setVariable("wasDeleted", false) + } + + @Test + public void validateSDNCResp_Fail404() { + ExecutionEntity mex = setupMock() + initValidateSDNCResp(mex) + + def resp = initValidateSDNCResp_Resp(404) + when(mex.getVariable(Prefix + "sdncRequestDataResponseCode")).thenReturn("404") + + DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceTXC.validateSDNCResp(mex, resp, "create") })) + } + + @Test + public void validateSDNCResp_Deactivate() { + ExecutionEntity mex = setupMock() + initValidateSDNCResp(mex) + def resp = initValidateSDNCResp_Resp(200) + + DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceTXC.validateSDNCResp(mex, resp, "deactivate") })) + } + + @Test + public void validateSDNCResp_BpmnError() { + ExecutionEntity mex = setupMock() + initValidateSDNCResp(mex) + def resp = initValidateSDNCResp_Resp(200) + + when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception")) + + DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceTXC.validateSDNCResp(mex, resp, "create") })) + } + + @Test + public void validateSDNCResp_Ex() { + ExecutionEntity mex = setupMock() + initValidateSDNCResp(mex) + def resp = initValidateSDNCResp_Resp(200) + + when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception")) + + DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceTXC.validateSDNCResp(mex, resp, "create") })) + } + + @Test + @Ignore + public void deleteAaiAR() { + ExecutionEntity mex = setupMock() + initDeleteAaiAR(mex) + + MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoDeleteAllottedResourceTXC/arGetById.xml") + MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) + + DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() + DoDeleteAllottedResourceTXC.deleteAaiAR(mex) + } + + @Test + public void deleteAaiAR_NoArPath() { + ExecutionEntity mex = setupMock() + initDeleteAaiAR(mex) + + MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoDeleteAllottedResourceTXC/arGetById.xml") + MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) + + when(mex.getVariable("aaiARPath")).thenReturn("") + + DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceTXC.deleteAaiAR(mex) })) + } + + @Test + public void deleteAaiAR_BpmnError() { + ExecutionEntity mex = setupMock() + initDeleteAaiAR(mex) + + MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoDeleteAllottedResourceTXC/arGetById.xml") + MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) + + when(mex.getVariable("aaiARPath")).thenThrow(new BpmnError("expected exception")) + + DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceTXC.deleteAaiAR(mex) })) + } + + @Test + public void deleteAaiAR_Ex() { + ExecutionEntity mex = setupMock() + initDeleteAaiAR(mex) + + MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoDeleteAllottedResourceTXC/arGetById.xml") + MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) + + when(mex.getVariable("aaiARPath")).thenThrow(new RuntimeException("expected exception")) + + DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() + + assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceTXC.deleteAaiAR(mex) })) + } + + private boolean checkMissingPreProcessRequest(String fieldnm) { + ExecutionEntity mex = setupMock() + initPreProcess(mex) + + DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() + + when(mex.getVariable(fieldnm)).thenReturn("") + + return doBpmnError({ _ -> DoDeleteAllottedResourceTXC.preProcessRequest(mex) }) + } + + private void initPreProcess(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("sdncurn") + when(mex.getVariable("serviceInstanceId")).thenReturn("sii") + when(mex.getVariable("allottedResourceId")).thenReturn("ari") + } + + private void initGetAaiAR(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("allottedResourceType")).thenReturn("TXC") + when(mex.getVariable("allottedResourceRole")).thenReturn("TXC") + when(mex.getVariable("allottedResourceId")).thenReturn(ARID) + when(mex.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn(UrnPropertiesReader.getVariable("mso.workflow.global.default.aai.namespace")) + when(mex.getVariable("mso.workflow.global.default.aai.version")).thenReturn(UrnPropertiesReader.getVariable("mso.workflow.global.default.aai.version")) + when(mex.getVariable("mso.workflow.default.aai.v8.nodes.query.uri")).thenReturn(UrnPropertiesReader.getVariable("mso.workflow.default.aai.v8.nodes-query.uri")) + when(mex.getVariable("aai.endpoint")).thenReturn(aaiUriPfx) + when(mex.getVariable("aaiARPath")).thenReturn("/business/customers/customer/" + CUST + "/service-subscriptions/service-subscription/" + SVC + "/service-instances/service-instance/" + INST + "/allotted-resources/allotted-resource/" + ARID) + when(mex.getVariable("aaiAROrchStatus")).thenReturn("Active") + } + + private initUpdateAaiAROrchStatus(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("aaiARPath")).thenReturn("/business/customers/customer/" + CUST + "/service-subscriptions/service-subscription/" + SVC + "/service-instances/service-instance/" + INST + "/allotted-resources/allotted-resource/" + ARID) + } + + private initBuildSDNCRequest(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("allottedResourceId")).thenReturn("ari") + when(mex.getVariable("serviceInstanceId")).thenReturn("sii") + when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii") + when(mex.getVariable("subscriptionServiceType")).thenReturn("sst") + when(mex.getVariable("globalCustomerId")).thenReturn("gci") + when(mex.getVariable("sdncCallbackUrl")).thenReturn("scu") + when(mex.getVariable("msoRequestId")).thenReturn("mri") + } + + private initPreProcessSDNC(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + } + + private initValidateSDNCResp(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("prefix")).thenReturn(Prefix) + when(mex.getVariable("SDNCA_SuccessIndicator")).thenReturn(true) + } + + private String initValidateSDNCResp_Resp(int code) { + return "<response-code>${code}</response-code>" + } + + private initDeleteAaiAR(ExecutionEntity mex) { + when(mex.getVariable(DBGFLAG)).thenReturn("true") + when(mex.getVariable("aaiARPath")).thenReturn("/business/customers/customer/" + CUST + "/service-subscriptions/service-subscription/" + SVC + "/service-instances/service-instance/" + INST + "/allotted-resources/allotted-resource/" + ARID) + when(mex.getVariable("aaiARResourceVersion")).thenReturn("myvers") + when(mex.getVariable("aai.endpoint")).thenReturn(aaiUriPfx) + } - ExecutionEntity mex = setupMock() - initGetAaiAR(mex) - when(client_MOCK.exists(any(AAIResourceUri.class))).thenReturn(true) - doDeleteAllottedResourceTXC.getAaiAR(mex) - verify(mex).setVariable("parentServiceInstanceId", INST) - } - - @Test - public void getAaiAR_EmptyResponse() { - ExecutionEntity mex = setupMock() - initGetAaiAR(mex) - when(client_MOCK.exists(any(AAIResourceUri.class))).thenReturn(false) - assertTrue(doBpmnError( { _ -> doDeleteAllottedResourceTXC.getAaiAR(mex) })) - } - - - // ***** updateAaiAROrchStatus ***** - - @Test - @Ignore - public void updateAaiAROrchStatus() { - ExecutionEntity mex = setupMock() - initUpdateAaiAROrchStatus(mex) - - MockPatchAllottedResource(CUST, SVC, INST, ARID) - - DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() - DoDeleteAllottedResourceTXC.updateAaiAROrchStatus(mex, "success") - } - - - // ***** buildSDNCRequest ***** - - @Test -// @Ignore - public void buildSDNCRequest() { - ExecutionEntity mex = setupMock() - initBuildSDNCRequest(mex) - - DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() - - String result = DoDeleteAllottedResourceTXC.buildSDNCRequest(mex, "myact", "myreq") - - assertTrue(result.indexOf("myreq= 0) - assertTrue(result.indexOf("myact= 0) - assertTrue(result.indexOf("ari= 0) - assertTrue(result.indexOf("sii= 0) - assertTrue(result.indexOf("sii= 0) - assertTrue(result.indexOf("psii= 0) - assertTrue(result.indexOf("sst= 0) - assertTrue(result.indexOf("gci= 0) - assertTrue(result.indexOf("scu= 0) - assertTrue(result.indexOf("mri= 0) - assertTrue(result.indexOf("") >= 0) - assertTrue(result.indexOf("") >= 0) - assertTrue(result.indexOf("") >= 0) - assertTrue(result.indexOf("") >= 0) - assertTrue(result.indexOf("") >= 0) - } - - @Test -// @Ignore - public void buildSDNCRequest_Ex() { - ExecutionEntity mex = setupMock() - initBuildSDNCRequest(mex) - - when(mex.getVariable("allottedResourceId")).thenThrow(new RuntimeException("expected exception")) - - DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() - - assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceTXC.buildSDNCRequest(mex, "myact", "myreq") })) - } - - - // ***** preProcessSDNCUnassign ***** - - @Test -// @Ignore - public void preProcessSDNCUnassign() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initPreProcessSDNC(mex) - - DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() - DoDeleteAllottedResourceTXC.preProcessSDNCUnassign(mex) - - def req = map.get("sdncUnassignRequest") - - assertTrue(req.indexOf("unassign= 0) - assertTrue(req.indexOf("DeleteTunnelXConnInstance= 0) - assertTrue(req.indexOf("") >= 0) - } - - @Test -// @Ignore - public void preProcessSDNCUnassign_BpmnError() { - ExecutionEntity mex = setupMock() - initPreProcessSDNC(mex) - - when(mex.getVariable("allottedResourceId")).thenThrow(new BpmnError("expected exception")) - - DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() - - assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceTXC.preProcessSDNCUnassign(mex) })) - } - - @Test -// @Ignore - public void preProcessSDNCUnassign_Ex() { - ExecutionEntity mex = setupMock() - initPreProcessSDNC(mex) - - when(mex.getVariable("allottedResourceId")).thenThrow(new RuntimeException("expected exception")) - - DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() - - assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceTXC.preProcessSDNCUnassign(mex) })) - } - - - // ***** preProcessSDNCDelete ***** - - @Test -// @Ignore - public void preProcessSDNCDelete() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initPreProcessSDNC(mex) - - DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() - DoDeleteAllottedResourceTXC.preProcessSDNCDelete(mex) - - def req = map.get("sdncDeleteRequest") - - assertTrue(req.indexOf("delete= 0) - assertTrue(req.indexOf("DeleteTunnelXConnInstance= 0) - assertTrue(req.indexOf("") >= 0) - } - - @Test -// @Ignore - public void preProcessSDNCDelete_BpmnError() { - ExecutionEntity mex = setupMock() - initPreProcessSDNC(mex) - - when(mex.getVariable("allottedResourceId")).thenThrow(new BpmnError("expected exception")) - - DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() - - assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceTXC.preProcessSDNCDelete(mex) })) - } - - @Test -// @Ignore - public void preProcessSDNCDelete_Ex() { - ExecutionEntity mex = setupMock() - initPreProcessSDNC(mex) - - when(mex.getVariable("allottedResourceId")).thenThrow(new RuntimeException("expected exception")) - - DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() - - assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceTXC.preProcessSDNCDelete(mex) })) - } - - - // ***** preProcessSDNCDeactivate ***** - - @Test -// @Ignore - public void preProcessSDNCDeactivate() { - ExecutionEntity mex = setupMock() - def map = setupMap(mex) - initPreProcessSDNC(mex) - - DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() - DoDeleteAllottedResourceTXC.preProcessSDNCDeactivate(mex) - - def req = map.get("sdncDeactivateRequest") - - assertTrue(req.indexOf("deactivate= 0) - assertTrue(req.indexOf("DeleteTunnelXConnInstance= 0) - assertTrue(req.indexOf("") >= 0) - } - - @Test -// @Ignore - public void preProcessSDNCDeactivate_BpmnError() { - ExecutionEntity mex = setupMock() - initPreProcessSDNC(mex) - - when(mex.getVariable("allottedResourceId")).thenThrow(new BpmnError("expected exception")) - - DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() - - assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceTXC.preProcessSDNCDeactivate(mex) })) - } - - @Test -// @Ignore - public void preProcessSDNCDeactivate_Ex() { - ExecutionEntity mex = setupMock() - initPreProcessSDNC(mex) - - when(mex.getVariable("allottedResourceId")).thenThrow(new RuntimeException("expected exception")) - - DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() - - assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceTXC.preProcessSDNCDeactivate(mex) })) - } - - - // ***** validateSDNCResp ***** - - @Test -// @Ignore - public void validateSDNCResp() { - ExecutionEntity mex = setupMock() - def data = initValidateSDNCResp(mex) - def resp = initValidateSDNCResp_Resp(200) - - when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true) - - DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() - - DoDeleteAllottedResourceTXC.validateSDNCResp(mex, resp, "create") - - verify(mex).getVariable("WorkflowException") - verify(mex).getVariable("SDNCA_SuccessIndicator") - verify(mex).getVariable(Prefix+"sdncResponseSuccess") - - verify(mex, never()).getVariable(Prefix + "sdncRequestDataResponseCode") - verify(mex, never()).setVariable("wasDeleted", false) - } - - @Test -// @Ignore - public void validateSDNCResp_Fail404_Deactivate_FailNotFound() { - ExecutionEntity mex = setupMock() - def data = initValidateSDNCResp(mex) - - def resp = initValidateSDNCResp_Resp(404) - when(mex.getVariable(Prefix+"sdncRequestDataResponseCode")).thenReturn("404") - when(mex.getVariable("failNotFound")).thenReturn("true") - - DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() - - assertTrue(doBpmnError( { _ -> DoDeleteAllottedResourceTXC.validateSDNCResp(mex, resp, "deactivate")})) - } - - @Test -// @Ignore - public void validateSDNCResp_Fail404_Deactivate() { - ExecutionEntity mex = setupMock() - def data = initValidateSDNCResp(mex) - - def resp = initValidateSDNCResp_Resp(404) - when(mex.getVariable(Prefix+"sdncRequestDataResponseCode")).thenReturn("404") - - DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() - - DoDeleteAllottedResourceTXC.validateSDNCResp(mex, resp, "deactivate") - - verify(mex).setVariable("ARNotFoundInSDNC", true) - verify(mex).setVariable("wasDeleted", false) - } - - @Test -// @Ignore - public void validateSDNCResp_Fail404() { - ExecutionEntity mex = setupMock() - def data = initValidateSDNCResp(mex) - - def resp = initValidateSDNCResp_Resp(404) - when(mex.getVariable(Prefix+"sdncRequestDataResponseCode")).thenReturn("404") - - DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() - - assertTrue(doBpmnError( { _ -> DoDeleteAllottedResourceTXC.validateSDNCResp(mex, resp, "create")})) - } - - @Test -// @Ignore - public void validateSDNCResp_Deactivate() { - ExecutionEntity mex = setupMock() - def data = initValidateSDNCResp(mex) - def resp = initValidateSDNCResp_Resp(200) - - DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() - - assertTrue(doBpmnError( { _ -> DoDeleteAllottedResourceTXC.validateSDNCResp(mex, resp, "deactivate")})) - } - - @Test -// @Ignore - public void validateSDNCResp_BpmnError() { - ExecutionEntity mex = setupMock() - initValidateSDNCResp(mex) - def resp = initValidateSDNCResp_Resp(200) - - when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception")) - - DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() - - assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceTXC.validateSDNCResp(mex, resp, "create") })) - } - - @Test -// @Ignore - public void validateSDNCResp_Ex() { - ExecutionEntity mex = setupMock() - initValidateSDNCResp(mex) - def resp = initValidateSDNCResp_Resp(200) - - when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception")) - - DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() - - assertTrue(doBpmnError({ _ -> DoDeleteAllottedResourceTXC.validateSDNCResp(mex, resp, "create") })) - } - - @Test - @Ignore - public void deleteAaiAR() { - ExecutionEntity mex = setupMock() - initDeleteAaiAR(mex) - - MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoDeleteAllottedResourceTXC/arGetById.xml") - MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) - - DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() - DoDeleteAllottedResourceTXC.deleteAaiAR(mex) - } - - @Test -// @Ignore - public void deleteAaiAR_NoArPath() { - ExecutionEntity mex = setupMock() - initDeleteAaiAR(mex) - - MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoDeleteAllottedResourceTXC/arGetById.xml") - MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) - - when(mex.getVariable("aaiARPath")).thenReturn("") - - DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() - - assertTrue(doBpmnError( { _ -> DoDeleteAllottedResourceTXC.deleteAaiAR(mex) })) - } - - @Test -// @Ignore - public void deleteAaiAR_BpmnError() { - ExecutionEntity mex = setupMock() - initDeleteAaiAR(mex) - - MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoDeleteAllottedResourceTXC/arGetById.xml") - MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) - - when(mex.getVariable("aaiARPath")).thenThrow(new BpmnError("expected exception")) - - DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() - - assertTrue(doBpmnError( { _ -> DoDeleteAllottedResourceTXC.deleteAaiAR(mex) })) - } - - @Test -// @Ignore - public void deleteAaiAR_Ex() { - ExecutionEntity mex = setupMock() - initDeleteAaiAR(mex) - - MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoDeleteAllottedResourceTXC/arGetById.xml") - MockDeleteAllottedResource(CUST, SVC, INST, ARID, VERS) - - when(mex.getVariable("aaiARPath")).thenThrow(new RuntimeException("expected exception")) - - DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() - - assertTrue(doBpmnError( { _ -> DoDeleteAllottedResourceTXC.deleteAaiAR(mex) })) - } - - private boolean checkMissingPreProcessRequest(String fieldnm) { - ExecutionEntity mex = setupMock() - initPreProcess(mex) - - DoDeleteAllottedResourceTXC DoDeleteAllottedResourceTXC = new DoDeleteAllottedResourceTXC() - - when(mex.getVariable(fieldnm)).thenReturn("") - - return doBpmnError( { _ -> DoDeleteAllottedResourceTXC.preProcessRequest(mex) }) - } - - private void initPreProcess(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("sdncurn") - when(mex.getVariable("serviceInstanceId")).thenReturn("sii") - when(mex.getVariable("allottedResourceId")).thenReturn("ari") - } - - private void initGetAaiAR(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("allottedResourceType")).thenReturn("TXC") - when(mex.getVariable("allottedResourceRole")).thenReturn("TXC") - when(mex.getVariable("allottedResourceId")).thenReturn(ARID) - when(mex.getVariable("CSI_service")).thenReturn(FileUtil.readResourceFile("__files/VCPE/DoDeleteAllottedResourceTXC/getAR.xml")) - when(mex.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn(UrnPropertiesReader.getVariable("mso.workflow.global.default.aai.namespace")) - when(mex.getVariable("mso.workflow.global.default.aai.version")).thenReturn(UrnPropertiesReader.getVariable("mso.workflow.global.default.aai.version")) - when(mex.getVariable("mso.workflow.default.aai.v8.nodes.query.uri")).thenReturn(UrnPropertiesReader.getVariable("mso.workflow.default.aai.v8.nodes-query.uri")) - when(mex.getVariable("aai.endpoint")).thenReturn(aaiUriPfx) - when(mex.getVariable("aaiARPath")).thenReturn("/business/customers/customer/"+CUST+"/service-subscriptions/service-subscription/"+SVC+"/service-instances/service-instance/"+INST+"/allotted-resources/allotted-resource/"+ARID) - when(mex.getVariable("aaiAROrchStatus")).thenReturn("Active") - } - - private initUpdateAaiAROrchStatus(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("aaiARPath")).thenReturn("/business/customers/customer/"+CUST+"/service-subscriptions/service-subscription/"+SVC+"/service-instances/service-instance/"+INST+"/allotted-resources/allotted-resource/"+ARID) - } - - private initBuildSDNCRequest(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("allottedResourceId")).thenReturn("ari") - when(mex.getVariable("serviceInstanceId")).thenReturn("sii") - when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii") - when(mex.getVariable("subscriptionServiceType")).thenReturn("sst") - when(mex.getVariable("globalCustomerId")).thenReturn("gci") - when(mex.getVariable("sdncCallbackUrl")).thenReturn("scu") - when(mex.getVariable("msoRequestId")).thenReturn("mri") - } - - private initPreProcessSDNC(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - } - - private initValidateSDNCResp(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("prefix")).thenReturn(Prefix) - when(mex.getVariable("SDNCA_SuccessIndicator")).thenReturn(true) - } - - private String initValidateSDNCResp_Resp(int code) { - return "<response-code>${code}</response-code>" - } - - private initDeleteAaiAR(ExecutionEntity mex) { - when(mex.getVariable(DBGFLAG)).thenReturn("true") - when(mex.getVariable("aaiARPath")).thenReturn("/business/customers/customer/"+CUST+"/service-subscriptions/service-subscription/"+SVC+"/service-instances/service-instance/"+INST+"/allotted-resources/allotted-resource/"+ARID) - when(mex.getVariable("aaiARResourceVersion")).thenReturn("myvers") - when(mex.getVariable("aai.endpoint")).thenReturn(aaiUriPfx) - } - } diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/GroovyTestBase.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/GroovyTestBase.groovy index 8ce3bdb6c3..1ff098b940 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/GroovyTestBase.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/GroovyTestBase.groovy @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -20,97 +22,94 @@ package org.onap.so.bpmn.vcpe.scripts - import org.camunda.bpm.engine.ProcessEngineServices import org.camunda.bpm.engine.RepositoryService +import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity import org.camunda.bpm.engine.repository.ProcessDefinition import org.junit.runner.RunWith import org.mockito.Mock -import org.camunda.bpm.engine.delegate.BpmnError -import org.mockito.runners.MockitoJUnitRunner +import org.mockito.junit.MockitoJUnitRunner import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor import org.onap.so.bpmn.common.scripts.AllottedResourceUtils import org.onap.so.bpmn.core.UrnPropertiesReader import org.onap.so.client.aai.AAIResourcesClient + +import static org.mockito.ArgumentMatchers.any import static org.mockito.Mockito.* @RunWith(MockitoJUnitRunner.class) class GroovyTestBase { - - static final int PORT = 28090 - static final String LOCAL_URI = "http://localhost:" + PORT - - static final String CUST = "SDN-ETHERNET-INTERNET" - static final String SVC = "123456789" - static final String INST = "MIS%252F1604%252F0026%252FSW_INTERNET" - static final String ARID = "arId-1" - static final String VERS = "myvers" - - static final String DBGFLAG = "isDebugLogEnabled" - - static String aaiUriPfx - - String processName + + static final int PORT = 28090 + static final String LOCAL_URI = "http://localhost:" + PORT + + static final String CUST = "SDN-ETHERNET-INTERNET" + static final String SVC = "123456789" + static final String INST = "MIS%252F1604%252F0026%252FSW_INTERNET" + static final String ARID = "arId-1" + static final String VERS = "myvers" + + static final String DBGFLAG = "isDebugLogEnabled" + + static String aaiUriPfx + + String processName AllottedResourceUtils allottedResourceUtils_MOCK @Mock AAIResourcesClient client_MOCK - public static void setUpBeforeClass() { - aaiUriPfx = UrnPropertiesReader.getVariable("aai.endpoint") - } - - public GroovyTestBase(String processName) { - this.processName = processName - } - - public boolean doBpmnError(def func) { - - try { - func() - return false; - - } catch(BpmnError e) { - return true; - } - } - - public ExecutionEntity setupMock() { - - ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class) - when(mockProcessDefinition.getKey()).thenReturn(processName) - RepositoryService mockRepositoryService = mock(RepositoryService.class) - when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition) - when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn(processName) - when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100") - ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class) - when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService) - - ExecutionEntity mex = mock(ExecutionEntity.class) - - when(mex.getId()).thenReturn("100") - when(mex.getProcessDefinitionId()).thenReturn(processName) - when(mex.getProcessInstanceId()).thenReturn(processName) - when(mex.getProcessEngineServices()).thenReturn(mockProcessEngineServices) - when(mex.getProcessEngineServices().getRepositoryService().getProcessDefinition(mex.getProcessDefinitionId())).thenReturn(mockProcessDefinition) - - when(mex.getVariable("isAsyncProcess")).thenReturn("true") - when(mex.getVariable(processName+"WorkflowResponseSent")).thenReturn("false") - - return mex - } - - public Map setupMap(ExecutionEntity mex) { - MapSetter mapset = new MapSetter(); - doAnswer(mapset).when(mex).setVariable(any(), any()) - return mapset.getMap(); - } - - void init(){ + public static void setUpBeforeClass() { + aaiUriPfx = UrnPropertiesReader.getVariable("aai.endpoint") + } + + public GroovyTestBase(String processName) { + this.processName = processName + } + + public boolean doBpmnError(def func) { + + try { + func() + return false; + + } catch (BpmnError e) { + return true; + } + } + + public ExecutionEntity setupMock() { + + ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class) + when(mockProcessDefinition.getKey()).thenReturn(processName) + RepositoryService mockRepositoryService = mock(RepositoryService.class) + when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition) + when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn(processName) + ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class) + when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService) + + ExecutionEntity mex = mock(ExecutionEntity.class) + + when(mex.getProcessDefinitionId()).thenReturn(processName) + when(mex.getProcessEngineServices()).thenReturn(mockProcessEngineServices) + when(mex.getProcessEngineServices().getRepositoryService().getProcessDefinition(mex.getProcessDefinitionId())).thenReturn(mockProcessDefinition) + + when(mex.getVariable("isAsyncProcess")).thenReturn("true") + when(mex.getVariable(processName + "WorkflowResponseSent")).thenReturn("false") + + return mex + } + + public Map setupMap(ExecutionEntity mex) { + MapSetter mapset = new MapSetter(); + doAnswer(mapset).when(mex).setVariable(any(), any()) + return mapset.getMap(); + } + + void initAllottedResourceMock() { allottedResourceUtils_MOCK = spy(new AllottedResourceUtils(mock(AbstractServiceTaskProcessor.class))) - when(allottedResourceUtils_MOCK.getAAIClient()).thenReturn(client_MOCK) } } diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/MapGetter.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/MapGetter.groovy index fa5dcec4bc..9b29c43a9c 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/MapGetter.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/MapGetter.groovy @@ -18,32 +18,29 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.bpmn.vcpe.scripts; +package org.onap.so.bpmn.vcpe.scripts -import java.util.HashMap; -import java.util.Map; - -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; +import org.mockito.invocation.InvocationOnMock +import org.mockito.stubbing.Answer class MapGetter implements Answer { - final Map map; - - public MapGetter() { - map = new HashMap<>(); - } - - public MapGetter(Map map) { - this.map = map; - } - - public Map getMap() { - return map; - } - - @Override - public Object answer(InvocationOnMock invocation) throws Throwable { - return map.get(invocation.getArgumentAt(0, String.class)); - } - -} + final Map map; + + public MapGetter() { + map = new HashMap<>(); + } + + public MapGetter(Map map) { + this.map = map; + } + + public Map getMap() { + return map; + } + + @Override + public Object answer(InvocationOnMock invocation) throws Throwable { + return map.get(invocation.getArgumentAt(0, String.class)); + } + +} \ No newline at end of file diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/MapSetter.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/MapSetter.groovy index 7b50c616ea..06057cdd61 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/MapSetter.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/vcpe/scripts/MapSetter.groovy @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -18,33 +20,30 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.bpmn.vcpe.scripts; - -import java.util.HashMap; -import java.util.Map; +package org.onap.so.bpmn.vcpe.scripts -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; +import org.mockito.invocation.InvocationOnMock +import org.mockito.stubbing.Answer class MapSetter implements Answer { - final Map map; - - public MapSetter() { - map = new HashMap<>(); - } - - public MapSetter(Map map) { - this.map = map; - } - - public Map getMap() { - return map; - } - - @Override - public Void answer(InvocationOnMock invocation) throws Throwable { - map.put(invocation.getArgumentAt(0, String.class), invocation.getArgumentAt(1, Object.class)); - return null; - } - -} + final Map map; + + public MapSetter() { + map = new HashMap<>(); + } + + public MapSetter(Map map) { + this.map = map; + } + + public Map getMap() { + return map; + } + + @Override + public Void answer(InvocationOnMock invocation) throws Throwable { + map.put((String) invocation.getArgument(0), invocation.getArgument(1)) + return null + } + +} \ No newline at end of file diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/AllTestsTestSuite.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/AllTestsTestSuite.java index 0c0f38c0f9..01f37ad655 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/AllTestsTestSuite.java +++ b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/AllTestsTestSuite.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -27,8 +29,8 @@ import com.googlecode.junittoolbox.WildcardPatternSuite; @RunWith(WildcardPatternSuite.class) @SuiteClasses({"!**/service/*Test.class", "!**/subprocess/*Test.class", "!**/process/*Test.class", - "!**/tasks/*Test.class", "!**/infrastructure/aai/*Test.class", - "!**/scripts/*Test.class", "**/*Test.class"}) + "!**/tasks/*Test.class", "!**/infrastructure/aai/*Test.class", + "!**/infrastructure/scripts/*Test.class", "**/*Test.class"}) public class AllTestsTestSuite { // the class remains empty, // used only as a holder for the above annotations diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/resources/__files/VCPE/DeleteVcpeResCustService/request.json b/bpmn/so-bpmn-infrastructure-common/src/test/resources/__files/VCPE/DeleteVcpeResCustService/request.json index dc4669e8d9..7c60512c36 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/resources/__files/VCPE/DeleteVcpeResCustService/request.json +++ b/bpmn/so-bpmn-infrastructure-common/src/test/resources/__files/VCPE/DeleteVcpeResCustService/request.json @@ -23,6 +23,7 @@ }, "cloudConfiguration": { + "cloudOwner":"CloudOwner", "lcpCloudRegionId":"mdt1", "tenantId":"8b1df54faa3b49078e3416e21370a3ba" }, -- cgit 1.2.3-korg