Search in sources :

Example 1 with Greeting

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

the class LoggingITest method logBodyWithPrettyPrintingUsingRequestLogSpecAndObjectMappingWhenXML.

@Test
public void logBodyWithPrettyPrintingUsingRequestLogSpecAndObjectMappingWhenXML() throws Exception {
    final StringWriter writer = new StringWriter();
    final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
    final Greeting greeting = new Greeting();
    greeting.setFirstName("John");
    greeting.setLastName("Doe");
    given().contentType(ContentType.XML).config(config().logConfig(new LogConfig(captor, true))).log().body().body(greeting).when().post("/body");
    assertThat(writer.toString(), equalTo("Body:\n<greeting>\n  <firstName>John</firstName>\n  <lastName>Doe</lastName>\n</greeting>" + LINE_SEPARATOR));
}
Also used : PrintStream(java.io.PrintStream) Greeting(io.restassured.itest.java.objects.Greeting) StringWriter(java.io.StringWriter) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) LogConfig(io.restassured.config.LogConfig) Test(org.junit.Test)

Example 2 with Greeting

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

the class MultiPartUploadITest method multiPartSupportsSpecifyingAnObjectMapperToMultiPartSpecBuilder.

@Test
public void multiPartSupportsSpecifyingAnObjectMapperToMultiPartSpecBuilder() throws Exception {
    // Given
    final Greeting greeting = new Greeting();
    greeting.setFirstName("John");
    greeting.setLastName("Doe");
    // When
    given().multiPart(new MultiPartSpecBuilder(greeting, new Jackson2Mapper(new DefaultJackson2ObjectMapperFactory())).fileName("RoleBasedAccessFeaturePlan.csv").controlName("text").mimeType("application/vnd.ms-excel").build()).when().post("/multipart/text").then().statusCode(200).body(containsString("John"), containsString("Doe"), containsString("{"));
}
Also used : Greeting(io.restassured.itest.java.objects.Greeting) MultiPartSpecBuilder(io.restassured.builder.MultiPartSpecBuilder) DefaultJackson2ObjectMapperFactory(io.restassured.mapper.factory.DefaultJackson2ObjectMapperFactory) Jackson2Mapper(io.restassured.internal.mapping.Jackson2Mapper) Test(org.junit.Test)

Example 3 with Greeting

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

the class MultiPartUploadITest method multiPartUploadingUsesEncoderConfigToKnowHowToSerializeCustomMimeTypesToJson.

@Test
public void multiPartUploadingUsesEncoderConfigToKnowHowToSerializeCustomMimeTypesToJson() throws Exception {
    // Given
    final Greeting greeting = new Greeting();
    greeting.setFirstName("John");
    greeting.setLastName("Doe");
    // When
    given().config(config().encoderConfig(EncoderConfig.encoderConfig().encodeContentTypeAs("application/vnd.ms-excel", ContentType.JSON))).multiPart(new MultiPartSpecBuilder(greeting).fileName("RoleBasedAccessFeaturePlan.csv").controlName("text").mimeType("application/vnd.ms-excel").build()).when().post("/multipart/text").then().statusCode(200).body(containsString("John"), containsString("Doe"), containsString("{"));
}
Also used : Greeting(io.restassured.itest.java.objects.Greeting) MultiPartSpecBuilder(io.restassured.builder.MultiPartSpecBuilder) Test(org.junit.Test)

Example 4 with Greeting

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

the class MultiPartUploadITest method multiPartUploadingThrowsExceptionWhenUsingEncoderConfigToSpecifyNonSerializableContentType.

@Test
public void multiPartUploadingThrowsExceptionWhenUsingEncoderConfigToSpecifyNonSerializableContentType() throws Exception {
    // Given
    exception.expect(IllegalArgumentException.class);
    exception.expectMessage("Cannot serialize because cannot determine how to serialize content-type application/vnd.ms-excel as HTML (no serializer supports this format)");
    final Greeting greeting = new Greeting();
    greeting.setFirstName("John");
    greeting.setLastName("Doe");
    // When
    given().config(config().encoderConfig(EncoderConfig.encoderConfig().encodeContentTypeAs("application/vnd.ms-excel", ContentType.HTML))).multiPart(new MultiPartSpecBuilder(greeting).fileName("RoleBasedAccessFeaturePlan.csv").controlName("text").mimeType("application/vnd.ms-excel").build()).when().post("/multipart/text");
}
Also used : Greeting(io.restassured.itest.java.objects.Greeting) MultiPartSpecBuilder(io.restassured.builder.MultiPartSpecBuilder) Test(org.junit.Test)

Example 5 with Greeting

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

the class MultiPartUploadITest method multiPartSupportsSpecifyingAnObjectMapperTypeToMultiPartSpecBuilder.

@Test
public void multiPartSupportsSpecifyingAnObjectMapperTypeToMultiPartSpecBuilder() throws Exception {
    // Given
    final Greeting greeting = new Greeting();
    greeting.setFirstName("John");
    greeting.setLastName("Doe");
    // When
    given().multiPart(new MultiPartSpecBuilder(greeting, ObjectMapperType.JACKSON_2).fileName("RoleBasedAccessFeaturePlan.csv").controlName("text").mimeType("application/vnd.ms-excel").build()).when().post("/multipart/text").then().statusCode(200).body(containsString("John"), containsString("Doe"), containsString("{"));
}
Also used : Greeting(io.restassured.itest.java.objects.Greeting) MultiPartSpecBuilder(io.restassured.builder.MultiPartSpecBuilder) 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