use of com.google.api.client.googleapis.testing.services.MockGoogleClientRequest in project google-api-java-client by google.
the class BatchRequestTest method getBatchPopulatedWithRequests.
private BatchRequest getBatchPopulatedWithRequests(boolean testServerError, boolean testAuthenticationError, boolean returnSuccessAuthenticatedContent, boolean testExponentialBackOff, boolean testRedirect, boolean testBinary, boolean testMissingLength) throws Exception {
transport = new MockTransport(testServerError, testAuthenticationError, testExponentialBackOff, testRedirect, testBinary, testMissingLength);
MockGoogleClient client = new MockGoogleClient.Builder(transport, ROOT_URL, SERVICE_PATH, null, null).setApplicationName("Test Application").build();
MockGoogleClientRequest<String> jsonHttpRequest1 = new MockGoogleClientRequest<String>(client, METHOD1, URI_TEMPLATE1, null, String.class);
MockGoogleClientRequest<String> jsonHttpRequest2 = new MockGoogleClientRequest<String>(client, METHOD2, URI_TEMPLATE2, null, String.class);
credential = new MockCredential();
ObjectParser parser = testBinary ? new ProtoObjectParser() : new JsonObjectParser(new JacksonFactory());
BatchRequest batchRequest = new BatchRequest(transport, credential).setBatchUrl(new GenericUrl(TEST_BATCH_URL));
HttpRequest request1 = jsonHttpRequest1.buildHttpRequest();
request1.setParser(parser);
HttpRequest request2 = jsonHttpRequest2.buildHttpRequest();
request2.setParser(parser);
if (testAuthenticationError) {
request2.setUnsuccessfulResponseHandler(new MockUnsuccessfulResponseHandler(transport, returnSuccessAuthenticatedContent));
}
if (testExponentialBackOff) {
request2.setBackOffPolicy(new MockExponentialBackOffPolicy());
}
if (testBinary) {
batchRequest.queue(request1, MockData.Class1.class, ErrorOutput.ErrorBody.class, new TestCallback1Adapter(callback1));
batchRequest.queue(request2, MockData.Class2.class, ErrorOutput.ErrorBody.class, new TestCallback2Adapter(callback2));
} else {
batchRequest.queue(request1, MockDataClass1.class, GoogleJsonErrorContainer.class, callback1);
batchRequest.queue(request2, MockDataClass2.class, GoogleJsonErrorContainer.class, callback2);
}
return batchRequest;
}
use of com.google.api.client.googleapis.testing.services.MockGoogleClientRequest in project google-api-java-client by google.
the class BatchRequestTest method subTestExecuteWithVoidCallback.
public void subTestExecuteWithVoidCallback(boolean testServerError) throws Exception {
MockTransport transport = new MockTransport(testServerError, false, false, false, false, false);
MockGoogleClient client = new MockGoogleClient.Builder(transport, ROOT_URL, SERVICE_PATH, null, null).setApplicationName("Test Application").build();
MockGoogleClientRequest<String> jsonHttpRequest1 = new MockGoogleClientRequest<String>(client, METHOD1, URI_TEMPLATE1, null, String.class);
MockGoogleClientRequest<String> jsonHttpRequest2 = new MockGoogleClientRequest<String>(client, METHOD2, URI_TEMPLATE2, null, String.class);
ObjectParser parser = new JsonObjectParser(new JacksonFactory());
BatchRequest batchRequest = new BatchRequest(transport, null).setBatchUrl(new GenericUrl(TEST_BATCH_URL));
HttpRequest request1 = jsonHttpRequest1.buildHttpRequest();
request1.setParser(parser);
HttpRequest request2 = jsonHttpRequest2.buildHttpRequest();
request2.setParser(parser);
batchRequest.queue(request1, MockDataClass1.class, GoogleJsonErrorContainer.class, callback1);
batchRequest.queue(request2, Void.class, Void.class, callback3);
batchRequest.execute();
// Assert transport called expected number of times.
assertEquals(1, transport.actualCalls);
}
use of com.google.api.client.googleapis.testing.services.MockGoogleClientRequest in project google-api-java-client by google.
the class AbstractGoogleClientTest method testMediaUpload_defaultGZip.
public void testMediaUpload_defaultGZip() throws Exception {
MediaTransport transport = new MediaTransport();
transport.contentLengthNotSpecified = true;
AbstractGoogleClient client = new MockGoogleClient.Builder(transport, TEST_RESUMABLE_REQUEST_URL, "", JSON_OBJECT_PARSER, new GZipCheckerInitializer(false)).setApplicationName("Test Application").build();
InputStream is = new ByteArrayInputStream(new byte[MediaHttpUploader.DEFAULT_CHUNK_SIZE]);
InputStreamContent mediaContent = new InputStreamContent(TEST_CONTENT_TYPE, is);
MockGoogleClientRequest<A> rq = new MockGoogleClientRequest<A>(client, "POST", "", null, A.class);
rq.initializeMediaUpload(mediaContent);
A result = rq.execute();
assertEquals("somevalue", result.foo);
}
use of com.google.api.client.googleapis.testing.services.MockGoogleClientRequest in project google-api-java-client by google.
the class AbstractGoogleClientTest method testMediaUpload.
public void testMediaUpload() throws Exception {
MediaTransport transport = new MediaTransport();
AbstractGoogleClient client = new MockGoogleClient.Builder(transport, TEST_RESUMABLE_REQUEST_URL, "", JSON_OBJECT_PARSER, null).setApplicationName("Test Application").build();
InputStream is = new ByteArrayInputStream(new byte[MediaHttpUploader.DEFAULT_CHUNK_SIZE]);
InputStreamContent mediaContent = new InputStreamContent(TEST_CONTENT_TYPE, is);
mediaContent.setLength(MediaHttpUploader.DEFAULT_CHUNK_SIZE);
MockGoogleClientRequest<A> rq = new MockGoogleClientRequest<A>(client, "POST", "", null, A.class);
rq.initializeMediaUpload(mediaContent);
A result = rq.execute();
assertEquals("somevalue", result.foo);
}
use of com.google.api.client.googleapis.testing.services.MockGoogleClientRequest in project google-api-java-client by google.
the class AbstractGoogleClientTest method testMediaUpload_enableGZip.
public void testMediaUpload_enableGZip() throws Exception {
MediaTransport transport = new MediaTransport();
transport.contentLengthNotSpecified = true;
AbstractGoogleClient client = new MockGoogleClient.Builder(transport, TEST_RESUMABLE_REQUEST_URL, "", JSON_OBJECT_PARSER, new GZipCheckerInitializer(false)).setApplicationName("Test Application").build();
InputStream is = new ByteArrayInputStream(new byte[MediaHttpUploader.DEFAULT_CHUNK_SIZE]);
InputStreamContent mediaContent = new InputStreamContent(TEST_CONTENT_TYPE, is);
MockGoogleClientRequest<A> rq = new MockGoogleClientRequest<A>(client, "POST", "", null, A.class);
rq.initializeMediaUpload(mediaContent);
rq.setDisableGZipContent(false);
A result = rq.execute();
assertEquals("somevalue", result.foo);
}
Aggregations