use of com.google.api.ads.common.lib.auth.OfflineCredentials.Builder in project googleads-java-lib by googleads.
the class OfflineCredentialsTest method testReadPropertiesFromConfiguration_dfp.
/**
* 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());
}
use of com.google.api.ads.common.lib.auth.OfflineCredentials.Builder in project googleads-java-lib by googleads.
the class OfflineCredentialsTest method testReadPropertiesFromConfiguration_properPrefixServiceAccount.
/**
* 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());
}
use of com.google.api.ads.common.lib.auth.OfflineCredentials.Builder in project googleads-java-lib by googleads.
the class OfflineCredentialsTest method testBuilder.
/**
* Tests that the builder builds correctly.
*/
@Test
public void testBuilder() throws Exception {
HttpTransport httpTransport = new NetHttpTransport();
OfflineCredentials offlineCredentials = new OfflineCredentials.Builder().forApi(OfflineCredentials.Api.AD_MANAGER).withClientSecrets("clientId", "clientSecret").withRefreshToken("refreshToken").withHttpTransport(httpTransport).build();
assertEquals("clientId", offlineCredentials.getClientId());
assertEquals("clientSecret", offlineCredentials.getClientSecret());
assertEquals("refreshToken", offlineCredentials.getRefreshToken());
assertSame(httpTransport, offlineCredentials.getHttpTransport());
}
use of com.google.api.ads.common.lib.auth.OfflineCredentials.Builder in project googleads-java-lib by googleads.
the class OfflineCredentialsTest method testReadPropertiesFromConfiguration_adWordsServiceAccount.
/**
* Tests that the builder correctly reads properties from a configuration.
*/
@Test
public void testReadPropertiesFromConfiguration_adWordsServiceAccount() throws ValidationException {
PropertiesConfiguration config = new PropertiesConfiguration();
String jsonKeyFilePath = "someJsonKeyFilePath";
config.setProperty("api.adwords.jsonKeyFilePath", jsonKeyFilePath);
OfflineCredentials offlineCredentials = new OfflineCredentials.Builder().forApi(OfflineCredentials.Api.ADWORDS).from(config).build();
assertEquals(jsonKeyFilePath, offlineCredentials.getJsonKeyFilePath());
assertNull("service account user should be null", offlineCredentials.getServiceAccountUser());
// Create another credential with the service account user set.
String serviceAccountUser = "someUser@example.com";
offlineCredentials = new OfflineCredentials.Builder().forApi(OfflineCredentials.Api.ADWORDS).from(config).withServiceAccountUser(serviceAccountUser).build();
assertEquals(jsonKeyFilePath, offlineCredentials.getJsonKeyFilePath());
assertEquals(serviceAccountUser, offlineCredentials.getServiceAccountUser());
}
use of com.google.api.ads.common.lib.auth.OfflineCredentials.Builder in project googleads-java-lib by googleads.
the class OfflineCredentialsTest method testReadPropertiesFromConfiguration_dfpServiceAccount.
/**
* Tests that the builder correctly reads properties from a configuration.
*/
@Test
public void testReadPropertiesFromConfiguration_dfpServiceAccount() throws ValidationException {
PropertiesConfiguration config = new PropertiesConfiguration();
String jsonKeyFilePath = "someJsonKeyFilePath";
config.setProperty("api.admanager.jsonKeyFilePath", jsonKeyFilePath);
OfflineCredentials offlineCredentials = new OfflineCredentials.Builder().forApi(OfflineCredentials.Api.AD_MANAGER).from(config).build();
assertEquals(jsonKeyFilePath, offlineCredentials.getJsonKeyFilePath());
assertNull("service account user should be null", offlineCredentials.getServiceAccountUser());
// Create another credential with the service account user set.
String serviceAccountUser = "someUser@example.com";
offlineCredentials = new OfflineCredentials.Builder().forApi(OfflineCredentials.Api.AD_MANAGER).from(config).withServiceAccountUser(serviceAccountUser).build();
assertEquals(jsonKeyFilePath, offlineCredentials.getJsonKeyFilePath());
assertEquals(serviceAccountUser, offlineCredentials.getServiceAccountUser());
}
Aggregations