Search in sources :

Example 6 with Builder

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());
}
Also used : Builder(com.google.api.ads.common.lib.auth.OfflineCredentials.Builder) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) Test(org.junit.Test)

Example 7 with Builder

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();
}
Also used : Builder(com.google.api.ads.common.lib.auth.OfflineCredentials.Builder) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) Test(org.junit.Test)

Example 8 with Builder

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());
}
Also used : Builder(com.google.api.ads.common.lib.auth.OfflineCredentials.Builder) Test(org.junit.Test)

Example 9 with Builder

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());
}
Also used : Builder(com.google.api.ads.common.lib.auth.OfflineCredentials.Builder) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) Test(org.junit.Test)

Example 10 with Builder

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());
}
Also used : ForApiBuilder(com.google.api.ads.common.lib.auth.OfflineCredentials.ForApiBuilder) Builder(com.google.api.ads.common.lib.auth.OfflineCredentials.Builder) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) Test(org.junit.Test)

Aggregations

Builder (com.google.api.ads.common.lib.auth.OfflineCredentials.Builder)15 Test (org.junit.Test)15 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)13 ForApiBuilder (com.google.api.ads.common.lib.auth.OfflineCredentials.ForApiBuilder)1 HttpTransport (com.google.api.client.http.HttpTransport)1 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)1