|
25 | 25 | import com.github.tomakehurst.wiremock.client.WireMock; |
26 | 26 | import com.github.tomakehurst.wiremock.junit.WireMockRule; |
27 | 27 | import com.github.tomakehurst.wiremock.matching.EqualToJsonPattern; |
| 28 | +import com.github.tomakehurst.wiremock.matching.EqualToPattern; |
| 29 | +import com.github.tomakehurst.wiremock.matching.MultipartValuePatternBuilder; |
28 | 30 | import java.io.ByteArrayInputStream; |
29 | 31 | import java.io.IOException; |
30 | 32 | import java.io.InputStream; |
@@ -1235,6 +1237,43 @@ public void testDeleteClassification() { |
1235 | 1237 | WireMock.verify(1, WireMock.deleteRequestedFor(WireMock.urlPathEqualTo(metadataURL))); |
1236 | 1238 | } |
1237 | 1239 |
|
| 1240 | + @Test |
| 1241 | + public void testUploadFileWithCorrectMultipartOrder() { |
| 1242 | + final String folderID = "0"; |
| 1243 | + final String fileURL = "/2.0/files/content"; |
| 1244 | + final String fileContent = "Test file"; |
| 1245 | + final String fileName = "Test File.txt"; |
| 1246 | + final String fileDescription = "Test Description"; |
| 1247 | + InputStream stream = new ByteArrayInputStream(fileContent.getBytes(StandardCharsets.UTF_8)); |
| 1248 | + final String expectedAttributesJson = |
| 1249 | + "{\"name\":\"Test File.txt\",\"parent\":{\"id\": \"0\"},\"description\":\"Test Description\"}"; |
| 1250 | + |
| 1251 | + String result = TestUtils.getFixture("BoxFile/CreateFileWithDescription201"); |
| 1252 | + |
| 1253 | + wireMockRule.stubFor(WireMock.post(WireMock.urlPathEqualTo(fileURL)) |
| 1254 | + .withRequestBody(WireMock.matching(".*attributes.*file.*")) // Check that attributes comes before file |
| 1255 | + .withMultipartRequestBody( |
| 1256 | + new MultipartValuePatternBuilder() |
| 1257 | + .withName("attributes") |
| 1258 | + .withBody(new EqualToJsonPattern(expectedAttributesJson, false, false)) |
| 1259 | + ).withMultipartRequestBody( |
| 1260 | + new MultipartValuePatternBuilder() |
| 1261 | + .withName("file") |
| 1262 | + .withBody(new EqualToPattern(fileContent)) |
| 1263 | + ) |
| 1264 | + .willReturn(WireMock.aResponse() |
| 1265 | + .withHeader("Content-Type", APPLICATION_JSON_PATCH) |
| 1266 | + .withBody(result) |
| 1267 | + .withStatus(201))); |
| 1268 | + |
| 1269 | + BoxFolder folder = new BoxFolder(this.api, folderID); |
| 1270 | + BoxFile.Info file = folder.uploadFile(stream, fileName, fileDescription); |
| 1271 | + |
| 1272 | + assertEquals(fileDescription, file.getDescription()); |
| 1273 | + assertEquals(folderID, file.getParent().getID()); |
| 1274 | + assertEquals(fileName, file.getName()); |
| 1275 | + } |
| 1276 | + |
1238 | 1277 | @Test |
1239 | 1278 | public void testUploadFileWithDescriptionSucceeds() { |
1240 | 1279 | final String folderID = "12345"; |
|
0 commit comments