/** * Helper method that invokes the correct overload of * {@code AdHocReportDownloadHelper.downloadReport} based on this test's {@code isTestRawDownload} * attribute. * * <p> * Return type is {@code void} because this should be used for download requests that are expected * to fail. */ private void downloadReport() throws ReportException, ReportDownloadResponseException { if (isTestRawDownload) { helper.downloadReport(reportRequest); } else { helper.downloadReport(reportRequest, exceptionBuilder); } }
@Override public int getReportDownloadTimeout() { return adHocReportDownloadHelper.getReportDownloadTimeout(); }
@Override public void setReportDownloadTimeout(int reportDownloadTimeout) { adHocReportDownloadHelper.setReportDownloadTimeout(reportDownloadTimeout); } }
/** * Tests that {@link AdHocReportDownloadHelper#setReportDownloadTimeout(int)} sets the * helper-specific timeout and does not affect the global timeout. */ @Test public void testSetReportDownloadTimeout() { int internalsTimeout = AdWordsInternals.getInstance().getAdWordsLibConfiguration().getReportDownloadTimeout(); assertEquals(internalsTimeout, helper.getReportDownloadTimeout()); int helperTimeout = internalsTimeout + 10; helper.setReportDownloadTimeout(helperTimeout); assertEquals("Timeout on helper does not reflect changes made via setReportDownloadTimeout", helperTimeout, helper.getReportDownloadTimeout()); assertEquals("Setting the timeout on a helper instance modified the global timeout", internalsTimeout, AdWordsInternals.getInstance().getAdWordsLibConfiguration().getReportDownloadTimeout()); }
@Test public void testHandleResponseWithNullInputStream_fails() throws Exception { RawReportDownloadResponse rawResponse = new RawReportDownloadResponse( 500, (InputStream) null, AdHocReportDownloadHelper.REPORT_CHARSET, "CSV"); thrown.expect(DetailedReportDownloadResponseException.class); helper.handleResponse(rawResponse, exceptionBuilder); }
@Test public void testHandleResponseNullResponse_fails() throws Exception { thrown.expect(NullPointerException.class); thrown.expectMessage("Null response"); helper.handleResponse(null, exceptionBuilder); }
@Override public ReportDownloadResponse downloadReport(String reportQuery, DownloadFormat format) throws ReportException, ReportDownloadResponseException { return adHocReportDownloadHelper.downloadReport( new AwqlReportRequest(reportQuery, format), new DetailedReportDownloadResponseException.Builder()); }
@Override public int getReportDownloadTimeout() { return adHocReportDownloadHelper.getReportDownloadTimeout(); }
@Override public void setReportDownloadTimeout(int reportDownloadTimeout) { adHocReportDownloadHelper.setReportDownloadTimeout(reportDownloadTimeout); } }
@Test public void testHandleSuccessfulResponse() throws Exception { String responseBody = "Successful,report,response"; RawReportDownloadResponse rawResponse = new RawReportDownloadResponse( 200, ByteSource.wrap(responseBody.getBytes(REPORT_CHARSET)).openStream(), REPORT_CHARSET, "CSV"); ReportDownloadResponse reportResponse = helper.handleResponse(rawResponse, exceptionBuilder); String actualResponseBody = new String(ByteStreams.toByteArray(reportResponse.getInputStream()), REPORT_CHARSET); assertEquals("Response body not expected value", responseBody, actualResponseBody); }
@Override public ReportDownloadResponse downloadReport(ReportDefinition reportDefinition) throws ReportException, ReportDownloadResponseException { return adHocReportDownloadHelper.downloadReport( new XmlReportDefinitionRequest(reportDefinition), new DetailedReportDownloadResponseException.Builder()); }
@Override public int getReportDownloadTimeout() { return adHocReportDownloadHelper.getReportDownloadTimeout(); }
@Override public void setReportDownloadTimeout(int reportDownloadTimeout) { adHocReportDownloadHelper.setReportDownloadTimeout(reportDownloadTimeout); } }
@Test public void testHandleResponseNullExceptionBuilder_fails() throws Exception { RawReportDownloadResponse rawResponse = new RawReportDownloadResponse( 200, ByteSource.wrap("a,b,c".getBytes(REPORT_CHARSET)).openStream(), REPORT_CHARSET, "CSV"); thrown.expect(NullPointerException.class); thrown.expectMessage("Null exception builder"); helper.handleResponse(rawResponse, null); } }
@Override public ReportDownloadResponse downloadReport(ReportDefinition reportDefinition) throws ReportException, ReportDownloadResponseException { return adHocReportDownloadHelper.downloadReport( new XmlReportDefinitionRequest(reportDefinition), new DetailedReportDownloadResponseException.Builder()); }
@Override public int getReportDownloadTimeout() { return adHocReportDownloadHelper.getReportDownloadTimeout(); }
@Override public void setReportDownloadTimeout(int reportDownloadTimeout) { adHocReportDownloadHelper.setReportDownloadTimeout(reportDownloadTimeout); } }
@Test public void testHandleResponseWithEmptyInputStream_fails() throws Exception { RawReportDownloadResponse rawResponse = new RawReportDownloadResponse( 500, ByteSource.empty().openStream(), REPORT_CHARSET, "CSV"); thrown.expect(DetailedReportDownloadResponseException.class); thrown.expect(Matchers.hasProperty("fieldPath", Matchers.nullValue())); thrown.expect(Matchers.hasProperty("trigger", Matchers.nullValue())); thrown.expect(Matchers.hasProperty("type", Matchers.nullValue())); helper.handleResponse(rawResponse, exceptionBuilder); }
@Override public ReportDownloadResponse downloadReport(ReportDefinition reportDefinition) throws ReportException, ReportDownloadResponseException { return adHocReportDownloadHelper.downloadReport( new XmlReportDefinitionRequest(reportDefinition), new DetailedReportDownloadResponseException.Builder()); }
@Override public int getReportDownloadTimeout() { return adHocReportDownloadHelper.getReportDownloadTimeout(); }