@Test public void testFailedResponse_fails() { RawReportDownloadResponse rawResponse = new RawReportDownloadResponse( HttpURLConnection.HTTP_BAD_REQUEST, new ByteArrayInputStream("failed".getBytes(UTF_8)), UTF_8, "CSV"); thrown.expect(IllegalArgumentException.class); new ReportDownloadResponse(rawResponse); } }
/** * Test method for * {@link com.google.api.ads.adwords.lib.utils.ReportDownloadResponse#getAsString()} * when response data is compressed. */ @Test public void testGetAsString_gzippedCSV() throws IOException { String expectedContents = "a,b,c\nd,e,f\n"; ByteArrayOutputStream zippedBytesOut = new ByteArrayOutputStream(); Streams.copy(new ByteArrayInputStream(expectedContents.getBytes(UTF_8)), new GZIPOutputStream(zippedBytesOut)); RawReportDownloadResponse rawResponse = new RawReportDownloadResponse(HttpURLConnection.HTTP_OK, new ByteArrayInputStream(zippedBytesOut.toByteArray()), UTF_8, "GZIPPED_CSV"); ReportDownloadResponse response = new ReportDownloadResponse(rawResponse); assertEquals("contents as string are incorrect for gzipped format", expectedContents, response.getAsString()); }
Preconditions.checkNotNull(exceptionBuilder, "Null exception builder"); if (rawResponse.getHttpStatus() == HttpURLConnection.HTTP_OK) { return new ReportDownloadResponse(rawResponse);
Preconditions.checkNotNull(exceptionBuilder, "Null exception builder"); if (rawResponse.getHttpStatus() == HttpURLConnection.HTTP_OK) { return new ReportDownloadResponse(rawResponse);
/** * Test method for * {@link com.google.api.ads.adwords.lib.utils.ReportDownloadResponse#getAsString()}. */ @Test public void testGetAsString() throws IOException { String expectedContents = "a,b,c\nd,e,f\n"; InputStream inputStream = new ByteArrayInputStream(expectedContents.getBytes(UTF_8)); RawReportDownloadResponse rawResponse = new RawReportDownloadResponse(HttpURLConnection.HTTP_OK, inputStream, UTF_8, "CSV"); ReportDownloadResponse response = new ReportDownloadResponse(rawResponse); assertEquals("contents as string are incorrect", expectedContents, response.getAsString()); }
/** * Test method for * {@link com.google.api.ads.adwords.lib.utils.ReportDownloadResponse#saveToFile(String)} */ @Test public void testSaveToFile() throws IOException { File outputFile = tempFolder.newFile("ReportOutput.csv"); String expectedContents = "a,b,c\nd,e,f\n"; InputStream inputStream = new ByteArrayInputStream(expectedContents.getBytes(UTF_8)); RawReportDownloadResponse rawResponse = new RawReportDownloadResponse(HttpURLConnection.HTTP_OK, inputStream, UTF_8, "CSV"); ReportDownloadResponse response = new ReportDownloadResponse(rawResponse); response.saveToFile(outputFile.getPath()); assertEquals("contents saved to file are incorrect", expectedContents, Streams.readAll(new FileInputStream(outputFile), UTF_8)); }
/** * Test method for * {@link com.google.api.ads.adwords.lib.utils.ReportDownloadResponse#getInputStream()}. */ @Test public void testGetInputStream() throws IOException { String expectedContents = "a,b,c\nd,e,f\n"; InputStream inputStream = new ByteArrayInputStream(expectedContents.getBytes(UTF_8)); RawReportDownloadResponse rawResponse = new RawReportDownloadResponse(HttpURLConnection.HTTP_OK, inputStream, UTF_8, "CSV"); ReportDownloadResponse response = new ReportDownloadResponse(rawResponse); String actualContents = Streams.readAll(response.getInputStream(), UTF_8); assertEquals("input stream contents are incorrect", expectedContents, actualContents); }
adHocDownloadHelper.downloadReport( Matchers.any(ReportRequest.class), Matchers.any(Builder.class))) .thenReturn(new ReportDownloadResponse(rawResponse)); } else {
adHocDownloadHelper.downloadReport( Matchers.any(ReportRequest.class), Matchers.any(Builder.class))) .thenReturn(new ReportDownloadResponse(rawResponse)); } else {
adHocDownloadHelper.downloadReport( Matchers.any(ReportRequest.class), Matchers.any(Builder.class))) .thenReturn(new ReportDownloadResponse(rawResponse)); } else {