/** * Tests that the builder correctly identifies the file path. */ @Test public void testReadPropertiesFromFile_refreshTokenBadWithFilePath() throws Exception { PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty("api.admanager.clientId", "clientId"); config.setProperty("api.admanager.clientSecret", "clientSecret"); when(configurationHelper.fromFile("/home/user/path")).thenReturn(config); ForApiBuilder builder = new OfflineCredentials.ForApiBuilder( configurationHelper, OfflineCredentials.Api.AD_MANAGER, oAuth2Helper); thrown.expect(ValidationException.class); thrown.expectMessage( "A refresh token must be set as api.admanager.refreshToken in /home/user/path." + "\nIt is required for offline credentials. If you need to create one, " + "see the GetRefreshToken example."); builder.fromFile("/home/user/path").build(); }
/** * Tests that the builder correctly identifies the file path. */ @Test public void testReadPropertiesFromFile_clientSecretTokenBadWithFilePath() throws Exception { PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty("api.admanager.clientId", "clientId"); config.setProperty("api.admanager.refreshToken", "refreshToken"); when(configurationHelper.fromFile("/home/user/path")).thenReturn(config); ForApiBuilder builder = new OfflineCredentials.ForApiBuilder( configurationHelper, OfflineCredentials.Api.AD_MANAGER, oAuth2Helper); thrown.expect(ValidationException.class); thrown.expectMessage( "Client secret must be set as api.admanager.clientSecret in /home/user/path." + "\nIf you do not have a client ID or secret, please create one in the API " + "console: https://console.developers.google.com/project"); builder.fromFile("/home/user/path").build(); }
/** * Tests that the builder correctly identifies the file path. */ @Test public void testReadPropertiesFromFile_clientIdTokenBadWithFilePath() throws Exception { PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty("api.admanager.clientSecret", "clientSecret"); config.setProperty("api.admanager.refreshToken", "refreshToken"); when(configurationHelper.fromFile("/home/user/path")).thenReturn(config); ForApiBuilder builder = new OfflineCredentials.ForApiBuilder( configurationHelper, OfflineCredentials.Api.AD_MANAGER, oAuth2Helper); thrown.expect(ValidationException.class); thrown.expectMessage( "Client ID must be set as api.admanager.clientId in /home/user/path." + "\nIf you do not have a client ID or secret, please create one in the API " + "console: https://console.developers.google.com/project"); builder.fromFile("/home/user/path").build(); }
/** * Tests that the builder correctly reads from a file. */ @Test public void testReadPropertiesFromFile_withOverride() throws Exception { PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty("api.admanager.clientId", "clientId"); config.setProperty("api.admanager.clientSecret", "clientSecret"); config.setProperty("api.admanager.refreshToken", "refreshToken"); when(configurationHelper.fromFile("path")).thenReturn(config); ForApiBuilder builder = new OfflineCredentials.ForApiBuilder( configurationHelper, OfflineCredentials.Api.AD_MANAGER, oAuth2Helper); OfflineCredentials offlineCredentials = builder.fromFile("path").withRefreshToken("overrideRefreshToken").build(); assertEquals("clientId", offlineCredentials.getClientId()); assertEquals("clientSecret", offlineCredentials.getClientSecret()); assertEquals("overrideRefreshToken", offlineCredentials.getRefreshToken()); }
/** * Tests that the builder correctly reads from a file. */ @Test public void testReadPropertiesFromFile() throws Exception { PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty("api.admanager.clientId", "clientId"); config.setProperty("api.admanager.clientSecret", "clientSecret"); config.setProperty("api.admanager.refreshToken", "refreshToken"); when(configurationHelper.fromFile("path")).thenReturn(config); ForApiBuilder builder = new OfflineCredentials.ForApiBuilder( configurationHelper, OfflineCredentials.Api.AD_MANAGER, oAuth2Helper); OfflineCredentials offlineCredentials = builder.fromFile("path").build(); assertEquals("clientId", offlineCredentials.getClientId()); assertEquals("clientSecret", offlineCredentials.getClientSecret()); assertEquals("refreshToken", offlineCredentials.getRefreshToken()); }
/** * Tests that the builder correctly leaves out the file path. */ @Test public void testReadPropertiesFromFile_clientIdNoFilePath() throws Exception { PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty("api.admanager.clientSecret", "clientSecret"); config.setProperty("api.admanager.refreshToken", "refreshToken"); ForApiBuilder builder = new OfflineCredentials.ForApiBuilder( configurationHelper, OfflineCredentials.Api.AD_MANAGER, oAuth2Helper); thrown.expect(ValidationException.class); thrown.expectMessage("Client ID must be set." + "\nIf you do not have a client ID or secret, please create one in the API " + "console: https://console.developers.google.com/project"); builder.from(config).build(); }
/** * Tests that the builder correctly leaves out the file path. */ @Test public void testReadPropertiesFromFile_clientSecretNoFilePath() throws Exception { PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty("api.admanager.clientId", "clientId"); config.setProperty("api.admanager.refreshToken", "refreshToken"); ForApiBuilder builder = new OfflineCredentials.ForApiBuilder( configurationHelper, OfflineCredentials.Api.AD_MANAGER, oAuth2Helper); thrown.expect(ValidationException.class); thrown.expectMessage("Client secret must be set." + "\nIf you do not have a client ID or secret, please create one in the API " + "console: https://console.developers.google.com/project"); builder.from(config).build(); }
/** * Tests that the builder correctly leaves out the file path. */ @Test public void testReadPropertiesFromFile_refreshTokenNoFilePath() throws Exception { PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty("api.admanager.clientId", "clientId"); config.setProperty("api.admanager.clientSecret", "clientSecret"); ForApiBuilder builder = new OfflineCredentials.ForApiBuilder( configurationHelper, OfflineCredentials.Api.AD_MANAGER, oAuth2Helper); thrown.expect(ValidationException.class); thrown.expectMessage("A refresh token must be set." + "\nIt is required for offline credentials. If you need to create one, " + "see the GetRefreshToken example."); builder.from(config).build(); }
/** * Specifies which {@link OAuthConfig} should this {@code OfflineCredentials} be * used for. Should be called first before any other builder methods. */ public ForApiBuilder forApi(OAuthConfig oAuthConfig) { defaultOptionals(oAuthConfig); return new ForApiBuilder(oAuthConfig, oAuth2Helper); }
/** * Specifies which {@link OAuthConfig} should this {@code OfflineCredentials} be * used for. Should be called first before any other builder methods. */ public ForApiBuilder forApi(OAuthConfig oAuthConfig) { defaultOptionals(oAuthConfig); return new ForApiBuilder(oAuthConfig, oAuth2Helper); }