use of com.google.api.client.http.HttpTransport in project google-api-java-client by google.
the class GooglePublicKeysManagerTest method testBuilder.
public void testBuilder() throws Exception {
HttpTransport transport = new MockHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
GooglePublicKeysManager.Builder builder = new GooglePublicKeysManager.Builder(transport, jsonFactory);
GooglePublicKeysManager certs = builder.build();
assertEquals(transport, certs.getTransport());
assertEquals(jsonFactory, certs.getJsonFactory());
}
use of com.google.api.client.http.HttpTransport in project google-api-java-client by google.
the class GoogleJsonErrorTest method testParse.
public void testParse() throws Exception {
HttpTransport transport = new ErrorTransport();
HttpRequest request = transport.createRequestFactory().buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL);
request.setThrowExceptionOnExecuteError(false);
HttpResponse response = request.execute();
GoogleJsonError errorResponse = GoogleJsonError.parse(FACTORY, response);
assertEquals(ERROR, FACTORY.toString(errorResponse));
}
use of com.google.api.client.http.HttpTransport in project google-api-java-client by google.
the class AbstractGoogleClientRequestTest method testCheckRequiredParameter.
public void testCheckRequiredParameter() throws Exception {
HttpTransport transport = new MockHttpTransport();
MockGoogleClient client = new MockGoogleClient.Builder(transport, ROOT_URL, SERVICE_PATH, JSON_OBJECT_PARSER, null).setApplicationName("Test Application").build();
MockGoogleClientRequest<String> request = new MockGoogleClientRequest<String>(client, HttpMethods.GET, URI_TEMPLATE, null, String.class);
// Should not throw an Exception.
request.checkRequiredParameter("Not Null", "notNull()");
try {
request.checkRequiredParameter(null, "content.getTest().getAnotherTest()");
fail("Expected " + IllegalArgumentException.class);
} catch (IllegalArgumentException iae) {
// Expected.
}
}
use of com.google.api.client.http.HttpTransport in project google-api-java-client by google.
the class AbstractGoogleClientRequestTest method testExecuteUsingHead.
public void testExecuteUsingHead() throws Exception {
HttpTransport transport = new MockHttpTransport() {
@Override
public LowLevelHttpRequest buildRequest(final String method, final String url) {
return new MockLowLevelHttpRequest() {
@Override
public LowLevelHttpResponse execute() {
assertEquals("HEAD", method);
assertEquals("https://www.googleapis.com/test/path/v1/tests/foo", url);
return new MockLowLevelHttpResponse();
}
};
}
};
MockGoogleClient client = new MockGoogleClient.Builder(transport, ROOT_URL, SERVICE_PATH, JSON_OBJECT_PARSER, null).setApplicationName("Test Application").build();
MockGoogleClientRequest<String> request = new MockGoogleClientRequest<String>(client, HttpMethods.GET, URI_TEMPLATE, null, String.class);
request.put("testId", "foo");
request.executeUsingHead();
}
use of com.google.api.client.http.HttpTransport in project google-api-java-client by google.
the class AbstractGoogleClientRequestTest method testExecute_void.
public void testExecute_void() throws Exception {
HttpTransport transport = new MockHttpTransport() {
@Override
public LowLevelHttpRequest buildRequest(final String method, final String url) {
return new MockLowLevelHttpRequest() {
@Override
public LowLevelHttpResponse execute() {
return new MockLowLevelHttpResponse().setContent("{\"a\":\"ignored\"}").setContentType(Json.MEDIA_TYPE);
}
};
}
};
MockGoogleClient client = new MockGoogleClient.Builder(transport, ROOT_URL, SERVICE_PATH, JSON_OBJECT_PARSER, null).setApplicationName("Test Application").build();
MockGoogleClientRequest<Void> request = new MockGoogleClientRequest<Void>(client, HttpMethods.GET, URI_TEMPLATE, null, Void.class);
Void v = request.execute();
assertNull(v);
}
Aggregations