Search in sources :

Example 46 with JsonPath

use of com.jayway.restassured.path.json.JsonPath in project data-prep by Talend.

the class PreparationAPITest method testPreparationsList_withFilterOnName.

@Test
public void testPreparationsList_withFilterOnName() throws Exception {
    // given
    String tagadaId = testClient.createDataset("dataset/dataset.csv", "tagada");
    String preparationId = testClient.createPreparationFromDataset(tagadaId, "testPreparation", home.getId());
    // when : short format
    final JsonPath shortFormat = when().get("/api/preparations/?format=short&name={name}", "testPreparation").jsonPath();
    // then
    final List<String> values = shortFormat.getList("id");
    assertThat(values.get(0), is(preparationId));
}
Also used : JsonPath(com.jayway.restassured.path.json.JsonPath) Test(org.junit.Test)

Example 47 with JsonPath

use of com.jayway.restassured.path.json.JsonPath in project data-prep by Talend.

the class PreparationAPITest method testPreparationsList.

@Test
public void testPreparationsList() throws Exception {
    // given
    String tagadaId = testClient.createDataset("dataset/dataset.csv", "tagada");
    String preparationId = testClient.createPreparationFromDataset(tagadaId, "testPreparation", home.getId());
    // when : short format
    final JsonPath shortFormat = when().get("/api/preparations/?format=short").jsonPath();
    // then
    final List<String> values = shortFormat.getList("id");
    assertThat(values.get(0), is(preparationId));
    // when : long format
    Response response1 = when().get("/api/preparations/?format=long");
    // then
    List<PreparationListItemDTO> preparations = mapper.readerFor(PreparationListItemDTO.class).<PreparationListItemDTO>readValues(response1.asInputStream()).readAll();
    assertEquals(1, preparations.size());
    PreparationListItemDTO userPreparation = preparations.iterator().next();
    assertThat(userPreparation.getDataSet().getDataSetName(), is("tagada"));
    assertThat(userPreparation.getId(), is(preparationId));
    // when : summary format
    Response response = when().get("/api/preparations/?format=summary");
    // then
    List<PreparationListItemDTO> preparationSummaries = mapper.readerFor(PreparationListItemDTO.class).<PreparationListItemDTO>readValues(response.asInputStream()).readAll();
    assertEquals(1, preparationSummaries.size());
    PreparationListItemDTO preparationSummary = preparationSummaries.iterator().next();
    assertThat(preparationSummary.getId(), is(preparationId));
    assertThat(preparationSummary.getName(), is("testPreparation"));
    assertThat(preparationSummary.getLastModificationDate(), is(notNullValue()));
}
Also used : Response(com.jayway.restassured.response.Response) JsonPath(com.jayway.restassured.path.json.JsonPath) PreparationListItemDTO(org.talend.dataprep.api.preparation.PreparationListItemDTO) Test(org.junit.Test)

Example 48 with JsonPath

use of com.jayway.restassured.path.json.JsonPath in project data-prep by Talend.

the class PreparationAPITest method testPreparationGet.

@Test
public void testPreparationGet() throws Exception {
    // when
    final String datasetId = testClient.createDataset("dataset/dataset.csv", "great dataset");
    final String preparationId = testClient.createPreparationFromDataset(datasetId, "1234", home.getId());
    // then
    final JsonPath longFormat = given().get("/api/preparations/{id}/details", preparationId).jsonPath();
    assertThat(longFormat.getString("dataSetId"), is(datasetId));
    assertThat(longFormat.getString("author"), is(security.getUserId()));
    assertThat(longFormat.getString("id"), is(preparationId));
    assertThat(longFormat.getList("actions").size(), is(0));
    assertThat(longFormat.getString("allowFullRun"), is("false"));
    // make sure the "steps" node is a string array
    final List<String> steps = longFormat.getList("steps");
    assertThat(steps.size(), is(1));
}
Also used : JsonPath(com.jayway.restassured.path.json.JsonPath) Test(org.junit.Test)

Example 49 with JsonPath

use of com.jayway.restassured.path.json.JsonPath in project data-prep by Talend.

the class PreparationAPITest method testPreparationsList_withFilterOnFolderPath.

@Test
public void testPreparationsList_withFilterOnFolderPath() throws Exception {
    // given
    String tagadaId = testClient.createDataset("dataset/dataset.csv", "tagada");
    String preparationName = "tagadaPreparation";
    String preparationId = testClient.createPreparationFromDataset(tagadaId, preparationName, home.getId());
    // when : short format
    final Response shouldNotBeEmpty = when().get("/api/preparations/?format=short&folder_path={folder_path}", "/");
    // then
    List<PreparationDTO> result = // 
    mapper.readerFor(// 
    PreparationDTO.class).<PreparationDTO>readValues(// 
    shouldNotBeEmpty.asInputStream()).readAll();
    assertThat(result.get(0).getId(), is(preparationId));
    // when
    final JsonPath shouldBeEmpty = when().get("/api/preparations/?format=short&folder_path={folder_path}", "/toto").jsonPath();
    // then
    assertThat(shouldBeEmpty.<String>getList("id"), is(empty()));
}
Also used : Response(com.jayway.restassured.response.Response) PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) JsonPath(com.jayway.restassured.path.json.JsonPath) Test(org.junit.Test)

Example 50 with JsonPath

use of com.jayway.restassured.path.json.JsonPath in project data-prep by Talend.

the class DatasetStep method thenTheDataSetIsCreatedWithColumns.

@Then("^I check that the dataSet \"(.*)\" is created with the following columns :$")
public void thenTheDataSetIsCreatedWithColumns(String datasetName, List<String> columns) throws IOException {
    Response response = api.getDataSetMetaData(context.getDatasetId(suffixName(datasetName)));
    response.then().statusCode(OK.value());
    final JsonPath jsonPath = response.body().jsonPath();
    final List<String> actual = jsonPath.getList("columns.name", String.class);
    checkColumnNames(datasetName, columns, actual);
}
Also used : Response(com.jayway.restassured.response.Response) JsonPath(com.jayway.restassured.path.json.JsonPath) Then(cucumber.api.java.en.Then)

Aggregations

JsonPath (com.jayway.restassured.path.json.JsonPath)87 Test (org.junit.Test)56 Response (com.jayway.restassured.response.Response)29 BaseRestTest (integration.BaseRestTest)11 BaseRestIntegrationTest (se.inera.intyg.webcert.web.web.controller.integrationtest.BaseRestIntegrationTest)10 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)9 Matchers.anyString (org.mockito.Matchers.anyString)8 ValidatableResponse (com.jayway.restassured.response.ValidatableResponse)6 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 Matchers.containsString (org.hamcrest.Matchers.containsString)6 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 Ignore (org.junit.Ignore)5 MongoDbSeed (integration.MongoDbSeed)4 HashMap (java.util.HashMap)3 Then (cucumber.api.java.en.Then)2 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)2 BaseMatcher (org.hamcrest.BaseMatcher)2 Description (org.hamcrest.Description)2 PreparationDTO (org.talend.dataprep.api.preparation.PreparationDTO)2