|
15 | 15 | import static org.junit.Assert.assertEquals; |
16 | 16 | import static org.junit.Assert.assertNull; |
17 | 17 | import static org.junit.Assert.assertTrue; |
| 18 | +import static org.junit.Assert.fail; |
18 | 19 |
|
19 | 20 | import com.box.sdk.sharedlink.BoxSharedLinkRequest; |
20 | 21 | import com.eclipsesource.json.Json; |
@@ -440,6 +441,88 @@ public void testGetThumbnailSucceeds() { |
440 | 441 | assertThat(output.toString(), equalTo("This is a JPG")); |
441 | 442 | } |
442 | 443 |
|
| 444 | + @Test |
| 445 | + public void testGetRepresentationContentThrowsWhenExceedingMaxRetries() { |
| 446 | + final String fileID = "12345"; |
| 447 | + wireMockRule.stubFor( |
| 448 | + WireMock.get(WireMock.urlPathEqualTo("/2.0/files/" + fileID)) |
| 449 | + .withQueryParam("fields", WireMock.equalTo("representations")) |
| 450 | + .willReturn(WireMock.aResponse() |
| 451 | + .withHeader("Content-Type", APPLICATION_JSON) |
| 452 | + .withBody(getFixture("BoxFile/GetFileRepresentations200", wireMockRule.httpsPort())) |
| 453 | + .withStatus(200)) |
| 454 | + ); |
| 455 | + wireMockRule.stubFor( |
| 456 | + WireMock.get(WireMock.urlPathEqualTo( |
| 457 | + "/2.0/internal_files/12345/versions/1116420931563/representations/jpg_thumb_32x32") |
| 458 | + ) |
| 459 | + .willReturn(WireMock.aResponse() |
| 460 | + .withHeader("Content-Type", APPLICATION_JSON) |
| 461 | + .withBody(getFixture("BoxFile/GetFileRepresentation200WithPending", wireMockRule.httpsPort())) |
| 462 | + .withStatus(200)) |
| 463 | + ); |
| 464 | + |
| 465 | + try { |
| 466 | + BoxFile file = new BoxFile(this.api, fileID); |
| 467 | + OutputStream output = new ByteArrayOutputStream(); |
| 468 | + file.getRepresentationContent("[jpg?dimensions=32x32]", "", output, 5); |
| 469 | + fail("getRepresentationContent did not fail with BoxAPIException due to pending status"); |
| 470 | + assertThat(output.toString(), equalTo("This is a JPG")); |
| 471 | + } catch (BoxAPIException apiException) { |
| 472 | + assertEquals(apiException.getMessage(), "Representation did non have a success status allowing it to be retrieved after 5 attempts"); |
| 473 | + } |
| 474 | + } |
| 475 | + |
| 476 | + @Test |
| 477 | + public void testGetRepresentationContentSuccess() { |
| 478 | + final String fileID = "12345"; |
| 479 | + wireMockRule.stubFor( |
| 480 | + WireMock.get(WireMock.urlPathEqualTo("/2.0/files/" + fileID)) |
| 481 | + .withQueryParam("fields", WireMock.equalTo("representations")) |
| 482 | + .willReturn(WireMock.aResponse() |
| 483 | + .withHeader("Content-Type", APPLICATION_JSON) |
| 484 | + .withBody(getFixture("BoxFile/GetFileRepresentations200", wireMockRule.httpsPort())) |
| 485 | + .withStatus(200)) |
| 486 | + ); |
| 487 | + wireMockRule.stubFor( |
| 488 | + WireMock.get(WireMock.urlPathEqualTo( |
| 489 | + "/2.0/internal_files/12345/versions/1116420931563/representations/jpg_thumb_32x32") |
| 490 | + ) |
| 491 | + .inScenario("Get file representation status info") |
| 492 | + .willSetStateTo("pending status") |
| 493 | + .willReturn(WireMock.aResponse() |
| 494 | + .withHeader("Content-Type", APPLICATION_JSON) |
| 495 | + .withBody(getFixture("BoxFile/GetFileRepresentation200WithPending", wireMockRule.httpsPort())) |
| 496 | + .withStatus(200)) |
| 497 | + ); |
| 498 | + wireMockRule.stubFor( |
| 499 | + WireMock.get(WireMock.urlPathEqualTo( |
| 500 | + "/2.0/internal_files/12345/versions/1116420931563/representations/jpg_thumb_32x32") |
| 501 | + ) |
| 502 | + .inScenario("Get file representation status info") |
| 503 | + .whenScenarioStateIs("pending status") |
| 504 | + .willReturn(WireMock.aResponse() |
| 505 | + .withHeader("Content-Type", APPLICATION_JSON) |
| 506 | + .withBody(getFixture("BoxFile/GetFileRepresentation200", wireMockRule.httpsPort())) |
| 507 | + .withStatus(200)) |
| 508 | + ); |
| 509 | + |
| 510 | + wireMockRule.stubFor( |
| 511 | + WireMock.get(WireMock.urlPathEqualTo( |
| 512 | + "/2.0/internal_files/1030335435441/versions/1116437417841/representations/jpg_thumb_32x32/content/" |
| 513 | + )) |
| 514 | + .willReturn(WireMock.aResponse() |
| 515 | + .withHeader("Content-Type", "image/jpg") |
| 516 | + .withBody("This is a JPG") |
| 517 | + .withStatus(200)) |
| 518 | + ); |
| 519 | + |
| 520 | + BoxFile file = new BoxFile(this.api, fileID); |
| 521 | + OutputStream output = new ByteArrayOutputStream(); |
| 522 | + file.getRepresentationContent("[jpg?dimensions=32x32]", output); |
| 523 | + assertThat(output.toString(), equalTo("This is a JPG")); |
| 524 | + } |
| 525 | + |
443 | 526 | @Test |
444 | 527 | public void testDeletePreviousFileVersionSucceeds() { |
445 | 528 | final String versionID = "12345"; |
|
0 commit comments