use of com.dropbox.core.v1.DbxClientV1.Downloader in project dropbox-sdk-java by dropbox.
the class DbxClientV1Test method testRetryDownload.
@Test
public void testRetryDownload() throws DbxException, IOException {
HttpRequestor mockRequestor = mock(HttpRequestor.class);
DbxRequestConfig config = createRequestConfig().withAutoRetryEnabled(3).withHttpRequestor(mockRequestor).build();
DbxClientV1 client = new DbxClientV1(config, "fakeAccessToken");
// load File metadata json
InputStream in = getClass().getResourceAsStream("/file-with-photo-info.json");
assertNotNull(in);
String metadataJson = IOUtil.toUtf8String(in);
byte[] expected = new byte[] { 1, 2, 3, 4 };
// 503 once, then return 200
when(mockRequestor.doGet(anyString(), anyHeaders())).thenReturn(createEmptyResponse(503)).thenReturn(createDownloaderResponse(expected, "X-Dropbox-Metadata", metadataJson));
Downloader downloader = client.startGetThumbnail(DbxThumbnailSize.w64h64, DbxThumbnailFormat.JPEG, "/foo/bar.jpg", null);
// should have been attempted twice
verify(mockRequestor, times(2)).doGet(anyString(), anyHeaders());
ByteArrayOutputStream bout = new ByteArrayOutputStream();
IOUtil.copyStreamToStream(downloader.body, bout);
byte[] actual = bout.toByteArray();
assertEquals(actual, expected);
assertEquals(downloader.metadata.path, "/Photos/Sample Album/Boston City Flow.jpg");
}
Aggregations