@Override public ForApiBuilder fromFile(File path) throws ConfigurationLoadException { return from(configHelper.fromFile(path), path.getAbsolutePath()); }
@Override public ForApiBuilder fromFile(URL path) throws ConfigurationLoadException { return from(configHelper.fromFile(path), path.toString()); }
@Override public ForApiBuilder fromFile(File path) throws ConfigurationLoadException { return from(configHelper.fromFile(path), path.getAbsolutePath()); }
/** * Tests that the builder correctly reads properties from a configuration. */ @Test public void testReadPropertiesFromConfiguration_properPrefix() throws ValidationException { PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty("api.admanager.clientId", "clientIdDfp"); config.setProperty("api.admanager.clientSecret", "clientSecretDfp"); config.setProperty("api.admanager.refreshToken", "refreshTokenDfp"); config.setProperty("api.adwords.clientId", "clientIdAdWords"); config.setProperty("api.adwords.clientSecret", "clientSecretAdWords"); config.setProperty("api.adwords.refreshToken", "refreshTokenAdWords"); OfflineCredentials offlineCredentials = new OfflineCredentials.Builder() .forApi(OfflineCredentials.Api.AD_MANAGER) .from(config) .build(); assertEquals("clientIdDfp", offlineCredentials.getClientId()); assertEquals("clientSecretDfp", offlineCredentials.getClientSecret()); assertEquals("refreshTokenDfp", offlineCredentials.getRefreshToken()); }
/** * Tests that the builder correctly reads properties from a configuration. */ @Test public void testReadPropertiesFromConfiguration_dfp() throws ValidationException { PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty("api.admanager.clientId", "clientId"); config.setProperty("api.admanager.clientSecret", "clientSecret"); config.setProperty("api.admanager.refreshToken", "refreshToken"); OfflineCredentials offlineCredentials = new OfflineCredentials.Builder() .forApi(OfflineCredentials.Api.AD_MANAGER) .from(config) .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_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(); }
/** * Tests that the builder correctly fails on a bad configuration that has serviceAccountUser * specified but does not have the jsonKeyFilePath. */ @Test public void testReadPropertiesFromConfiguration_serviceAccountUserNoKeyFile() throws Exception { PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty("api.admanager.clientId", "clientId"); config.setProperty("api.admanager.clientSecret", "clientSecret"); config.setProperty("api.admanager.refreshToken", "refreshToken"); config.setProperty("api.admanager.serviceAccountUser", "someUser@example.com"); thrown.expect(ValidationException.class); new OfflineCredentials.Builder() .forApi(OfflineCredentials.Api.AD_MANAGER) .from(config) .build(); }
/** * Tests that the builder correctly reads properties from a configuration. */ @Test public void testReadPropertiesFromConfiguration_adwords() throws ValidationException { PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty("api.adwords.clientId", "clientId"); config.setProperty("api.adwords.clientSecret", "clientSecret"); config.setProperty("api.adwords.refreshToken", "refreshToken"); OfflineCredentials offlineCredentials = new OfflineCredentials.Builder() .forApi(OfflineCredentials.Api.ADWORDS) .from(config) .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 reads properties from a configuration. */ @Test public void testReadPropertiesFromConfiguration_properPrefixServiceAccount() throws ValidationException { PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty("api.admanager.jsonKeyFilePath", "jsonKeyFilePathDfp"); config.setProperty("api.adwords.jsonKeyFilePath", "jsonKeyFilePathAdWords"); OfflineCredentials offlineCredentials = new OfflineCredentials.Builder() .forApi(OfflineCredentials.Api.AD_MANAGER) .from(config) .build(); assertEquals("jsonKeyFilePathDfp", offlineCredentials.getJsonKeyFilePath()); }
/** * Tests that the builder does not fail when missing everything but a service account key and * service account user. */ @Test public void testReadPropertiesFromConfiguration_onlyKeyFilePathAndUser() throws Exception { PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty("api.admanager.jsonKeyFilePath", "jsonKeyFilePath"); config.setProperty("api.admanager.serviceAccountUser", "someUser@example.com"); OfflineCredentials credentials = new Builder().forApi(Api.AD_MANAGER).from(config).build(); assertEquals( "service account user should have been set from the config", "someUser@example.com", credentials.getServiceAccountUser()); }
/** * Tests that the builder correctly fails on a bad configuration. */ @Test public void testReadPropertiesFromConfiguration_missingClientId() throws Exception { PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty("api.admanager.clientSecret", "clientSecret"); config.setProperty("api.admanager.refreshToken", "refreshToken"); thrown.expect(ValidationException.class); new OfflineCredentials.Builder() .forApi(OfflineCredentials.Api.AD_MANAGER) .from(config) .build(); }
@Override public ForApiBuilder fromFile(String path) throws ConfigurationLoadException { return from(configHelper.fromFile(path), path.toString()); }
/** * Tests that the builder correctly fails on a bad configuration. */ @Test public void testReadPropertiesFromConfiguration_multipleOAuthTypes() throws Exception { PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty("api.admanager.clientSecret", "clientSecret"); config.setProperty("api.admanager.jsonKeyFilePath", "jsonKeyFilePath"); thrown.expect(ValidationException.class); new OfflineCredentials.Builder() .forApi(OfflineCredentials.Api.AD_MANAGER) .from(config) .build(); }
/** * Tests that the builder correctly fails on a bad configuration. */ @Test public void testReadPropertiesFromConfiguration_missingRefreshToken() throws Exception { PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty("api.admanager.clientId", "clientId"); config.setProperty("api.admanager.clientSecret", "clientSecret"); thrown.expect(ValidationException.class); new OfflineCredentials.Builder() .forApi(OfflineCredentials.Api.AD_MANAGER) .from(config) .build(); }
/** * Tests that the builder correctly fails on a bad configuration. */ @Test public void testReadPropertiesFromConfiguration_missingClientSecret() throws Exception { PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty("api.admanager.clientId", "clientId"); config.setProperty("api.admanager.refreshToken", "refreshToken"); thrown.expect(ValidationException.class); new OfflineCredentials.Builder() .forApi(OfflineCredentials.Api.AD_MANAGER) .from(config) .build(); }
@Override public ForApiBuilder fromFile(URL path) throws ConfigurationLoadException { return from(configHelper.fromFile(path), path.toString()); }
@Override public ForApiBuilder fromFile(String path) throws ConfigurationLoadException { return from(configHelper.fromFile(path), path.toString()); }
/** * Tests that the builder does not fail when missing everything but a service account key. */ @Test public void testReadPropertiesFromConfiguration_onlyKeyFilePath() throws Exception { PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty("api.admanager.jsonKeyFilePath", "jsonKeyFilePath"); new OfflineCredentials.Builder() .forApi(OfflineCredentials.Api.AD_MANAGER) .from(config) .build(); }