Java Code Examples for com.jayway.restassured.response.Response#getStatusCode()

The following examples show how to use com.jayway.restassured.response.Response#getStatusCode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PreparationClientTest.java    From data-prep with Apache License 2.0 6 votes vote down vote up
/**
 * Return the details of a preparation at a given (optional) step.
 *
 * @param preparationId the wanted preparation id.
 * @param wantedStepId the optional wanted step id.
 * @return the details of a preparation at a given (optional) step.
 */
public PreparationDetailsDTO getDetails(String preparationId, String wantedStepId) {
    final RequestSpecification specs = given();

    if (StringUtils.isNotBlank(wantedStepId)) {
        specs.queryParam("stepId", wantedStepId);
    }
    final Response response = specs.when().get("/preparations/{id}/details", preparationId);

    if (response.getStatusCode() != 200) {
        throw new MockTDPException(response);
    }

    try {
        return mapper.readerFor(PreparationDetailsDTO.class).readValue(response.asString());
    } catch (IOException e) {
        throw new TDPException(UNABLE_TO_READ_CONTENT);
    }

}
 
Example 2
Source File: OSDataPrepAPIHelper.java    From data-prep with Apache License 2.0 6 votes vote down vote up
/**
 * Export the current preparation sample depending the given parameters.
 *
 * @param parameters the export parameters.
 * @return the response.
 */
public Response executeExport(Map<String, String> parameters) throws IOException {
    Response response = given() //
            .contentType(JSON) //
            .when() //
            .queryParameters(parameters) //
            .get("/api/export");

    if (HttpStatus.ACCEPTED.value() == response.getStatusCode()) {
        // first time we have a 202 with a Location to see asynchronous method status
        final String asyncMethodStatusUrl = response.getHeader(HttpHeaders.LOCATION);

        waitForAsyncMethodToFinish(asyncMethodStatusUrl);

        response = given() //
                .contentType(JSON) //
                .when() //
                .queryParameters(parameters) //
                .get("/api/export");
    }
    return response;
}
 
Example 3
Source File: APIClientTest.java    From data-prep with Apache License 2.0 6 votes vote down vote up
public String createDataset(final InputStream resourceAsStream, MediaType contentType, final String name)
        throws IOException {
    assertNotNull(resourceAsStream);
    final String datasetContent = IOUtils.toString(resourceAsStream, UTF_8);
    final Response post = given() //
            .contentType(contentType.toString()) //
            .body(datasetContent) //
            .queryParam("name", name) //
            .when() //
            .post("/api/datasets");

    final int statusCode = post.getStatusCode();
    if (statusCode != 200) {
        LOGGER.error("Unable to create dataset (HTTP " + statusCode + "). Error: {}", post.asString());
    }
    assertThat(statusCode, is(200));
    final String dataSetId = post.asString();
    assertNotNull(dataSetId);
    assertThat(dataSetId, not(""));

    return dataSetId;
}
 
Example 4
Source File: APIClientTest.java    From data-prep with Apache License 2.0 6 votes vote down vote up
public Response getFailedPreparationWithFilter(String preparationId, String malformedFilter) throws IOException {
    Response transformedResponse = given() //
            .when() //
            .get("/api/preparations/{prepId}/content?version={version}&from={stepId}&filter={filter}",
                    preparationId, "head", "HEAD", malformedFilter);

    if (ACCEPTED.value() == transformedResponse.getStatusCode()) {
        // first time we have a 202 with a Location to see asynchronous method status
        final String asyncMethodStatusUrl = transformedResponse.getHeader("Location");

        AsyncExecution.Status asyncStatus = waitForAsyncMethodToFinish(asyncMethodStatusUrl);
        assertEquals(AsyncExecution.Status.FAILED, asyncStatus);

        return given()
                .expect() //
                .statusCode(200) //
                .log()
                .ifError() //
                .when() //
                .get(asyncMethodStatusUrl);
    }
    return transformedResponse;
}
 
Example 5
Source File: OSDataPrepAPIHelper.java    From data-prep with Apache License 2.0 5 votes vote down vote up
/**
 * Get preparation content by id and at a given version.
 *
 * @param preparationId the preparation id.
 * @param version version of the preparation
 * @param from Where to get the data from (HEAD if no value)
 * @param tql The TQL filter to apply (pass null if you want the non-filtered preparation content)
 * @return the response.
 */
public Response getPreparationContent(String preparationId, String version, String from, String tql)
        throws IOException {
    RequestSpecification given = given() //
            .queryParam(VERSION, version) //
            .queryParam(FROM, from);
    if (tql != null) {
        given.queryParam("filter", tql);
    }
    Response response = given
            .when() //
            .get("/api/preparations/{preparationId}/content", preparationId);

    if (HttpStatus.ACCEPTED.value() == response.getStatusCode()) {
        // first time we have a 202 with a Location to see asynchronous method status
        final String asyncMethodStatusUrl = response.getHeader(HttpHeaders.LOCATION);

        waitForAsyncMethodToFinish(asyncMethodStatusUrl);

        response = given() //
                .queryParam(VERSION, version) //
                .queryParam(FROM, from) //
                .queryParam("filter", tql) //
                .when() //
                .get("/api/preparations/{preparationId}/content", preparationId);
    }
    return response;
}
 
Example 6
Source File: APIClientTest.java    From data-prep with Apache License 2.0 4 votes vote down vote up
/**
 * Method handling 202/200 status to get the transformation content
 *
 * @param preparationId is of the preparation
 * @param version version of the preparation
 * @param stepId like HEAD or FILTER, etc.
 * @param filter TQL filter to filter the preparation content
 * @return the content of a preparation
 * @throws IOException
 */
public Response getPreparation(String preparationId, String version, String stepId, String filter)
        throws IOException {
    // when
    Response transformedResponse;
    RequestSpecification initialRequest = given().when();
    if (filter.isEmpty()) {
        transformedResponse = initialRequest //
                .get("/api/preparations/{prepId}/content?version={version}&from={stepId}", preparationId, version,
                        stepId);
    } else {
        transformedResponse = initialRequest //
                .get("/api/preparations/{prepId}/content?version={version}&from={stepId}&filter={filter}",
                        preparationId, version, stepId, filter);
    }

    if (ACCEPTED.value() == transformedResponse.getStatusCode()) {
        // first time we have a 202 with a Location to see asynchronous method status
        final String asyncMethodStatusUrl = transformedResponse.getHeader("Location");

        waitForAsyncMethodToFinishWithSuccess(asyncMethodStatusUrl);

        ResponseSpecification contentRequest = given() //
                .when() //
                .expect() //
                .statusCode(200) //
                .log() //
                .ifError();
        if (filter.isEmpty()) {
            transformedResponse = contentRequest //
                    .get("/api/preparations/{prepId}/content?version={version}&from={stepId}", preparationId,
                            version, stepId);
        } else {
            transformedResponse = contentRequest //
                    .get("/api/preparations/{prepId}/content?version={version}&from={stepId}&filter={filter}",
                            preparationId, version, stepId, filter);
        }
    }

    return transformedResponse;
}
 
Example 7
Source File: MockTDPException.java    From data-prep with Apache License 2.0 2 votes vote down vote up
/**
 * Create a MockTDPException out of the given response.
 *
 * @param response the reponse to create the excepion from.
 */
public MockTDPException(Response response) {
    super(response.asString());
    this.statusCode = response.getStatusCode();
}