@Override public GoogleClientSecretsForApiBuilder fromFile(File path) throws ConfigurationLoadException { return from(configHelper.fromFile(path), path.getAbsolutePath()); }
@Override public GoogleClientSecretsForApiBuilder fromFile(URL path) throws ConfigurationLoadException { return from(configHelper.fromFile(path), path.toString()); }
@Override public GoogleClientSecretsForApiBuilder fromFile(URL path) throws ConfigurationLoadException { return from(configHelper.fromFile(path), path.toString()); }
/** * Reads properties from the provided {@link Configuration} object * <br><br> * Understands the following properties suffixes: * <br><br> * <ul> * <li>clientId</li> * <li>clientSecret</li> * </ul><br> * For example, the AdWords OAuth2 client ID can be read from: * <code>api.adwords.clientId</code> * * @param config the configuration * @param filePath the file path of the configuration * @return Builder populated from the Configuration */ private GoogleClientSecretsForApiBuilder from(Configuration config, String filePath) { from(config); this.filePath = filePath; return this; }
/** * Tests that the builder correctly throws exception when client secret is a * default value. */ @Test public void testReadPropertiesFromFile_defaultClientSecret() throws Exception { PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty("api.admanager.clientId", "clientId"); config.setProperty("api.admanager.clientId", "INSERT_CLIENT_SECRET_HERE"); GoogleClientSecretsForApiBuilder builder = new GoogleClientSecretsForApiBuilder( configurationHelper, GoogleClientSecretsBuilder.Api.AD_MANAGER); 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"); builder.from(config).build(); } }
/** * Tests that the builder correctly reads properties from a configuration. */ @Test public void testGoogleSecretsReadPropertiesFromConfiguration_properPrefix() throws ValidationException { PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty("api.admanager.clientId", "clientIdDfp"); config.setProperty("api.admanager.clientSecret", "clientSecretDfp"); config.setProperty("api.adwords.clientId", "clientIdAdWords"); config.setProperty("api.adwords.clientSecret", "clientSecretAdWords"); GoogleClientSecrets googleClientSecrets = new GoogleClientSecretsBuilder() .forApi(GoogleClientSecretsBuilder.Api.AD_MANAGER) .from(config) .build(); assertEquals("clientIdDfp", googleClientSecrets.getInstalled().getClientId()); assertEquals("clientSecretDfp", googleClientSecrets.getInstalled().getClientSecret()); }
/** * Reads properties from the provided {@link Configuration} object * <br><br> * Understands the following properties suffixes: * <br><br> * <ul> * <li>clientId</li> * <li>clientSecret</li> * </ul><br> * For example, the AdWords OAuth2 client ID can be read from: * <code>api.adwords.clientId</code> * * @param config the configuration * @param filePath the file path of the configuration * @return Builder populated from the Configuration */ private GoogleClientSecretsForApiBuilder from(Configuration config, String filePath) { from(config); this.filePath = filePath; return this; }
/** * Tests that the builder correctly throws exception when client ID is a * default value. */ @Test public void testReadPropertiesFromFile_defaultClientId() throws Exception { PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty("api.admanager.clientId", "INSERT_CLIENT_ID_HERE"); GoogleClientSecretsForApiBuilder builder = new GoogleClientSecretsForApiBuilder( configurationHelper, GoogleClientSecretsBuilder.Api.AD_MANAGER); 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"); builder.from(config).build(); }
/** * 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"); GoogleClientSecretsForApiBuilder builder = new GoogleClientSecretsForApiBuilder( configurationHelper, GoogleClientSecretsBuilder.Api.AD_MANAGER); 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"); 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"); GoogleClientSecretsForApiBuilder builder = new GoogleClientSecretsForApiBuilder( configurationHelper, GoogleClientSecretsBuilder.Api.AD_MANAGER); 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"); builder.from(config).build(); }
/** * Tests that the builder correctly reads properties from a configuration. */ @Test public void testGoogleSecretsReadPropertiesFromConfiguration() throws ValidationException { PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty("api.admanager.clientId", "clientId"); config.setProperty("api.admanager.clientSecret", "clientSecret"); GoogleClientSecrets googleClientSecrets = new GoogleClientSecretsBuilder() .forApi(GoogleClientSecretsBuilder.Api.AD_MANAGER) .from(config) .build(); assertEquals("clientId", googleClientSecrets.getInstalled().getClientId()); assertEquals("clientSecret", googleClientSecrets.getInstalled().getClientSecret()); }
@Override public GoogleClientSecretsForApiBuilder fromFile(File path) throws ConfigurationLoadException { return from(configHelper.fromFile(path), path.getAbsolutePath()); }
/** * Tests that the builder correctly fails on a bad configuration. */ @Test public void testGoogleSecretsReadPropertiesFromConfiguration_missingClientSecret() throws Exception { PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty("api.admanager.clientId", "clientId"); thrown.expect(ValidationException.class); new GoogleClientSecretsBuilder() .forApi(GoogleClientSecretsBuilder.Api.AD_MANAGER) .from(config) .build(); }
/** * Tests that the builder correctly fails on a bad configuration. */ @Test public void testGoogleSecretsReadPropertiesFromConfiguration_missingClientId() throws Exception { PropertiesConfiguration config = new PropertiesConfiguration(); config.setProperty("api.admanager.clientSecret", "clientSecret"); thrown.expect(ValidationException.class); new GoogleClientSecretsBuilder() .forApi(GoogleClientSecretsBuilder.Api.AD_MANAGER) .from(config) .build(); }
@Override public GoogleClientSecretsForApiBuilder fromFile(String path) throws ConfigurationLoadException { return from(configHelper.fromFile(path), path); }
@Override public GoogleClientSecretsForApiBuilder fromFile(String path) throws ConfigurationLoadException { return from(configHelper.fromFile(path), path); }