Search in sources :

Example 1 with OofRequest

use of org.onap.so.client.oof.beans.OofRequest in project so by onap.

the class OofClientTestIT method testPostDemands_error_failed.

@Test(expected = BadResponseException.class)
public void testPostDemands_error_failed() throws JsonProcessingException, BadResponseException {
    String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"missing data\", \"requestStatus\": \"failed\"}";
    wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
    client.postDemands(new OofRequest());
// TODO assertEquals("missing data", );
}
Also used : OofRequest(org.onap.so.client.oof.beans.OofRequest) Test(org.junit.Test) BaseIntegrationTest(org.onap.so.BaseIntegrationTest)

Example 2 with OofRequest

use of org.onap.so.client.oof.beans.OofRequest in project so by onap.

the class OofClientTestIT method testPostDemands_error_noStatus.

@Test(expected = BadResponseException.class)
public void testPostDemands_error_noStatus() throws JsonProcessingException, BadResponseException {
    String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"missing data\", \"requestStatus\": null}";
    wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
    client.postDemands(new OofRequest());
}
Also used : OofRequest(org.onap.so.client.oof.beans.OofRequest) Test(org.junit.Test) BaseIntegrationTest(org.onap.so.BaseIntegrationTest)

Example 3 with OofRequest

use of org.onap.so.client.oof.beans.OofRequest in project so by onap.

the class OofClientTestIT method testAsyncResponse_success.

@Test
public void testAsyncResponse_success() throws BadResponseException, JsonProcessingException {
    String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"status\", \"requestStatus\": \"accepted\"}";
    wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
    client.postDemands(new OofRequest());
}
Also used : OofRequest(org.onap.so.client.oof.beans.OofRequest) Test(org.junit.Test) BaseIntegrationTest(org.onap.so.BaseIntegrationTest)

Example 4 with OofRequest

use of org.onap.so.client.oof.beans.OofRequest in project so by onap.

the class OofHomingV2 method callOof.

/**
 * Generates the request payload then sends to Oof to perform homing and licensing for the provided demands
 *
 * @param execution
 */
public void callOof(BuildingBlockExecution execution) {
    logger.trace("Started Oof Homing Call Oof");
    try {
        GeneralBuildingBlock bb = execution.getGeneralBuildingBlock();
        RequestContext requestContext = bb.getRequestContext();
        String requestId = requestContext.getMsoRequestId();
        ServiceInstance serviceInstance = bb.getCustomer().getServiceSubscription().getServiceInstances().get(0);
        Customer customer = bb.getCustomer();
        String timeout = execution.getVariable("timeout");
        if (isBlank(timeout)) {
            timeout = env.getProperty("oof.timeout", "PT30M");
        }
        OofRequest oofRequest = new OofRequest();
        RequestInfo requestInfo = buildRequestInfo(requestId, timeout);
        oofRequest.setRequestInformation(requestInfo);
        ServiceInfo serviceInfo = buildServiceInfo(serviceInstance);
        oofRequest.setServiceInformation(serviceInfo);
        PlacementInfo placementInfo = buildPlacementInfo(customer);
        placementInfo = buildPlacementDemands(serviceInstance, placementInfo);
        oofRequest.setPlacementInformation(placementInfo);
        LicenseInfo licenseInfo = buildLicenseInfo(serviceInstance);
        oofRequest.setLicenseInformation(licenseInfo);
        if (!placementInfo.getPlacementDemands().isEmpty() || !licenseInfo.getLicenseDemands().isEmpty()) {
            oofClient.postDemands(oofRequest);
        } else {
            logger.debug(SERVICE_MISSING_DATA + " resources eligible for homing or licensing");
            throw new BpmnError(UNPROCESSABLE, SERVICE_MISSING_DATA + " resources eligible for homing or licensing");
        }
        // Variables for ReceiveWorkflowMessage subflow
        execution.setVariable("asyncCorrelator", requestId);
        execution.setVariable("asyncMessageType", "OofResponse");
        execution.setVariable("asyncTimeout", timeout);
        logger.trace("Completed Oof Homing Call Oof");
    } catch (BpmnError e) {
        logger.debug(ERROR_WHILE_PREPARING_OOF_REQUEST + e.getStackTrace());
        exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(e.getErrorCode()), e.getMessage());
    } catch (BadResponseException e) {
        logger.debug(ERROR_WHILE_PREPARING_OOF_REQUEST + e.getStackTrace());
        exceptionUtil.buildAndThrowWorkflowException(execution, 400, e.getMessage());
    } catch (Exception e) {
        logger.debug(ERROR_WHILE_PREPARING_OOF_REQUEST + e.getStackTrace());
        exceptionUtil.buildAndThrowWorkflowException(execution, INTERNAL, "Internal Error - occurred while " + "preparing oof request: " + e + "   Stack:" + ExceptionUtils.getFullStackTrace(e));
    }
}
Also used : LicenseInfo(org.onap.so.client.oof.beans.LicenseInfo) GeneralBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock) Customer(org.onap.so.bpmn.servicedecomposition.bbobjects.Customer) BadResponseException(org.onap.so.client.exception.BadResponseException) ServiceInstance(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance) ModelInfoServiceInstance(org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance) RequestInfo(org.onap.so.client.oof.beans.RequestInfo) BadResponseException(org.onap.so.client.exception.BadResponseException) ServiceInfo(org.onap.so.client.oof.beans.ServiceInfo) PlacementInfo(org.onap.so.client.oof.beans.PlacementInfo) RequestContext(org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext) OofRequest(org.onap.so.client.oof.beans.OofRequest) BpmnError(org.camunda.bpm.engine.delegate.BpmnError)

Example 5 with OofRequest

use of org.onap.so.client.oof.beans.OofRequest in project so by onap.

the class OofClientTestIT method testPostDemands_error_empty.

@Test(expected = BadResponseException.class)
public void testPostDemands_error_empty() throws JsonProcessingException, BadResponseException {
    String mockResponse = "{ }";
    wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse)));
    client.postDemands(new OofRequest());
}
Also used : OofRequest(org.onap.so.client.oof.beans.OofRequest) Test(org.junit.Test) BaseIntegrationTest(org.onap.so.BaseIntegrationTest)

Aggregations

OofRequest (org.onap.so.client.oof.beans.OofRequest)7 Test (org.junit.Test)6 BaseIntegrationTest (org.onap.so.BaseIntegrationTest)6 LicenseInfo (org.onap.so.client.oof.beans.LicenseInfo)2 PlacementInfo (org.onap.so.client.oof.beans.PlacementInfo)2 RequestInfo (org.onap.so.client.oof.beans.RequestInfo)2 ServiceInfo (org.onap.so.client.oof.beans.ServiceInfo)2 ArrayList (java.util.ArrayList)1 BpmnError (org.camunda.bpm.engine.delegate.BpmnError)1 Customer (org.onap.so.bpmn.servicedecomposition.bbobjects.Customer)1 ServiceInstance (org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance)1 GeneralBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock)1 RequestContext (org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext)1 ModelInfoServiceInstance (org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance)1 BadResponseException (org.onap.so.client.exception.BadResponseException)1 ModelInfo (org.onap.so.client.oof.beans.ModelInfo)1 OofRequestParameters (org.onap.so.client.oof.beans.OofRequestParameters)1 PlacementDemand (org.onap.so.client.oof.beans.PlacementDemand)1 ResourceModelInfo (org.onap.so.client.oof.beans.ResourceModelInfo)1 SubscriberInfo (org.onap.so.client.oof.beans.SubscriberInfo)1