Search in sources :

Example 11 with Greeting

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

the class ObjectMappingITest method whenRequestContentTypeIsJsonAndCharsetIsUtf16ThenRestAssuredSerializesToJSON.

@Test
public void whenRequestContentTypeIsJsonAndCharsetIsUtf16ThenRestAssuredSerializesToJSON() throws Exception {
    final Greeting object = new Greeting();
    object.setFirstName("John");
    object.setLastName("Doe");
    final Greeting actual = given().contentType("application/json; charset=UTF-16").and().body(object).when().post("/reflect").as(Greeting.class);
    assertThat(object, equalTo(actual));
}
Also used : Greeting(io.restassured.itest.java.objects.Greeting) Test(org.junit.Test)

Example 12 with Greeting

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

the class ObjectMappingITest method serializesUsingJAXBWhenJAXBObjectMapperIsSpecified.

@Test
public void serializesUsingJAXBWhenJAXBObjectMapperIsSpecified() throws Exception {
    final Greeting object = new Greeting();
    object.setFirstName("John");
    object.setLastName("Doe");
    final Greeting actual = given().body(object, ObjectMapperType.JAXB).when().post("/reflect").as(Greeting.class, ObjectMapperType.JAXB);
    assertThat(object, equalTo(actual));
}
Also used : Greeting(io.restassured.itest.java.objects.Greeting) Test(org.junit.Test)

Example 13 with Greeting

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

the class ObjectMappingITest method mapResponseToObjectUsingJaxb.

@Test
public void mapResponseToObjectUsingJaxb() throws Exception {
    final Greeting object = given().parameters("firstName", "John", "lastName", "Doe").when().get("/greetXML").as(Greeting.class);
    assertThat(object.getFirstName(), equalTo("John"));
    assertThat(object.getLastName(), equalTo("Doe"));
}
Also used : Greeting(io.restassured.itest.java.objects.Greeting) Test(org.junit.Test)

Example 14 with Greeting

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

the class ObjectMappingITest method serializesUsingJacksonWhenJacksonObjectMapperIsSpecified.

@Test
public void serializesUsingJacksonWhenJacksonObjectMapperIsSpecified() throws Exception {
    final Greeting object = new Greeting();
    object.setFirstName("John");
    object.setLastName("Doe");
    final Greeting actual = given().body(object, ObjectMapperType.JACKSON_1).when().post("/reflect").as(Greeting.class, ObjectMapperType.JACKSON_1);
    assertThat(object, equalTo(actual));
}
Also used : Greeting(io.restassured.itest.java.objects.Greeting) Test(org.junit.Test)

Example 15 with Greeting

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

the class CustomObjectMappingITest method using_custom_object_mapper_factory.

@Test
public void using_custom_object_mapper_factory() {
    final Greeting greeting = new Greeting();
    greeting.setFirstName("John");
    greeting.setLastName("Doe");
    RestAssured.config = RestAssuredConfig.config().objectMapperConfig(objectMapperConfig().gsonObjectMapperFactory(new GsonObjectMapperFactory() {

        public Gson create(Type cls, String charset) {
            return new GsonBuilder().setFieldNamingPolicy(LOWER_CASE_WITH_UNDERSCORES).create();
        }
    }));
    final Greeting returnedGreeting = given().contentType("application/json").body(greeting, GSON).expect().body("first_name", equalTo("John")).when().post("/reflect").as(Greeting.class, GSON);
    assertThat(returnedGreeting.getFirstName(), equalTo("John"));
    assertThat(returnedGreeting.getLastName(), equalTo("Doe"));
}
Also used : Greeting(io.restassured.itest.java.objects.Greeting) Type(java.lang.reflect.Type) GsonObjectMapperFactory(io.restassured.mapper.factory.GsonObjectMapperFactory) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) Test(org.junit.Test)

Aggregations

Greeting (io.restassured.itest.java.objects.Greeting)24 Test (org.junit.Test)24 MultiPartSpecBuilder (io.restassured.builder.MultiPartSpecBuilder)6 PrintStream (java.io.PrintStream)2 StringWriter (java.io.StringWriter)2 Type (java.lang.reflect.Type)2 WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 LogConfig (io.restassured.config.LogConfig)1 Jackson2Mapper (io.restassured.internal.mapping.Jackson2Mapper)1 DefaultJackson2ObjectMapperFactory (io.restassured.mapper.factory.DefaultJackson2ObjectMapperFactory)1 GsonObjectMapperFactory (io.restassured.mapper.factory.GsonObjectMapperFactory)1 InputStream (java.io.InputStream)1 Map (java.util.Map)1