Search in sources :

Example 6 with JsonPath

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

the class StreamsTest method createStreamByTitleOnly.

@Test
public void createStreamByTitleOnly() throws Exception {
    final int beforeCount = streamCount();
    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("TestStream")).body("disabled", equalTo(true)).body("matching_type", equalTo("AND")).body("description", equalTo(null));
}
Also used : JsonPath(com.jayway.restassured.path.json.JsonPath) Test(org.junit.Test) BaseRestTest(integration.BaseRestTest)

Example 7 with JsonPath

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

the class StreamsTest method createStreamWithTitleAndDescription.

@Test
public void createStreamWithTitleAndDescription() throws Exception {
    final int beforeCount = streamCount();
    final String streamTitle = "Another Test Stream";
    final String description = "This is a test stream.";
    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("AND")).body("description", equalTo(description));
}
Also used : JsonPath(com.jayway.restassured.path.json.JsonPath) Test(org.junit.Test) BaseRestTest(integration.BaseRestTest)

Example 8 with JsonPath

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

the class StreamsTest method updatingNonexistendStreamShouldFail.

@Test
@MongoDbSeed(locations = { "single-stream", "second-single-stream" })
public void updatingNonexistendStreamShouldFail() {
    // id of nonexistent stream to be updated
    final String streamId = "55affeaffeaffeaffeaffeaf";
    // id of stream that is supposed to be left untampered
    final String otherStreamId = "552b92b2e4b0c055e41ffb8e";
    given().when().body("{\"title\":\"foo\", \"description\":\"bar\", \"index_set_id\":\"582f3c4e43761335e4859f72\"}").put("/streams/" + streamId).then().statusCode(404);
    final JsonPath otherStreamResponse = given().when().get("/streams/" + otherStreamId).then().statusCode(200).extract().jsonPath();
    assertThat(otherStreamResponse.getString("title")).isEqualTo("Just a stream");
    assertThat(otherStreamResponse.getString("description")).isEqualTo("This is just a stream");
}
Also used : JsonPath(com.jayway.restassured.path.json.JsonPath) Test(org.junit.Test) BaseRestTest(integration.BaseRestTest) MongoDbSeed(integration.MongoDbSeed)

Example 9 with JsonPath

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

the class StreamsTest method updatingTitleOfSingleStream.

@Test
@MongoDbSeed(locations = { "single-stream", "second-single-stream" })
public void updatingTitleOfSingleStream() {
    // id of stream to be updated
    final String streamId = "552b92b2e4b0c055e41ffb8d";
    // id of stream that is supposed to be left untampered
    final String otherStreamId = "552b92b2e4b0c055e41ffb8e";
    assertThat(streamCount()).isEqualTo(2);
    final JsonPath response = given().when().body(jsonResourceForMethod()).put("/streams/" + streamId).then().statusCode(200).contentType(ContentType.JSON).extract().jsonPath();
    assertThat(response.getString("title")).isEqualTo("Updated Title");
    assertThat(response.getString("description")).isEqualTo("This is yet another stream");
    final JsonPath getResponse = given().when().get("/streams/" + streamId).then().statusCode(200).extract().jsonPath();
    assertThat(getResponse.getString("title")).isEqualTo("Updated Title");
    assertThat(getResponse.getString("description")).isEqualTo("This is yet another stream");
    final JsonPath otherStreamResponse = given().when().get("/streams/" + otherStreamId).then().statusCode(200).extract().jsonPath();
    assertThat(otherStreamResponse.getString("title")).isEqualTo("Just a stream");
    assertThat(otherStreamResponse.getString("description")).isEqualTo("This is just a stream");
}
Also used : JsonPath(com.jayway.restassured.path.json.JsonPath) Test(org.junit.Test) BaseRestTest(integration.BaseRestTest) MongoDbSeed(integration.MongoDbSeed)

Example 10 with JsonPath

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

the class StreamsTest method updatingUsingInvalidMatchingTypeOfStreamShouldFail.

@Test
@MongoDbSeed(locations = { "single-stream", "second-single-stream" })
public void updatingUsingInvalidMatchingTypeOfStreamShouldFail() {
    final String streamId = "552b92b2e4b0c055e41ffb8d";
    given().when().body("{\"matching_type\":\"INVALID\"}").put("/streams/" + streamId).then().statusCode(400);
    final JsonPath getResponse = getStream(streamId).statusCode(200).extract().jsonPath();
    assertThat(getResponse.getString("matching_type")).isEqualTo("AND");
}
Also used : JsonPath(com.jayway.restassured.path.json.JsonPath) Test(org.junit.Test) BaseRestTest(integration.BaseRestTest) MongoDbSeed(integration.MongoDbSeed)

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