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