use of com.google.api.client.testing.http.MockHttpTransport 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.testing.http.MockHttpTransport 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.testing.http.MockHttpTransport in project google-api-java-client by google.
the class GoogleCredentialTest method testFromStreamServiceAccountMissingPrivateKeyThrows.
public void testFromStreamServiceAccountMissingPrivateKeyThrows() throws IOException {
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);
serviceAccountContents.put("client_email", serviceAccountEmail);
serviceAccountContents.put("private_key_id", SA_KEY_ID);
serviceAccountContents.put("type", GoogleCredential.SERVICE_ACCOUNT_FILE_TYPE);
String json = serviceAccountContents.toPrettyString();
InputStream serviceAccountStream = new ByteArrayInputStream(json.getBytes());
try {
GoogleCredential.fromStream(serviceAccountStream, transport, JSON_FACTORY);
fail();
} catch (IOException expected) {
assertTrue(expected.getMessage().contains("private_key"));
}
}
use of com.google.api.client.testing.http.MockHttpTransport 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.testing.http.MockHttpTransport in project google-api-java-client by google.
the class GoogleJsonResponseExceptionTest method testFrom_noDetails.
public void testFrom_noDetails() throws Exception {
HttpTransport transport = new MockHttpTransport();
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("200", ge.getMessage());
}
Aggregations