Search in sources :

Example 26 with ServiceInstancesResponse

use of org.onap.so.serviceinstancebeans.ServiceInstancesResponse in project so by onap.

the class ServiceInstancesTest method createVfModuleInstance.

@Test
public void createVfModuleInstance() throws IOException {
    wireMockServer.stubFor(get(urlMatching("/vfModuleCustomization/search/findFirstByModelCustomizationUUIDOrderByCreatedDesc\\?MODEL_CUSTOMIZATION_UUID=cb82ffd8-252a-11e7-93ae-92361f002671")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBody(getWiremockResponseForCatalogdb("vfModuleCustomization_Response.json")).withStatus(org.apache.http.HttpStatus.SC_OK)));
    wireMockServer.stubFor(get(urlMatching("/vfModule/20c4431c-246d-11e7-93ae-92361f002671")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBody(getWiremockResponseForCatalogdb("vfModule_Response.json")).withStatus(org.apache.http.HttpStatus.SC_OK)));
    wireMockServer.stubFor(get(urlMatching("/vfModuleCustomization/1/vfModule")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBody(getWiremockResponseForCatalogdb("vfModule_Response.json")).withStatus(org.apache.http.HttpStatus.SC_OK)));
    wireMockServer.stubFor(get(urlMatching("/vfModuleCustomization/search/findFirstByModelCustomizationUUIDOrderByCreatedDesc\\?MODEL_CUSTOMIZATION_UUID=20c4431c-246d-11e7-93ae-92361f002671")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBody(getWiremockResponseForCatalogdb("vfModule_Response.json")).withStatus(org.apache.http.HttpStatus.SC_OK)));
    wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/CreateVfModuleInfra")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
    wireMockServer.stubFor(get(urlMatching("/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction" + "[?]vfModuleModelUUID=20c4431c-246d-11e7-93ae-92361f002671&vnfComponentType=vfModule&action=createInstance")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBody(getWiremockResponseForCatalogdb("vnfComponentRecipe_Response.json")).withStatus(org.apache.http.HttpStatus.SC_OK)));
    // expected response
    ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
    RequestReferences requestReferences = new RequestReferences();
    requestReferences.setInstanceId("1882939");
    requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
    expectedResponse.setRequestReferences(requestReferences);
    uri = servInstanceuri + "v7" + "/serviceInstances/7a88cbeb-0ec8-4765-a271-4f9e90c3da7b/vnfs/cbba721b-4803-4df7-9347-307c9a955426/vfModules";
    ResponseEntity<String> response = sendRequest(inputStream("/VfModuleWithRelatedInstances.json"), uri, HttpMethod.POST, headers);
    assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
    ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
    assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
    assertTrue(response.getBody().contains("1882939"));
}
Also used : ServiceInstancesResponse(org.onap.so.serviceinstancebeans.ServiceInstancesResponse) RequestReferences(org.onap.so.serviceinstancebeans.RequestReferences) Test(org.junit.Test)

Example 27 with ServiceInstancesResponse

use of org.onap.so.serviceinstancebeans.ServiceInstancesResponse in project so by onap.

the class ServiceInstancesTest method deleteInstanceGroupNoRquestorIdHeader.

@Test
public void deleteInstanceGroupNoRquestorIdHeader() throws IOException {
    HttpHeaders noRequestorIdHheaders = new HttpHeaders();
    noRequestorIdHheaders.set(ONAPLogConstants.Headers.REQUEST_ID, "eca3a1b1-43ab-457e-ab1c-367263d148b4");
    noRequestorIdHheaders.set(ONAPLogConstants.Headers.PARTNER_NAME, "eca3a1b1-43ab-457e-ab1c-367263d148b4");
    // expect
    ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
    RequestReferences requestReferences = new RequestReferences();
    requestReferences.setInstanceId("1882939");
    expectedResponse.setRequestReferences(requestReferences);
    uri = servInstanceuri + "/v7/instanceGroups/e05864f0-ab35-47d0-8be4-56fd9619ba3c";
    ResponseEntity<String> response = sendRequest(null, uri, HttpMethod.DELETE, noRequestorIdHheaders);
    // then
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
    RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
    assertEquals(realResponse.getServiceException().getText(), "No valid X-RequestorID header is specified");
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) RequestError(org.onap.so.serviceinstancebeans.RequestError) ServiceInstancesResponse(org.onap.so.serviceinstancebeans.ServiceInstancesResponse) RequestReferences(org.onap.so.serviceinstancebeans.RequestReferences) Test(org.junit.Test)

Example 28 with ServiceInstancesResponse

use of org.onap.so.serviceinstancebeans.ServiceInstancesResponse in project so by onap.

the class ServiceInstancesTest method createNetworkInstanceTestApiVnfApi.

@Test
public void createNetworkInstanceTestApiVnfApi() throws IOException {
    wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/CreateNetworkInstance")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
    wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBody(getWiremockResponseForCatalogdb("networkResourceCustomization_Response.json")).withStatus(HttpStatus.SC_OK)));
    wireMockServer.stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac/networkResource")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBody(getWiremockResponseForCatalogdb("networkResource_Response.json")).withStatus(HttpStatus.SC_OK)));
    wireMockServer.stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]" + "modelName=VNF-API-DEFAULT&action=createInstance")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBody(getWiremockResponseForCatalogdb("networkRecipeVNF_API_Response.json")).withStatus(org.apache.http.HttpStatus.SC_OK)));
    uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks";
    ResponseEntity<String> response = sendRequest(inputStream("/NetworkCreateTestApiVnfApi.json"), uri, HttpMethod.POST, headers);
    // expected response
    ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
    RequestReferences requestReferences = new RequestReferences();
    requestReferences.setInstanceId("1882939");
    requestReferences.setRequestSelfLink(createExpectedSelfLink("v7", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
    expectedResponse.setRequestReferences(requestReferences);
    assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
    ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
    assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
}
Also used : ServiceInstancesResponse(org.onap.so.serviceinstancebeans.ServiceInstancesResponse) RequestReferences(org.onap.so.serviceinstancebeans.RequestReferences) Test(org.junit.Test)

Example 29 with ServiceInstancesResponse

use of org.onap.so.serviceinstancebeans.ServiceInstancesResponse in project so by onap.

the class AbstractRestHandlerTest method test_createResponse.

@Test
public void test_createResponse() throws MalformedURLException {
    ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
    RequestReferences requestReferences = new RequestReferences();
    URL selfLinkURL = new URL("http://localhost:8080/v1");
    requestReferences.setInstanceId("instanceId");
    requestReferences.setRequestId("requestId");
    requestReferences.setRequestSelfLink(selfLinkURL);
    expectedResponse.setRequestReferences(requestReferences);
    doReturn("http://localhost:8080/v1").when(restHandler).getRequestUri(mockRequestContext);
    doReturn(Optional.of(selfLinkURL)).when(restHandler).buildSelfLinkUrl("http://localhost:8080/v1", "requestId");
    ServiceInstancesResponse actualResponse = restHandler.createResponse("instanceId", "requestId", mockRequestContext);
    assertThat(actualResponse, sameBeanAs(expectedResponse));
}
Also used : ServiceInstancesResponse(org.onap.so.serviceinstancebeans.ServiceInstancesResponse) RequestReferences(org.onap.so.serviceinstancebeans.RequestReferences) URL(java.net.URL) Test(org.junit.Test)

Example 30 with ServiceInstancesResponse

use of org.onap.so.serviceinstancebeans.ServiceInstancesResponse in project so by onap.

the class RequestHandlerUtils method postBPELRequest.

public Response postBPELRequest(InfraActiveRequests currentActiveReq, RequestClientParameter requestClientParameter, String orchestrationUri, String requestScope) throws ApiException {
    ObjectMapper mapper = new ObjectMapper();
    ResponseEntity<String> response = postRequest(currentActiveReq, requestClientParameter, orchestrationUri);
    ServiceInstancesResponse jsonResponse = null;
    int bpelStatus = responseHandler.setStatus(response.getStatusCodeValue());
    try {
        responseHandler.acceptedResponse(response);
        CamundaResponse camundaResponse = responseHandler.getCamundaResponse(response);
        String responseBody = camundaResponse.getResponse();
        if ("Success".equalsIgnoreCase(camundaResponse.getMessage())) {
            jsonResponse = mapper.readValue(responseBody, ServiceInstancesResponse.class);
            jsonResponse.getRequestReferences().setRequestId(requestClientParameter.getRequestId());
            Optional<URL> selfLinkUrl = buildSelfLinkUrl(currentActiveReq.getRequestUrl(), requestClientParameter.getRequestId());
            if (selfLinkUrl.isPresent()) {
                jsonResponse.getRequestReferences().setRequestSelfLink(selfLinkUrl.get());
            } else {
                jsonResponse.getRequestReferences().setRequestSelfLink(null);
            }
        } else {
            BPMNFailureException bpmnException = new BPMNFailureException.Builder(String.valueOf(bpelStatus) + responseBody, bpelStatus, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).build();
            updateStatus(currentActiveReq, Status.FAILED, bpmnException.getMessage());
            throw bpmnException;
        }
    } catch (ApiException e) {
        updateStatus(currentActiveReq, Status.FAILED, e.getMessage());
        throw e;
    } catch (IOException e) {
        logger.error("Exception caught mapping Camunda JSON response to object: ", e);
        updateStatus(currentActiveReq, Status.FAILED, e.getMessage());
        throw new ValidateException.Builder("Exception caught mapping Camunda JSON response to object", HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).build();
    }
    return builder.buildResponse(HttpStatus.SC_ACCEPTED, requestClientParameter.getRequestId(), jsonResponse, requestClientParameter.getApiVersion());
}
Also used : ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) CamundaResponse(org.onap.so.apihandler.camundabeans.CamundaResponse) IOException(java.io.IOException) URL(java.net.URL) BPMNFailureException(org.onap.so.apihandlerinfra.exceptions.BPMNFailureException) ServiceInstancesResponse(org.onap.so.serviceinstancebeans.ServiceInstancesResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException)

Aggregations

ServiceInstancesResponse (org.onap.so.serviceinstancebeans.ServiceInstancesResponse)71 RequestReferences (org.onap.so.serviceinstancebeans.RequestReferences)65 Test (org.junit.Test)60 Service (org.onap.so.db.catalog.beans.Service)10 ServiceRecipe (org.onap.so.db.catalog.beans.ServiceRecipe)10 InfraActiveRequests (org.onap.so.db.request.beans.InfraActiveRequests)8 ServiceInstancesRequest (org.onap.so.serviceinstancebeans.ServiceInstancesRequest)8 Operation (io.swagger.v3.oas.annotations.Operation)5 Transactional (javax.transaction.Transactional)5 Consumes (javax.ws.rs.Consumes)5 DELETE (javax.ws.rs.DELETE)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 ResponseUpdater (org.onap.so.apihandler.filters.ResponseUpdater)5 Recipe (org.onap.so.db.catalog.beans.Recipe)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 IOException (java.io.IOException)4 ApiException (org.onap.so.apihandlerinfra.exceptions.ApiException)4 ValidateException (org.onap.so.apihandlerinfra.exceptions.ValidateException)4 URL (java.net.URL)3