@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); }
@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); }
@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); } }
@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); }
@Test public void testHandleErrorResponse_fails() throws Exception { RawReportDownloadResponse rawResponse = new RawReportDownloadResponse( 500, ByteSource.wrap(ERROR_XML.getBytes(REPORT_CHARSET)).openStream(), REPORT_CHARSET, "CSV"); thrown.expect(DetailedReportDownloadResponseException.class); thrown.expect(Matchers.hasProperty("fieldPath", Matchers.equalTo("foobar"))); thrown.expect(Matchers.hasProperty("trigger", Matchers.equalTo("AdFormatt"))); thrown.expect( Matchers.hasProperty( "type", Matchers.equalTo("ReportDefinitionError.INVALID_FIELD_NAME_FOR_REPORT"))); helper.handleResponse(rawResponse, exceptionBuilder); }