Search in sources :

Example 6 with MockGoogleClient

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

Example 7 with MockGoogleClient

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.
    }
}
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) MockGoogleClient(com.google.api.client.googleapis.testing.services.MockGoogleClient) MockGoogleClientRequest(com.google.api.client.googleapis.testing.services.MockGoogleClientRequest)

Example 8 with MockGoogleClient

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();
}
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 9 with MockGoogleClient

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);
}
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)

Aggregations

MockGoogleClient (com.google.api.client.googleapis.testing.services.MockGoogleClient)9 MockGoogleClientRequest (com.google.api.client.googleapis.testing.services.MockGoogleClientRequest)8 MockHttpTransport (com.google.api.client.testing.http.MockHttpTransport)6 MockLowLevelHttpRequest (com.google.api.client.testing.http.MockLowLevelHttpRequest)6 HttpTransport (com.google.api.client.http.HttpTransport)5 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