Search in sources :

Example 1 with ScalatraObject

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

the class LoggingITest method loggingRequestAndResponseAtTheSameTimeWhenResponseFilterIsAddedBeforeRequestFilter.

@Test
public void loggingRequestAndResponseAtTheSameTimeWhenResponseFilterIsAddedBeforeRequestFilter() 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().filters(new ResponseLoggingFilter(captor), new RequestLoggingFilter(captor)).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 + "HTTP/1.1 200 OK\nContent-Type: text/plain;charset=iso-8859-1\nContent-Length: 23\nServer: Jetty(9.3.2.v20150730)\n\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) ResponseLoggingFilter(io.restassured.filter.log.ResponseLoggingFilter) Test(org.junit.Test)

Example 2 with ScalatraObject

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

the class ObjectMappingITest method mapResponseToObjectUsingGsonWithGsonObjectMapperDefined.

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

Example 3 with ScalatraObject

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

the class ObjectMappingITest method whenNoRequestContentTypeIsSpecifiedThenRestAssuredSerializesToJSON.

@Test
public void whenNoRequestContentTypeIsSpecifiedThenRestAssuredSerializesToJSON() throws Exception {
    final ScalatraObject object = new ScalatraObject();
    object.setHello("Hello world");
    final ScalatraObject actual = expect().defaultParser(JSON).given().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 4 with ScalatraObject

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

the class ObjectMappingITest method mapResponseToObjectUsingJackson.

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

Example 5 with ScalatraObject

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

the class LoggingITest method loggingRequestAndResponseAtTheSameTimeWhenRequestFilterIsAddedBeforeResponseFilter.

@Test
public void loggingRequestAndResponseAtTheSameTimeWhenRequestFilterIsAddedBeforeResponseFilter() 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().filters(new RequestLoggingFilter(captor), new ResponseLoggingFilter(captor)).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 + "HTTP/1.1 200 OK\nContent-Type: text/plain;charset=iso-8859-1\nContent-Length: 23\nServer: Jetty(9.3.2.v20150730)\n\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) ResponseLoggingFilter(io.restassured.filter.log.ResponseLoggingFilter) 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