summaryrefslogtreecommitdiffstats
path: root/bpmn
diff options
context:
space:
mode:
authorSteve Smokowski <ss835w@att.com>2018-12-12 12:39:37 +0000
committerGerrit Code Review <gerrit@onap.org>2018-12-12 12:39:37 +0000
commit1de8dfa545994cfd0bed04a8e97a48a0f1ce3abd (patch)
treea454d90882ebe1c5486f9fee6d694a80c6bfbb38 /bpmn
parentdf1b65156a5ea77536b9aea644f3400b5f3e87ea (diff)
parentbb341d733984377eb1c04d7951a9b177f7f51720 (diff)
Merge "ConfirmVolumeGroupNameTest improvements"
Diffstat (limited to 'bpmn')
-rw-r--r--bpmn/MSOCommonBPMN/pom.xml6
-rw-r--r--bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupName.groovy42
-rw-r--r--bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupNameFactory.groovy31
-rw-r--r--bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExceptionUtil.groovy2
-rw-r--r--bpmn/MSOCommonBPMN/src/main/resources/subprocess/ConfirmVolumeGroupName.bpmn10
-rw-r--r--bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupNameTest.groovy258
6 files changed, 275 insertions, 74 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/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupNameFactory.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupNameFactory.groovy
new file mode 100644
index 0000000000..f032d640d5
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ConfirmVolumeGroupNameFactory.groovy
@@ -0,0 +1,31 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.bpmn.common.scripts
+
+import org.onap.so.bpmn.common.scripts.ConfirmVolumeGroupName
+import org.onap.so.bpmn.common.scripts.ExceptionUtil
+
+public class ConfirmVolumeGroupNameFactory {
+
+ 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/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"))
-
- }
}