@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"))); }
new BatchJobUploadStatus(0, URI.create(mockHttpServer.getServerUrl())); String uploadRequestBody = "testUpload"; when(uploadBodyProvider.getHttpContent(request, true, true)) .thenReturn(new ByteArrayContent(null, uploadRequestBody.getBytes(UTF_8))); List<MockResponse> expectedResponses =
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"));
new BatchJobUploadStatus(10, URI.create(mockHttpServer.getServerUrl())); String uploadRequestBody = "<mutate>testUpload</mutate>"; when(uploadBodyProvider.getHttpContent(request, false, false)) .thenReturn(new ByteArrayContent(null, uploadRequestBody.getBytes(UTF_8))); mockHttpServer.setMockResponse(new MockResponse("testUploadResponse"));
ByteArrayContent content = request.createBatchJobUploadBodyProvider().getHttpContent( request, effectiveStatus.getTotalContentLength() == 0, isLastRequest); try {
ByteArrayContent content = request.createBatchJobUploadBodyProvider().getHttpContent( request, effectiveStatus.getTotalContentLength() == 0, isLastRequest); try {
@Test public void testValidOperations() throws BatchJobException, IOException, SAXException { RequestT request = createMutateRequest(); addBudgetOperation(request, -1L, "Test budget", 50000000L, "STANDARD"); addCampaignOperation( request, -2L, "Test campaign #1", "PAUSED", "SEARCH", -1L, "MANUAL_CPC", false); addCampaignOperation( request, -3L, "Test campaign #2", "PAUSED", "SEARCH", -1L, "MANUAL_CPC", false); addCampaignNegativeKeywordOperation(request, -2L, "venus", "BROAD"); addCampaignNegativeKeywordOperation(request, -3L, "venus", "BROAD"); ByteArrayContent httpContent = request.createBatchJobUploadBodyProvider().getHttpContent(request, true, true); String actualRequestXml = Streams.readAll(httpContent.getInputStream(), Charset.forName(UTF_8)); actualRequestXml = SoapRequestXmlProvider.normalizeXmlForComparison(actualRequestXml, getApiVersion()); String expectedRequestXml = SoapRequestXmlProvider.getTestBatchUploadRequest(getApiVersion()); // Perform an XML diff using the custom difference listener that properly handles namespaces // and attributes. Diff diff = new Diff(expectedRequestXml, actualRequestXml); DifferenceListener diffListener = new CustomDifferenceListener(); diff.overrideDifferenceListener(diffListener); XMLAssert.assertXMLEqual("Serialized upload request does not match expected XML", diff, true); } }