Search in sources :

Example 11 with MockGoogleClientRequest

use of com.google.api.client.googleapis.testing.services.MockGoogleClientRequest 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);
}
Also used : MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport) HttpTransport(com.google.api.client.http.HttpTransport) MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport) MockLowLevelHttpResponse(com.google.api.client.testing.http.MockLowLevelHttpResponse) MockGoogleClient(com.google.api.client.googleapis.testing.services.MockGoogleClient) MockGoogleClientRequest(com.google.api.client.googleapis.testing.services.MockGoogleClientRequest) MockLowLevelHttpRequest(com.google.api.client.testing.http.MockLowLevelHttpRequest)

Example 12 with MockGoogleClientRequest

use of com.google.api.client.googleapis.testing.services.MockGoogleClientRequest in project google-api-java-client by google.

the class AbstractGoogleClientTest method testMediaUpload_disableGZip.

public void testMediaUpload_disableGZip() throws Exception {
    MediaTransport transport = new MediaTransport();
    transport.contentLengthNotSpecified = true;
    AbstractGoogleClient client = new MockGoogleClient.Builder(transport, TEST_RESUMABLE_REQUEST_URL, "", JSON_OBJECT_PARSER, new GZipCheckerInitializer(true)).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(true);
    A result = rq.execute();
    assertEquals("somevalue", result.foo);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InputStreamContent(com.google.api.client.http.InputStreamContent) MockGoogleClientRequest(com.google.api.client.googleapis.testing.services.MockGoogleClientRequest)

Aggregations

MockGoogleClientRequest (com.google.api.client.googleapis.testing.services.MockGoogleClientRequest)12 MockGoogleClient (com.google.api.client.googleapis.testing.services.MockGoogleClient)8 MockLowLevelHttpRequest (com.google.api.client.testing.http.MockLowLevelHttpRequest)6 HttpTransport (com.google.api.client.http.HttpTransport)5 MockHttpTransport (com.google.api.client.testing.http.MockHttpTransport)5 InputStreamContent (com.google.api.client.http.InputStreamContent)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)4 HttpRequest (com.google.api.client.http.HttpRequest)3 LowLevelHttpRequest (com.google.api.client.http.LowLevelHttpRequest)3 MockLowLevelHttpResponse (com.google.api.client.testing.http.MockLowLevelHttpResponse)3 GenericUrl (com.google.api.client.http.GenericUrl)2 JsonObjectParser (com.google.api.client.json.JsonObjectParser)2 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)2 ProtoObjectParser (com.google.api.client.protobuf.ProtoObjectParser)2 ObjectParser (com.google.api.client.util.ObjectParser)2 EmptyContent (com.google.api.client.http.EmptyContent)1 HttpResponseException (com.google.api.client.http.HttpResponseException)1