From dc9f07fe21c16e7225edad7d4bd33ce2f9cd2969 Mon Sep 17 00:00:00 2001 From: Lukasz Muszkieta Date: Thu, 20 Sep 2018 12:21:59 +0200 Subject: Add junit tests for ConfirmVolumeGroupName Change-Id: I382bf9599dfee3a30c129c121d91fddeec42937f Issue-ID: SO-784 Signed-off-by: Lukasz Muszkieta --- .../common/scripts/ConfirmVolumeGroupName.groovy | 15 ----- .../scripts/ConfirmVolumeGroupNameTest.groovy | 78 ++++++++++++++++------ 2 files changed, 59 insertions(+), 34 deletions(-) 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 8b786bc152..bcd740eae9 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 @@ -43,7 +43,6 @@ public class ConfirmVolumeGroupName extends AbstractServiceTaskProcessor{ execution.setVariable("CVGN_queryVolumeGroupResponseCode",null) execution.setVariable("CVGN_queryVolumeGroupResponse","") execution.setVariable("CVGN_ResponseCode",null) -// execution.setVariable("CVGN_ErrorResponse","") execution.setVariable("RollbackData", null) } @@ -125,10 +124,6 @@ public class ConfirmVolumeGroupName extends AbstractServiceTaskProcessor{ // generates a WorkflowException if the A&AI query returns a response code other than 200/404 public void handleAAIQueryFailure(DelegateExecution execution) { msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Error occurred attempting to query AAI, Response Code " + execution.getVariable("CVGN_queryVolumeGroupResponseCode"), "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "ErrorResponse is:\n" + execution.getVariable("CVGN_queryVolumeGroupResponse")); - //String processKey = getProcessKey(execution); - //WorkflowException exception = new WorkflowException(processKey, 5000, - //execution.getVariable("CVGN_queryVolumeGroupResponse")) - //execution.setVariable("WorkflowException", exception) } // generates a WorkflowException if the volume group name does not match AAI record for this volume group @@ -137,16 +132,6 @@ public class ConfirmVolumeGroupName extends AbstractServiceTaskProcessor{ " 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) - //String processKey = getProcessKey(execution); - //WorkflowException exception = new WorkflowException(processKey, 1002, - // errorNotAssociated) - //execution.setVariable("WorkflowException", exception) } - // sends a successful WorkflowResponse - public void reportSuccess(DelegateExecution execution) { - msoLogger.debug("Sending 200 back to the caller") - def responseXML = "" - execution.setVariable("WorkflowResponse", responseXML) - } } \ No newline at end of file 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 9b3b8c2fb0..e065ccd14f 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 @@ -22,28 +22,12 @@ package org.onap.so.bpmn.common.scripts import com.github.tomakehurst.wiremock.junit.WireMockRule -import static org.junit.Assert.*; import static org.mockito.Mockito.* - -import org.onap.so.rest.HttpHeader -import org.mockito.MockitoAnnotations -import org.mockito.runners.MockitoJUnitRunner -import org.mockito.internal.debugging.MockitoDebuggerImpl -import org.junit.Before -import org.onap.so.bpmn.common.scripts.AaiUtil; -import org.junit.Rule; -import org.junit.Test -import org.junit.Ignore -import org.junit.runner.RunWith -import org.junit.Before; -import org.junit.Test; import org.camunda.bpm.engine.ProcessEngineServices import org.camunda.bpm.engine.RepositoryService import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity -import org.camunda.bpm.engine.impl.pvm.process.ProcessDefinitionImpl import org.camunda.bpm.engine.repository.ProcessDefinition import org.junit.Assert -import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @@ -51,22 +35,78 @@ import org.mockito.ArgumentCaptor import org.mockito.Captor import org.mockito.Mockito import org.mockito.runners.MockitoJUnitRunner -import org.onap.so.bpmn.common.scripts.ConfirmVolumeGroupName import org.onap.so.bpmn.core.WorkflowException import static com.github.tomakehurst.wiremock.client.WireMock.* -import static org.mockito.Mockito.* @RunWith(MockitoJUnitRunner.class) -@Ignore class ConfirmVolumeGroupNameTest extends MsoGroovyTest { + private static final def AAA_URI = "uri_test" + private static final def AIC_CLOUD_REGION = "AicClReg_test" + private static final def VOLUME_GROUP_NAME = "volumeTestGName" + private static final def VOLUME_GROUP_ID = "vol_gr_id_test" + @Captor ArgumentCaptor captor= ArgumentCaptor.forClass(ExecutionEntity.class); @Rule public WireMockRule wireMockRule = new WireMockRule(8090); + @Test + void preProcessRequestSuccessful() { + ExecutionEntity mockExecution = setupMock() + when(mockExecution.getVariable("ConfirmVolumeGroupName_volumeGroupId")).thenReturn(VOLUME_GROUP_ID) + when(mockExecution.getVariable("ConfirmVolumeGroupName_volumeGroupName")).thenReturn(VOLUME_GROUP_NAME) + when(mockExecution.getVariable("ConfirmVolumeGroupName_aicCloudRegion")).thenReturn(AIC_CLOUD_REGION) + + when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('namespace_test') + when(mockExecution.getVariable("mso.workflow.ConfirmVolumeGroupName.aai.cloud-region.uri")).thenReturn(AAA_URI) + new ConfirmVolumeGroupName().preProcessRequest(mockExecution) + + verifyInitProcessVariables(mockExecution) + verify(mockExecution).setVariable("CVGN_volumeGroupId", VOLUME_GROUP_ID) + verify(mockExecution).setVariable("CVGN_volumeGroupName", "volumeTestGName") + verify(mockExecution).setVariable("CVGN_aicCloudRegion", AIC_CLOUD_REGION) + verify(mockExecution).setVariable("CVGN_volumeGroupGetEndpoint", + "${AAA_URI}/${AIC_CLOUD_REGION}/volume-groups/volume-group/" + VOLUME_GROUP_ID) + } + + private void verifyInitProcessVariables(ExecutionEntity mockExecution) { + verify(mockExecution).setVariable("prefix", "CVGN_") + verify(mockExecution).setVariable("CVGN_volumeGroupId", null) + verify(mockExecution).setVariable("CVGN_volumeGroupName", null) + verify(mockExecution).setVariable("CVGN_aicCloudRegion", null) + verify(mockExecution).setVariable("CVGN_volumeGroupGetEndpoint", null) + verify(mockExecution).setVariable("CVGN_volumeGroupNameMatches", false) + verify(mockExecution).setVariable("CVGN_queryVolumeGroupResponseCode", null) + verify(mockExecution).setVariable("CVGN_queryVolumeGroupResponse", "") + verify(mockExecution).setVariable("CVGN_ResponseCode", null) + verify(mockExecution).setVariable("RollbackData", null) + } + + @Test + void checkAAIQueryResult_volumeGroupNamesMatch() { + ExecutionEntity mockExecution = setupMock() + commonPartOfCheckAAIQueryTest(mockExecution, VOLUME_GROUP_NAME) + verify(mockExecution).setVariable("CVGN_volumeGroupNameMatches", true) + } + + @Test + void checkAAIQueryResult_volumeGroupNamesDoNotMatch() { + ExecutionEntity mockExecution = setupMock() + commonPartOfCheckAAIQueryTest(mockExecution, "grName2") + verify(mockExecution, Mockito.times(0)).setVariable("CVGN_volumeGroupNameMatches", true) + } + + private void commonPartOfCheckAAIQueryTest(ExecutionEntity mockExecution, def volumeGroupName) { + when(mockExecution.getVariable("CVGN_volumeGroupName")).thenReturn(VOLUME_GROUP_NAME) + def xml = "" + volumeGroupName + "" + when(mockExecution.getVariable("CVGN_queryVolumeGroupResponse")).thenReturn(xml) + new ConfirmVolumeGroupName().checkAAIQueryResult(mockExecution) + verify(mockExecution).setVariable("CVGN_volumeGroupNameMatches", false) + } + @Test public void testQueryAAIForVolumeGroupId() { ExecutionEntity mockExecution = setupMock() -- cgit 1.2.3-korg