public int getHttpStatus() { return rawResponse.getHttpStatus(); }
public int getHttpStatus() { return rawResponse.getHttpStatus(); }
/** * Constructs a new instance from a successful raw response. * * @throws NullPointerException if {@code rawResponse} is null. * @throws IllegalArgumentException if {@code rawResponse} does not have a successful HTTP status. */ public ReportDownloadResponse(RawReportDownloadResponse rawResponse) { this.rawResponse = Preconditions.checkNotNull(rawResponse, "Null raw response"); Preconditions.checkArgument(rawResponse.getHttpStatus() == HttpURLConnection.HTTP_OK, "Expected a successful raw response but raw response status is: %s", rawResponse.getHttpStatus()); }
/** * Constructs a new instance from a successful raw response. * * @throws NullPointerException if {@code rawResponse} is null. * @throws IllegalArgumentException if {@code rawResponse} does not have a successful HTTP status. */ public ReportDownloadResponse(RawReportDownloadResponse rawResponse) { this.rawResponse = Preconditions.checkNotNull(rawResponse, "Null raw response"); Preconditions.checkArgument(rawResponse.getHttpStatus() == HttpURLConnection.HTTP_OK, "Expected a successful raw response but raw response status is: %s", rawResponse.getHttpStatus()); }
Preconditions.checkNotNull(rawResponse, "Null response"); Preconditions.checkNotNull(exceptionBuilder, "Null exception builder"); if (rawResponse.getHttpStatus() == HttpURLConnection.HTTP_OK) { return new ReportDownloadResponse(rawResponse); responseText = Streams.readAll(rawResponse.getInputStream(), rawResponse.getCharset()); } catch (IOException e1) { throw new ReportDownloadResponseException(rawResponse.getHttpStatus(), e1); exceptionBuilder.build(rawResponse.getHttpStatus(), responseText); Map<String, String> fields = xmlFieldExtractor.extract(
Preconditions.checkNotNull(rawResponse, "Null response"); Preconditions.checkNotNull(exceptionBuilder, "Null exception builder"); if (rawResponse.getHttpStatus() == HttpURLConnection.HTTP_OK) { return new ReportDownloadResponse(rawResponse); responseText = Streams.readAll(rawResponse.getInputStream(), rawResponse.getCharset()); } catch (IOException e1) { throw new ReportDownloadResponseException(rawResponse.getHttpStatus(), e1); exceptionBuilder.build(rawResponse.getHttpStatus(), responseText); Map<String, String> fields = xmlFieldExtractor.extract(
/** * Tests that the helper will properly capture an internal server error (500) status returned by * the mock HTTP server. */ @Test public void testDownloadReportWithServerErrorStatus() throws Exception { when(reportRequest.getRequestType()).thenReturn(RequestType.AWQL); String awqlString = "SELECT BadField1 FROM NOT_A_REPORT DURING NOT_A_TIME_PERIOD"; when(reportRequest.getReportRequestString()).thenReturn(awqlString); // Do not set the next response body on the test server. This will trigger an error // (500) from the test server. RawReportDownloadResponse response = helper.downloadReport(reportRequest); assertEquals("Response status code not failure", 500, response.getHttpStatus()); assertEquals("", Streams.readAll(response.getInputStream(), response.getCharset())); }
RawReportDownloadResponse rawResponse, String expectedErrorText) throws ReportException, ReportDownloadResponseException { if (rawResponse.getHttpStatus() == 200) { adHocDownloadHelper.downloadReport( Matchers.any(ReportRequest.class), Matchers.any(Builder.class))) .thenThrow(new Builder().build(rawResponse.getHttpStatus(), expectedErrorText));
RawReportDownloadResponse rawResponse, String expectedErrorText) throws ReportException, ReportDownloadResponseException { if (rawResponse.getHttpStatus() == 200) { adHocDownloadHelper.downloadReport( Matchers.any(ReportRequest.class), Matchers.any(Builder.class))) .thenThrow(new Builder().build(rawResponse.getHttpStatus(), expectedErrorText));
RawReportDownloadResponse rawResponse, String expectedErrorText) throws ReportException, ReportDownloadResponseException { if (rawResponse.getHttpStatus() == 200) { adHocDownloadHelper.downloadReport( Matchers.any(ReportRequest.class), Matchers.any(Builder.class))) .thenThrow(new Builder().build(rawResponse.getHttpStatus(), expectedErrorText));
assertEquals("Response status code not success", 200, response.getHttpStatus()); assertEquals( "Response charset incorrect",
assertEquals("Response status code not success", 200, response.getHttpStatus()); assertEquals( "Response charset incorrect",