Search in sources :

Example 11 with JsonPath

use of com.jayway.restassured.path.json.JsonPath in project graylog2-server by Graylog2.

the class StreamsTest method createOrMatchingStreamWithTitleAndDescription.

@Test
public void createOrMatchingStreamWithTitleAndDescription() throws Exception {
    final int beforeCount = streamCount();
    final String streamTitle = "Another Test Stream";
    final String description = "This is a test stream.";
    final String matchingType = "OR";
    final JsonPath response = createStreamFromRequest(jsonResourceForMethod()).statusCode(201).body(".", containsAllKeys("stream_id")).extract().jsonPath();
    final String streamId = response.getString("stream_id");
    assertThat(streamId).isNotNull().isNotEmpty();
    final int afterCount = streamCount();
    assertThat(afterCount).isEqualTo(beforeCount + 1);
    getStream(streamId).statusCode(200).assertThat().body("title", equalTo(streamTitle)).body("disabled", equalTo(true)).body("matching_type", equalTo(matchingType)).body("description", equalTo(description));
}
Also used : JsonPath(com.jayway.restassured.path.json.JsonPath) Test(org.junit.Test) BaseRestTest(integration.BaseRestTest)

Example 12 with JsonPath

use of com.jayway.restassured.path.json.JsonPath in project docker-maven-plugin by fabric8io.

the class VersionIT method testVersion.

@Test
public void testVersion() {
    String versionExpected = System.getProperty("jolokia.version");
    String jolokiaUrl = System.getProperty("jolokia.url");
    RestAssured.baseURI = jolokiaUrl;
    RestAssured.defaultParser = Parser.JSON;
    System.out.println("Checking URL: " + jolokiaUrl);
    // Need to do it that way since Jolokia doesnt return application/json as mimetype by default
    JsonPath json = with(get("/version").asString());
    json.prettyPrint();
    assertEquals(versionExpected, json.get("value.agent"));
    // Alternatively, set the mime type before, then Rest-assured's fluent API can be used
    given().param("mimeType", "application/json").get("/version").then().assertThat().header("content-type", containsString("application/json")).body("value.agent", equalTo(versionExpected)).body("timestamp", lessThanOrEqualTo((int) (System.currentTimeMillis() / 1000))).body("status", equalTo(200)).body("value.protocol", equalTo("7.2")).body("value.config", notNullValue());
}
Also used : JsonPath(com.jayway.restassured.path.json.JsonPath) Test(org.junit.Test)

Example 13 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<String> result = mapper.readerFor(String.class).<String>readValues(shouldNotBeEmpty.asInputStream()).readAll();
    assertThat(result.get(0), is(preparationId));
    // when
    final JsonPath shouldBeEmpty = when().get("/api/preparations/?format=short&folder_path={folder_path}", "/toto").jsonPath();
    // then
    assertThat(shouldBeEmpty.<String>getList(""), is(empty()));
}
Also used : Response(com.jayway.restassured.response.Response) JsonPath(com.jayway.restassured.path.json.JsonPath) Test(org.junit.Test)

Example 14 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("");
    assertThat(values.get(0), is(preparationId));
    // when : long format
    Response response1 = when().get("/api/preparations/?format=long");
    // then
    List<UserPreparation> preparations = mapper.readerFor(UserPreparation.class).<UserPreparation>readValues(response1.asInputStream()).readAll();
    assertEquals(1, preparations.size());
    UserPreparation userPreparation = preparations.iterator().next();
    assertThat(userPreparation.getDataSetId(), is(tagadaId));
    assertThat(userPreparation.getAuthor(), is(security.getUserId()));
    assertThat(userPreparation.getId(), is(preparationId));
    assertThat(userPreparation.getActions(), is(empty()));
    // when : summary format
    Response response = when().get("/api/preparations/?format=summary");
    // then
    List<PreparationSummary> preparationSummaries = mapper.readerFor(PreparationSummary.class).<PreparationSummary>readValues(response.asInputStream()).readAll();
    assertEquals(1, preparationSummaries.size());
    PreparationSummary preparationSummary = preparationSummaries.iterator().next();
    assertThat(preparationSummary.getId(), is(preparationId));
    assertThat(preparationSummary.getName(), is("testPreparation"));
    assertThat(preparationSummary.getLastModificationDate(), is(notNullValue()));
    assertThat(preparationSummary.isAllowDistributedRun(), is(notNullValue()));
}
Also used : Response(com.jayway.restassured.response.Response) UserPreparation(org.talend.dataprep.preparation.service.UserPreparation) PreparationSummary(org.talend.dataprep.api.preparation.PreparationSummary) JsonPath(com.jayway.restassured.path.json.JsonPath) Test(org.junit.Test)

Example 15 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("");
    assertThat(values.get(0), is(preparationId));
}
Also used : JsonPath(com.jayway.restassured.path.json.JsonPath) Test(org.junit.Test)

Aggregations

JsonPath (com.jayway.restassured.path.json.JsonPath)83 Test (org.junit.Test)56 Response (com.jayway.restassured.response.Response)25 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 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)2 BaseMatcher (org.hamcrest.BaseMatcher)2 Description (org.hamcrest.Description)2 UserPreparation (org.talend.dataprep.preparation.service.UserPreparation)2 Application (org.talend.dataprep.transformation.Application)2