Search in sources :

Example 6 with Message

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

the class LoggingITest method logBodyWithPrettyPrintingUsingRequestLogSpecAndObjectMapping.

@Test
public void logBodyWithPrettyPrintingUsingRequestLogSpecAndObjectMapping() throws Exception {
    final StringWriter writer = new StringWriter();
    final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
    final Message message = new Message();
    message.setMessage("My message");
    given().contentType(ContentType.JSON).config(config().logConfig(new LogConfig(captor, true))).log().body().body(message).when().post("/body");
    assertThat(writer.toString(), equalTo("Body:\n{\n    \"message\": \"My message\"\n}" + LINE_SEPARATOR));
}
Also used : PrintStream(java.io.PrintStream) StringWriter(java.io.StringWriter) Message(io.restassured.itest.java.objects.Message) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) LogConfig(io.restassured.config.LogConfig) Test(org.junit.Test)

Example 7 with Message

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

the class MultiPartUploadITest method multiPartUploadingWorksForJsonObjectsWhenMimeTypeIsSpecified.

@Test
public void multiPartUploadingWorksForJsonObjectsWhenMimeTypeIsSpecified() throws Exception {
    // Given
    final Message message = new Message();
    message.setMessage("Hello World");
    // When
    given().multiPart("text", message, "application/some+json").expect().statusCode(200).body(is("{\"message\":\"Hello World\"}")).when().post("/multipart/text");
}
Also used : Message(io.restassured.itest.java.objects.Message) Test(org.junit.Test)

Example 8 with Message

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

the class ObjectMappingITest method mapResponseToObjectUsingJacksonWhenNoContentTypeIsDefined.

@Test
public void mapResponseToObjectUsingJacksonWhenNoContentTypeIsDefined() throws Exception {
    final Message message = expect().defaultParser(JSON).when().get("/noContentTypeJsonCompatible").as(Message.class);
    assertThat(message.getMessage(), equalTo("It works"));
}
Also used : Message(io.restassured.itest.java.objects.Message) Test(org.junit.Test)

Example 9 with Message

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

the class ObjectMappingITest method contentTypesEndingWithPlusJsonWorksForJsonObjectMapping.

@Test
public void contentTypesEndingWithPlusJsonWorksForJsonObjectMapping() throws Exception {
    final Message message = get("/mimeTypeWithPlusJson").as(Message.class);
    assertThat(message.getMessage(), equalTo("It works"));
}
Also used : Message(io.restassured.itest.java.objects.Message) Test(org.junit.Test)

Example 10 with Message

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

the class CustomObjectMappingITest method using_custom_object_mapper_statically.

@Test
public void using_custom_object_mapper_statically() {
    final Message message = new Message();
    message.setMessage("A message");
    final ObjectMapper mapper = new ObjectMapper() {

        public Object deserialize(ObjectMapperDeserializationContext context) {
            final String toDeserialize = context.getDataToDeserialize().asString();
            final String unquoted = StringUtils.remove(toDeserialize, "##");
            final Message message = new Message();
            message.setMessage(unquoted);
            customDeserializationUsed.set(true);
            return message;
        }

        public Object serialize(ObjectMapperSerializationContext context) {
            final Message objectToSerialize = context.getObjectToSerializeAs(Message.class);
            final String message = objectToSerialize.getMessage();
            customSerializationUsed.set(true);
            return "##" + message + "##";
        }
    };
    RestAssured.config = RestAssuredConfig.config().objectMapperConfig(new ObjectMapperConfig(mapper));
    final Message returnedMessage = given().body(message).when().post("/reflect").as(Message.class);
    assertThat(returnedMessage.getMessage(), equalTo("A message"));
    assertThat(customSerializationUsed.get(), is(true));
    assertThat(customDeserializationUsed.get(), is(true));
}
Also used : ObjectMapperConfig(io.restassured.config.ObjectMapperConfig) Message(io.restassured.itest.java.objects.Message) ObjectMapperDeserializationContext(io.restassured.mapper.ObjectMapperDeserializationContext) ObjectMapperSerializationContext(io.restassured.mapper.ObjectMapperSerializationContext) ObjectMapper(io.restassured.mapper.ObjectMapper) Test(org.junit.Test)

Aggregations

Message (io.restassured.itest.java.objects.Message)10 Test (org.junit.Test)10 ObjectMapperConfig (io.restassured.config.ObjectMapperConfig)4 ObjectMapper (io.restassured.mapper.ObjectMapper)2 ObjectMapperDeserializationContext (io.restassured.mapper.ObjectMapperDeserializationContext)2 ObjectMapperSerializationContext (io.restassured.mapper.ObjectMapperSerializationContext)2 LogConfig (io.restassured.config.LogConfig)1 ObjectMapperType (io.restassured.mapper.ObjectMapperType)1 PrintStream (java.io.PrintStream)1 StringWriter (java.io.StringWriter)1 Type (java.lang.reflect.Type)1 Map (java.util.Map)1 WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)1