Search in sources :

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

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

Example 3 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.

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

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

Example 5 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_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());
}
Also used : 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