use of org.springframework.http.client.MultipartBodyBuilder in project spring-framework by spring-projects.
the class MultipartControllerTests method multipartRequestWithOptionalFileListNotPresent.
@Test
public void multipartRequestWithOptionalFileListNotPresent() 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("/optionalfilelist").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 multipartRequestWithOptionalFileArray.
@Test
public void multipartRequestWithOptionalFileArray() 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("/optionalfilearray").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 multipartRequestWithServletParts.
@Test
public void multipartRequestWithServletParts() 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("/multipartfile").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 multipartRequestWithSingleFile.
@Test
public void multipartRequestWithSingleFile() 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("/multipartfile").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 multipartRequestWithOptionalFileArrayNotPresent.
@Test
public void multipartRequestWithOptionalFileArrayNotPresent() 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("/optionalfilearray").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));
}
Aggregations