use of com.google.api.client.http.HttpTransport in project google-api-java-client by google.
the class DefaultCredentialProviderTest method testDefaultCredentialAppEngineSingleClassLoadAttempt.
public void testDefaultCredentialAppEngineSingleClassLoadAttempt() {
HttpTransport transport = new MockHttpTransport();
TestDefaultCredentialProvider testProvider = new TestDefaultCredentialProvider();
try {
testProvider.getDefaultCredential(transport, JSON_FACTORY);
fail("No credential expected for default test provider.");
} catch (IOException expected) {
}
assertEquals(1, testProvider.getForNameCallCount());
// Try a second time.
try {
testProvider.getDefaultCredential(transport, JSON_FACTORY);
fail("No credential expected for default test provider.");
} catch (IOException expected) {
}
assertEquals(1, testProvider.getForNameCallCount());
}
use of com.google.api.client.http.HttpTransport in project google-api-java-client by google.
the class DefaultCredentialProviderTest method testDefaultCredentialCompute.
public void testDefaultCredentialCompute() throws IOException {
HttpTransport transport = new MockMetadataServerTransport(ACCESS_TOKEN);
TestDefaultCredentialProvider testProvider = new TestDefaultCredentialProvider();
Credential defaultCredential = testProvider.getDefaultCredential(transport, JSON_FACTORY);
assertNotNull(defaultCredential);
assertTrue(defaultCredential.refreshToken());
assertEquals(ACCESS_TOKEN, defaultCredential.getAccessToken());
}
use of com.google.api.client.http.HttpTransport in project google-api-java-client by google.
the class DefaultCredentialProviderTest method testDefaultCredentialCaches.
public void testDefaultCredentialCaches() 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 firstCall = testProvider.getDefaultCredential(transport, JSON_FACTORY);
assertNotNull(firstCall);
Credential secondCall = testProvider.getDefaultCredential(transport, JSON_FACTORY);
assertSame(firstCall, secondCall);
}
use of com.google.api.client.http.HttpTransport in project google-api-java-client by google.
the class GoogleCredentialTest method testGetApplicationDefaultNullJsonFactoryThrows.
public void testGetApplicationDefaultNullJsonFactoryThrows() throws IOException {
HttpTransport transport = new MockHttpTransport();
try {
GoogleCredential.getApplicationDefault(transport, null);
fail();
} catch (NullPointerException expected) {
}
}
use of com.google.api.client.http.HttpTransport in project google-api-java-client by google.
the class GoogleJsonResponseExceptionTest method testFrom_errorEmptyContentButWithJsonContentType.
public void testFrom_errorEmptyContentButWithJsonContentType() throws Exception {
HttpTransport transport = new ErrorTransport(null, Json.MEDIA_TYPE);
HttpRequest request = transport.createRequestFactory().buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL);
request.setThrowExceptionOnExecuteError(false);
HttpResponse response = request.execute();
GoogleJsonResponseException ge = GoogleJsonResponseException.from(GoogleJsonErrorTest.FACTORY, response);
assertNull(ge.getDetails());
assertEquals("403", ge.getMessage());
}
Aggregations