use of com.google.api.client.googleapis.testing.compute.MockMetadataServerTransport in project google-api-java-client by google.
the class DefaultCredentialProviderTest method testDefaultCredentialComputeErrorUnexpected.
public void testDefaultCredentialComputeErrorUnexpected() throws IOException {
MockMetadataServerTransport transport = new MockMetadataServerTransport(ACCESS_TOKEN);
transport.setTokenRequestStatusCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR);
TestDefaultCredentialProvider testProvider = new TestDefaultCredentialProvider();
Credential defaultCredential = testProvider.getDefaultCredential(transport, JSON_FACTORY);
assertNotNull(defaultCredential);
try {
defaultCredential.refreshToken();
fail("Expected error refreshing token.");
} catch (IOException expected) {
String message = expected.getMessage();
assertTrue(message.contains(Integer.toString(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)));
assertTrue(message.contains("Unexpected"));
}
}
use of com.google.api.client.googleapis.testing.compute.MockMetadataServerTransport 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.googleapis.testing.compute.MockMetadataServerTransport in project google-api-java-client by google.
the class DefaultCredentialProviderTest method testGetDefaultCredentials_cloudshell_withComputCredentialsPresent.
public void testGetDefaultCredentials_cloudshell_withComputCredentialsPresent() throws IOException {
MockMetadataServerTransport transport = new MockMetadataServerTransport(ACCESS_TOKEN);
TestDefaultCredentialProvider testProvider = new TestDefaultCredentialProvider();
testProvider.setEnv(DefaultCredentialProvider.CLOUD_SHELL_ENV_VAR, "4");
GoogleCredential defaultCredential = testProvider.getDefaultCredential(transport, JSON_FACTORY);
assertTrue(defaultCredential instanceof CloudShellCredential);
assertEquals(((CloudShellCredential) defaultCredential).getAuthPort(), 4);
}
use of com.google.api.client.googleapis.testing.compute.MockMetadataServerTransport in project google-api-java-client by google.
the class ComputeCredentialTest method testExecuteRefreshToken.
public void testExecuteRefreshToken() throws Exception {
HttpTransport transport = new MockMetadataServerTransport(ACCESS_TOKEN);
ComputeCredential credential = new ComputeCredential(transport, new JacksonFactory());
assertTrue(credential.refreshToken());
assertEquals(ACCESS_TOKEN, credential.getAccessToken());
}
use of com.google.api.client.googleapis.testing.compute.MockMetadataServerTransport in project google-api-java-client by google.
the class DefaultCredentialProviderTest method testDefaultCredentialComputeErrorNotFound.
public void testDefaultCredentialComputeErrorNotFound() throws IOException {
MockMetadataServerTransport transport = new MockMetadataServerTransport(ACCESS_TOKEN);
transport.setTokenRequestStatusCode(HttpStatusCodes.STATUS_CODE_NOT_FOUND);
TestDefaultCredentialProvider testProvider = new TestDefaultCredentialProvider();
Credential defaultCredential = testProvider.getDefaultCredential(transport, JSON_FACTORY);
assertNotNull(defaultCredential);
try {
defaultCredential.refreshToken();
fail("Expected error refreshing token.");
} catch (IOException expected) {
String message = expected.getMessage();
assertTrue(message.contains(Integer.toString(HttpStatusCodes.STATUS_CODE_NOT_FOUND)));
assertTrue(message.contains("scope"));
}
}
Aggregations