Search in sources :

Example 6 with ScalatraObject

use of io.restassured.itest.java.objects.ScalatraObject in project rest-assured by rest-assured.

the class LoggingITest method loggingRequestFilterWithBody.

@Test
public void loggingRequestFilterWithBody() throws Exception {
    final StringWriter writer = new StringWriter();
    final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
    final ScalatraObject object = new ScalatraObject();
    object.setHello("Hello world");
    given().filter(new RequestLoggingFilter(captor)).and().body(object).expect().defaultParser(JSON).when().post("/reflect");
    assertThat(writer.toString(), equalTo("Request method:\tPOST\nRequest URI:\thttp://localhost:8080/reflect\nProxy:\t\t\t<none>\nRequest params:\t<none>\nQuery params:\t<none>\nForm params:\t<none>\nPath params:\t<none>\nHeaders:\t\tAccept=*/*\n\t\t\t\tContent-Type=text/plain; charset=" + RestAssured.config().getEncoderConfig().defaultContentCharset() + "\nCookies:\t\t<none>\nMultiparts:\t\t<none>\nBody:\n{\"hello\":\"Hello world\"}" + LINE_SEPARATOR));
}
Also used : PrintStream(java.io.PrintStream) ScalatraObject(io.restassured.itest.java.objects.ScalatraObject) StringWriter(java.io.StringWriter) RequestLoggingFilter(io.restassured.filter.log.RequestLoggingFilter) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) Test(org.junit.Test)

Example 7 with ScalatraObject

use of io.restassured.itest.java.objects.ScalatraObject in project rest-assured by rest-assured.

the class ObjectMappingITest method mapResponseToObjectUsingJackson2WithJacksonObjectMapperDefined.

@Test
public void mapResponseToObjectUsingJackson2WithJacksonObjectMapperDefined() throws Exception {
    final ScalatraObject object = get("/hello").as(ScalatraObject.class, ObjectMapperType.JACKSON_2);
    assertThat(object.getHello(), equalTo("Hello Scalatra"));
}
Also used : ScalatraObject(io.restassured.itest.java.objects.ScalatraObject) Test(org.junit.Test)

Example 8 with ScalatraObject

use of io.restassured.itest.java.objects.ScalatraObject in project rest-assured by rest-assured.

the class ObjectMappingITest method whenRequestContentTypeIsJsonThenRestAssuredSerializesToJSON.

@Test
public void whenRequestContentTypeIsJsonThenRestAssuredSerializesToJSON() throws Exception {
    final ScalatraObject object = new ScalatraObject();
    object.setHello("Hello world");
    final ScalatraObject actual = given().contentType(ContentType.JSON).and().body(object).when().post("/reflect").as(ScalatraObject.class);
    assertThat(object, equalTo(actual));
}
Also used : ScalatraObject(io.restassured.itest.java.objects.ScalatraObject) Test(org.junit.Test)

Example 9 with ScalatraObject

use of io.restassured.itest.java.objects.ScalatraObject in project rest-assured by rest-assured.

the class ObjectMappingITest method mapResponseToObjectUsingJackson1WithJacksonObjectMapperDefined.

@Test
public void mapResponseToObjectUsingJackson1WithJacksonObjectMapperDefined() throws Exception {
    final ScalatraObject object = get("/hello").as(ScalatraObject.class, ObjectMapperType.JACKSON_1);
    assertThat(object.getHello(), equalTo("Hello Scalatra"));
}
Also used : ScalatraObject(io.restassured.itest.java.objects.ScalatraObject) Test(org.junit.Test)

Aggregations

ScalatraObject (io.restassured.itest.java.objects.ScalatraObject)9 Test (org.junit.Test)9 RequestLoggingFilter (io.restassured.filter.log.RequestLoggingFilter)3 PrintStream (java.io.PrintStream)3 StringWriter (java.io.StringWriter)3 WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)3 ResponseLoggingFilter (io.restassured.filter.log.ResponseLoggingFilter)2