use of com.google.api.client.testing.http.MockHttpTransport 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.testing.http.MockHttpTransport 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.testing.http.MockHttpTransport 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);
}
use of com.google.api.client.testing.http.MockHttpTransport in project google-api-java-client by google.
the class MethodOverrideTest method testInterceptMaxLength.
public void testInterceptMaxLength() throws IOException {
HttpTransport transport = new MockHttpTransport();
GenericUrl url = new GenericUrl(HttpTesting.SIMPLE_URL);
url.set("a", "foo");
HttpRequest request = transport.createRequestFactory().buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL);
new MethodOverride().intercept(request);
assertEquals(HttpMethods.GET, request.getRequestMethod());
assertNull(request.getHeaders().get(MethodOverride.HEADER));
assertNull(request.getContent());
char[] arr = new char[MethodOverride.MAX_URL_LENGTH];
Arrays.fill(arr, 'x');
url.set("a", new String(arr));
request.setUrl(url);
new MethodOverride().intercept(request);
assertEquals(HttpMethods.POST, request.getRequestMethod());
assertEquals(HttpMethods.GET, request.getHeaders().get(MethodOverride.HEADER));
assertEquals(HttpTesting.SIMPLE_GENERIC_URL, request.getUrl());
char[] arr2 = new char[arr.length + 2];
Arrays.fill(arr2, 'x');
arr2[0] = 'a';
arr2[1] = '=';
UrlEncodedContent content = (UrlEncodedContent) request.getContent();
ByteArrayOutputStream out = new ByteArrayOutputStream();
content.writeTo(out);
assertEquals(new String(arr2), out.toString());
}
use of com.google.api.client.testing.http.MockHttpTransport in project google-api-java-client by google.
the class MethodOverrideTest method testIntercept.
public void testIntercept() throws Exception {
subtestIntercept(ImmutableSet.<String>of(), new MockHttpTransport(), new MethodOverride());
subtestIntercept(OVERRIDDEN_METHODS, new MockHttpTransport(), new MethodOverride.Builder().setOverrideAllMethods(true).build());
subtestIntercept(OVERRIDDEN_METHODS, new MockHttpTransport.Builder().setSupportedMethods(ImmutableSet.<String>of(HttpMethods.GET, HttpMethods.POST)).build(), new MethodOverride());
}
Aggregations