use of com.google.api.client.googleapis.testing.services.MockGoogleClientRequest in project google-api-java-client by google.
the class AbstractGoogleClientRequestTest method testUserAgentSuffix.
public void testUserAgentSuffix() throws Exception {
AssertUserAgentTransport transport = new AssertUserAgentTransport();
// Specify an Application Name.
String applicationName = "Test Application";
transport.expectedUserAgent = applicationName + " " + AbstractGoogleClientRequest.USER_AGENT_SUFFIX + " " + HttpRequest.USER_AGENT_SUFFIX;
MockGoogleClient client = new MockGoogleClient.Builder(transport, ROOT_URL, SERVICE_PATH, JSON_OBJECT_PARSER, null).setApplicationName(applicationName).build();
MockGoogleClientRequest<Void> request = new MockGoogleClientRequest<Void>(client, HttpMethods.GET, URI_TEMPLATE, null, Void.class);
request.executeUnparsed();
// Don't specify an Application Name.
transport.expectedUserAgent = AbstractGoogleClientRequest.USER_AGENT_SUFFIX + " " + HttpRequest.USER_AGENT_SUFFIX;
client = new MockGoogleClient.Builder(transport, ROOT_URL, SERVICE_PATH, JSON_OBJECT_PARSER, null).build();
request = new MockGoogleClientRequest<Void>(client, HttpMethods.GET, URI_TEMPLATE, null, Void.class);
request.executeUnparsed();
}
use of com.google.api.client.googleapis.testing.services.MockGoogleClientRequest in project google-api-java-client by google.
the class AbstractGoogleClientRequestTest method testExecuteUnparsed_error.
public void testExecuteUnparsed_error() throws Exception {
HttpTransport transport = new MockHttpTransport() {
@Override
public LowLevelHttpRequest buildRequest(final String method, final String url) {
return new MockLowLevelHttpRequest() {
@Override
public LowLevelHttpResponse execute() {
assertEquals("GET", method);
assertEquals("https://www.googleapis.com/test/path/v1/tests/foo", url);
MockLowLevelHttpResponse result = new MockLowLevelHttpResponse();
result.setStatusCode(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
result.setContentType(Json.MEDIA_TYPE);
result.setContent(ERROR_CONTENT);
return result;
}
};
}
};
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);
try {
request.put("testId", "foo");
request.executeUnparsed();
fail("expected " + HttpResponseException.class);
} catch (HttpResponseException e) {
// expected
assertEquals("401" + StringUtils.LINE_SEPARATOR + ERROR_CONTENT, e.getMessage());
}
}
use of com.google.api.client.googleapis.testing.services.MockGoogleClientRequest in project google-api-java-client by google.
the class AbstractGoogleClientRequestTest method subtestBuildHttpRequest_emptyContent.
private void subtestBuildHttpRequest_emptyContent(String method, boolean expectEmptyContent) 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, method, URI_TEMPLATE, null, String.class);
HttpRequest httpRequest = request.buildHttpRequest();
if (expectEmptyContent) {
assertTrue(httpRequest.getContent() instanceof EmptyContent);
} else {
assertNull(httpRequest.getContent());
}
}
use of com.google.api.client.googleapis.testing.services.MockGoogleClientRequest 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.MockGoogleClientRequest 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();
}
Aggregations