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