use of com.google.api.ads.common.lib.auth.OfflineCredentials.Builder in project googleads-java-lib by googleads.
the class OfflineCredentialsTest method testReadPropertiesFromConfiguration_properPrefix.
/**
* 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());
}
use of com.google.api.ads.common.lib.auth.OfflineCredentials.Builder in project googleads-java-lib by googleads.
the class OfflineCredentialsTest method testReadPropertiesFromConfiguration_missingRefreshToken.
/**
* 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();
}
use of com.google.api.ads.common.lib.auth.OfflineCredentials.Builder in project googleads-java-lib by googleads.
the class OfflineCredentialsTest method testBuilder_serviceAccount.
/**
* Tests that the builder builds correctly using a service account key file.
*/
@Test
public void testBuilder_serviceAccount() throws Exception {
OfflineCredentials offlineCredentials = new OfflineCredentials.Builder().forApi(OfflineCredentials.Api.AD_MANAGER).withJsonKeyFilePath("jsonKeyFilePath").build();
assertEquals("jsonKeyFilePath", offlineCredentials.getJsonKeyFilePath());
}
use of com.google.api.ads.common.lib.auth.OfflineCredentials.Builder in project googleads-java-lib by googleads.
the class OfflineCredentialsTest method testReadPropertiesFromConfiguration_adwords.
/**
* 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());
}
use of com.google.api.ads.common.lib.auth.OfflineCredentials.Builder in project googleads-java-lib by googleads.
the class OfflineCredentialsTest method testReadPropertiesFromConfiguration_onlyKeyFilePathAndUser.
/**
* 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());
}
Aggregations