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

The following examples show how to use com.jayway.restassured.response.Response#as() . 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: PreparationStep.java    From data-prep with Apache License 2.0 6 votes vote down vote up
@Then("^The preparation \"(.*)\" should have the following quality bar characteristics on the column number \"(.*)\":$")
public void thePreparationShouldHaveThefollowingQualityBar(String preparationName, String columnNumber,
        DataTable dataTable) throws Exception {
    Response response = api.getPreparationContent(context.getPreparationId(suffixName(preparationName)),
            VERSION_HEAD, HEAD_ID, StringUtils.EMPTY);
    response.then().statusCode(OK.value());

    DatasetContent datasetContent = response.as(DatasetContent.class);

    final Map<String, String> parameters = dataTable.asMap(String.class, String.class);
    Integer validExpected = Integer.parseInt(parameters.get(VALID_CELL));
    Integer invalidExpected = Integer.parseInt(parameters.get(INVALID_CELL));
    Integer emptyExpected = Integer.parseInt(parameters.get(EMPTY_CELL));

    ContentMetadataColumn columnMetadata = datasetContent.metadata.columns.get(Integer.parseInt(columnNumber));
    assertEquals(validExpected, columnMetadata.quality.get(VALID_CELL));
    assertEquals(invalidExpected, columnMetadata.quality.get(INVALID_CELL));
    assertEquals(emptyExpected, columnMetadata.quality.get(EMPTY_CELL));
}
 
Example 2
Source File: PreparationStep.java    From data-prep with Apache License 2.0 6 votes vote down vote up
@Then("^The preparation \"(.*)\" should have the following invalid characteristics on the row number \"(.*)\":$")
public void thePreparationShouldHaveThefollowingInvalidCells(String preparationName, String columnNumber,
        DataTable dataTable) throws Exception {
    Response response = api.getPreparationContent(context.getPreparationId(suffixName(preparationName)),
            VERSION_HEAD, HEAD_ID, StringUtils.EMPTY);
    response.then().statusCode(OK.value());

    DatasetContent datasetContent = response.as(DatasetContent.class);

    final Map<String, String> parameters = dataTable.asMap(String.class, String.class);
    String invalidCells = parameters.get("invalidCells");

    HashMap values = (HashMap<String, String>) datasetContent.records.get(Integer.parseInt(columnNumber));
    if (!invalidCells.equals(StringUtils.EMPTY)) {
        assertEquals(invalidCells, values.get(TDP_INVALID_MARKER));
    } else {
        // there is no invalid cell
        assertNull(values.get(TDP_INVALID_MARKER));
    }
}
 
Example 3
Source File: FolderAPITest.java    From data-prep with Apache License 2.0 6 votes vote down vote up
@Test
public void updateFolderWithUnknownParent_TDP_4959() {
    // check non encoding issue on path query parameter
    Response response = given() //
            .queryParam("parentId", "ZAP%n%s%n%s%n%s%n%s%n%s") //
            .queryParam("path", "new-folder") //
            .expect()
            .statusCode(400)
            .log()
            .ifError() //
            .when() //
            .put("/api/folders");

    TdpExceptionDto exception = response.as(TdpExceptionDto.class);

    assertTrue(exception.getCode().endsWith(FOLDER_DOES_NOT_EXIST.getCode()));
}
 
Example 4
Source File: PreparationAPITest.java    From data-prep with Apache License 2.0 6 votes vote down vote up
@Test
public void encodingIssuePreparationDetailsGet_TDP_4959() throws IOException {
    // given a preparation
    final String preparationId = testClient.createPreparationFromFile("dataset/dataset.csv", "foo", home.getId());

    // should return 400 instead of 500 (exception due to encoding issue for stepId parameter)
    Response response = given() //
            .queryParam("stepId", "%00") //
            .when() //
            .expect()
            .statusCode(400)
            .log()
            .ifError()
            .get("/api/preparations/{preparationId}/details", preparationId);
    TdpExceptionDto exception = response.as(TdpExceptionDto.class);

    assertTrue(exception.getCode().endsWith(UNABLE_TO_GET_PREPARATION_DETAILS.getCode()));
}
 
Example 5
Source File: PreparationStep.java    From data-prep with Apache License 2.0 5 votes vote down vote up
@Then("^The preparation \"(.*)\" should have the following type \"(.*)\" on the following column \"(.*)\"$")
public void thePreparationShouldHaveThefollowingTypeOnThefollowingColumn(String preparationName, String columnType,
        String columnNumber) throws Exception {
    Response response = api.getPreparationContent(context.getPreparationId(suffixName(preparationName)),
            VERSION_HEAD, HEAD_ID, StringUtils.EMPTY);
    response.then().statusCode(OK.value());

    DatasetContent datasetContent = response.as(DatasetContent.class);

    ContentMetadataColumn columnMetadata = datasetContent.metadata.columns.get(Integer.parseInt(columnNumber));
    assertEquals(columnType, columnMetadata.type);
}
 
Example 6
Source File: ActionStep.java    From data-prep with Apache License 2.0 5 votes vote down vote up
@When("^I disable the last \"(.*)\" steps of the preparation \"(.*)\"$")
public void iDisableTheLastStepsOfThePreparation(int nbStepsToDisable, String prepName) throws Throwable {
    // Get steps in order to retrieve the id of the nth last one
    String prepId = context.getPreparationId(suffixName(prepName));
    List<String> steps = getPreparationDetails(prepId).steps;
    assertTrue("Not enough steps in the preparation to disable", steps.size() > nbStepsToDisable);
    String version = steps.get(steps.size() - nbStepsToDisable - 1);
    Response response = api.getPreparationContent(prepId, version, "HEAD", null);
    response.then().statusCode(OK.value());
    PreparationContent preparationContent = response.as(PreparationContent.class);
    context.storeObject("preparationContent", preparationContent);
}
 
Example 7
Source File: ExportPreparationStep.java    From data-prep with Apache License 2.0 5 votes vote down vote up
@Then("^I check that \"(.*)\" available export formats are :$")
public void thenIReceivedTheRightExportFormatList(String preparationName, DataTable dataTable) throws IOException {
    String preparationId = context.getPreparationId(suffixName(preparationName));
    Response apiResponse = api.getExportFormats(preparationId);
    ExportFormatMessage[] exportFormats = apiResponse.as(ExportFormatMessage[].class);

    List<String> exportFormatsIds = Arrays
            .stream(exportFormats) //
            .map(ExportFormatMessage::getId) //
            .collect(Collectors.toList());

    List<String> expectedFormatList = dataTable.asList(String.class);
    assertTrue(exportFormatsIds.containsAll(expectedFormatList));
}
 
Example 8
Source File: DataPrepStep.java    From data-prep with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieve the details of a preparation from its id.
 *
 * @param preparationId the preparation id.
 * @return the preparation details.
 */
protected PreparationDetails getPreparationDetails(String preparationId) {
    Response response = api.getPreparationDetails(preparationId);
    response.then().statusCode(HttpStatus.OK.value());

    return response.as(PreparationDetails.class);
}
 
Example 9
Source File: DataPrepStep.java    From data-prep with Apache License 2.0 5 votes vote down vote up
protected PreparationContent getPreparationContent(String preparationName, String tql) throws IOException {
    String preparationId = context.getPreparationId(suffixName(preparationName));
    Response response = api.getPreparationContent(preparationId, VERSION_HEAD, HEAD_ID, tql);
    response.then().statusCode(200);

    return response.as(PreparationContent.class);
}
 
Example 10
Source File: FooLiveTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenMethodArgumentMismatch_thenBadRequest() {
    final Response response = givenAuth().get(URL_PREFIX + "/api/foos/ccc");
    final ApiError error = response.as(ApiError.class);
    assertEquals(HttpStatus.BAD_REQUEST, error.getStatus());
    assertEquals(1, error.getErrors().size());
    assertTrue(error.getErrors().get(0).contains("should be of type"));
}
 
Example 11
Source File: FooLiveTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenNoHandlerForHttpRequest_thenNotFound() {
    final Response response = givenAuth().delete(URL_PREFIX + "/api/xx");
    final ApiError error = response.as(ApiError.class);
    assertEquals(HttpStatus.NOT_FOUND, error.getStatus());
    assertEquals(1, error.getErrors().size());
    assertTrue(error.getErrors().get(0).contains("No handler found"));
    System.out.println(response.asString());

}
 
Example 12
Source File: FooLiveTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenHttpRequestMethodNotSupported_thenMethodNotAllowed() {
    final Response response = givenAuth().delete(URL_PREFIX + "/api/foos/1");
    final ApiError error = response.as(ApiError.class);
    assertEquals(HttpStatus.METHOD_NOT_ALLOWED, error.getStatus());
    assertEquals(1, error.getErrors().size());
    assertTrue(error.getErrors().get(0).contains("Supported methods are"));
    System.out.println(response.asString());

}
 
Example 13
Source File: FooLiveTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenSendInvalidHttpMediaType_thenUnsupportedMediaType() {
    final Response response = givenAuth().body("").post(URL_PREFIX + "/api/foos");
    final ApiError error = response.as(ApiError.class);
    assertEquals(HttpStatus.UNSUPPORTED_MEDIA_TYPE, error.getStatus());
    assertEquals(1, error.getErrors().size());
    assertTrue(error.getErrors().get(0).contains("media type is not supported"));
    System.out.println(response.asString());

}