use of io.restassured.itest.java.objects.Message in project rest-assured by rest-assured.
the class MultiPartUploadITest method multiPartUploadingWorksForJsonObjects.
@Test
public void multiPartUploadingWorksForJsonObjects() throws Exception {
// Given
final Message message = new Message();
message.setMessage("Hello World");
// When
given().multiPart("text", message).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 CustomObjectMappingITest method using_explicit_custom_object_mapper.
@Test
public void using_explicit_custom_object_mapper() throws Exception {
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 + "##";
}
};
final Message returnedMessage = given().body(message, mapper).when().post("/reflect").as(Message.class, mapper);
assertThat(returnedMessage.getMessage(), equalTo("A message"));
assertThat(customSerializationUsed.get(), is(true));
assertThat(customDeserializationUsed.get(), is(true));
}
use of io.restassured.itest.java.objects.Message in project rest-assured by rest-assured.
the class CustomObjectMappingITest method using_default_object_mapper_type_if_specified.
@Test
public void using_default_object_mapper_type_if_specified() {
final Message message = new Message();
message.setMessage("A message");
RestAssured.config = RestAssuredConfig.config().objectMapperConfig(new ObjectMapperConfig(GSON));
final Message returnedMessage = given().body(message).when().post("/reflect").as(Message.class);
assertThat(returnedMessage.getMessage(), equalTo("A message"));
}
use of io.restassured.itest.java.objects.Message in project rest-assured by rest-assured.
the class CustomObjectMappingITest method using_as_specified_object.
@Test
public void using_as_specified_object() {
final Message message = new Message();
message.setMessage("A message");
RestAssured.config = RestAssuredConfig.config().objectMapperConfig(new ObjectMapperConfig(GSON));
final String returnedMessage = given().body(message).when().post("/reflect").as(Message.class).getMessage();
assertThat(returnedMessage, equalTo("A message"));
}
use of io.restassured.itest.java.objects.Message in project rest-assured by rest-assured.
the class TypeObjectMappingITest method shouldUseMapTypeWithObjectMappers.
@Test
public void shouldUseMapTypeWithObjectMappers() {
String expected = "A message";
final Message message = new Message();
message.setMessage(expected);
RestAssured.config = RestAssuredConfig.config().objectMapperConfig(new ObjectMapperConfig(mapperType));
Type type = new TypeToken<Map<String, String>>() {
}.getType();
final Map<String, String> returnedMessage = given().body(message).when().post("/reflect").as(type);
assertThat(returnedMessage.get("message"), equalTo(expected));
}
Aggregations