/** * Test that verifies that {@link BatchJobUploadStatus} instances are serializable. */ @Test public void testSerializable() throws IOException, ClassNotFoundException { BatchJobUploadStatus status = new BatchJobUploadStatus(500L, URI.create("http://www.example.com/upload")); ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream(); ObjectOutputStream outputStream = new ObjectOutputStream(byteOutputStream); outputStream.writeObject(status); outputStream.close(); ObjectInputStream inputStream = new ObjectInputStream(new ByteArrayInputStream(byteOutputStream.toByteArray())); Object deserializedObject = inputStream.readObject(); assertTrue( "Deserialized status should be a BatchJobUploadStatus", deserializedObject instanceof BatchJobUploadStatus); BatchJobUploadStatus deserializedStatus = (BatchJobUploadStatus) deserializedObject; assertEquals("Deserialized status upload URI does not match original", status.getResumableUploadUri(), deserializedStatus.getResumableUploadUri()); assertEquals("Deserialized status total content length does not match original", status.getTotalContentLength(), deserializedStatus.getTotalContentLength()); }
Preconditions.checkNotNull(batchJobUploadStatus, "Null batch job upload status"); Preconditions.checkNotNull( batchJobUploadStatus.getResumableUploadUri(), "No resumable session URI"); URI uploadUri = initiateResumableUpload(batchJobUploadStatus.getResumableUploadUri()); effectiveStatus = new BatchJobUploadStatus(0, uploadUri); } else { new GenericUrl(effectiveStatus.getResumableUploadUri()), content); response, effectiveStatus.getTotalContentLength() + httpRequest.getContent().getLength(), effectiveStatus.getResumableUploadUri()); return batchJobUploadResponse; } catch (HttpResponseException e) { new BatchJobUploadResponse(new ByteArrayInputStream(new byte[0]), e.getStatusCode(), e.getStatusMessage(), effectiveStatus.getTotalContentLength() + contentLength, effectiveStatus.getResumableUploadUri()); return batchJobUploadResponse; } finally { batchJobLogger.logUpload( requestXml, effectiveStatus.getResumableUploadUri(), batchJobUploadResponse, exception);
Preconditions.checkNotNull(batchJobUploadStatus, "Null batch job upload status"); Preconditions.checkNotNull( batchJobUploadStatus.getResumableUploadUri(), "No resumable session URI"); URI uploadUri = initiateResumableUpload(batchJobUploadStatus.getResumableUploadUri()); effectiveStatus = new BatchJobUploadStatus(0, uploadUri); } else { new GenericUrl(effectiveStatus.getResumableUploadUri()), content); response, effectiveStatus.getTotalContentLength() + httpRequest.getContent().getLength(), effectiveStatus.getResumableUploadUri()); return batchJobUploadResponse; } catch (HttpResponseException e) { new BatchJobUploadResponse(new ByteArrayInputStream(new byte[0]), e.getStatusCode(), e.getStatusMessage(), effectiveStatus.getTotalContentLength() + contentLength, effectiveStatus.getResumableUploadUri()); return batchJobUploadResponse; } finally { batchJobLogger.logUpload( requestXml, effectiveStatus.getResumableUploadUri(), batchJobUploadResponse, exception);
@Test public void testUploadIncrementalBatchJobOperations_logging() throws Exception { BatchJobUploadStatus status = new BatchJobUploadStatus(10, URI.create(mockHttpServer.getServerUrl())); String uploadRequestBody = "<mutate>testUpload</mutate>"; when(uploadBodyProvider.getHttpContent(request, false, true)) .thenReturn(new ByteArrayContent(null, uploadRequestBody.getBytes(UTF_8))); mockHttpServer.setMockResponse(new MockResponse("testUploadResponse")); String expectedBody = "testUpload</mutate>"; expectedBody = Strings.padEnd(expectedBody, BatchJobUploader.REQUIRED_CONTENT_LENGTH_INCREMENT, ' '); // Invoke the incremental upload method. BatchJobUploadResponse response = uploader.uploadIncrementalBatchJobOperations(request, true, status); verify(batchJobLogger, times(1)).logUpload( expectedBody, status.getResumableUploadUri(), response, null ); }
assertEquals( "Status resumable upload URI is incorrect", expectedStatus.getResumableUploadUri(), actualStatus.getResumableUploadUri());
assertEquals( "Status resumable upload URI is incorrect", expectedStatus.getResumableUploadUri(), actualStatus.getResumableUploadUri());
assertEquals( "Status resumable upload URI is incorrect", expectedStatus.getResumableUploadUri(), actualStatus.getResumableUploadUri());