@Override public BatchJobUploadResponse uploadIncrementalBatchJobOperations( Iterable<? extends Operation> operations, boolean isLastRequest, BatchJobUploadStatus batchJobUploadStatus) throws BatchJobException { BatchJobMutateRequest request = new BatchJobMutateRequest(); request.addOperations(operations); return uploader.uploadIncrementalBatchJobOperations( request, isLastRequest, batchJobUploadStatus); }
@Override public BatchJobUploadResponse uploadIncrementalBatchJobOperations( Iterable<? extends Operation> operations, boolean isLastRequest, BatchJobUploadStatus batchJobUploadStatus) throws BatchJobException { BatchJobMutateRequest request = new BatchJobMutateRequest(); request.addOperations(operations); return uploader.uploadIncrementalBatchJobOperations( request, isLastRequest, batchJobUploadStatus); }
@Override public BatchJobUploadResponse uploadIncrementalBatchJobOperations( Iterable<? extends Operation> operations, boolean isLastRequest, BatchJobUploadStatus batchJobUploadStatus) throws BatchJobException { BatchJobMutateRequest request = new BatchJobMutateRequest(); request.addOperations(operations); return uploader.uploadIncrementalBatchJobOperations( request, isLastRequest, batchJobUploadStatus); }
@Override public BatchJobUploadResponse uploadIncrementalBatchJobOperations( Iterable<? extends Operation> operations, boolean isLastRequest, BatchJobUploadStatus batchJobUploadStatus) throws BatchJobException { BatchJobMutateRequest request = new BatchJobMutateRequest(); request.addOperations(operations); return uploader.uploadIncrementalBatchJobOperations( request, isLastRequest, batchJobUploadStatus); }
@Override public BatchJobUploadResponse uploadIncrementalBatchJobOperations( Iterable<? extends Operation> operations, boolean isLastRequest, BatchJobUploadStatus batchJobUploadStatus) throws BatchJobException { BatchJobMutateRequest request = new BatchJobMutateRequest(); request.addOperations(operations); return uploader.uploadIncrementalBatchJobOperations( request, isLastRequest, batchJobUploadStatus); }
@Override public BatchJobUploadResponse uploadIncrementalBatchJobOperations( Iterable<? extends Operation> operations, boolean isLastRequest, BatchJobUploadStatus batchJobUploadStatus) throws BatchJobException { BatchJobMutateRequest request = new BatchJobMutateRequest(); request.addOperations(operations); return uploader.uploadIncrementalBatchJobOperations( request, isLastRequest, batchJobUploadStatus); }
@Override public BatchJobUploadResponse uploadIncrementalBatchJobOperations( Iterable<? extends Operation> operations, boolean isLastRequest, BatchJobUploadStatus batchJobUploadStatus) throws BatchJobException { BatchJobMutateRequest request = new BatchJobMutateRequest(); request.addOperations(operations); return uploader.uploadIncrementalBatchJobOperations( request, isLastRequest, batchJobUploadStatus); }
@Override public BatchJobUploadResponse uploadIncrementalBatchJobOperations( Iterable<? extends Operation> operations, boolean isLastRequest, BatchJobUploadStatus batchJobUploadStatus) throws BatchJobException { BatchJobMutateRequest request = new BatchJobMutateRequest(); request.addOperations(operations); return uploader.uploadIncrementalBatchJobOperations( request, isLastRequest, batchJobUploadStatus); }
@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 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 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_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 ); }
/** * Tests that IOExceptions from executing an upload request are propagated properly. */ @SuppressWarnings("rawtypes") @Test public void testUploadBatchJobOperations_ioException_fails() throws Exception { final IOException ioException = new IOException("mock IO exception"); MockLowLevelHttpRequest lowLevelHttpRequest = new MockLowLevelHttpRequest(){ @Override public LowLevelHttpResponse execute() throws IOException { throw ioException; } }; when(uploadBodyProvider.getHttpContent(request, true, true)) .thenReturn(new ByteArrayContent(null, "foo".getBytes(UTF_8))); MockHttpTransport transport = new MockHttpTransport.Builder() .setLowLevelHttpRequest(lowLevelHttpRequest).build(); uploader = new BatchJobUploader(adWordsSession, transport, batchJobLogger); BatchJobUploadStatus uploadStatus = new BatchJobUploadStatus(0, URI.create("http://www.example.com")); thrown.expect(BatchJobException.class); thrown.expectCause(Matchers.sameInstance(ioException)); uploader.uploadIncrementalBatchJobOperations(request, true, uploadStatus); }
/** * Tests that IOExceptions from initiating an upload are propagated properly. */ @SuppressWarnings("rawtypes") @Test public void testUploadBatchJobOperations_initiateFails_fails() throws Exception { final IOException ioException = new IOException("mock IO exception"); MockLowLevelHttpRequest lowLevelHttpRequest = new MockLowLevelHttpRequest(){ @Override public LowLevelHttpResponse execute() throws IOException { throw ioException; } }; when(uploadBodyProvider.getHttpContent(request, true, true)) .thenReturn(new ByteArrayContent(null, "foo".getBytes(UTF_8))); MockHttpTransport transport = new MockHttpTransport.Builder() .setLowLevelHttpRequest(lowLevelHttpRequest).build(); uploader = new BatchJobUploader(adWordsSession, transport, batchJobLogger); thrown.expect(BatchJobException.class); thrown.expectCause(Matchers.sameInstance(ioException)); thrown.expectMessage("initiate upload"); uploader.uploadIncrementalBatchJobOperations(request, true, new BatchJobUploadStatus( 0, URI.create("http://www.example.com"))); }
uploader.uploadIncrementalBatchJobOperations(request, true, status); assertEquals("Should have made two requests", 2, mockHttpServer.getAllResponses().size());
uploader.uploadIncrementalBatchJobOperations(request, true, status); assertEquals("Should have made one request", 1, mockHttpServer.getAllResponses().size());
uploader.uploadIncrementalBatchJobOperations(request, false, status); assertEquals("Should have made one request", 1, mockHttpServer.getAllResponses().size());