use of com.google.api.client.googleapis.testing.services.json.MockGoogleJsonClient 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.googleapis.testing.services.json.MockGoogleJsonClient in project google-api-java-client by google.
the class CommonGoogleJsonClientRequestInitializerTest method testInitialize.
public void testInitialize() throws Exception {
CommonGoogleJsonClientRequestInitializer key = new CommonGoogleJsonClientRequestInitializer("foo");
MockGoogleJsonClient client = new MockGoogleJsonClient.Builder(new MockHttpTransport(), new JacksonFactory(), HttpTesting.SIMPLE_URL, "test/", null, false).setApplicationName("Test Application").build();
MyRequest request = new MyRequest(client, "GET", "", null, String.class);
assertNull(request.key);
key.initialize(request);
assertEquals("foo", request.key);
}
Aggregations