Search in sources :

Example 21 with HttpTransport

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

the class DefaultCredentialProviderTest method testDefaultCredentialAppEngineDeployed.

public void testDefaultCredentialAppEngineDeployed() throws IOException {
    HttpTransport transport = new MockHttpTransport();
    TestDefaultCredentialProvider testProvider = new TestDefaultCredentialProvider();
    testProvider.addType(DefaultCredentialProvider.APP_ENGINE_CREDENTIAL_CLASS, MockAppEngineCredential.class);
    testProvider.addType(GAE_SIGNAL_CLASS, MockAppEngineSystemProperty.class);
    Credential defaultCredential = testProvider.getDefaultCredential(transport, JSON_FACTORY);
    assertNotNull(defaultCredential);
    assertTrue(defaultCredential instanceof MockAppEngineCredential);
    assertSame(transport, defaultCredential.getTransport());
    assertSame(JSON_FACTORY, defaultCredential.getJsonFactory());
}
Also used : MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport) HttpTransport(com.google.api.client.http.HttpTransport) Credential(com.google.api.client.auth.oauth2.Credential) MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport)

Example 22 with HttpTransport

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

the class DefaultCredentialProviderTest method testDefaultCredentialNotFoundError.

public void testDefaultCredentialNotFoundError() {
    HttpTransport transport = new MockHttpTransport();
    TestDefaultCredentialProvider testProvider = new TestDefaultCredentialProvider();
    try {
        testProvider.getDefaultCredential(transport, JSON_FACTORY);
        fail();
    } catch (IOException e) {
        String message = e.getMessage();
        assertTrue(message.contains(DefaultCredentialProvider.HELP_PERMALINK));
    }
}
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) IOException(java.io.IOException)

Example 23 with HttpTransport

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

the class DefaultCredentialProviderTest method testDefaultCredentialAppEngineWithoutDependencyThrowsHelpfulLoadError.

public void testDefaultCredentialAppEngineWithoutDependencyThrowsHelpfulLoadError() {
    HttpTransport transport = new MockHttpTransport();
    TestDefaultCredentialProvider testProvider = new TestDefaultCredentialProvider();
    testProvider.addType(GAE_SIGNAL_CLASS, MockAppEngineSystemProperty.class);
    try {
        testProvider.getDefaultCredential(transport, JSON_FACTORY);
        fail("Credential expected to fail to load if credential class not present.");
    } catch (IOException e) {
        String message = e.getMessage();
        assertFalse(message.contains(DefaultCredentialProvider.HELP_PERMALINK));
        assertTrue(message.contains(DefaultCredentialProvider.APP_ENGINE_CREDENTIAL_CLASS));
    }
}
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) IOException(java.io.IOException)

Example 24 with HttpTransport

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

the class DefaultCredentialProviderTest method testDefaultCredentialNonExistentFileThrows.

public void testDefaultCredentialNonExistentFileThrows() throws Exception {
    File nonExistentFile = new java.io.File(getTempDirectory(), "DefaultCredentialBadFile.json");
    assertFalse(nonExistentFile.exists());
    HttpTransport transport = new MockHttpTransport();
    TestDefaultCredentialProvider testProvider = new TestDefaultCredentialProvider();
    testProvider.setEnv(DefaultCredentialProvider.CREDENTIAL_ENV_VAR, nonExistentFile.getAbsolutePath());
    try {
        testProvider.getDefaultCredential(transport, JSON_FACTORY);
        fail("Non existent user credential should throw exception.");
    } catch (IOException e) {
        String message = e.getMessage();
        assertTrue(message.contains(DefaultCredentialProvider.CREDENTIAL_ENV_VAR));
        assertTrue(message.contains(nonExistentFile.getAbsolutePath()));
    }
}
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) IOException(java.io.IOException) File(java.io.File)

Example 25 with HttpTransport

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

the class DefaultCredentialProviderTest method testDefaultCredentialAppEngineComponentOffAppEngineGivesNotFoundError.

public void testDefaultCredentialAppEngineComponentOffAppEngineGivesNotFoundError() {
    HttpTransport transport = new MockHttpTransport();
    TestDefaultCredentialProvider testProvider = new TestDefaultCredentialProvider();
    testProvider.addType(DefaultCredentialProvider.APP_ENGINE_CREDENTIAL_CLASS, MockAppEngineCredential.class);
    testProvider.addType(GAE_SIGNAL_CLASS, MockOffAppEngineSystemProperty.class);
    try {
        testProvider.getDefaultCredential(transport, JSON_FACTORY);
        fail("No credential expected when not on App Engine.");
    } catch (IOException e) {
        String message = e.getMessage();
        assertTrue(message.contains(DefaultCredentialProvider.HELP_PERMALINK));
    }
}
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) IOException(java.io.IOException)

Aggregations

HttpTransport (com.google.api.client.http.HttpTransport)106 MockHttpTransport (com.google.api.client.testing.http.MockHttpTransport)40 JsonFactory (com.google.api.client.json.JsonFactory)35 HttpRequest (com.google.api.client.http.HttpRequest)29 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)28 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)28 GoogleCredential (com.google.api.client.googleapis.auth.oauth2.GoogleCredential)27 IOException (java.io.IOException)24 GoogleNetHttpTransport (com.google.api.client.googleapis.javanet.GoogleNetHttpTransport)21 HttpResponse (com.google.api.client.http.HttpResponse)21 GenericUrl (com.google.api.client.http.GenericUrl)15 MockLowLevelHttpRequest (com.google.api.client.testing.http.MockLowLevelHttpRequest)12 MockLowLevelHttpResponse (com.google.api.client.testing.http.MockLowLevelHttpResponse)11 Credential (com.google.api.client.auth.oauth2.Credential)10 HttpRequestFactory (com.google.api.client.http.HttpRequestFactory)10 Storage (com.google.api.services.storage.Storage)9 HttpRequestInitializer (com.google.api.client.http.HttpRequestInitializer)8 Test (org.junit.Test)8 Monitor (org.datatransferproject.api.launcher.Monitor)7 ErrorTransport (com.google.api.client.googleapis.json.GoogleJsonErrorTest.ErrorTransport)6