Search in sources :

Example 61 with MockHttpTransport

use of com.google.api.client.testing.http.MockHttpTransport in project google-api-java-client by google.

the class BatchRequestTest method testExecute_checkWriteTo.

public void testExecute_checkWriteTo() throws Exception {
    String request1Method = HttpMethods.POST;
    String request1Url = "http://test/dummy/url1";
    String request1ContentType = "application/json";
    String request1Content = "{\"data\":{\"foo\":{\"v1\":{}}}}";
    String request2Method = HttpMethods.GET;
    String request2Url = "http://test/dummy/url2";
    final StringBuilder expectedOutput = new StringBuilder();
    expectedOutput.append("--__END_OF_PART__\r\n");
    expectedOutput.append("Content-Length: 118\r\n");
    expectedOutput.append("Content-Type: application/http\r\n");
    expectedOutput.append("content-id: 1\r\n");
    expectedOutput.append("content-transfer-encoding: binary\r\n");
    expectedOutput.append("\r\n");
    expectedOutput.append("POST http://test/dummy/url1 HTTP/1.1\r\n");
    expectedOutput.append("Content-Length: 26\r\n");
    expectedOutput.append("Content-Type: " + request1ContentType + "\r\n");
    expectedOutput.append("\r\n");
    expectedOutput.append(request1Content + "\r\n");
    expectedOutput.append("--__END_OF_PART__\r\n");
    expectedOutput.append("Content-Length: 39\r\n");
    expectedOutput.append("Content-Type: application/http\r\n");
    expectedOutput.append("content-id: 2\r\n");
    expectedOutput.append("content-transfer-encoding: binary\r\n");
    expectedOutput.append("\r\n");
    expectedOutput.append("GET http://test/dummy/url2 HTTP/1.1\r\n");
    expectedOutput.append("\r\n");
    expectedOutput.append("\r\n");
    expectedOutput.append("--__END_OF_PART__--\r\n");
    MockHttpTransport transport = new MockHttpTransport();
    HttpRequest request1 = transport.createRequestFactory().buildRequest(request1Method, new GenericUrl(request1Url), new ByteArrayContent(request1ContentType, request1Content.getBytes(UTF_8)));
    HttpRequest request2 = transport.createRequestFactory().buildRequest(request2Method, new GenericUrl(request2Url), null);
    subtestExecute_checkWriteTo(expectedOutput.toString(), request1, request2);
}
Also used : LowLevelHttpRequest(com.google.api.client.http.LowLevelHttpRequest) HttpRequest(com.google.api.client.http.HttpRequest) MockLowLevelHttpRequest(com.google.api.client.testing.http.MockLowLevelHttpRequest) MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport) GenericUrl(com.google.api.client.http.GenericUrl) ByteArrayContent(com.google.api.client.http.ByteArrayContent)

Example 62 with MockHttpTransport

use of com.google.api.client.testing.http.MockHttpTransport in project google-api-java-client by google.

the class BatchRequestTest method testExecute_checkWriteToNoHeaders.

public void testExecute_checkWriteToNoHeaders() throws Exception {
    MockHttpTransport transport = new MockHttpTransport();
    HttpRequest request1 = transport.createRequestFactory().buildPostRequest(HttpTesting.SIMPLE_GENERIC_URL, new HttpContent() {

        @Override
        public long getLength() {
            return -1;
        }

        @Override
        public String getType() {
            return null;
        }

        @Override
        public void writeTo(OutputStream out) {
        }

        @Override
        public boolean retrySupported() {
            return true;
        }
    });
    subtestExecute_checkWriteTo(new StringBuilder().append("--__END_OF_PART__\r\n").append("Content-Length: 36\r\n").append("Content-Type: application/http\r\n").append("content-id: 1\r\n").append("content-transfer-encoding: binary\r\n").append("\r\n").append("POST http://google.com/ HTTP/1.1\r\n").append("\r\n").append("\r\n").append("--__END_OF_PART__--\r\n").toString(), request1);
}
Also used : LowLevelHttpRequest(com.google.api.client.http.LowLevelHttpRequest) HttpRequest(com.google.api.client.http.HttpRequest) MockLowLevelHttpRequest(com.google.api.client.testing.http.MockLowLevelHttpRequest) MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) HttpContent(com.google.api.client.http.HttpContent)

Example 63 with MockHttpTransport

use of com.google.api.client.testing.http.MockHttpTransport in project google-api-java-client by google.

the class GoogleAuthorizationCodeTokenRequestTest method test.

public void test() {
    GoogleAuthorizationCodeTokenRequest request = new GoogleAuthorizationCodeTokenRequest(new MockHttpTransport(), new JacksonFactory(), CLIENT_ID, CLIENT_SECRET, CODE, REDIRECT_URI);
    ClientParametersAuthentication clientAuthentication = (ClientParametersAuthentication) request.getClientAuthentication();
    assertEquals(CLIENT_ID, clientAuthentication.getClientId());
    assertEquals(CLIENT_SECRET, clientAuthentication.getClientSecret());
    assertEquals(CODE, request.getCode());
    assertEquals(REDIRECT_URI, request.getRedirectUri());
    assertEquals("authorization_code", request.getGrantType());
    assertNull(request.getScopes());
    assertNotNull(request.getTokenServerUrl());
}
Also used : ClientParametersAuthentication(com.google.api.client.auth.oauth2.ClientParametersAuthentication) MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory)

Example 64 with MockHttpTransport

use of com.google.api.client.testing.http.MockHttpTransport in project google-api-java-client by google.

the class GooglePublicKeysManagerTest method testBuilder.

public void testBuilder() throws Exception {
    HttpTransport transport = new MockHttpTransport();
    JsonFactory jsonFactory = new JacksonFactory();
    GooglePublicKeysManager.Builder builder = new GooglePublicKeysManager.Builder(transport, jsonFactory);
    GooglePublicKeysManager certs = builder.build();
    assertEquals(transport, certs.getTransport());
    assertEquals(jsonFactory, certs.getJsonFactory());
}
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) JsonFactory(com.google.api.client.json.JsonFactory) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory)

Example 65 with MockHttpTransport

use of com.google.api.client.testing.http.MockHttpTransport in project google-api-java-client by google.

the class GooglePublicKeysManagerTest method testGetCacheTimeInSec.

public void testGetCacheTimeInSec() throws Exception {
    GooglePublicKeysManager certs = new GooglePublicKeysManager.Builder(new MockHttpTransport(), new JacksonFactory()).build();
    assertEquals(12000, certs.getCacheTimeInSec(new HttpHeaders().setAge(345L).setCacheControl("max-age=" + MAX_AGE)));
    assertEquals(0, certs.getCacheTimeInSec(new HttpHeaders()));
    assertEquals(0, certs.getCacheTimeInSec(new HttpHeaders().setAge(345L)));
    assertEquals(0, certs.getCacheTimeInSec(new HttpHeaders().setAge(345L).setCacheControl("max-age=300")));
}
Also used : HttpHeaders(com.google.api.client.http.HttpHeaders) MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory)

Aggregations

MockHttpTransport (com.google.api.client.testing.http.MockHttpTransport)83 MockLowLevelHttpRequest (com.google.api.client.testing.http.MockLowLevelHttpRequest)44 MockLowLevelHttpResponse (com.google.api.client.testing.http.MockLowLevelHttpResponse)42 Test (org.junit.Test)32 HttpTransport (com.google.api.client.http.HttpTransport)30 IOException (java.io.IOException)29 LowLevelHttpRequest (com.google.api.client.http.LowLevelHttpRequest)26 LowLevelHttpResponse (com.google.api.client.http.LowLevelHttpResponse)23 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)19 HttpRequest (com.google.api.client.http.HttpRequest)14 JsonFactory (com.google.api.client.json.JsonFactory)13 GenericJson (com.google.api.client.json.GenericJson)12 Storage (com.google.api.services.storage.Storage)9 HttpResponse (com.google.api.client.http.HttpResponse)7 MockGoogleClient (com.google.api.client.googleapis.testing.services.MockGoogleClient)6 GenericUrl (com.google.api.client.http.GenericUrl)6 MockGoogleClientRequest (com.google.api.client.googleapis.testing.services.MockGoogleClientRequest)5 Objectify (com.googlecode.objectify.Objectify)5 MockTokenServerTransport (com.google.api.client.googleapis.testing.auth.oauth2.MockTokenServerTransport)4 ByteArrayContent (com.google.api.client.http.ByteArrayContent)4