diff options
Diffstat (limited to 'bpmn')
23 files changed, 560 insertions, 282 deletions
diff --git a/bpmn/MSOCommonBPMN/pom.xml b/bpmn/MSOCommonBPMN/pom.xml index c85bcd7522..934aea8241 100644 --- a/bpmn/MSOCommonBPMN/pom.xml +++ b/bpmn/MSOCommonBPMN/pom.xml @@ -397,5 +397,11 @@ <version>1.2.4.RELEASE</version> <scope>test</scope> </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <version>3.11.1</version> + <scope>test</scope> + </dependency> </dependencies> </project> diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupName.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupName.groovy index c309c3bb68..f4e7926c8e 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupName.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupName.groovy @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright 2018 Nokia + * ================================================================================ * 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,6 +21,11 @@ */ package org.onap.so.bpmn.common.scripts + +import joptsimple.internal.Strings +import org.onap.so.bpmn.common.scripts.ExceptionUtil +import org.springframework.http.HttpStatus + import javax.ws.rs.core.UriBuilder import org.camunda.bpm.engine.delegate.DelegateExecution @@ -33,8 +40,12 @@ import org.onap.so.logger.MsoLogger public class ConfirmVolumeGroupName extends AbstractServiceTaskProcessor{ private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, ConfirmVolumeGroupName.class); - def Prefix="CVGN_" - ExceptionUtil exceptionUtil = new ExceptionUtil() + def static final Prefix = "CVGN_" + private final ExceptionUtil exceptionUtil + + ConfirmVolumeGroupName(ExceptionUtil exceptionUtil) { + this.exceptionUtil = exceptionUtil + } public void initProcessVariables(DelegateExecution execution) { execution.setVariable("prefix",Prefix) @@ -74,40 +85,39 @@ public class ConfirmVolumeGroupName extends AbstractServiceTaskProcessor{ try { Optional<VolumeGroup> volumeGroupOp = getAAIClient().get(VolumeGroup.class, resourceUri) if(volumeGroupOp.isPresent()){ - execution.setVariable("CVGN_queryVolumeGroupResponseCode", 200) + execution.setVariable("CVGN_queryVolumeGroupResponseCode", HttpStatus.OK.value()) execution.setVariable("CVGN_queryVolumeGroupResponse", volumeGroupOp.get()) }else{ - execution.setVariable("CVGN_queryVolumeGroupResponseCode", 404) + execution.setVariable("CVGN_queryVolumeGroupResponseCode", HttpStatus.NOT_FOUND.value()) execution.setVariable("CVGN_queryVolumeGroupResponse", "Volume Group not Found!") } } catch (Exception ex) { msoLogger.debug("Exception occurred while executing AAI GET:" + ex.getMessage()) - execution.setVariable("CVGN_queryVolumeGroupResponseCode", 500) + execution.setVariable("CVGN_queryVolumeGroupResponseCode", HttpStatus.INTERNAL_SERVER_ERROR.value()) execution.setVariable("CVGN_queryVolumeGroupResponse", "AAI GET Failed:" + ex.getMessage()) - exceptionUtil.buildAndThrowWorkflowException(execution, 500, "AAI GET Failed") + exceptionUtil.buildAndThrowWorkflowException(execution, HttpStatus.INTERNAL_SERVER_ERROR.value(), "AAI GET Failed") } } // process the result from queryAAIVolumeGroupId() public void checkAAIQueryResult(DelegateExecution execution) { - def result = execution.getVariable("CVGN_queryVolumeGroupResponse") - def actualVolumeGroupName = "" - if (execution.getVariable("CVGN_queryVolumeGroupResponseCode") == 404) { + if (execution.getVariable("CVGN_queryVolumeGroupResponseCode") == HttpStatus.NOT_FOUND.value()) { msoLogger.debug('volumeGroupId does not exist in AAI') } - else if (execution.getVariable("CVGN_queryVolumeGroupResponseCode") == 200) { + else if (execution.getVariable("CVGN_queryVolumeGroupResponseCode") == HttpStatus.OK.value()) { VolumeGroup volumeGroup = execution.getVariable("CVGN_queryVolumeGroupResponse") - if(volumeGroup.getVolumeGroupName()!=null){ + + if (!Strings.isNullOrEmpty(volumeGroup.getVolumeGroupName())) { actualVolumeGroupName = volumeGroup.getVolumeGroupName() - } - msoLogger.debug("volumeGroupId exists in AAI") + msoLogger.debug("volumeGroupId exists in AAI") + } } execution.setVariable("CVGN_volumeGroupNameMatches", false) def volumeGroupName = execution.getVariable("CVGN_volumeGroupName") - if (volumeGroupName.equals(actualVolumeGroupName)) { + if (!actualVolumeGroupName.isEmpty() && volumeGroupName.equals(actualVolumeGroupName)) { msoLogger.debug('Volume Group Name Matches AAI records') execution.setVariable("CVGN_volumeGroupNameMatches", true) } @@ -121,8 +131,8 @@ public class ConfirmVolumeGroupName extends AbstractServiceTaskProcessor{ // generates a WorkflowException if the volume group name does not match AAI record for this volume group public void handleVolumeGroupNameNoMatch(DelegateExecution execution) { - def errorNotAssociated = "Error occurred - volume group id " + execution.getVariable("CVGN_volumeGroupId") + - " is not associated with " + execution.getVariable("CVGN_volumeGroupName") + def errorNotAssociated = "Error occurred - volume group id ${execution.getVariable('CVGN_volumeGroupId')} " + + "is not associated with ${execution.getVariable('CVGN_volumeGroupName')}" msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, errorNotAssociated, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, ""); exceptionUtil.buildAndThrowWorkflowException(execution, 1002, errorNotAssociated) } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/restproperties/AaiPropertiesConfiguration.java b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupNameFactory.groovy index b7582922b1..f032d640d5 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/restproperties/AaiPropertiesConfiguration.java +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupNameFactory.groovy @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * ONAP - SO * ================================================================================ - * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018 Nokia. * ================================================================================ * 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 - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -18,25 +18,14 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.client.restproperties; +package org.onap.so.bpmn.common.scripts -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; +import org.onap.so.bpmn.common.scripts.ConfirmVolumeGroupName +import org.onap.so.bpmn.common.scripts.ExceptionUtil -@Service -public class AaiPropertiesConfiguration { +public class ConfirmVolumeGroupNameFactory { - @Value("${aai.endpoint}") - private String endpoint; - - @Value("${aai.auth}") - private String auth; - - public String getEndpoint() { - return endpoint; - } - - public String getAuth() { - return auth; - } + ConfirmVolumeGroupName create() { + return new ConfirmVolumeGroupName(new ExceptionUtil()); + } } diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExceptionUtil.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExceptionUtil.groovy index 4b701e6a58..e132b411a5 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExceptionUtil.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExceptionUtil.groovy @@ -293,7 +293,7 @@ class ExceptionUtil extends AbstractServiceTaskProcessor { execution.setVariable("WorkflowException", exception); msoLogger.debug("Outgoing WorkflowException is " + exception) msoLogger.debug("Throwing MSOWorkflowException") - throw new BpmnError("MSOWorkflowException") + throw new BpmnError(errorCode.toString(), String.format("MSOWorkflowException: %s", errorMessage)) } /** diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/PrepareUpdateAAIVfModule.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/PrepareUpdateAAIVfModule.groovy index 8f0e481c9a..15f00ac25f 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/PrepareUpdateAAIVfModule.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/PrepareUpdateAAIVfModule.groovy @@ -223,7 +223,7 @@ public class PrepareUpdateAAIVfModule extends VfModuleBase { AAIResourcesClient client = new AAIResourcesClient() AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId) client.update(uri, vfModule) - + execution.setVariable('PUAAIVfMod_updateVfModuleResponseCode', 200) // Set the output for this flow. The updated VfModule is an output, the generic VNF name, and for // backward compatibilty, the heat-stack-id is an output execution.setVariable('PUAAIVfMod_outVfModule', vfModule) @@ -238,9 +238,11 @@ public class PrepareUpdateAAIVfModule extends VfModuleBase { msoLogger.trace('Exited ' + method) } catch (BpmnError e) { + execution.setVariable('PUAAIVfMod_updateVfModuleResponseCode', 500) throw e; } catch (Exception e) { msoLogger.error(e) + execution.setVariable('PUAAIVfMod_updateVfModuleResponseCode', 500) exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in updateVfModule(): ' + e.getMessage()) } } diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapter.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapter.groovy index a5e7c0fd06..a430cdb715 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapter.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapter.groovy @@ -58,11 +58,10 @@ public class SDNCAdapter extends AbstractServiceTaskProcessor { execution.setVariable("SDNCA_InterimNotify", false) String requestId = execution.getVariable("mso-request-id") - if(isNotBlank(requestId)){ - execution.setVariable(Prefix + "requestId", requestId) - }else{ + if(isBlank(requestId)){ exceptionUtil.buildAndThrowWorkflowException(execution, 400, 'mso-request-id not provided by calling flow') } + // Authorization Info String basicAuthValue = UrnPropertiesReader.getVariable("mso.adapters.po.auth", execution) @@ -124,6 +123,7 @@ public class SDNCAdapter extends AbstractServiceTaskProcessor { //calling process should pass a generated uuid if sending multiple sdnc requests def sdncRequestId = utils.getNodeText(requestHeader, "RequestId") + execution.setVariable(Prefix + "requestId", sdncRequestId) // Prepare SDNC Request to the SDNC Adapter String sdncAdapterRequest = """ diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIVfModule.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIVfModule.groovy index a6568fb80a..3c4edd21ca 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIVfModule.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIVfModule.groovy @@ -184,11 +184,17 @@ public class UpdateAAIVfModule extends AbstractServiceTaskProcessor { try { AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId) getAAIClient().update(resourceUri, payload) + execution.setVariable('UAAIVfMod_updateVfModuleResponseCode', 200) + execution.setVariable('UAAIVfMod_updateVfModuleResponse', "Success") }catch(NotFoundException ignored){ msoLogger.debug("VF-Module not found!!") + execution.setVariable('UAAIVfMod_updateVfModuleResponseCode', 404) + execution.setVariable('UAAIVfMod_updateVfModuleResponse', ignored.getMessage()) exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "vf-module " + vfModuleId + " not found for under vnf " + vnfId + " in A&AI!") } catch(Exception ex){ + execution.setVariable('UAAIVfMod_updateVfModuleResponseCode', 500) + execution.setVariable('UAAIVfMod_updateVfModuleResponse', 'AAI PATCH Failed:' + ex.getMessage()) exceptionUtil.buildAndThrowWorkflowException(execution, 2500, 'Exception occurred while executing AAI PATCH:' + ex.getMessage()) } } catch (BpmnError e) { diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java index b794e4174b..0017c4eeb1 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java @@ -609,16 +609,27 @@ public class BBInputSetup implements JavaDelegate { vnf = createGenericVnf(lookupKeyMap, instanceName, platform, lineOfBusiness, resourceId, generatedVnfType, instanceParams); serviceInstance.getVnfs().add(vnf); + mapVnfcCollectionInstanceGroup(vnf, modelInfo, service); } if(vnf != null) { mapCatalogVnf(vnf, modelInfo, service); - mapVnfcCollectionInstanceGroup(vnf, modelInfo, service); - if (instanceGroupId != null && instanceGroupModelInfo != null) { + if (instanceGroupId != null && instanceGroupModelInfo != null + && instanceGroupModelInfo.getModelType().equals(ModelType.networkInstanceGroup) + && !instanceGroupInList(vnf, instanceGroupId)) { mapNetworkCollectionInstanceGroup(vnf, instanceGroupId); } } } + protected boolean instanceGroupInList(GenericVnf vnf, String instanceGroupId) { + for(InstanceGroup instanceGroup : vnf.getInstanceGroups()) { + if(instanceGroup.getId() != null && instanceGroup.getId().equalsIgnoreCase(instanceGroupId)) { + return true; + } + } + return false; + } + protected void mapVnfcCollectionInstanceGroup(GenericVnf genericVnf, ModelInfo modelInfo, Service service) { VnfResourceCustomization vnfResourceCustomization = getVnfResourceCustomizationFromService(modelInfo, service); if(vnfResourceCustomization != null) { @@ -865,8 +876,13 @@ public class BBInputSetup implements JavaDelegate { String serviceInstanceId, boolean aLaCarte, String bbName) throws Exception { ServiceInstance serviceInstance = this.getServiceInstanceHelper(requestDetails, customer, project, owningEntity, lookupKeyMap, serviceInstanceId, aLaCarte, service, bbName); - org.onap.aai.domain.yang.ServiceInstance serviceInstanceAAI = this.bbInputSetupUtils - .getAAIServiceInstanceById(serviceInstanceId); + org.onap.aai.domain.yang.ServiceInstance serviceInstanceAAI = null; + if(customer != null && customer.getServiceSubscription() != null) { + serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceByIdAndCustomer(customer.getGlobalCustomerId(), + customer.getServiceSubscription().getServiceType(), serviceInstanceId); + } else { + serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId); + } if (serviceInstanceAAI != null && !serviceInstanceAAI.getModelVersionId().equalsIgnoreCase(service.getModelUUID())) { Service tempService = this.bbInputSetupUtils diff --git a/bpmn/MSOCommonBPMN/src/main/resources/subprocess/ConfirmVolumeGroupName.bpmn b/bpmn/MSOCommonBPMN/src/main/resources/subprocess/ConfirmVolumeGroupName.bpmn index 0e99ce9683..403be98c8e 100644 --- a/bpmn/MSOCommonBPMN/src/main/resources/subprocess/ConfirmVolumeGroupName.bpmn +++ b/bpmn/MSOCommonBPMN/src/main/resources/subprocess/ConfirmVolumeGroupName.bpmn @@ -13,7 +13,7 @@ <bpmn2:incoming>SequenceFlow_23</bpmn2:incoming> <bpmn2:outgoing>SequenceFlow_18</bpmn2:outgoing> <bpmn2:script><![CDATA[import org.onap.so.bpmn.common.scripts.* -def cvgn= new ConfirmVolumeGroupName() +def cvgn= new ConfirmVolumeGroupNameFactory().create() cvgn.handleAAIQueryFailure(execution)]]></bpmn2:script> </bpmn2:scriptTask> <bpmn2:sequenceFlow id="SequenceFlow_18" name="" sourceRef="AAIQueryFailure" targetRef="EndEvent_7"/> @@ -25,7 +25,7 @@ cvgn.handleAAIQueryFailure(execution)]]></bpmn2:script> <bpmn2:incoming>SequenceFlow_38</bpmn2:incoming> <bpmn2:outgoing>SequenceFlow_39</bpmn2:outgoing> <bpmn2:script><![CDATA[import org.onap.so.bpmn.common.scripts.* -def cvgn= new ConfirmVolumeGroupName() +def cvgn= new ConfirmVolumeGroupNameFactory().create() cvgn.queryAAIForVolumeGroupId(execution)]]></bpmn2:script> </bpmn2:scriptTask> <bpmn2:sequenceFlow id="SequenceFlow_39" name="" sourceRef="QueryAAIForVolumeGroupId" targetRef="ExclusiveGateway_3"/> @@ -33,7 +33,7 @@ cvgn.queryAAIForVolumeGroupId(execution)]]></bpmn2:script> <bpmn2:incoming>SequenceFlow_1</bpmn2:incoming> <bpmn2:outgoing>SequenceFlow_38</bpmn2:outgoing> <bpmn2:script><![CDATA[import org.onap.so.bpmn.common.scripts.* -def cvgn= new ConfirmVolumeGroupName() +def cvgn= new ConfirmVolumeGroupNameFactory().create() cvgn.preProcessRequest(execution)]]></bpmn2:script> </bpmn2:scriptTask> <bpmn2:sequenceFlow id="SequenceFlow_38" name="" sourceRef="InitializeVariables" targetRef="QueryAAIForVolumeGroupId"/> @@ -42,7 +42,7 @@ cvgn.preProcessRequest(execution)]]></bpmn2:script> <bpmn2:incoming>SequenceFlow_2</bpmn2:incoming> <bpmn2:outgoing>SequenceFlow_4</bpmn2:outgoing> <bpmn2:script><![CDATA[import org.onap.so.bpmn.common.scripts.* -def cvgn= new ConfirmVolumeGroupName() +def cvgn= new ConfirmVolumeGroupNameFactory().create() cvgn.checkAAIQueryResult(execution)]]></bpmn2:script> </bpmn2:scriptTask> <bpmn2:sequenceFlow id="SequenceFlow_4" name="" sourceRef="CheckAAIQueryResult" targetRef="ExclusiveGateway_1"/> @@ -50,7 +50,7 @@ cvgn.checkAAIQueryResult(execution)]]></bpmn2:script> <bpmn2:incoming>SequenceFlow_7</bpmn2:incoming> <bpmn2:outgoing>SequenceFlow_11</bpmn2:outgoing> <bpmn2:script><![CDATA[import org.onap.so.bpmn.common.scripts.* -def cvgn= new ConfirmVolumeGroupName() +def cvgn= new ConfirmVolumeGroupNameFactory().create() cvgn.handleVolumeGroupNameNoMatch(execution)]]></bpmn2:script> </bpmn2:scriptTask> <bpmn2:exclusiveGateway id="ExclusiveGateway_1" default="SequenceFlow_7"> diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupNameTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupNameTest.groovy index a96127aa2d..79aacdfbe9 100644 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupNameTest.groovy +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupNameTest.groovy @@ -4,12 +4,14 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright 2018 Nokia + * ================================================================================ * 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 - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,64 +22,216 @@ package org.onap.so.bpmn.common.scripts -import static org.mockito.Mockito.* - -import javax.ws.rs.core.UriBuilder - +import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.delegate.DelegateExecution -import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake -import org.junit.Assert import org.junit.Before import org.junit.Test -import org.mockito.ArgumentCaptor -import org.mockito.Captor -import org.mockito.Mockito +import org.mockito.Mock import org.mockito.MockitoAnnotations -import org.mockito.Spy +import org.onap.aai.domain.yang.RelationshipList import org.onap.aai.domain.yang.VolumeGroup +import org.onap.so.bpmn.common.scripts.ConfirmVolumeGroupName +import org.onap.so.bpmn.common.scripts.ConfirmVolumeGroupNameFactory +import org.onap.so.bpmn.common.scripts.ExceptionUtil import org.onap.so.client.aai.AAIObjectType +import org.onap.so.client.aai.AAIResourcesClient import org.onap.so.client.aai.entities.uri.AAIResourceUri import org.onap.so.client.aai.entities.uri.AAIUriFactory +import org.onap.so.constants.Defaults +import org.springframework.http.HttpStatus + +import javax.ws.rs.core.UriBuilder + +import static org.assertj.core.api.Assertions.catchThrowableOfType +import static org.junit.Assert.assertEquals +import static org.junit.Assert.assertFalse +import static org.junit.Assert.assertTrue +import static org.mockito.Mockito.spy +import static org.mockito.Mockito.when + +class ConfirmVolumeGroupNameTest { + + private static final AAIResourceUri RESOURCE_URI = AAIUriFactory.createResourceFromExistingURI( + AAIObjectType.VOLUME_GROUP, UriBuilder.fromPath('/aai/test/volume-groups/volume-group/testVolumeGroup').build()) + + private ConfirmVolumeGroupName confirmVolumeGroupName + @Mock + private VolumeGroup volumeGroup + @Mock + private AAIResourcesClient client + private ExceptionUtilFake exceptionUtilFake + + private DelegateExecution delegateExecution + + @Before + public void init() throws IOException { + exceptionUtilFake = new ExceptionUtilFake() + confirmVolumeGroupName = spy(new ConfirmVolumeGroupName(exceptionUtilFake)) + MockitoAnnotations.initMocks(this) + delegateExecution = new DelegateExecutionFake() + volumeGroup = createVolumeGroup() + when(confirmVolumeGroupName.getAAIClient()).thenReturn(client) + } + + @Test + public void preProcessRequest_shouldSetUpVariables() { + String volumeGroupId = "volume-group-id-1" + String volumeGroupName = "volume-group-name-1" + String aicCloudRegion = "aic-cloud-region-1" + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VOLUME_GROUP, Defaults.CLOUD_OWNER, aicCloudRegion, volumeGroupId) + + delegateExecution.setVariable("ConfirmVolumeGroupName_volumeGroupId", volumeGroupId) + delegateExecution.setVariable("ConfirmVolumeGroupName_volumeGroupName", volumeGroupName) + delegateExecution.setVariable("ConfirmVolumeGroupName_aicCloudRegion", aicCloudRegion) + delegateExecution.setVariable("CVGN_volumeGroupGetEndpoint", uri) + + confirmVolumeGroupName.preProcessRequest(delegateExecution) + + assertEquals(ConfirmVolumeGroupName.Prefix, delegateExecution.getVariable("prefix")) + + assertEquals(volumeGroupId, delegateExecution.getVariable("CVGN_volumeGroupId")) + assertEquals(volumeGroupName, delegateExecution.getVariable("CVGN_volumeGroupName")) + assertEquals(aicCloudRegion, delegateExecution.getVariable("CVGN_aicCloudRegion")) + } + + @Test + public void queryAAIForVolumeGroupId_shouldSucceed_whenVolumeGroupExists() { + delegateExecution.setVariable("CVGN_queryVolumeGroupResponseCode", HttpStatus.OK) + delegateExecution.setVariable("CVGN_queryVolumeGroupResponse", volumeGroup) + delegateExecution.setVariable("CVGN_volumeGroupGetEndpoint", RESOURCE_URI) + when(client.get(VolumeGroup.class, RESOURCE_URI)).thenReturn(Optional.of(volumeGroup)) + + confirmVolumeGroupName.queryAAIForVolumeGroupId(delegateExecution) + + assertEquals(HttpStatus.OK.value(), delegateExecution.getVariable("CVGN_queryVolumeGroupResponseCode")) + assertEquals(volumeGroup, delegateExecution.getVariable("CVGN_queryVolumeGroupResponse")) + } + + @Test + public void queryAAIForVolumeGroupId_shouldFailWith404_whenVolumeGroupDoesNotExist() { + delegateExecution.setVariable("CVGN_volumeGroupGetEndpoint", RESOURCE_URI) + when(client.get(VolumeGroup.class, RESOURCE_URI)).thenReturn(Optional.empty()) + + confirmVolumeGroupName.queryAAIForVolumeGroupId(delegateExecution) + + assertEquals(HttpStatus.NOT_FOUND.value(), delegateExecution.getVariable("CVGN_queryVolumeGroupResponseCode")) + assertEquals("Volume Group not Found!", delegateExecution.getVariable("CVGN_queryVolumeGroupResponse")) + } + + @Test + public void queryAAIForVolumeGroupId_shouldThrowWorkflowException_whenRuntimeExceptionIsThrown() throws BpmnError { + delegateExecution.setVariable("CVGN_volumeGroupGetEndpoint", RESOURCE_URI) + delegateExecution.setVariable("testProcessKey", "process-key1") + + def errorMsg = "my runtime exception" + when(client.get(VolumeGroup.class, RESOURCE_URI)).thenThrow(new RuntimeException(errorMsg)) + + def exceptionMsg = "AAI GET Failed" + + BpmnError error = catchThrowableOfType( + { -> confirmVolumeGroupName.queryAAIForVolumeGroupId(delegateExecution) }, BpmnError.class) + + assertEquals(String.format("MSOWorkflowException: %s", exceptionMsg), error.getMessage()) + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.value().toString(), error.getErrorCode()) + + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.value(), delegateExecution.getVariable("CVGN_queryVolumeGroupResponseCode")) + assertEquals(String.format("AAI GET Failed:%s", errorMsg), delegateExecution.getVariable("CVGN_queryVolumeGroupResponse")) + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.value(), exceptionUtilFake.getErrorCode()) + assertEquals(exceptionMsg, exceptionUtilFake.getErrorMessage()) + assertEquals(delegateExecution, exceptionUtilFake.getDelegateExecution()) + } + + @Test + public void checkAAIQueryResult_shouldSetVolumeGroupNameMatchesToFalse_whenResponseCodeIs404() { + delegateExecution.setVariable("CVGN_queryVolumeGroupResponseCode", HttpStatus.NOT_FOUND) + delegateExecution.setVariable("CVGN_volumeGroupName", "") + + confirmVolumeGroupName.checkAAIQueryResult(delegateExecution) + + assertFalse(delegateExecution.getVariable("CVGN_volumeGroupNameMatches")) + } + + @Test + public void checkAAIQueryResult_shouldSetVolumeGroupNameMatchesToTrue_whenResponseCodeIs200AndVolumeGroupNameExists() { + delegateExecution.setVariable("CVGN_queryVolumeGroupResponseCode", HttpStatus.OK.value()) + delegateExecution.setVariable("CVGN_queryVolumeGroupResponse", volumeGroup) + delegateExecution.setVariable("CVGN_volumeGroupName", volumeGroup.getVolumeGroupName()) + + confirmVolumeGroupName.checkAAIQueryResult(delegateExecution) + + assertTrue(delegateExecution.getVariable("CVGN_volumeGroupNameMatches")) + } + + @Test + public void handleVolumeGroupNameNoMatch_shouldThrowBpmnErrorException() { + def volumeGroupId = "volume-group-id" + def volumeGroupName = "volume-group-name" + + delegateExecution.setVariable("CVGN_volumeGroupId", volumeGroupId) + delegateExecution.setVariable("CVGN_volumeGroupName", volumeGroupName) + + def errorMessage = String.format("Error occurred - volume group id %s is not associated with %s", + delegateExecution.getVariable('CVGN_volumeGroupId'), delegateExecution.getVariable('CVGN_volumeGroupName')) + + BpmnError error = catchThrowableOfType( + { -> confirmVolumeGroupName.handleVolumeGroupNameNoMatch(delegateExecution) }, BpmnError.class) + + assertEquals(String.format("MSOWorkflowException: %s", errorMessage), error.getMessage()) + assertEquals("1002", error.getErrorCode()) + + assertEquals(1002, exceptionUtilFake.getErrorCode()) + assertEquals(errorMessage, exceptionUtilFake.getErrorMessage()) + assertEquals(delegateExecution, exceptionUtilFake.getDelegateExecution()) + } + + @Test + public void reportSuccess_shouldSetWorkflowResponseToEmptyString() { + confirmVolumeGroupName.reportSuccess(delegateExecution) + assertEquals("", delegateExecution.getVariable("WorkflowResponse")) + } + + private VolumeGroup createVolumeGroup() { + VolumeGroup volumeGroup = new VolumeGroup() + + volumeGroup.setVolumeGroupId("volume-group-id") + volumeGroup.setVolumeGroupName("volume-group-name") + volumeGroup.setHeatStackId("heat-stack-id") + volumeGroup.setVnfType("vnf-type") + volumeGroup.setOrchestrationStatus("orchestration-status") + volumeGroup.setModelCustomizationId("model-customization-id") + volumeGroup.setVfModuleModelCustomizationId("vf-module-model-customization-id") + volumeGroup.setResourceVersion("resource-version") + volumeGroup.setRelationshipList(new RelationshipList()) + + return volumeGroup + } + + private static class ExceptionUtilFake extends ExceptionUtil { + + private int errorCode + private String errorMessage + private DelegateExecution execution + + @Override + public void buildAndThrowWorkflowException(DelegateExecution execution, int errorCode, String errorMessage) { + this.errorCode = errorCode + this.errorMessage = errorMessage + this.execution = execution + throw new BpmnError(errorCode.toString(), "MSOWorkflowException: ${errorMessage}") + } + + public int getErrorCode() { + return errorCode + } + + public String getErrorMessage() { + return errorMessage + } + + public DelegateExecution getDelegateExecution() { + return execution + } + } -class ConfirmVolumeGroupNameTest extends MsoGroovyTest { - - @Spy - private ConfirmVolumeGroupName confirmVolumeGroupName; - - @Before - public void init() throws IOException { - super.init("ConfirmVolumeGroupName") - MockitoAnnotations.initMocks(this); - when(confirmVolumeGroupName.getAAIClient()).thenReturn(client) - - } - - @Test - public void testQueryAAIForVolumeGroupId() { - - AAIResourceUri resourceUri = AAIUriFactory.createResourceFromExistingURI(AAIObjectType.VOLUME_GROUP, UriBuilder.fromPath('/aai/test/volume-groups/volume-group/testVolumeGroup').build()); - when(mockExecution.getVariable("CVGN_volumeGroupGetEndpoint")).thenReturn(resourceUri) - VolumeGroup volumeGroup = new VolumeGroup() - volumeGroup.setVolumeGroupId("Test") - when(client.get(VolumeGroup.class,resourceUri)).thenReturn(Optional.of(volumeGroup)) - confirmVolumeGroupName.queryAAIForVolumeGroupId(mockExecution) - Mockito.verify(mockExecution).setVariable("CVGN_queryVolumeGroupResponseCode",200) - Mockito.verify(mockExecution).setVariable("CVGN_queryVolumeGroupResponse",volumeGroup) - } - - @Test - public void testQueryAAIForVolumeGroupId_404() { - AAIResourceUri resourceUri = AAIUriFactory.createResourceFromExistingURI(AAIObjectType.VOLUME_GROUP, UriBuilder.fromPath('/aai/test/volume-groups/volume-group/testVolumeGroup').build()); - when(client.get(VolumeGroup.class, resourceUri)).thenReturn(Optional.empty()) - DelegateExecution execution = new DelegateExecutionFake() - try { - execution.setVariable("CVGN_volumeGroupGetEndpoint", resourceUri) - confirmVolumeGroupName.queryAAIForVolumeGroupId(execution) - } - catch(Exception ex){} - Assert.assertEquals(404, execution.getVariable("CVGN_queryVolumeGroupResponseCode")) - Assert.assertEquals("Volume Group not Found!", execution.getVariable("CVGN_queryVolumeGroupResponse")) - - } } diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterTest.groovy index ec69bf5eb9..e351210586 100644 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterTest.groovy +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterTest.groovy @@ -844,11 +844,11 @@ def sdncAdapterResponseError = verify(mockExecution).setVariable("asynchronousResponseTimeout",false) verify(mockExecution).setVariable("continueListening",false) verify(mockExecution).setVariable("serviceConfigActivate",false) - verify(mockExecution).setVariable("SDNCA_requestId", "testReqId") verify(mockExecution).setVariable("SDNCA_SuccessIndicator",false) verify(mockExecution).setVariable("SDNCA_InterimNotify",false) verify(mockExecution).setVariable("BasicAuthHeaderValue","Basic dGVzdDp0ZXN0") verify(mockExecution).setVariable("source","") + verify(mockExecution).setVariable("SDNCA_requestId", "745b1b50-e39e-4685-9cc8-c71f0bde8bf0") verify(mockExecution).setVariable("sdncAdapterRequest", sdncAdapterRequest) } diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIVfModuleTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIVfModuleTest.groovy index cb9bb5c541..2d2f58b415 100644 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIVfModuleTest.groovy +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIVfModuleTest.groovy @@ -113,6 +113,7 @@ class UpdateAAIVfModuleTest extends MsoGroovyTest { when(mockExecution.getVariable(prefix + "getVfModuleResponse")).thenReturn(vfModule) doNothing().when(client).update(isA(AAIResourceUri.class), anyObject()) updateAAIVfModule.updateVfModule(mockExecution) + verify(mockExecution).setVariable("UAAIVfMod_updateVfModuleResponseCode", 200) } @Test @@ -128,6 +129,7 @@ class UpdateAAIVfModuleTest extends MsoGroovyTest { doThrow(new NotFoundException("Vf Module not found")).when(client).update(isA(AAIResourceUri.class), anyObject()) thrown.expect(BpmnError.class) updateAAIVfModule.updateVfModule(mockExecution) + verify(mockExecution).setVariable("UAAIVfMod_updateVfModuleResponseCode", 404) } @@ -144,6 +146,7 @@ class UpdateAAIVfModuleTest extends MsoGroovyTest { doThrow(new IllegalStateException("Error in AAI client")).when(client).update(isA(AAIResourceUri.class), anyObject()) thrown.expect(BpmnError.class) updateAAIVfModule.updateVfModule(mockExecution) + verify(mockExecution).setVariable("UAAIVfMod_updateVfModuleResponseCode", 500) } } diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java index f6e433bf38..78238f0271 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java @@ -1314,12 +1314,11 @@ public class BBInputSetupTest { doReturn(vnf2AAI).when(SPY_bbInputSetupUtils).getAAIGenericVnf(vnf2.getVnfId()); doNothing().when(SPY_bbInputSetup).mapCatalogVnf(vnf2, modelInfo, service); doNothing().when(SPY_bbInputSetup).mapNetworkCollectionInstanceGroup(vnf2, "{instanceGroupId}"); - doNothing().when(SPY_bbInputSetup).mapVnfcCollectionInstanceGroup(vnf2, modelInfo, service); SPY_bbInputSetup.populateGenericVnf(modelInfo, instanceName, platform, lineOfBusiness, service, bbName, serviceInstance, lookupKeyMap, requestDetails.getRelatedInstanceList(), resourceId, vnfType, null); verify(SPY_bbInputSetup, times(2)).mapCatalogVnf(vnf2, modelInfo, service); verify(SPY_bbInputSetup, times(2)).mapNetworkCollectionInstanceGroup(vnf2, "{instanceGroupId}"); - verify(SPY_bbInputSetup, times(2)).mapVnfcCollectionInstanceGroup(vnf2, modelInfo, service); + verify(SPY_bbInputSetup, times(1)).mapVnfcCollectionInstanceGroup(vnf2, modelInfo, service); } @Test diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/restproperties/RestPropertiesPojoTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/restproperties/RestPropertiesPojoTest.java deleted file mode 100644 index 863338548e..0000000000 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/restproperties/RestPropertiesPojoTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.client.restproperties; - -import org.junit.Test; - -import com.openpojo.reflection.PojoClass; -import com.openpojo.reflection.impl.PojoClassFactory; -import com.openpojo.validation.Validator; -import com.openpojo.validation.ValidatorBuilder; -import com.openpojo.validation.rule.impl.NoPrimitivesRule; -import com.openpojo.validation.rule.impl.NoPublicFieldsRule; -import com.openpojo.validation.test.impl.GetterTester; - -public class RestPropertiesPojoTest { - @Test - public void pojoStructure() { - test(PojoClassFactory.getPojoClass(AaiPropertiesConfiguration.class)); - } - - private void test(PojoClass pojoClass) { - Validator validator = ValidatorBuilder.create() - .with(new NoPrimitivesRule()) - .with(new NoPublicFieldsRule()) - .with(new GetterTester()) - .build(); - validator.validate(pojoClass); - } -} diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/WorkflowActionBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/WorkflowActionBB.bpmn index 4b075d403b..2ca9437e9b 100644 --- a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/WorkflowActionBB.bpmn +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/WorkflowActionBB.bpmn @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.4.0"> +<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.8.2"> <bpmn:process id="WorkflowActionBB" name="WorkflowActionBB" isExecutable="true"> <bpmn:startEvent id="Start_WorkflowActionBB" name="start"> <bpmn:outgoing>SequenceFlow_15s0okp</bpmn:outgoing> @@ -79,7 +79,7 @@ <bpmn:endEvent id="ErrorEnd" name="end"> <bpmn:incoming>SequenceFlow_0wvzfgf</bpmn:incoming> </bpmn:endEvent> - <bpmn:serviceTask id="Task_UpdateDb" name="Update Request To Failed" camunda:expression="${WorkflowActionBBTasks.updateRequestStatusToFailed(execution)}"> + <bpmn:serviceTask id="Task_UpdateDb" name="Update Request To Failed" camunda:expression="${WorkflowActionBBFailure.updateRequestStatusToFailed(execution)}"> <bpmn:incoming>SequenceFlow_024g0d1</bpmn:incoming> <bpmn:incoming>SequenceFlow_0eana0l</bpmn:incoming> <bpmn:outgoing>SequenceFlow_0wvzfgf</bpmn:outgoing> @@ -116,7 +116,7 @@ <bpmn:sequenceFlow id="SequenceFlow_11530ei" name="Abort = true" sourceRef="ExclusiveGateway_Finished" targetRef="ExclusiveGateway_isTopLevelFlowAbort"> <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression"><![CDATA[${execution.getVariable("handlingCode")=="Abort"}]]></bpmn:conditionExpression> </bpmn:sequenceFlow> - <bpmn:serviceTask id="Task_AbortAndCallErrorHandling" name="Update Request To Failed" camunda:expression="${WorkflowActionBBTasks.updateRequestStatusToFailed(execution)}"> + <bpmn:serviceTask id="Task_AbortAndCallErrorHandling" name="Update Request To Failed" camunda:expression="${WorkflowActionBBFailure.updateRequestStatusToFailed(execution)}"> <bpmn:incoming>SequenceFlow_02ksbt0</bpmn:incoming> <bpmn:outgoing>SequenceFlow_1p8yxu6</bpmn:outgoing> </bpmn:serviceTask> @@ -164,7 +164,7 @@ <bpmn:sequenceFlow id="SequenceFlow_11dlyzt" name="Rollback Not Needed" sourceRef="Task_RollbackExecutionPath" targetRef="Task_UpdateRequestToFailed"> <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression"><![CDATA[${execution.getVariable("isRollbackNeeded")==false}]]></bpmn:conditionExpression> </bpmn:sequenceFlow> - <bpmn:serviceTask id="Task_UpdateRequestToFailed" name="Update Request To Failed" camunda:expression="${WorkflowActionBBTasks.updateRequestStatusToFailedWithRollback(execution)}"> + <bpmn:serviceTask id="Task_UpdateRequestToFailed" name="Update Request To Failed" camunda:expression="${WorkflowActionBBFailure.updateRequestStatusToFailedWithRollback(execution)}"> <bpmn:incoming>SequenceFlow_11dlyzt</bpmn:incoming> <bpmn:incoming>SequenceFlow_0l7kaba</bpmn:incoming> <bpmn:outgoing>SequenceFlow_1ui67mc</bpmn:outgoing> diff --git a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/BaseBPMNTest.java b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/BaseBPMNTest.java index f9ff28a023..1e3f175cf1 100644 --- a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/BaseBPMNTest.java +++ b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/BaseBPMNTest.java @@ -68,6 +68,7 @@ import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCUnassignTasks; import org.onap.so.bpmn.infrastructure.workflow.tasks.FlowCompletionTasks; import org.onap.so.bpmn.infrastructure.workflow.tasks.OrchestrationStatusValidator; import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowAction; +import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionBBFailure; import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionBBTasks; import org.onap.so.bpmn.sdno.tasks.SDNOHealthCheckTasks; import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup; @@ -219,6 +220,9 @@ public abstract class BaseBPMNTest { @MockBean protected SniroHomingV2 sniroHoming; + + @MockBean + protected WorkflowActionBBFailure workflowActionBBFailure; @LocalServerPort protected int port; diff --git a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/process/WorkflowActionBBTest.java b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/process/WorkflowActionBBTest.java index 5da6d3a577..45dafbe606 100644 --- a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/process/WorkflowActionBBTest.java +++ b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/process/WorkflowActionBBTest.java @@ -92,7 +92,7 @@ public class WorkflowActionBBTest extends BaseBPMNTest { Map<String, String> map = new HashMap<>(); map.put("handlingCode", "Abort"); - doThrow(new BpmnError("7000", "TESTING ERRORS")).when(workflowActionBBTasks).abortCallErrorHandling(any(DelegateExecution.class)); + doThrow(new BpmnError("7000", "TESTING ERRORS")).when(workflowActionBBFailure).abortCallErrorHandling(any(DelegateExecution.class)); mockSubprocess("ExecuteBuildingBlock", "Mocked ExecuteBuildingBlock", "GenericStub", map); ProcessInstance pi = runtimeService.startProcessInstanceByKey("WorkflowActionBB", variables); diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateVfModuleVolumeV2.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateVfModuleVolumeV2.groovy index 93379c72be..aa22cdaefd 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateVfModuleVolumeV2.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateVfModuleVolumeV2.groovy @@ -298,6 +298,7 @@ class DoCreateVfModuleVolumeV2 extends VfModuleBase { getAAIClient().create(volumeGroupUri, volumeGroup) getAAIClient().connect(volumeGroupUri, vnfUri) getAAIClient().connect(volumeGroupUri, tenantUri) + execution.setVariable("queriedVolumeGroupId", volumeGroupId) RollbackData rollbackData = execution.getVariable("rollbackData") rollbackData.put("DCVFMODULEVOL", "isAAIRollbackNeeded", "true") } catch (NotFoundException ignored) { diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateVfModuleVolumeV2Test.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateVfModuleVolumeV2Test.groovy index 26d3ab8d9d..6841ceee44 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateVfModuleVolumeV2Test.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateVfModuleVolumeV2Test.groovy @@ -250,6 +250,7 @@ class DoCreateVfModuleVolumeV2Test extends MsoGroovyTest { when(mockExecution.getVariable(cloudOwner)).thenReturn(cloudOwner) when(mockExecution.getVariable("rollbackData")).thenReturn(new RollbackData()) doCreateVfModuleVolumeV2.callRESTCreateAAIVolGrpName(mockExecution,null) + verify(mockExecution).setVariable("queriedVolumeGroupId", "volumeGroupId") } @Test diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBFailure.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBFailure.java new file mode 100644 index 0000000000..7e6eb2a23d --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBFailure.java @@ -0,0 +1,116 @@ +package org.onap.so.bpmn.infrastructure.workflow.tasks; + +import java.util.Optional; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.onap.so.bpmn.core.WorkflowException; +import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.db.request.client.RequestsDbClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class WorkflowActionBBFailure { + + private static final Logger logger = LoggerFactory.getLogger(WorkflowActionBBFailure.class); + @Autowired + private RequestsDbClient requestDbclient; + @Autowired + private WorkflowAction workflowAction; + + protected void updateRequestErrorStatusMessage(DelegateExecution execution) { + try { + String requestId = (String) execution.getVariable("mso-request-id"); + InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId); + String errorMsg = ""; + Optional<String> errorMsgOp = retrieveErrorMessage(execution); + if(errorMsgOp.isPresent()){ + errorMsg = errorMsgOp.get(); + }else{ + errorMsg = "Failed to determine error message"; + } + request.setStatusMessage(errorMsg); + requestDbclient.updateInfraActiveRequests(request); + } catch (Exception e) { + logger.error("Failed to update Request db with the status message after retry or rollback has been initialized.",e); + } + } + + public void updateRequestStatusToFailed(DelegateExecution execution) { + try { + String requestId = (String) execution.getVariable("mso-request-id"); + InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId); + String rollbackErrorMsg = ""; + String errorMsg = ""; + Boolean rollbackCompletedSuccessfully = (Boolean) execution.getVariable("isRollbackComplete"); + Boolean isRollbackFailure = (Boolean) execution.getVariable("isRollback"); + + if(rollbackCompletedSuccessfully==null) + rollbackCompletedSuccessfully = false; + + if(isRollbackFailure==null) + isRollbackFailure = false; + + if(rollbackCompletedSuccessfully){ + rollbackErrorMsg = "Rollback has been completed successfully."; + request.setRollbackStatusMessage(rollbackErrorMsg); + execution.setVariable("RollbackErrorMessage", rollbackErrorMsg); + }else if(isRollbackFailure){ + Optional<String> rollbackErrorMsgOp = retrieveErrorMessage(execution); + if(rollbackErrorMsgOp.isPresent()){ + rollbackErrorMsg = rollbackErrorMsgOp.get(); + }else{ + rollbackErrorMsg = "Failed to determine rollback error message."; + } + request.setRollbackStatusMessage(rollbackErrorMsg); + execution.setVariable("RollbackErrorMessage", rollbackErrorMsg); + }else{ + Optional<String> errorMsgOp = retrieveErrorMessage(execution); + if(errorMsgOp.isPresent()){ + errorMsg = errorMsgOp.get(); + }else{ + errorMsg = "Failed to determine error message"; + } + request.setStatusMessage(errorMsg); + execution.setVariable("ErrorMessage", errorMsg); + } + request.setProgress(Long.valueOf(100)); + request.setRequestStatus("FAILED"); + request.setLastModifiedBy("CamundaBPMN"); + requestDbclient.updateInfraActiveRequests(request); + } catch (Exception e) { + workflowAction.buildAndThrowException(execution, "Error Updating Request Database", e); + } + } + + private Optional<String> retrieveErrorMessage (DelegateExecution execution){ + String errorMsg = ""; + try { + WorkflowException exception = (WorkflowException) execution.getVariable("WorkflowException"); + if(exception != null && (exception.getErrorMessage()!=null || !exception.getErrorMessage().equals(""))){ + errorMsg = exception.getErrorMessage(); + } + if(errorMsg == null || errorMsg.equals("")){ + errorMsg = (String) execution.getVariable("WorkflowExceptionErrorMessage"); + } + return Optional.of(errorMsg); + } catch (Exception ex) { + logger.error("Failed to extract workflow exception from execution.",ex); + } + return Optional.of(errorMsg); + } + + public void updateRequestStatusToFailedWithRollback(DelegateExecution execution) { + execution.setVariable("isRollbackComplete", true); + updateRequestStatusToFailed(execution); + } + + public void abortCallErrorHandling(DelegateExecution execution) { + String msg = "Flow has failed. Rainy day handler has decided to abort the process."; + logger.error(msg); + throw new BpmnError(msg); + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java index 7670e0245d..d9125e4104 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java @@ -22,6 +22,7 @@ package org.onap.so.bpmn.infrastructure.workflow.tasks; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import org.camunda.bpm.engine.delegate.BpmnError; import org.camunda.bpm.engine.delegate.DelegateExecution; @@ -57,6 +58,8 @@ public class WorkflowActionBBTasks { private RequestsDbClient requestDbclient; @Autowired private WorkflowAction workflowAction; + @Autowired + private WorkflowActionBBFailure workflowActionBBFailure; public void selectBB(DelegateExecution execution) { List<ExecuteBuildingBlock> flowsToExecute = (List<ExecuteBuildingBlock>) execution @@ -207,7 +210,7 @@ public class WorkflowActionBBTasks { String retryDuration = (String) execution.getVariable("RetryDuration"); int retryCount = (int) execution.getVariable(RETRY_COUNT); if (handlingCode.equals("Retry")){ - updateRequestErrorStatusMessage(execution); + workflowActionBBFailure.updateRequestErrorStatusMessage(execution); try{ InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId); request.setRetryStatusMessage("Retry " + retryCount+1 + "/5 will be started in " + retryDuration); @@ -267,7 +270,7 @@ public class WorkflowActionBBTasks { } } - updateRequestErrorStatusMessage(execution); + workflowActionBBFailure.updateRequestErrorStatusMessage(execution); if (rollbackFlows.isEmpty()) execution.setVariable("isRollbackNeeded", false); @@ -282,99 +285,4 @@ public class WorkflowActionBBTasks { workflowAction.buildAndThrowException(execution, "Rollback has already been called. Cannot rollback a request that is currently in the rollback state."); } } - - protected void updateRequestErrorStatusMessage(DelegateExecution execution) { - try { - String requestId = (String) execution.getVariable(G_REQUEST_ID); - InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId); - String errorMsg = retrieveErrorMessage(execution); - if(errorMsg == null || errorMsg.equals("")){ - errorMsg = "Failed to determine error message"; - } - request.setStatusMessage(errorMsg); - logger.debug("Updating RequestDB to failed: errorMsg = " + errorMsg); - requestDbclient.updateInfraActiveRequests(request); - } catch (Exception e) { - logger.error("Failed to update Request db with the status message after retry or rollback has been initialized.",e); - } - } - - public void abortCallErrorHandling(DelegateExecution execution) { - String msg = "Flow has failed. Rainy day handler has decided to abort the process."; - logger.error(msg); - throw new BpmnError(msg); - } - - public void updateRequestStatusToFailed(DelegateExecution execution) { - try { - String requestId = (String) execution.getVariable(G_REQUEST_ID); - InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId); - String errorMsg = null; - String rollbackErrorMsg = null; - Boolean rollbackCompleted = (Boolean) execution.getVariable("isRollbackComplete"); - Boolean isRollbackFailure = (Boolean) execution.getVariable("isRollback"); - - if(rollbackCompleted==null) - rollbackCompleted = false; - - if(isRollbackFailure==null) - isRollbackFailure = false; - - if(rollbackCompleted){ - rollbackErrorMsg = "Rollback has been completed successfully."; - request.setRollbackStatusMessage(rollbackErrorMsg); - logger.debug("Updating RequestDB to failed: Rollback has been completed successfully"); - }else{ - if(isRollbackFailure){ - rollbackErrorMsg = retrieveErrorMessage(execution); - if(rollbackErrorMsg == null || rollbackErrorMsg.equals("")){ - rollbackErrorMsg = "Failed to determine rollback error message."; - } - request.setRollbackStatusMessage(rollbackErrorMsg); - logger.debug("Updating RequestDB to failed: rollbackErrorMsg = " + rollbackErrorMsg); - }else{ - errorMsg = retrieveErrorMessage(execution); - if(errorMsg == null || errorMsg.equals("")){ - errorMsg = "Failed to determine error message"; - } - request.setStatusMessage(errorMsg); - logger.debug("Updating RequestDB to failed: errorMsg = " + errorMsg); - } - } - request.setProgress(Long.valueOf(100)); - request.setRequestStatus("FAILED"); - request.setLastModifiedBy("CamundaBPMN"); - requestDbclient.updateInfraActiveRequests(request); - } catch (Exception e) { - workflowAction.buildAndThrowException(execution, "Error Updating Request Database", e); - } - } - - private String retrieveErrorMessage (DelegateExecution execution){ - String errorMsg = ""; - try { - WorkflowException exception = (WorkflowException) execution.getVariable("WorkflowException"); - if(exception != null && (exception.getErrorMessage()!=null || !exception.getErrorMessage().equals(""))){ - errorMsg = exception.getErrorMessage(); - } - } catch (Exception ex) { - //log error and attempt to extact WorkflowExceptionMessage - logger.error("Failed to extract workflow exception from execution.",ex); - } - - if (errorMsg == null){ - try { - errorMsg = (String) execution.getVariable("WorkflowExceptionErrorMessage"); - } catch (Exception ex) { - logger.error("Failed to extract workflow exception message from WorkflowException",ex); - errorMsg = "Unexpected Error in BPMN."; - } - } - return errorMsg; - } - - public void updateRequestStatusToFailedWithRollback(DelegateExecution execution) { - execution.setVariable("isRollbackComplete", true); - updateRequestStatusToFailed(execution); - } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBFailureTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBFailureTest.java new file mode 100644 index 0000000000..d9a7eeb8f7 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBFailureTest.java @@ -0,0 +1,126 @@ +package org.onap.so.bpmn.infrastructure.workflow.tasks; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.when; + +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.core.WorkflowException; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; +import org.onap.so.db.request.beans.InfraActiveRequests; + +public class WorkflowActionBBFailureTest extends BaseTaskTest { + + @Mock + protected WorkflowAction workflowAction; + + @InjectMocks + @Spy + protected WorkflowActionBBFailure workflowActionBBFailure; + + @Mock + InfraActiveRequests reqMock; + + private DelegateExecution execution; + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Before + public void before() throws Exception { + execution = new DelegateExecutionFake(); + org.onap.aai.domain.yang.ServiceInstance servInstance = new org.onap.aai.domain.yang.ServiceInstance(); + servInstance.setServiceInstanceId("TEST"); + when(bbSetupUtils.getAAIServiceInstanceByName(anyString(), isA(Customer.class))).thenReturn(servInstance); + workflowAction.setBbInputSetupUtils(bbSetupUtils); + workflowAction.setBbInputSetup(bbInputSetup); + } + + @Test + public void updateRequestStatusToFailed_Null_Rollback(){ + String reqId = "reqId123"; + execution.setVariable("mso-request-id", reqId); + execution.setVariable("retryCount", 3); + execution.setVariable("handlingCode","Success"); + execution.setVariable("gCurrentSequence",1); + WorkflowException we = new WorkflowException("WorkflowAction",1231,"Error Case"); + execution.setVariable("WorkflowException",we); + + doReturn(reqMock).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId); + workflowActionBBFailure.updateRequestStatusToFailed(execution); + Mockito.verify( reqMock, Mockito.times(1)).setStatusMessage("Error Case"); + Mockito.verify( reqMock, Mockito.times(1)).setRequestStatus("FAILED"); + Mockito.verify( reqMock, Mockito.times(1)).setProgress(Long.valueOf(100)); + Mockito.verify( reqMock, Mockito.times(1)).setLastModifiedBy("CamundaBPMN"); + } + + @Test + public void updateRequestStatusToFailed(){ + execution.setVariable("mso-request-id", "123"); + execution.setVariable("isRollbackComplete", false); + execution.setVariable("isRollback", false); + InfraActiveRequests req = new InfraActiveRequests(); + WorkflowException wfe = new WorkflowException("processKey123", 1, "error in test case"); + execution.setVariable("WorkflowException", wfe); + doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId("123"); + doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class)); + workflowActionBBFailure.updateRequestStatusToFailed(execution); + String errorMsg = (String) execution.getVariable("ErrorMessage"); + assertEquals("error in test case", errorMsg); + } + + @Test + public void updateRequestStatusToFailedRollback(){ + execution.setVariable("mso-request-id", "123"); + execution.setVariable("isRollbackComplete", false); + execution.setVariable("isRollback", true); + InfraActiveRequests req = new InfraActiveRequests(); + WorkflowException wfe = new WorkflowException("processKey123", 1, "error in rollback"); + execution.setVariable("WorkflowException", wfe); + doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId("123"); + doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class)); + workflowActionBBFailure.updateRequestStatusToFailed(execution); + String errorMsg = (String) execution.getVariable("RollbackErrorMessage"); + assertEquals("error in rollback", errorMsg); + } + + @Test + public void updateRequestStatusToFailedRollbackCompleted(){ + execution.setVariable("mso-request-id", "123"); + execution.setVariable("isRollbackComplete", true); + execution.setVariable("isRollback", true); + InfraActiveRequests req = new InfraActiveRequests(); + doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId("123"); + doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class)); + workflowActionBBFailure.updateRequestStatusToFailed(execution); + String errorMsg = (String) execution.getVariable("RollbackErrorMessage"); + assertEquals("Rollback has been completed successfully.", errorMsg); + } + + @Test + public void updateRequestStatusToFailedNoWorkflowException(){ + execution.setVariable("mso-request-id", "123"); + execution.setVariable("isRollbackComplete", false); + execution.setVariable("isRollback", false); + execution.setVariable("WorkflowExceptionErrorMessage", "error in test case"); + InfraActiveRequests req = new InfraActiveRequests(); + doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId("123"); + doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class)); + workflowActionBBFailure.updateRequestStatusToFailed(execution); + String errorMsg = (String) execution.getVariable("ErrorMessage"); + assertEquals("error in test case", errorMsg); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java index 0ef764ac99..189ecb96c7 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java @@ -52,6 +52,9 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { @Mock protected WorkflowAction workflowAction; + @Mock + protected WorkflowActionBBFailure workflowActionBBFailure; + @InjectMocks @Spy protected WorkflowActionBBTasks workflowActionBBTasks; @@ -146,8 +149,8 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { execution.setVariable("flowsToExecute", flowsToExecute); execution.setVariable("gCurrentSequence", 3); - doNothing().when(workflowActionBBTasks).updateRequestErrorStatusMessage(isA(DelegateExecution.class)); - + doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class)); + workflowActionBBTasks.rollbackExecutionPath(execution); List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"DeactivateVfModuleBB"); @@ -179,8 +182,8 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { execution.setVariable("flowsToExecute", flowsToExecute); execution.setVariable("gCurrentSequence", 2); - doNothing().when(workflowActionBBTasks).updateRequestErrorStatusMessage(isA(DelegateExecution.class)); - + doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class)); + workflowActionBBTasks.rollbackExecutionPath(execution); List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"DeleteVfModuleBB"); @@ -217,8 +220,8 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { execution.setVariable("flowsToExecute", flowsToExecute); execution.setVariable("gCurrentSequence", 3); - doNothing().when(workflowActionBBTasks).updateRequestErrorStatusMessage(isA(DelegateExecution.class)); - + doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class)); + workflowActionBBTasks.rollbackExecutionPath(execution); List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"UnassignNetworkBB"); @@ -255,7 +258,7 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { execution.setVariable("flowsToExecute", flowsToExecute); execution.setVariable("gCurrentSequence", 3); - doNothing().when(workflowActionBBTasks).updateRequestErrorStatusMessage(isA(DelegateExecution.class)); + doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class)); workflowActionBBTasks.rollbackExecutionPath(execution); List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); @@ -267,7 +270,7 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { public void checkRetryStatusTest(){ String reqId = "reqId123"; execution.setVariable("mso-request-id", reqId); - doNothing().when(workflowActionBBTasks).updateRequestErrorStatusMessage(isA(DelegateExecution.class)); + doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class)); execution.setVariable("handlingCode","Retry"); execution.setVariable("retryCount", 1); execution.setVariable("gCurrentSequence",1); @@ -289,23 +292,4 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { workflowActionBBTasks.checkRetryStatus(execution); assertEquals(0,execution.getVariable("retryCount")); } - - - @Test - public void updateRequestStatusToFailed_Null_Rollback(){ - String reqId = "reqId123"; - execution.setVariable("mso-request-id", reqId); - execution.setVariable("retryCount", 3); - execution.setVariable("handlingCode","Success"); - execution.setVariable("gCurrentSequence",1); - WorkflowException we = new WorkflowException("WorkflowAction",1231,"Error Case"); - execution.setVariable("WorkflowException",we); - - doReturn(reqMock).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId); - workflowActionBBTasks.updateRequestStatusToFailed(execution); - Mockito.verify( reqMock, Mockito.times(1)).setStatusMessage("Error Case"); - Mockito.verify( reqMock, Mockito.times(1)).setRequestStatus("FAILED"); - Mockito.verify( reqMock, Mockito.times(1)).setProgress(Long.valueOf(100)); - Mockito.verify( reqMock, Mockito.times(1)).setLastModifiedBy("CamundaBPMN"); - } } |