/** * 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(); }
/** * 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 throws exception when client ID or client * secret is a default value. */ @Test public void testBuilder_defaultClientIdAndSecret() throws Exception { 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"); new GoogleClientSecretsBuilder() .forApi(GoogleClientSecretsBuilder.Api.AD_MANAGER) .withClientSecrets("INSERT_CLIENT_ID_HERE", "INSERT_CLIENT_SECRET_HERE") .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()); }
/** * Tests that the builder builds correctly. */ @Test public void testBuilder() throws Exception { GoogleClientSecrets clientSecrets = new GoogleClientSecretsBuilder() .forApi(GoogleClientSecretsBuilder.Api.AD_MANAGER) .withClientSecrets("clientId", "clientSecret") .build(); assertNotNull(clientSecrets.getDetails()); assertEquals("clientId", clientSecrets.getDetails().getClientId()); assertEquals("clientSecret", clientSecrets.getDetails().getClientSecret()); }
/** * 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()); }