Package com.google.api.client.testing.http

Examples of com.google.api.client.testing.http.MockHttpTransport


  private static final String CLIENT_SECRET = "secret";
  private static final GenericUrl TOKEN_SERVER_URL = new GenericUrl("http://example.com/token");

  private Credential createCredential() {
    return new Credential.Builder(BearerToken.queryParameterAccessMethod()).setTransport(
        new MockHttpTransport())
        .setJsonFactory(new MockJsonFactory())
        .setTokenServerUrl(TOKEN_SERVER_URL)
        .setClientAuthentication(new BasicAuthentication(CLIENT_ID, CLIENT_SECRET))
        .build()
        .setAccessToken(ACCESS_TOKEN)
View Full Code Here


    assertEquals(ACCESS_TOKEN,
        ((Map<?, ?>) ((UrlEncodedContent) request.getContent()).getData()).get("access_token"));
  }

  private HttpRequest subtestConstructor(Credential credential) throws Exception {
    MockHttpTransport transport = new MockHttpTransport();
    HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
    HttpRequest request = requestFactory.buildDeleteRequest(HttpTesting.SIMPLE_GENERIC_URL);
    request.execute();
    return request;
  }
View Full Code Here

  private static final String CLIENT_ID = "s6BhdRkqt3";
  private static final String CLIENT_SECRET = "7Fjfp0ZBr1KtDRbnfVdmIw";

  public void test() throws Exception {
    HttpRequest request = new MockHttpTransport().createRequestFactory()
        .buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL);
    ClientParametersAuthentication auth =
        new ClientParametersAuthentication(CLIENT_ID, CLIENT_SECRET);
    assertEquals(CLIENT_ID, auth.getClientId());
    assertEquals(CLIENT_SECRET, auth.getClientSecret());
View Full Code Here

    assertEquals(CLIENT_ID, data.get("client_id"));
    assertEquals(CLIENT_SECRET, data.get("client_secret"));
  }

  public void test_noSecret() throws Exception {
    HttpRequest request = new MockHttpTransport().createRequestFactory()
        .buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL);
    ClientParametersAuthentication auth =
        new ClientParametersAuthentication(CLIENT_ID, null);
    assertEquals(CLIENT_ID, auth.getClientId());
    assertNull(auth.getClientSecret());
View Full Code Here

    } catch (NullPointerException expected) {
    }
  }

  public void testGetApplicationDefaultNullJsonFactoryThrows() throws IOException {
    HttpTransport transport = new MockHttpTransport();
    try {
      GoogleCredential.getApplicationDefault(transport, null);
      fail();
    } catch (NullPointerException expected) {
    }
View Full Code Here

    } catch (NullPointerException expected) {
    }
  }

  public void testFromStreamNullJsonFactoryThrows() throws IOException {
    HttpTransport transport = new MockHttpTransport();
    InputStream stream = new ByteArrayInputStream("foo".getBytes());
    try {
      GoogleCredential.fromStream(stream, transport, null);
      fail();
    } catch (NullPointerException expected) {
View Full Code Here

    } catch (NullPointerException expected) {
    }
  }

  public void testFromStreamNullStreamThrows() throws IOException {
    HttpTransport transport = new MockHttpTransport();
    try {
      GoogleCredential.fromStream(null, transport, JSON_FACTORY);
      fail();
    } catch (NullPointerException expected) {
    }
View Full Code Here

  public void testFromStreamServiceAccountMissingClientIdThrows() throws IOException {
    final String serviceAccountEmail =
        "36680232662-vrd7ji19qgchd0ah2csanun6bnr@developer.gserviceaccount.com";

    MockHttpTransport transport = new MockTokenServerTransport();

    // Write out user file
    GenericJson serviceAccountContents = new GenericJson();
    serviceAccountContents.setFactory(JSON_FACTORY);
    serviceAccountContents.put("client_email", serviceAccountEmail);
View Full Code Here

  public void testFromStreamServiceAccountMissingClientEmailThrows() throws IOException {
    final String serviceAccountId =
        "36680232662-vrd7ji19qe3nelgchd0ah2csanun6bnr.apps.googleusercontent.com";

    MockHttpTransport transport = new MockTokenServerTransport();

    // Write out user file
    GenericJson serviceAccountContents = new GenericJson();
    serviceAccountContents.setFactory(JSON_FACTORY);
    serviceAccountContents.put("client_id", serviceAccountId);
View Full Code Here

    final String serviceAccountId =
        "36680232662-vrd7ji19qe3nelgchd0ah2csanun6bnr.apps.googleusercontent.com";
    final String serviceAccountEmail =
        "36680232662-vrd7ji19qgchd0ah2csanun6bnr@developer.gserviceaccount.com";

    MockHttpTransport transport = new MockTokenServerTransport();

    // Write out user file
    GenericJson serviceAccountContents = new GenericJson();
    serviceAccountContents.setFactory(JSON_FACTORY);
    serviceAccountContents.put("client_id", serviceAccountId);
View Full Code Here

TOP

Related Classes of com.google.api.client.testing.http.MockHttpTransport

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.