diff options
6 files changed, 186 insertions, 127 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CreateAAIVfModule.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CreateAAIVfModule.groovy index 48268464d8..370600755b 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CreateAAIVfModule.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CreateAAIVfModule.groovy @@ -19,6 +19,8 @@ */ package org.onap.so.bpmn.common.scripts + +import org.apache.commons.lang.StringUtils import org.camunda.bpm.engine.delegate.DelegateExecution import org.onap.aai.domain.yang.GenericVnf import org.onap.so.bpmn.core.RollbackData @@ -94,55 +96,25 @@ public class CreateAAIVfModule extends AbstractServiceTaskProcessor{ execution.setVariable("CAAIVfMod_vnfName", vnfName) String vnfType = execution.getVariable("vnfType") - if (vnfType != null && !vnfType.isEmpty()) { - execution.setVariable("CAAIVfMod_vnfType", vnfType) - } else { - execution.setVariable("CAAIVfMod_vnfType","") - } + execution.setVariable("CAAIVfMod_vnfType", StringUtils.defaultString(vnfType)) execution.setVariable("CAAIVfMod_serviceId", execution.getVariable("serviceId")) String personaModelId = execution.getVariable("personaModelId") + execution.setVariable("CAAIVfMod_personaId",StringUtils.defaultString(personaModelId)) - if (personaModelId != null && !personaModelId.isEmpty()) { - execution.setVariable("CAAIVfMod_personaId",personaModelId) - } else { - execution.setVariable("CAAIVfMod_personaId","") - } - String personaModelVersion = execution.getVariable("personaModelVersion") + execution.setVariable("CAAIVfMod_personaVer", StringUtils.defaultString(personaModelVersion)) - if (personaModelVersion != null && !personaModelVersion.isEmpty()) { - execution.setVariable("CAAIVfMod_personaVer", personaModelVersion) - } else { - execution.setVariable("CAAIVfMod_personaVer","") - } - - String modelCustomizationId = execution.getVariable("modelCustomizationId") + execution.setVariable("CAAIVfMod_modelCustomizationId",StringUtils.defaultString(modelCustomizationId)) - if (modelCustomizationId != null && !modelCustomizationId.isEmpty()) { - execution.setVariable("CAAIVfMod_modelCustomizationId",modelCustomizationId) - } else { - execution.setVariable("CAAIVfMod_modelCustomizationId","") - } - String vnfPersonaModelId = execution.getVariable("vnfPersonaModelId") - - if (vnfPersonaModelId != null && !vnfPersonaModelId.isEmpty()) { - execution.setVariable("CAAIVfMod_vnfPersonaId",vnfPersonaModelId) - } else { - execution.setVariable("CAAIVfMod_vnfPersonaId","") - } - + execution.setVariable("CAAIVfMod_vnfPersonaId", StringUtils.defaultString(vnfPersonaModelId)) + String vnfPersonaModelVersion = execution.getVariable("vnfPersonaModelVersion") + execution.setVariable("CAAIVfMod_vnfPersonaVer", StringUtils.defaultString(vnfPersonaModelVersion)) - if (vnfPersonaModelVersion != null && !vnfPersonaModelVersion.isEmpty()) { - execution.setVariable("CAAIVfMod_vnfPersonaVer",vnfPersonaModelVersion) - } else { - execution.setVariable("CAAIVfMod_vnfPersonaVer","") - } - //isBaseVfModule Boolean isBaseVfModule = false String isBaseVfModuleString = execution.getVariable("isBaseVfModule") @@ -150,7 +122,7 @@ public class CreateAAIVfModule extends AbstractServiceTaskProcessor{ isBaseVfModule = true } execution.setVariable("CAAIVfMod_isBaseVfModule", isBaseVfModule) - + String isVidRequest = execution.getVariable("isVidRequest") if (isVidRequest != null && "true".equals(isVidRequest)) { msoLogger.debug("VID Request received") @@ -166,7 +138,7 @@ public class CreateAAIVfModule extends AbstractServiceTaskProcessor{ execution.setVariable("CAAIVfMod_aaiNamespace",aaiNamespace) } - + // send a GET request to AA&I to retrieve the Generic VNF/VF Module information based on a Vnf Name // expect a 200 response with the information in the response body or a 404 if the Generic VNF does not exist public void queryAAIForGenericVnf(DelegateExecution execution) { @@ -424,8 +396,9 @@ public class CreateAAIVfModule extends AbstractServiceTaskProcessor{ } } } + if (qryModuleList != null && !qryModuleList.getVfModule().isEmpty() && !execution.getVariable("CAAIVfMod_baseModuleConflict")) { - def qryModules = qryModuleList.getVfModule() + def qryModules = qryModuleList.getVfModule() for (org.onap.aai.domain.yang.VfModule qryModule : qryModules) { if (qryModule.isBaseVfModule) { // a base module already exists in this VNF - failure @@ -501,73 +474,4 @@ public class CreateAAIVfModule extends AbstractServiceTaskProcessor{ exceptionUtil.buildAndThrowWorkflowException(execution, errorCode, errorResponse) msoLogger.debug("Workflow exception occurred in CreateAAIVfModule: " + errorResponse) } - - /** - * Performs a rollback. - * TBD: This method requires additional testing once integrated with the - * main CreateVfModule flow. - * @param execution the execution - */ - public void rollback(DelegateExecution execution) { - def method = getClass().getSimpleName() + ".rollback(" + - "execution=" + execution.getId() + - ")" - msoLogger.debug("Entered " + method) - - try { - RollbackData rollbackData = (RollbackData) execution.getVariable("RollbackData") - msoLogger.debug("RollbackData:" + rollbackData) - - AaiUtil aaiUriUtil = new AaiUtil(this) - - if (rollbackData != null) { - if (rollbackData.hasType("VFMODULE")) { - // use the DeleteAAIVfModule groovy methods for the rollback - def vnfId = rollbackData.get("VFMODULE", "vnfId") - def vfModuleId = rollbackData.get("VFMODULE", "vfModuleId") - def isBaseModule = rollbackData.get("VFMODULE", "isBaseModule") - execution.setVariable("DAAIVfMod_vnfId", vnfId) - execution.setVariable("DAAIVfMod_vfModuleId", vfModuleId) - - DeleteAAIVfModule dvm = new DeleteAAIVfModule() - // query A&AI to get the needed information for the delete(s) - dvm.queryAAIForGenericVnf(execution) - dvm.parseForVfModule(execution) - - // roll back the base or add-on module - dvm.deleteVfModule(execution) - def responseCode = execution.getVariable("DAAIVfMod_deleteVfModuleResponseCode") - def response = execution.getVariable("DAAIVfMod_deleteVfModuleResponseCode") - - if (isOneOf(responseCode, 200, 204)) { - msoLogger.debug("Received " + responseCode + " to VF Module rollback request") - } else { - msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Received " + responseCode + " to VF Module rollback request", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, rollbackData + System.lineSeparator() + "Response: " + response); - } - - // a new Generic VNF was created that needs to be rolled back - if (isBaseModule.equals("true")) { - dvm.queryAAIForGenericVnf(execution) - dvm.parseForResourceVersion(execution) - dvm.deleteGenericVnf(execution) - responseCode = execution.getVariable("DAAIVfMod_deleteGenericVnfResponseCode") - response = execution.getVariable("DAAIVfMod_deleteGenericVnfResponse") - - if (isOneOf(responseCode, 200, 204)) { - msoLogger.debug("Received " + responseCode + " to Generic VNF rollback request") - execution.setVariable("RollbackResult", "SUCCESS") - } else { - msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Received " + responseCode + " to Generic VNF rollback request", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, rollbackData + System.lineSeparator() + "Response: " + response); - } - } else { - execution.setVariable("RollbackResult", "SUCCESS") - } - } - } - - msoLogger.debug("Exited " + method) - } catch (Exception e) { - msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Caught exception in " + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e); - } - } } diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CreateAAIVfModuleTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CreateAAIVfModuleTest.groovy index 886e92bd45..1fa10a56c5 100644 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CreateAAIVfModuleTest.groovy +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CreateAAIVfModuleTest.groovy @@ -10,9 +10,9 @@ * 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. @@ -23,6 +23,8 @@ package org.onap.so.bpmn.common.scripts +import org.camunda.bpm.engine.delegate.DelegateExecution + import static org.assertj.core.api.Assertions.assertThat import static org.mockito.ArgumentMatchers.any import static org.mockito.ArgumentMatchers.anyObject @@ -57,12 +59,12 @@ class CreateAAIVfModuleTest extends MsoGroovyTest{ private static final String VF_MODULE_MODEL_NAME = "modModelNameTest" private static final String DEFAULT_AAI_VERSION = "9" private static final String DEFAULT_AAI_NAMESPACE = "defaultTestNamespace" - + @Spy CreateAAIVfModule createAAIVfModule ; private DelegateExecutionFake executionFake; - + @Before public void init() throws IOException { super.init("CreateAAIVfModule") @@ -236,7 +238,7 @@ class CreateAAIVfModuleTest extends MsoGroovyTest{ @Test void parseForAddOnModule_moduleNameFound() { - + GenericVnf vnf = new GenericVnf(); VfModule module = new VfModule(); VfModules modules = new VfModules(); @@ -302,7 +304,7 @@ class CreateAAIVfModuleTest extends MsoGroovyTest{ modules.getVfModule().add(module) module.setVfModuleName(VF_MODULE_NAME) module.setIsBaseVfModule(true) - + executionFake.setVariable("CAAIVfMod_queryGenericVnfResponse", vnf) executionFake.setVariable("CAAIVfMod_baseModuleConflict", false) @@ -331,6 +333,103 @@ class CreateAAIVfModuleTest extends MsoGroovyTest{ .isEqualTo("VF Module " + VF_MODULE_NAME + " does not exist for Generic VNF " + VNF_NAME) } + @Test + void handleFailure_errorCode5000() { + executionFake.setVariable("CAAIVfMod_createGenericVnfResponseCode", "123") + executionFake.setVariable("CAAIVfMod_createGenericVnfResponse", "responseTest") + + ExceptionUtilForTesting exceptionUtilForTesting = new ExceptionUtilForTesting() + createAAIVfModule.setExceptionUtil(exceptionUtilForTesting) + + createAAIVfModule.handleCreateVfModuleFailure(executionFake) + + assertThat(exceptionUtilForTesting.getErrorCode()).isEqualTo(5000) + assertThat(exceptionUtilForTesting.getErrorMessage()).isEqualTo("responseTest") + } + + @Test + void handleFailure_errorCode1002() { + executionFake.setVariable("CAAIVfMod_queryGenericVnfResponse", "responseTest") + executionFake.setVariable("CAAIVfMod_newGenericVnf", true) + + ExceptionUtilForTesting exceptionUtilForTesting = new ExceptionUtilForTesting() + createAAIVfModule.setExceptionUtil(exceptionUtilForTesting) + + createAAIVfModule.handleCreateVfModuleFailure(executionFake) + + assertThat(exceptionUtilForTesting.getErrorCode()).isEqualTo(1002) + assertThat(exceptionUtilForTesting.getErrorMessage()).isEqualTo("responseTest") + } + + @Test + void handleFailure_errorCode1002_queryGenericVnfResponse() { + executionFake.setVariable("CAAIVfMod_queryGenericVnfResponse", "responseTest") + executionFake.setVariable("CAAIVfMod_queryGenericVnfResponseCode", 404) + executionFake.setVariable("CAAIVfMod_newGenericVnf", false) + + ExceptionUtilForTesting exceptionUtilForTesting = new ExceptionUtilForTesting() + createAAIVfModule.setExceptionUtil(exceptionUtilForTesting) + + createAAIVfModule.handleCreateVfModuleFailure(executionFake) + + assertThat(exceptionUtilForTesting.getErrorCode()).isEqualTo(1002) + assertThat(exceptionUtilForTesting.getErrorMessage()).isEqualTo("responseTest") + } + + @Test + void handleFailure_errorCode5000_createVfModuleResponseCode() { + executionFake.setVariable("CAAIVfMod_createVfModuleResponseCode", "123") + executionFake.setVariable("CAAIVfMod_createVfModuleResponse", "responseTest") + + ExceptionUtilForTesting exceptionUtilForTesting = new ExceptionUtilForTesting() + createAAIVfModule.setExceptionUtil(exceptionUtilForTesting) + + createAAIVfModule.handleCreateVfModuleFailure(executionFake) + + assertThat(exceptionUtilForTesting.getErrorCode()).isEqualTo(5000) + assertThat(exceptionUtilForTesting.getErrorMessage()).isEqualTo("responseTest") + } + + @Test + void handleFailure_errorCode1002_moduleExists() { + executionFake.setVariable("CAAIVfMod_moduleExists", true) + executionFake.setVariable("CAAIVfMod_parseModuleResponse", "responseTest") + + ExceptionUtilForTesting exceptionUtilForTesting = new ExceptionUtilForTesting() + createAAIVfModule.setExceptionUtil(exceptionUtilForTesting) + + createAAIVfModule.handleCreateVfModuleFailure(executionFake) + + assertThat(exceptionUtilForTesting.getErrorCode()).isEqualTo(1002) + assertThat(exceptionUtilForTesting.getErrorMessage()).isEqualTo("responseTest") + } + + @Test + void handleFailure_errorCode1002_baseModuleConflict() { + executionFake.setVariable("CAAIVfMod_baseModuleConflict", true) + executionFake.setVariable("CAAIVfMod_parseModuleResponse", "responseTest") + + ExceptionUtilForTesting exceptionUtilForTesting = new ExceptionUtilForTesting() + createAAIVfModule.setExceptionUtil(exceptionUtilForTesting) + + createAAIVfModule.handleCreateVfModuleFailure(executionFake) + + assertThat(exceptionUtilForTesting.getErrorCode()).isEqualTo(1002) + assertThat(exceptionUtilForTesting.getErrorMessage()).isEqualTo("responseTest") + } + + @Test + void handleFailure_errorCode2000() { + ExceptionUtilForTesting exceptionUtilForTesting = new ExceptionUtilForTesting() + createAAIVfModule.setExceptionUtil(exceptionUtilForTesting) + + createAAIVfModule.handleCreateVfModuleFailure(executionFake) + + assertThat(exceptionUtilForTesting.getErrorCode()).isEqualTo(2000) + assertThat(exceptionUtilForTesting.getErrorMessage()). + isEqualTo("Unknown error occurred during CreateAAIVfModule flow") + } + private void prepareUrnPropertiesReader() { Environment mockEnvironment = mock(Environment.class) when(mockEnvironment.getProperty("mso.workflow.global.default.aai.version")).thenReturn(DEFAULT_AAI_VERSION) @@ -338,4 +437,25 @@ class CreateAAIVfModuleTest extends MsoGroovyTest{ UrnPropertiesReader urnPropertiesReader = new UrnPropertiesReader() urnPropertiesReader.setEnvironment(mockEnvironment) } + + class ExceptionUtilForTesting extends ExceptionUtil { + private int errorCode + private String errorMessage + + int getErrorCode() { + return errorCode + } + + String getErrorMessage() { + return errorMessage + } + + @Override + void buildAndThrowWorkflowException(DelegateExecution execution, int errorCode, + String errorMessage) { + this.errorCode = errorCode + this.errorMessage = errorMessage + } + } + } diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegate.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegate.java index 469069e136..8d353f134d 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegate.java +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegate.java @@ -29,20 +29,23 @@ import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.engine.delegate.JavaDelegate; import org.onap.so.bpmn.common.scripts.ExceptionUtil; import org.onap.so.bpmn.infrastructure.pnf.implementation.AaiConnection; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** * Implementation of "Check AAI for correlation_id" task in CreateAndActivatePnfResource.bpmn * - * Inputs: - * - correlationId - String + * Inputs: - correlationId - String * - * Outputs: - * - aaiContainsInfoAboutPnf - local Boolean + * Outputs: - aaiContainsInfoAboutPnf - local Boolean */ @Component public class CheckAaiForCorrelationIdDelegate implements JavaDelegate { + + private static final Logger logger = LoggerFactory.getLogger(CheckAaiForCorrelationIdDelegate.class); + private AaiConnection aaiConnection; @Autowired @@ -58,6 +61,7 @@ public class CheckAaiForCorrelationIdDelegate implements JavaDelegate { } try { boolean isEntry = aaiConnection.getEntryFor(correlationId).isPresent(); + logger.debug("AAI entry is found for pnf correlation id {}: {}", CORRELATION_ID, isEntry); execution.setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, isEntry); } catch (IOException e) { new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, e.getMessage()); diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateAaiEntryWithPnfIdDelegate.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateAaiEntryWithPnfIdDelegate.java index a8754cd4a0..209cbac98a 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateAaiEntryWithPnfIdDelegate.java +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateAaiEntryWithPnfIdDelegate.java @@ -26,6 +26,8 @@ import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.engine.delegate.JavaDelegate; import org.onap.aai.domain.yang.Pnf; import org.onap.so.bpmn.infrastructure.pnf.implementation.AaiConnection; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -38,6 +40,7 @@ import org.springframework.stereotype.Component; @Component public class CreateAaiEntryWithPnfIdDelegate implements JavaDelegate { + private static final Logger logger = LoggerFactory.getLogger(CreateAaiEntryWithPnfIdDelegate.class); private AaiConnection aaiConnection; @Autowired @@ -53,5 +56,6 @@ public class CreateAaiEntryWithPnfIdDelegate implements JavaDelegate { pnf.setPnfId(correlationId); pnf.setPnfName(correlationId); aaiConnection.createEntry(correlationId, pnf); + logger.debug("AAI entry is created for pnf correlation id: {}", correlationId); } } diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClient.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClient.java index 373e84bb9d..f29044456c 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClient.java +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClient.java @@ -35,7 +35,8 @@ import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; -import org.onap.so.logger.MsoLogger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; @@ -43,8 +44,7 @@ import org.springframework.stereotype.Component; @Component public class PnfEventReadyDmaapClient implements DmaapClient { - private static final MsoLogger LOGGER = MsoLogger - .getMsoLogger(MsoLogger.Catalog.RA, PnfEventReadyDmaapClient.class); + private static final Logger logger = LoggerFactory.getLogger(PnfEventReadyDmaapClient.class); private HttpClient httpClient; private Map<String, Runnable> pnfCorrelationIdToThreadMap; @@ -70,7 +70,7 @@ public class PnfEventReadyDmaapClient implements DmaapClient { @Override public synchronized void registerForUpdate(String correlationId, Runnable informConsumer) { - LOGGER.debug("registering for pnf ready dmaap event for correlation id: " + correlationId); + logger.debug("registering for pnf ready dmaap event for correlation id: {}", correlationId); pnfCorrelationIdToThreadMap.put(correlationId, informConsumer); if (!dmaapThreadListenerIsRunning) { startDmaapThreadListener(); @@ -79,7 +79,7 @@ public class PnfEventReadyDmaapClient implements DmaapClient { @Override public synchronized Runnable unregister(String correlationId) { - LOGGER.debug("unregistering from pnf ready dmaap event for correlation id: " + correlationId); + logger.debug("unregistering from pnf ready dmaap event for correlation id: {}", correlationId); Runnable runnable = pnfCorrelationIdToThreadMap.remove(correlationId); if (pnfCorrelationIdToThreadMap.isEmpty()) { stopDmaapThreadListener(); @@ -111,10 +111,11 @@ public class PnfEventReadyDmaapClient implements DmaapClient { @Override public void run() { try { + logger.debug("dmaap listener starts listening pnf ready dmaap topic"); HttpResponse response = httpClient.execute(getRequest); getCorrelationIdListFromResponse(response).forEach(this::informAboutPnfReadyIfCorrelationIdFound); } catch (IOException e) { - LOGGER.error("Exception caught during sending rest request to dmaap for listening event topic", e); + logger.error("Exception caught during sending rest request to dmaap for listening event topic", e); } } @@ -131,7 +132,7 @@ public class PnfEventReadyDmaapClient implements DmaapClient { private void informAboutPnfReadyIfCorrelationIdFound(String correlationId) { Runnable runnable = unregister(correlationId); if (runnable != null) { - LOGGER.debug("pnf ready event got from dmaap for correlationId: " + correlationId); + logger.debug("dmaap listener gets pnf ready event for correlationId: {}", correlationId); runnable.run(); } } diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientRedirectStrategyTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientRedirectStrategyTest.java index b631dab999..87b51e9357 100644 --- a/cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientRedirectStrategyTest.java +++ b/cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientRedirectStrategyTest.java @@ -105,6 +105,33 @@ public class HttpClientRedirectStrategyTest { assertThat(httpUriRequest.getURI()).isEqualTo(expectedUri); } + @Test + public void getRedirect_shouldCopyHttpRequestAndSetNewUri_forMovedTemporarilyStatus() throws URISyntaxException, ProtocolException { + assertHttpRequestIsCopied(HttpStatus.SC_MOVED_TEMPORARILY); + } + + @Test + public void getRedirect_shouldCopyHttpRequestAndSetNewUri_forTemporaryRedirectStatus() throws URISyntaxException, ProtocolException { + assertHttpRequestIsCopied(HttpStatus.SC_TEMPORARY_REDIRECT); + } + + private void assertHttpRequestIsCopied(int expectedHttpStatus) throws URISyntaxException, ProtocolException { + // GIVEN + HttpRequest request = mock(HttpRequest.class, RETURNS_DEEP_STUBS); + given(request.getRequestLine().getMethod()).willReturn(HttpGet.METHOD_NAME); + given(request.getRequestLine().getUri()).willReturn("http://hostname"); + HttpResponse response = mock(HttpResponse.class, RETURNS_DEEP_STUBS); + given(response.getStatusLine().getStatusCode()).willReturn(expectedHttpStatus); + URI expectedUri = new URI("http://localhost/host"); + HttpContext context = null; + // WHEN + HttpUriRequest httpUriRequest = new TestableHttpClientRedirectStrategy(expectedUri) + .getRedirect(request, response, context); + // THEN + assertThat(httpUriRequest).isInstanceOf(HttpGet.class); + assertThat(httpUriRequest.getURI()).isEqualTo(expectedUri); + } + private static class TestableHttpClientRedirectStrategy extends HttpClientRedirectStrategy { private final URI expectedUri; @@ -112,7 +139,6 @@ public class HttpClientRedirectStrategyTest { public TestableHttpClientRedirectStrategy(URI expectedUri) { this.expectedUri = expectedUri; } - @Override public URI getLocationURI(HttpRequest request, HttpResponse response, HttpContext context) { return expectedUri; |