Skip to content

Commit a9b1b5e

Browse files
committed
Add testRequestPartWithListOfPojosAndListOfMultipartFiles
1 parent 348a062 commit a9b1b5e

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/valid/FeignClientTests.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,20 @@ public void testRequestPartWithListOfMultipartFiles() {
489489
assertThat(fileNames).contains("hello1.bin", "hello2.bin");
490490
}
491491

492+
@Test
493+
public void testRequestPartWithListOfPojosAndListOfMultipartFiles() {
494+
Hello pojo1 = new Hello(HELLO_WORLD_1);
495+
Hello pojo2 = new Hello(OI_TERRA_2);
496+
MockMultipartFile file1 = new MockMultipartFile("file1", "hello1.bin", null,
497+
"hello".getBytes());
498+
MockMultipartFile file2 = new MockMultipartFile("file2", "hello2.bin", null,
499+
"hello".getBytes());
500+
String response = this.multipartClient
501+
.requestPartListOfPojosAndListOfMultipartFiles(Arrays.asList(pojo1, pojo2), Arrays.asList(file1, file2));
502+
assertThat(response).isEqualTo("hello world 1oi terra 2hello1.binhello2.bin");
503+
}
504+
505+
492506
@Test
493507
public void testRequestBodyWithSingleMultipartFile() {
494508
String partName = UUID.randomUUID().toString();
@@ -722,6 +736,13 @@ String requestPartListOfMultipartFilesReturnsPartNames(
722736
String requestPartListOfMultipartFilesReturnsFileNames(
723737
@RequestPart("files") List<MultipartFile> files);
724738

739+
@RequestMapping(method = RequestMethod.POST, path = "/multipartPojosFiles",
740+
consumes = MediaType.MULTIPART_FORM_DATA_VALUE,
741+
produces = MediaType.TEXT_PLAIN_VALUE)
742+
String requestPartListOfPojosAndListOfMultipartFiles(
743+
@RequestPart("pojos") List<Hello> pojos,
744+
@RequestPart("files") List<MultipartFile> files);
745+
725746
@RequestMapping(method = RequestMethod.POST, path = "/multipartNames",
726747
consumes = MediaType.MULTIPART_FORM_DATA_VALUE,
727748
produces = MediaType.TEXT_PLAIN_VALUE)
@@ -1113,6 +1134,24 @@ String multipartFilenames(HttpServletRequest request) throws Exception {
11131134
.collect(Collectors.joining(","));
11141135
}
11151136

1137+
@RequestMapping(method = RequestMethod.POST, path = "/multipartPojosFiles",
1138+
consumes = MediaType.MULTIPART_FORM_DATA_VALUE,
1139+
produces = MediaType.TEXT_PLAIN_VALUE)
1140+
String requestPartListOfPojosAndListOfMultipartFiles(
1141+
@RequestPart("pojos") List<Hello> pojos,
1142+
@RequestPart("files") List<MultipartFile> files) {
1143+
StringBuilder result = new StringBuilder();
1144+
1145+
for (Hello pojo : pojos) {
1146+
result.append(pojo.getMessage());
1147+
}
1148+
1149+
for (MultipartFile file : files) {
1150+
result.append(file.getOriginalFilename());
1151+
}
1152+
1153+
return result.toString();
1154+
}
11161155
}
11171156

11181157
public static class Hello {

0 commit comments

Comments
 (0)