Search in sources :

Example 1 with MultiPartSpecBuilder

use of io.restassured.builder.MultiPartSpecBuilder 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 2 with MultiPartSpecBuilder

use of io.restassured.builder.MultiPartSpecBuilder 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 3 with MultiPartSpecBuilder

use of io.restassured.builder.MultiPartSpecBuilder 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 4 with MultiPartSpecBuilder

use of io.restassured.builder.MultiPartSpecBuilder 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)

Example 5 with MultiPartSpecBuilder

use of io.restassured.builder.MultiPartSpecBuilder in project rest-assured by rest-assured.

the class MultiPartUploadITest method multiPartUploadingUsesEncoderConfigToKnowHowToSerializeCustomMimeTypesToXml.

@Test
public void multiPartUploadingUsesEncoderConfigToKnowHowToSerializeCustomMimeTypesToXml() 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.XML))).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)

Aggregations

MultiPartSpecBuilder (io.restassured.builder.MultiPartSpecBuilder)18 Test (org.junit.Test)17 InputStream (java.io.InputStream)9 Greeting (io.restassured.itest.java.objects.Greeting)6 NoAuthScheme (io.restassured.authentication.NoAuthScheme)1 RequestSpecificationImpl (io.restassured.internal.RequestSpecificationImpl)1 FilterContextImpl (io.restassured.internal.filter.FilterContextImpl)1 Jackson2Mapper (io.restassured.internal.mapping.Jackson2Mapper)1 DefaultJackson2ObjectMapperFactory (io.restassured.mapper.factory.DefaultJackson2ObjectMapperFactory)1 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)1