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("fooPart", resource);
builder.part("barPart", "bar");
return builder.build();
}
use of org.springframework.http.client.MultipartBodyBuilder in project spring-framework by spring-projects.
the class CancelWithoutDemandCodecTests method cancelWithMultipartContent.
// gh-22107
@Test
public void cancelWithMultipartContent() {
MultipartBodyBuilder builder = new MultipartBodyBuilder();
builder.part("part1", "value1");
builder.part("part2", "value2");
List<HttpMessageWriter<?>> writers = ClientCodecConfigurer.create().getWriters();
MultipartHttpMessageWriter writer = new MultipartHttpMessageWriter(writers);
CancellingOutputMessage outputMessage = new CancellingOutputMessage(this.bufferFactory);
writer.write(Mono.just(builder.build()), null, MediaType.MULTIPART_FORM_DATA, outputMessage, Collections.emptyMap()).block(Duration.ofSeconds(5));
}
use of org.springframework.http.client.MultipartBodyBuilder in project spring-framework by spring-projects.
the class MultipartControllerTests method multipartRequestWithOptionalFileNotPresent.
@Test
public void multipartRequestWithOptionalFileNotPresent() throws Exception {
Map<String, String> json = Collections.singletonMap("name", "yeeeah");
MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder();
bodyBuilder.part("json", json, MediaType.APPLICATION_JSON);
EntityExchangeResult<Void> exchangeResult = testClient.post().uri("/optionalfile").bodyValue(bodyBuilder.build()).exchange().expectStatus().isFound().expectBody().isEmpty();
// Further assertions on the server response
MockMvcWebTestClient.resultActionsFor(exchangeResult).andExpect(model().attributeDoesNotExist("fileContent")).andExpect(model().attribute("jsonContent", json));
}
use of org.springframework.http.client.MultipartBodyBuilder in project spring-framework by spring-projects.
the class MultipartControllerTests method multipartRequestWithOptionalFileList.
@Test
public void multipartRequestWithOptionalFileList() 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("/optionalfilelist").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 MultipartControllerTests method multipartRequestWithOptionalFile.
@Test
public void multipartRequestWithOptionalFile() 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("json", json, MediaType.APPLICATION_JSON);
EntityExchangeResult<Void> exchangeResult = testClient.post().uri("/optionalfile").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));
}
Aggregations