@@ -735,36 +735,43 @@ public void createEditableSharedLinkSucceeds() {
735735 @ Test
736736 public void testDownloadFromSharedLinkWithPassword () {
737737 final String sharedItemsURL = "/2.0/shared_items" ;
738+ final String fileContentURL = "/2.0/files/12345/content" ;
738739 final String sharedLink = "https://app.box.com/s/abcdef123456" ;
739740 final String password = "password" ;
740741 final byte [] fileContent = "This is a test file content" .getBytes ();
741742 final String expectedSharedLinkHeaderValue = "shared_link=" + sharedLink + "&shared_link_password=" + password ;
742743 final String expectedDownloadPath = "/shared/static/rh935iit6ewrmw0unyul.jpeg" ;
743744 final String expectedDownloadUrl = format ("https://localhost:%d%s" , wireMockRule .httpsPort (), expectedDownloadPath );
744745
745- String sharedItemsResponse = format (
746- "{ \" download_url\" : \" %s\" , \" type\" : \" file\" , \" id\" : \" 12345\" }" ,
747- expectedDownloadUrl
748- );
746+ String sharedItemsResponse = "{ \" type\" : \" file\" , \" id\" : \" 12345\" }" ;
749747
750748 wireMockRule .stubFor (WireMock .get (WireMock .urlPathEqualTo (sharedItemsURL ))
751749 .willReturn (WireMock .aResponse ()
752750 .withHeader ("Content-Type" , APPLICATION_JSON )
753751 .withBody (sharedItemsResponse )));
754752
755- wireMockRule .stubFor (WireMock .get (WireMock .urlPathEqualTo (expectedDownloadPath ))
753+ wireMockRule .stubFor (WireMock .get (WireMock .urlPathEqualTo (fileContentURL ))
754+ .withHeader ("boxapi" , WireMock .equalTo (expectedSharedLinkHeaderValue ))
756755 .willReturn (WireMock .aResponse ()
757- .withHeader ("Content-Type" , "application/octet-stream" )
758- .withBody (fileContent )));
756+ .withStatus (302 )
757+ .withHeader ("Location" , expectedDownloadUrl )));
758+
759+ wireMockRule .stubFor (WireMock .get (WireMock .urlPathEqualTo (expectedDownloadPath ))
760+ .willReturn (WireMock .aResponse ()
761+ .withHeader ("Content-Type" , "application/octet-stream" )
762+ .withBody (fileContent )));
759763
760764
761765 ByteArrayOutputStream output = new ByteArrayOutputStream ();
762766 BoxFile .downloadFromSharedLink (api , output , sharedLink , password );
763767
764768 verify (1 , getRequestedFor (
765- urlEqualTo ("/2.0/shared_items?fields=download_url " )).
769+ urlEqualTo ("/2.0/shared_items?fields=id " )).
766770 withHeader ("BoxApi" , WireMock .equalTo (expectedSharedLinkHeaderValue )));
767771
772+ verify (1 , getRequestedFor (urlEqualTo (fileContentURL )).
773+ withHeader ("boxapi" , WireMock .equalTo (expectedSharedLinkHeaderValue )));
774+
768775 verify (1 , getRequestedFor (urlEqualTo (expectedDownloadPath )));
769776
770777 assertArrayEquals (fileContent , output .toByteArray ());
@@ -773,6 +780,7 @@ public void testDownloadFromSharedLinkWithPassword() {
773780 @ Test
774781 public void testDownloadFromSharedLinkWithProgressListener () {
775782 final String sharedItemsURL = "/2.0/shared_items" ;
783+ final String fileContentURL = "/2.0/files/12345/content" ;
776784 final String sharedLink = "https://app.box.com/s/abcdef123456" ;
777785 final byte [] fileContent = "This is a test file content" .getBytes ();
778786 final String expectedSharedLinkHeaderValue = "shared_link=" + sharedLink ;
@@ -791,6 +799,12 @@ public void testDownloadFromSharedLinkWithProgressListener() {
791799 .withHeader ("Content-Type" , APPLICATION_JSON )
792800 .withBody (sharedItemsResponse )));
793801
802+ wireMockRule .stubFor (WireMock .get (WireMock .urlPathEqualTo (fileContentURL ))
803+ .withHeader ("boxapi" , WireMock .equalTo (expectedSharedLinkHeaderValue ))
804+ .willReturn (WireMock .aResponse ()
805+ .withStatus (302 )
806+ .withHeader ("Location" , expectedDownloadUrl )));
807+
794808 wireMockRule .stubFor (WireMock .get (WireMock .urlPathEqualTo (expectedDownloadPath ))
795809 .willReturn (WireMock .aResponse ()
796810 .withHeader ("Content-Type" , "application/octet-stream" )
@@ -804,9 +818,12 @@ public void testDownloadFromSharedLinkWithProgressListener() {
804818 BoxFile .downloadFromSharedLink (api , output , sharedLink , listener );
805819
806820 verify (1 , getRequestedFor (
807- urlEqualTo ("/2.0/shared_items?fields=download_url " )).
821+ urlEqualTo ("/2.0/shared_items?fields=id " )).
808822 withHeader ("BoxApi" , WireMock .equalTo (expectedSharedLinkHeaderValue )));
809823
824+ verify (1 , getRequestedFor (urlEqualTo (fileContentURL )).
825+ withHeader ("boxapi" , WireMock .equalTo (expectedSharedLinkHeaderValue )));
826+
810827 verify (1 , getRequestedFor (urlEqualTo (expectedDownloadPath )));
811828
812829 assertArrayEquals (fileContent , output .toByteArray ());
0 commit comments