Java Code Examples for com.google.api.client.testing.http.MockLowLevelHttpResponse#setReasonPhrase()

The following examples show how to use com.google.api.client.testing.http.MockLowLevelHttpResponse#setReasonPhrase() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpResponseExceptionTest.java    From google-http-java-client with Apache License 2.0 6 votes vote down vote up
public void testConstructorWithStatusMessage() throws Exception {
  HttpTransport transport =
      new MockHttpTransport() {
        @Override
        public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
          return new MockLowLevelHttpRequest() {
            @Override
            public LowLevelHttpResponse execute() throws IOException {
              MockLowLevelHttpResponse result = new MockLowLevelHttpResponse();
              result.setReasonPhrase("OK");
              return result;
            }
          };
        }
      };
  HttpRequest request = transport.createRequestFactory().buildGetRequest(SIMPLE_GENERIC_URL);
  HttpResponse response = request.execute();
  HttpResponseException responseException = new HttpResponseException(response);
  assertEquals("OK", responseException.getStatusMessage());
}
 
Example 2
Source File: HttpResponseExceptionTest.java    From google-http-java-client with Apache License 2.0 6 votes vote down vote up
public void testComputeMessage() throws Exception {
  HttpTransport transport =
      new MockHttpTransport() {
        @Override
        public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
          return new MockLowLevelHttpRequest() {
            @Override
            public LowLevelHttpResponse execute() throws IOException {
              MockLowLevelHttpResponse result = new MockLowLevelHttpResponse();
              result.setReasonPhrase("Foo");
              return result;
            }
          };
        }
      };
  HttpRequest request = transport.createRequestFactory().buildGetRequest(SIMPLE_GENERIC_URL);
  HttpResponse response = request.execute();
  assertThat(HttpResponseException.computeMessageBuffer(response).toString())
      .isEqualTo("200 Foo\nGET " + SIMPLE_GENERIC_URL);
}
 
Example 3
Source File: HttpResponseExceptionTest.java    From google-http-java-client with Apache License 2.0 5 votes vote down vote up
public void testConstructor_messageButNoStatusCode() throws Exception {
  HttpTransport transport =
      new MockHttpTransport() {
        @Override
        public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
          return new MockLowLevelHttpRequest() {
            @Override
            public LowLevelHttpResponse execute() throws IOException {
              MockLowLevelHttpResponse result = new MockLowLevelHttpResponse();
              result.setStatusCode(0);
              result.setReasonPhrase("Foo");
              return result;
            }
          };
        }
      };
  final HttpRequest request =
      transport.createRequestFactory().buildGetRequest(SIMPLE_GENERIC_URL);
  HttpResponseException responseException =
      assertThrows(
          HttpResponseException.class,
          new ThrowingRunnable() {
            @Override
            public void run() throws Throwable {
              request.execute();
            }
          });
  assertThat(responseException).hasMessageThat().isEqualTo("Foo\nGET " + SIMPLE_GENERIC_URL);
}
 
Example 4
Source File: HttpResponseExceptionTest.java    From google-http-java-client with Apache License 2.0 5 votes vote down vote up
public void testThrown() throws Exception {
  HttpTransport transport =
      new MockHttpTransport() {
        @Override
        public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
          return new MockLowLevelHttpRequest() {
            @Override
            public LowLevelHttpResponse execute() throws IOException {
              MockLowLevelHttpResponse result = new MockLowLevelHttpResponse();
              result.setStatusCode(HttpStatusCodes.STATUS_CODE_NOT_FOUND);
              result.setReasonPhrase("Not Found");
              result.setContent("Unable to find resource");
              return result;
            }
          };
        }
      };
  final HttpRequest request =
      transport.createRequestFactory().buildGetRequest(SIMPLE_GENERIC_URL);
  HttpResponseException responseException =
      assertThrows(
          HttpResponseException.class,
          new ThrowingRunnable() {
            @Override
            public void run() throws Throwable {
              request.execute();
            }
          });

  assertThat(responseException)
      .hasMessageThat()
      .isEqualTo(
          "404 Not Found\nGET "
              + SIMPLE_GENERIC_URL
              + LINE_SEPARATOR
              + "Unable to find resource");
}
 
Example 5
Source File: HttpResponseExceptionTest.java    From google-http-java-client with Apache License 2.0 5 votes vote down vote up
public void testInvalidCharset() throws Exception {
  HttpTransport transport =
      new MockHttpTransport() {
        @Override
        public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
          return new MockLowLevelHttpRequest() {
            @Override
            public LowLevelHttpResponse execute() throws IOException {
              MockLowLevelHttpResponse result = new MockLowLevelHttpResponse();
              result.setStatusCode(HttpStatusCodes.STATUS_CODE_NOT_FOUND);
              result.setReasonPhrase("Not Found");
              result.setContentType("text/plain; charset=");
              result.setContent("Unable to find resource");
              return result;
            }
          };
        }
      };
  final HttpRequest request =
      transport.createRequestFactory().buildGetRequest(SIMPLE_GENERIC_URL);
  HttpResponseException responseException =
      assertThrows(
          HttpResponseException.class,
          new ThrowingRunnable() {
            @Override
            public void run() throws Throwable {
              request.execute();
            }
          });

  assertThat(responseException)
      .hasMessageThat()
      .isEqualTo("404 Not Found\nGET " + SIMPLE_GENERIC_URL);
}
 
Example 6
Source File: HttpResponseExceptionTest.java    From google-http-java-client with Apache License 2.0 5 votes vote down vote up
public void testUnsupportedCharset() throws Exception {
  HttpTransport transport =
      new MockHttpTransport() {
        @Override
        public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
          return new MockLowLevelHttpRequest() {
            @Override
            public LowLevelHttpResponse execute() throws IOException {
              MockLowLevelHttpResponse result = new MockLowLevelHttpResponse();
              result.setStatusCode(HttpStatusCodes.STATUS_CODE_NOT_FOUND);
              result.setReasonPhrase("Not Found");
              result.setContentType("text/plain; charset=invalid-charset");
              result.setContent("Unable to find resource");
              return result;
            }
          };
        }
      };
  final HttpRequest request =
      transport.createRequestFactory().buildGetRequest(SIMPLE_GENERIC_URL);
  HttpResponseException responseException =
      assertThrows(
          HttpResponseException.class,
          new ThrowingRunnable() {
            @Override
            public void run() throws Throwable {
              request.execute();
            }
          });
  assertThat(responseException)
      .hasMessageThat()
      .isEqualTo("404 Not Found\nGET " + SIMPLE_GENERIC_URL);
}