use of com.google.api.client.http.HttpTransport in project google-api-java-client by google.
the class GoogleJsonResponseExceptionTest method testFrom_noDetails.
public void testFrom_noDetails() throws Exception {
HttpTransport transport = new MockHttpTransport();
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("200", ge.getMessage());
}
use of com.google.api.client.http.HttpTransport 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 + "{"));
}
use of com.google.api.client.http.HttpTransport 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());
}
use of com.google.api.client.http.HttpTransport in project google-api-java-client by google.
the class AbstractGoogleJsonClientTest method testExecuteUnparsed_error.
public void testExecuteUnparsed_error() throws Exception {
HttpTransport transport = new MockHttpTransport() {
@Override
public LowLevelHttpRequest buildRequest(String name, String url) {
return new MockLowLevelHttpRequest() {
@Override
public LowLevelHttpResponse execute() {
MockLowLevelHttpResponse result = new MockLowLevelHttpResponse();
result.setStatusCode(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
result.setContentType(Json.MEDIA_TYPE);
result.setContent("{\"error\":{\"code\":401,\"errors\":[{\"domain\":\"global\"," + "\"location\":\"Authorization\",\"locationType\":\"header\"," + "\"message\":\"me\",\"reason\":\"authError\"}],\"message\":\"me\"}}");
return result;
}
};
}
};
JsonFactory jsonFactory = new JacksonFactory();
MockGoogleJsonClient client = new MockGoogleJsonClient.Builder(transport, jsonFactory, HttpTesting.SIMPLE_URL, "", null, false).setApplicationName("Test Application").build();
MockGoogleJsonClientRequest<String> request = new MockGoogleJsonClientRequest<String>(client, "GET", "foo", null, String.class);
try {
request.executeUnparsed();
fail("expected " + GoogleJsonResponseException.class);
} catch (GoogleJsonResponseException e) {
// expected
GoogleJsonError details = e.getDetails();
assertEquals("me", details.getMessage());
assertEquals("me", details.getErrors().get(0).getMessage());
}
}
use of com.google.api.client.http.HttpTransport in project google-api-java-client by google.
the class UtilsTest method testGetDefaultTransport.
public void testGetDefaultTransport() {
HttpTransport transport = Utils.getDefaultTransport();
assertNotNull(transport);
assertTrue(transport instanceof NetHttpTransport);
HttpTransport secondCall = Utils.getDefaultTransport();
assertSame(transport, secondCall);
}
Aggregations