use of org.springframework.http.client.MultipartBodyBuilder in project spring-framework by spring-projects.
the class MultipartControllerTests method multipartRequestWithFileArray.
@Test
public void multipartRequestWithFileArray() throws Exception {
byte[] fileContent = "bar".getBytes(StandardCharsets.UTF_8);
Map<String, String> json = Collections.singletonMap("name", "yeeeah");
MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder();
bodyBuilder.part("file", fileContent).filename("orig");
bodyBuilder.part("file", fileContent).filename("orig");
bodyBuilder.part("json", json, MediaType.APPLICATION_JSON);
EntityExchangeResult<Void> exchangeResult = testClient.post().uri("/multipartfilearray").bodyValue(bodyBuilder.build()).exchange().expectStatus().isFound().expectBody().isEmpty();
// Further assertions on the server response
MockMvcWebTestClient.resultActionsFor(exchangeResult).andExpect(model().attribute("fileContent", fileContent)).andExpect(model().attribute("jsonContent", json));
}
use of org.springframework.http.client.MultipartBodyBuilder in project spring-framework by spring-projects.
the class RequestPartMethodArgumentResolverTests method part.
@Test
void part() {
MethodParameter param = this.testMethod.annot(requestPart()).arg(Part.class);
MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder();
bodyBuilder.part("name", new Person("Jones"));
Part actual = resolveArgument(param, bodyBuilder);
DataBuffer buffer = DataBufferUtils.join(actual.content()).block();
assertThat(buffer.toString(UTF_8)).isEqualTo("{\"name\":\"Jones\"}");
}
use of org.springframework.http.client.MultipartBodyBuilder in project spring-framework by spring-projects.
the class MultipartHttpMessageWriterTests method singleSubscriberWithStrings.
// SPR-16402
@Test
public void singleSubscriberWithStrings() {
@SuppressWarnings("deprecation") reactor.core.publisher.UnicastProcessor<String> processor = reactor.core.publisher.UnicastProcessor.create();
Flux.just("foo", "bar", "baz").subscribe(processor);
MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder();
bodyBuilder.asyncPart("name", processor, String.class);
Mono<MultiValueMap<String, HttpEntity<?>>> result = Mono.just(bodyBuilder.build());
this.writer.write(result, null, MediaType.MULTIPART_FORM_DATA, this.response, Collections.emptyMap()).block(Duration.ofSeconds(5));
// Make sure body is consumed to avoid leak reports
this.response.getBodyAsString().block(Duration.ofSeconds(5));
}
use of org.springframework.http.client.MultipartBodyBuilder in project spring-framework by spring-projects.
the class MultipartIntegrationTests method generateBody.
private MultiValueMap<String, HttpEntity<?>> generateBody() {
MultipartBodyBuilder builder = new MultipartBodyBuilder();
builder.part("fieldPart", "fieldValue");
builder.part("fileParts", new ClassPathResource("foo.txt", MultipartHttpMessageReader.class));
builder.part("fileParts", new ClassPathResource("logo.png", getClass()));
builder.part("jsonPart", new Person("Jason"));
return builder.build();
}
use of org.springframework.http.client.MultipartBodyBuilder in project spring-framework by spring-projects.
the class RequestPartMethodArgumentResolverTests method partRequired.
@Test
void partRequired() {
MethodParameter param = this.testMethod.annot(requestPart()).arg(Part.class);
ServerWebExchange exchange = createExchange(new MultipartBodyBuilder());
Mono<Object> result = this.resolver.resolveArgument(param, new BindingContext(), exchange);
StepVerifier.create(result).expectError(ServerWebInputException.class).verify();
}
Aggregations