InstanceMetadata { public OAuth2ServiceTokenMetadata serviceToken(final String scope) { return serviceToken("default", scope); } InstanceMetadata(JsonFactory jsonFactory, HttpTransport httpTransport); String metadata(String keyName); static String resourceShortName(String resource); String customMetadata(String keyName); OAuth2ServiceTokenMetadata serviceToken(final String scope); OAuth2ServiceTokenMetadata serviceToken(final String serviceAccount, final String scope); NetworkMetadata network();  }
@Test public void testOAuth2Scopes() { InstanceMetadata metadata = mockOkayRequest( "{\"accessToken\":\"abc\",\"expiresAt\":1346953416,\"expiresIn\":3412}"); OAuth2ServiceTokenMetadata token = metadata.serviceToken("http: assertEquals("abc", token.getAccessToken()); assertEquals(Long.valueOf(1346953416L), token.getExpiresAt()); assertEquals(Long.valueOf(3412L), token.getExpiresIn()); }
@Test(expected = MetadataOAuth2ScopeNotFoundException.class) public void testOAuth2MissingScope() { InstanceMetadata metadata = mockRequest(HttpStatusCodes.STATUS_CODE_NOT_FOUND); metadata.serviceToken("default", "http: }
@Test(expected = IllegalStateException.class) public void testOAuth2ScopeError() { InstanceMetadata metadata = mockRequest(HttpStatusCodes.STATUS_CODE_SERVER_ERROR); metadata.serviceToken("default", "http: }