/** * @param responseContent the contents of the response * @param httpStatus the HTTP status code from the response * @param httpResponseMessage the HTTP status message from the response * @param totalContentLength the total content length for the batch job, including the length * from this response's corresponding request * @param resumableSessionURI the URI to use for further incremental uploads * @throws NullPointerException if {@code responseContent} is null. */ public BatchJobUploadResponse(InputStream responseContent, int httpStatus, String httpResponseMessage, long totalContentLength, @Nullable URI resumableSessionURI) { this.responseContent = Preconditions.checkNotNull(responseContent, "Null response content"); this.httpStatus = httpStatus; this.httpResponseMessage = httpResponseMessage; this.uploadStatus = new BatchJobUploadStatus(totalContentLength, resumableSessionURI); }
@Override public BatchJobUploadResponse uploadBatchJobOperations( Iterable<Operation> operations, String uploadUrl) throws BatchJobException { // All uploads must go through the incremental upload workflow. return uploadIncrementalBatchJobOperations( operations, true, new BatchJobUploadStatus(0, URI.create(uploadUrl))); }
@Override public BatchJobUploadResponse uploadBatchJobOperations( Iterable<Operation> operations, String uploadUrl) throws BatchJobException { // All uploads must go through the incremental upload workflow. return uploadIncrementalBatchJobOperations( operations, true, new BatchJobUploadStatus(0, URI.create(uploadUrl))); }
@Override public BatchJobUploadResponse uploadBatchJobOperations( Iterable<Operation> operations, String uploadUrl) throws BatchJobException { // All uploads must go through the incremental upload workflow. return uploadIncrementalBatchJobOperations( operations, true, new BatchJobUploadStatus(0, URI.create(uploadUrl))); }
@Override public BatchJobUploadResponse uploadBatchJobOperations( Iterable<Operation> operations, String uploadUrl) throws BatchJobException { // All uploads must go through the incremental upload workflow. return uploadIncrementalBatchJobOperations( operations, true, new BatchJobUploadStatus(0, URI.create(uploadUrl))); }
@Override public BatchJobUploadResponse uploadBatchJobOperations( Iterable<Operation> operations, String uploadUrl) throws BatchJobException { // All uploads must go through the incremental upload workflow. return uploadIncrementalBatchJobOperations( operations, true, new BatchJobUploadStatus(0, URI.create(uploadUrl))); }
@Override public BatchJobUploadResponse uploadBatchJobOperations( Iterable<Operation> operations, String uploadUrl) throws BatchJobException { // All uploads must go through the incremental upload workflow. return uploadIncrementalBatchJobOperations( operations, true, new BatchJobUploadStatus(0, URI.create(uploadUrl))); }
@Override public BatchJobUploadResponse uploadBatchJobOperations( Iterable<Operation> operations, String uploadUrl) throws BatchJobException { // All uploads must go through the incremental upload workflow. return uploadIncrementalBatchJobOperations( operations, true, new BatchJobUploadStatus(0, URI.create(uploadUrl))); }
@Override public BatchJobUploadResponse uploadBatchJobOperations( Iterable<Operation> operations, String uploadUrl) throws BatchJobException { // All uploads must go through the incremental upload workflow. return uploadIncrementalBatchJobOperations( operations, true, new BatchJobUploadStatus(0, URI.create(uploadUrl))); }
@Test public void testUploadBatchJobOperations() throws BatchJobException { BatchJobUploadStatus status = new BatchJobUploadStatus(0L, URI.create(UPLOAD_URL)); batchJobHelper.uploadBatchJobOperations(operations, UPLOAD_URL); verify(uploader) .uploadIncrementalBatchJobOperations( Matchers.<BatchJobMutateRequestInterface>any(), Matchers.eq(true), Matchers.eq(status)); }
@Test public void testUploadIncrementalBatchJobOperations() throws BatchJobException { BatchJobUploadStatus status = new BatchJobUploadStatus(0L, URI.create(UPLOAD_URL)); batchJobHelper.uploadIncrementalBatchJobOperations(operations, false, status); verify(uploader) .uploadIncrementalBatchJobOperations( Matchers.<BatchJobMutateRequestInterface>any(), Matchers.eq(false), Matchers.eq(status)); }
@Test public void testUploadIncrementalBatchJobOperations_isLastRequest() throws BatchJobException { BatchJobUploadStatus status = new BatchJobUploadStatus(0L, URI.create(UPLOAD_URL)); batchJobHelper.uploadIncrementalBatchJobOperations(operations, true, status); verify(uploader) .uploadIncrementalBatchJobOperations( Matchers.<BatchJobMutateRequestInterface>any(), Matchers.eq(true), Matchers.eq(status)); }
/** * Test that verifies that a negative total content length is not permitted. */ @Test public void testInvalidContentLength_fails() { thrown.expect(IllegalArgumentException.class); new BatchJobUploadStatus(-1L, URI.create("http://www.example.com")); }
/** * Test that verifies that a null resumable upload URI is permitted. */ @Test public void testNullResumableUploadURI_succeeds() { BatchJobUploadStatus status = new BatchJobUploadStatus(100L, null); assertNotNull(status); } }
@Test public void testToString() { Long totalContentLength = 500L; String uploadUrl = "http://www.example.com/upload"; BatchJobUploadStatus status = new BatchJobUploadStatus(totalContentLength, URI.create(uploadUrl)); assertThat( "toString should contain the total content length", status.toString(), Matchers.containsString(totalContentLength.toString())); assertThat( "toString should contain the upload URL", status.toString(), Matchers.containsString(uploadUrl)); }
@Test public void testConstructContentRangeHeaderValue_notLast_nonZeroLength_zeroPrevious() { BatchJobUploadStatus status = new BatchJobUploadStatus(0, null); long requestLength = 100; String expectedContentRange = "bytes 0-99/*"; assertEquals( expectedContentRange, uploader.constructContentRangeHeaderValue(requestLength, false, status)); }
@Test public void testConstructContentRangeHeaderValue_isLast_nonZeroLength_zeroPrevious() { BatchJobUploadStatus status = new BatchJobUploadStatus(0, null); long requestLength = 100; String expectedContentRange = "bytes 0-99/100"; assertEquals( expectedContentRange, uploader.constructContentRangeHeaderValue(requestLength, true, status)); }
@Test public void testConstructContentRangeHeaderValue_notLast_nonZeroLength_nonZeroPrevious() { BatchJobUploadStatus status = new BatchJobUploadStatus(100, null); long requestLength = 100; String expectedContentRange = "bytes 100-199/*"; assertEquals( expectedContentRange, uploader.constructContentRangeHeaderValue(requestLength, false, status)); }
@Test public void testConstructContentRangeHeaderValue_isLast_nonZeroLength_nonZeroPrevious() { BatchJobUploadStatus status = new BatchJobUploadStatus(100, null); long requestLength = 100; String expectedContentRange = "bytes 100-199/200"; assertEquals( expectedContentRange, uploader.constructContentRangeHeaderValue(requestLength, true, status)); }
@Test public void testConstructContentRangeHeaderValue_notLast_zeroLength() { BatchJobUploadStatus status = new BatchJobUploadStatus(0, null); thrown.expect(IllegalArgumentException.class); uploader.constructContentRangeHeaderValue(0, false, status); }