Search in sources :

Example 31 with MultipartBodyBuilder

use of org.springframework.http.client.MultipartBodyBuilder in project spring-framework by spring-projects.

the class RequestPartMethodArgumentResolverTests method personNotRequired.

@Test
void personNotRequired() {
    MethodParameter param = this.testMethod.annot(requestPart().notRequired()).arg(Person.class);
    ServerWebExchange exchange = createExchange(new MultipartBodyBuilder());
    Mono<Object> result = this.resolver.resolveArgument(param, new BindingContext(), exchange);
    StepVerifier.create(result).verifyComplete();
}
Also used : MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) ServerWebExchange(org.springframework.web.server.ServerWebExchange) MultipartBodyBuilder(org.springframework.http.client.MultipartBodyBuilder) MethodParameter(org.springframework.core.MethodParameter) BindingContext(org.springframework.web.reactive.BindingContext) Test(org.junit.jupiter.api.Test)

Example 32 with MultipartBodyBuilder

use of org.springframework.http.client.MultipartBodyBuilder in project spring-framework by spring-projects.

the class RequestPartMethodArgumentResolverTests method listPart.

@Test
void listPart() {
    MethodParameter param = this.testMethod.annot(requestPart()).arg(List.class, Part.class);
    MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder();
    bodyBuilder.part("name", new Person("Jones"));
    bodyBuilder.part("name", new Person("James"));
    List<Part> actual = resolveArgument(param, bodyBuilder);
    assertThat(partToUtf8String(actual.get(0))).isEqualTo("{\"name\":\"Jones\"}");
    assertThat(partToUtf8String(actual.get(1))).isEqualTo("{\"name\":\"James\"}");
}
Also used : MultipartBodyBuilder(org.springframework.http.client.MultipartBodyBuilder) RequestPart(org.springframework.web.bind.annotation.RequestPart) Part(org.springframework.http.codec.multipart.Part) MvcAnnotationPredicates.requestPart(org.springframework.web.testfixture.method.MvcAnnotationPredicates.requestPart) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.jupiter.api.Test)

Example 33 with MultipartBodyBuilder

use of org.springframework.http.client.MultipartBodyBuilder in project spring-framework by spring-projects.

the class RequestPartMethodArgumentResolverTests method partNotRequired.

@Test
void partNotRequired() {
    MethodParameter param = this.testMethod.annot(requestPart().notRequired()).arg(Part.class);
    ServerWebExchange exchange = createExchange(new MultipartBodyBuilder());
    Mono<Object> result = this.resolver.resolveArgument(param, new BindingContext(), exchange);
    StepVerifier.create(result).verifyComplete();
}
Also used : MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) ServerWebExchange(org.springframework.web.server.ServerWebExchange) MultipartBodyBuilder(org.springframework.http.client.MultipartBodyBuilder) MethodParameter(org.springframework.core.MethodParameter) BindingContext(org.springframework.web.reactive.BindingContext) Test(org.junit.jupiter.api.Test)

Example 34 with MultipartBodyBuilder

use of org.springframework.http.client.MultipartBodyBuilder in project spring-framework by spring-projects.

the class RequestPartMethodArgumentResolverTests method listPerson.

@Test
void listPerson() {
    MethodParameter param = this.testMethod.annot(requestPart()).arg(List.class, Person.class);
    MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder();
    bodyBuilder.part("name", Arrays.asList(new Person("Jones"), new Person("James")));
    List<Person> actual = resolveArgument(param, bodyBuilder);
    assertThat(actual.get(0).getName()).isEqualTo("Jones");
    assertThat(actual.get(1).getName()).isEqualTo("James");
}
Also used : MultipartBodyBuilder(org.springframework.http.client.MultipartBodyBuilder) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.jupiter.api.Test)

Example 35 with MultipartBodyBuilder

use of org.springframework.http.client.MultipartBodyBuilder in project spring-framework by spring-projects.

the class RequestPartMethodArgumentResolverTests method fluxPerson.

@Test
void fluxPerson() {
    MethodParameter param = this.testMethod.annot(requestPart()).arg(Flux.class, Person.class);
    MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder();
    bodyBuilder.part("name", new Person("Jones"));
    bodyBuilder.part("name", new Person("James"));
    Flux<Person> actual = resolveArgument(param, bodyBuilder);
    List<Person> persons = actual.collectList().block();
    assertThat(persons.get(0).getName()).isEqualTo("Jones");
    assertThat(persons.get(1).getName()).isEqualTo("James");
}
Also used : MultipartBodyBuilder(org.springframework.http.client.MultipartBodyBuilder) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.jupiter.api.Test)

Aggregations

MultipartBodyBuilder (org.springframework.http.client.MultipartBodyBuilder)36 Test (org.junit.jupiter.api.Test)34 MethodParameter (org.springframework.core.MethodParameter)18 Part (org.springframework.http.codec.multipart.Part)7 RequestPart (org.springframework.web.bind.annotation.RequestPart)7 MvcAnnotationPredicates.requestPart (org.springframework.web.testfixture.method.MvcAnnotationPredicates.requestPart)7 ClassPathResource (org.springframework.core.io.ClassPathResource)4 MultiValueMap (org.springframework.util.MultiValueMap)4 BindingContext (org.springframework.web.reactive.BindingContext)4 ServerWebExchange (org.springframework.web.server.ServerWebExchange)4 MockServerWebExchange (org.springframework.web.testfixture.server.MockServerWebExchange)4 Resource (org.springframework.core.io.Resource)3 DataBuffer (org.springframework.core.io.buffer.DataBuffer)3 ServerWebInputException (org.springframework.web.server.ServerWebInputException)2 HttpEntity (org.springframework.http.HttpEntity)1 HttpHeaders (org.springframework.http.HttpHeaders)1 MediaType (org.springframework.http.MediaType)1 MultipartHttpMessageReader (org.springframework.http.codec.multipart.MultipartHttpMessageReader)1 MultipartHttpMessageWriter (org.springframework.http.codec.multipart.MultipartHttpMessageWriter)1 WebTestClient (org.springframework.test.web.reactive.server.WebTestClient)1