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));
}
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");
}
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"));
}
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"));
}
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));
}
Aggregations