Search in sources :

Example 1 with ErrorTransport

use of com.google.api.client.googleapis.json.GoogleJsonErrorTest.ErrorTransport in project google-api-java-client by google.

the class GoogleJsonResponseExceptionTest method testFrom_errorEmptyContentButWithJsonContentType.

public void testFrom_errorEmptyContentButWithJsonContentType() throws Exception {
    HttpTransport transport = new ErrorTransport(null, Json.MEDIA_TYPE);
    HttpRequest request = transport.createRequestFactory().buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL);
    request.setThrowExceptionOnExecuteError(false);
    HttpResponse response = request.execute();
    GoogleJsonResponseException ge = GoogleJsonResponseException.from(GoogleJsonErrorTest.FACTORY, response);
    assertNull(ge.getDetails());
    assertEquals("403", ge.getMessage());
}
Also used : HttpRequest(com.google.api.client.http.HttpRequest) MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport) HttpTransport(com.google.api.client.http.HttpTransport) HttpResponse(com.google.api.client.http.HttpResponse) ErrorTransport(com.google.api.client.googleapis.json.GoogleJsonErrorTest.ErrorTransport)

Example 2 with ErrorTransport

use of com.google.api.client.googleapis.json.GoogleJsonErrorTest.ErrorTransport in project google-api-java-client by google.

the class GoogleJsonResponseExceptionTest method testFrom_withDetails.

public void testFrom_withDetails() throws Exception {
    HttpTransport transport = new ErrorTransport();
    HttpRequest request = transport.createRequestFactory().buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL);
    request.setThrowExceptionOnExecuteError(false);
    HttpResponse response = request.execute();
    GoogleJsonResponseException ge = GoogleJsonResponseException.from(GoogleJsonErrorTest.FACTORY, response);
    assertEquals(GoogleJsonErrorTest.ERROR, GoogleJsonErrorTest.FACTORY.toString(ge.getDetails()));
    assertTrue(ge.getMessage(), ge.getMessage().startsWith("403" + StringUtils.LINE_SEPARATOR + "{"));
}
Also used : HttpRequest(com.google.api.client.http.HttpRequest) MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport) HttpTransport(com.google.api.client.http.HttpTransport) HttpResponse(com.google.api.client.http.HttpResponse) ErrorTransport(com.google.api.client.googleapis.json.GoogleJsonErrorTest.ErrorTransport)

Example 3 with ErrorTransport

use of com.google.api.client.googleapis.json.GoogleJsonErrorTest.ErrorTransport in project google-api-java-client by google.

the class GoogleJsonResponseExceptionTest method testFrom_detailsMissingContent.

public void testFrom_detailsMissingContent() throws Exception {
    HttpTransport transport = new ErrorTransport(null, Json.MEDIA_TYPE);
    HttpRequest request = transport.createRequestFactory().buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL);
    request.setThrowExceptionOnExecuteError(false);
    HttpResponse response = request.execute();
    GoogleJsonResponseException ge = GoogleJsonResponseException.from(GoogleJsonErrorTest.FACTORY, response);
    assertNull(ge.getDetails());
    assertEquals("403", ge.getMessage());
}
Also used : HttpRequest(com.google.api.client.http.HttpRequest) MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport) HttpTransport(com.google.api.client.http.HttpTransport) HttpResponse(com.google.api.client.http.HttpResponse) ErrorTransport(com.google.api.client.googleapis.json.GoogleJsonErrorTest.ErrorTransport)

Example 4 with ErrorTransport

use of com.google.api.client.googleapis.json.GoogleJsonErrorTest.ErrorTransport in project google-api-java-client by google.

the class GoogleJsonResponseExceptionTest method testFrom_detailsArbitraryJsonContent.

public void testFrom_detailsArbitraryJsonContent() throws Exception {
    HttpTransport transport = new ErrorTransport("{\"foo\":\"bar\"}", Json.MEDIA_TYPE);
    HttpRequest request = transport.createRequestFactory().buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL);
    request.setThrowExceptionOnExecuteError(false);
    HttpResponse response = request.execute();
    GoogleJsonResponseException ge = GoogleJsonResponseException.from(GoogleJsonErrorTest.FACTORY, response);
    assertNull(ge.getDetails());
    assertEquals("403", ge.getMessage());
}
Also used : HttpRequest(com.google.api.client.http.HttpRequest) MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport) HttpTransport(com.google.api.client.http.HttpTransport) HttpResponse(com.google.api.client.http.HttpResponse) ErrorTransport(com.google.api.client.googleapis.json.GoogleJsonErrorTest.ErrorTransport)

Example 5 with ErrorTransport

use of com.google.api.client.googleapis.json.GoogleJsonErrorTest.ErrorTransport in project google-api-java-client by google.

the class GoogleJsonResponseExceptionTest method testFrom_errorNoContentButWithJsonContentType.

public void testFrom_errorNoContentButWithJsonContentType() throws Exception {
    HttpTransport transport = new ErrorTransport("", Json.MEDIA_TYPE);
    HttpRequest request = transport.createRequestFactory().buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL);
    request.setThrowExceptionOnExecuteError(false);
    HttpResponse response = request.execute();
    GoogleJsonResponseException ge = GoogleJsonResponseException.from(GoogleJsonErrorTest.FACTORY, response);
    assertNull(ge.getDetails());
    assertEquals("403", ge.getMessage());
}
Also used : HttpRequest(com.google.api.client.http.HttpRequest) MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport) HttpTransport(com.google.api.client.http.HttpTransport) HttpResponse(com.google.api.client.http.HttpResponse) ErrorTransport(com.google.api.client.googleapis.json.GoogleJsonErrorTest.ErrorTransport)

Aggregations

ErrorTransport (com.google.api.client.googleapis.json.GoogleJsonErrorTest.ErrorTransport)6 HttpRequest (com.google.api.client.http.HttpRequest)6 HttpResponse (com.google.api.client.http.HttpResponse)6 HttpTransport (com.google.api.client.http.HttpTransport)6 MockHttpTransport (com.google.api.client.testing.http.MockHttpTransport)6