Search in sources :

Example 1 with Builder

use of com.google.api.ads.adwords.lib.client.AdWordsSession.Builder in project googleads-java-lib by googleads.

the class AdWordsSessionTest method testReadPropertiesFromConfiguration.

/**
 * Tests that the builder correctly reads properties from a configuration.
 */
@Test
public void testReadPropertiesFromConfiguration() throws ValidationException {
    PropertiesConfiguration config = new PropertiesConfiguration();
    config.setProperty("api.adwords.clientCustomerId", "1234567890");
    config.setProperty("api.adwords.userAgent", "FooBar");
    config.setProperty("api.adwords.developerToken", "devTokendevTokendevTok");
    config.setProperty("api.adwords.isPartialFailure", "false");
    AdWordsSession session = build(new AdWordsSession.Builder().from(config).withOAuth2Credential(credential));
    assertEquals("1234567890", session.getClientCustomerId());
    assertEquals("FooBar", session.getUserAgent());
    assertEquals("devTokendevTokendevTok", session.getDeveloperToken());
    assertFalse(session.isPartialFailure());
    ReportingConfiguration reportingConfig = session.getReportingConfiguration();
    assertNotNull("reporting configuration is null", reportingConfig);
    // Verify that the ReportingConfiguration's attributes are set to the expected default value
    // (null).
    assertNull("include zero impressions is not null when no reporting options in config", reportingConfig.isIncludeZeroImpressions());
    assertNull("skip column header is not null, but no reporting options in config", reportingConfig.isSkipColumnHeader());
    assertNull("skip report header is not null, but no reporting options in config", reportingConfig.isSkipReportHeader());
    assertNull("skip report summary is not null, but no reporting options in config", reportingConfig.isSkipReportSummary());
    assertNull("use raw enum values is not null, but no reporting options in config", reportingConfig.isUseRawEnumValues());
    assertNull("download timeout is not null, but no reporting options in config", reportingConfig.getReportDownloadTimeout());
}
Also used : Builder(com.google.api.ads.adwords.lib.client.AdWordsSession.Builder) ImmutableAdWordsSession(com.google.api.ads.adwords.lib.client.AdWordsSession.ImmutableAdWordsSession) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) ReportingConfiguration(com.google.api.ads.adwords.lib.client.reporting.ReportingConfiguration) Test(org.junit.Test)

Example 2 with Builder

use of com.google.api.ads.adwords.lib.client.AdWordsSession.Builder in project googleads-java-lib by googleads.

the class AdWordsSessionTest method testReadPropertiesFromConfiguration_badEndpoint.

/**
 * Tests that the builder correctly reads properties from a configuration.
 */
@Test
public void testReadPropertiesFromConfiguration_badEndpoint() throws ValidationException {
    String badEndpoint = "3efsdafasd";
    PropertiesConfiguration config = new PropertiesConfiguration();
    config.setProperty("api.adwords.clientCustomerId", "1234567890");
    config.setProperty("api.adwords.userAgent", "FooBar");
    config.setProperty("api.adwords.developerToken", "devTokendevTokendevTok");
    config.setProperty("api.adwords.isPartialFailure", "false");
    config.setProperty("api.adwords.endpoint", badEndpoint);
    thrown.expect(ValidationException.class);
    thrown.expect(createTriggerMatcher(Matchers.<String>equalTo("endpoint")));
    thrown.expectMessage(badEndpoint);
    build(new AdWordsSession.Builder().from(config).withOAuth2Credential(credential));
}
Also used : Builder(com.google.api.ads.adwords.lib.client.AdWordsSession.Builder) ImmutableAdWordsSession(com.google.api.ads.adwords.lib.client.AdWordsSession.ImmutableAdWordsSession) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) Test(org.junit.Test)

Example 3 with Builder

use of com.google.api.ads.adwords.lib.client.AdWordsSession.Builder in project googleads-java-lib by googleads.

the class AdWordsSessionTest method testReadPropertiesFromConfiguration_defaultUserAgent.

/**
 * Tests that the builder correctly reads properties from a configuration.
 */
@Test
public void testReadPropertiesFromConfiguration_defaultUserAgent() throws ValidationException {
    PropertiesConfiguration config = new PropertiesConfiguration();
    config.setProperty("api.adwords.userAgent", "INSERT_USERAGENT_HERE");
    AdWordsSession adWordsSession = build(new AdWordsSession.Builder().from(config).withDeveloperToken("devTokendevTokendevTok").withOAuth2Credential(credential));
    assertEquals(AdWordsSession.UNKNOWN_USER_AGENT, adWordsSession.getUserAgent());
}
Also used : ImmutableAdWordsSession(com.google.api.ads.adwords.lib.client.AdWordsSession.ImmutableAdWordsSession) Builder(com.google.api.ads.adwords.lib.client.AdWordsSession.Builder) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) Test(org.junit.Test)

Example 4 with Builder

use of com.google.api.ads.adwords.lib.client.AdWordsSession.Builder in project googleads-java-lib by googleads.

the class AdWordsSessionTest method testBuilder_noUserAgent.

/**
 * Tests that the builder builds with the 'unknown' user agent if none specified.
 */
@Test
public void testBuilder_noUserAgent() throws Exception {
    AdWordsSession adWordsSession = build(new AdWordsSession.Builder().withOAuth2Credential(credential).withEndpoint("https://www.google.com").withDeveloperToken("developerToken"));
    assertEquals(AdWordsSession.UNKNOWN_USER_AGENT, adWordsSession.getUserAgent());
}
Also used : ImmutableAdWordsSession(com.google.api.ads.adwords.lib.client.AdWordsSession.ImmutableAdWordsSession) Builder(com.google.api.ads.adwords.lib.client.AdWordsSession.Builder) Test(org.junit.Test)

Example 5 with Builder

use of com.google.api.ads.adwords.lib.client.AdWordsSession.Builder in project googleads-java-lib by googleads.

the class AdWordsSessionTest method testReadPropertiesFromConfigurationWithReportingConfig.

/**
 * Tests that the builder correctly reads properties from a configuration when reporting options
 * are included in the configuration.
 */
@Test
public void testReadPropertiesFromConfigurationWithReportingConfig() throws ValidationException {
    PropertiesConfiguration config = new PropertiesConfiguration();
    config.setProperty("api.adwords.clientCustomerId", "1234567890");
    config.setProperty("api.adwords.userAgent", "FooBar");
    config.setProperty("api.adwords.developerToken", "devTokendevTokendevTok");
    config.setProperty("api.adwords.isPartialFailure", "false");
    config.setProperty("api.adwords.reporting.skipHeader", "true");
    config.setProperty("api.adwords.reporting.skipColumnHeader", "true");
    config.setProperty("api.adwords.reporting.skipSummary", "false");
    config.setProperty("api.adwords.reporting.useRawEnumValues", "false");
    config.setProperty("api.adwords.reportDownloadTimeout", 9999999);
    AdWordsSession session = build(new AdWordsSession.Builder().from(config).withOAuth2Credential(credential));
    assertEquals("1234567890", session.getClientCustomerId());
    assertEquals("FooBar", session.getUserAgent());
    assertEquals("devTokendevTokendevTok", session.getDeveloperToken());
    assertFalse(session.isPartialFailure());
    assertNotNull("reporting configuration should not be null", session.getReportingConfiguration());
    assertTrue(session.getReportingConfiguration().isSkipReportHeader());
    assertTrue(session.getReportingConfiguration().isSkipColumnHeader());
    assertFalse(session.getReportingConfiguration().isSkipReportSummary());
    assertFalse(session.getReportingConfiguration().isUseRawEnumValues());
    assertEquals(9999999, session.getReportingConfiguration().getReportDownloadTimeout().intValue());
    assertNull("includeZeroImpressions is not settable from ads.properties, so should be null", session.getReportingConfiguration().isIncludeZeroImpressions());
}
Also used : Builder(com.google.api.ads.adwords.lib.client.AdWordsSession.Builder) ImmutableAdWordsSession(com.google.api.ads.adwords.lib.client.AdWordsSession.ImmutableAdWordsSession) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) Test(org.junit.Test)

Aggregations

Builder (com.google.api.ads.adwords.lib.client.AdWordsSession.Builder)12 ImmutableAdWordsSession (com.google.api.ads.adwords.lib.client.AdWordsSession.ImmutableAdWordsSession)11 Test (org.junit.Test)11 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)5 ReportingConfiguration (com.google.api.ads.adwords.lib.client.reporting.ReportingConfiguration)2 ApiError (com.google.api.ads.adwords.axis.v201809.cm.ApiError)1 ApiException (com.google.api.ads.adwords.axis.v201809.cm.ApiException)1 AdWordsSession (com.google.api.ads.adwords.lib.client.AdWordsSession)1 AdWordsServicesInterface (com.google.api.ads.adwords.lib.factory.AdWordsServicesInterface)1 OfflineCredentials (com.google.api.ads.common.lib.auth.OfflineCredentials)1 ConfigurationLoadException (com.google.api.ads.common.lib.conf.ConfigurationLoadException)1 OAuthException (com.google.api.ads.common.lib.exception.OAuthException)1 ValidationException (com.google.api.ads.common.lib.exception.ValidationException)1 Credential (com.google.api.client.auth.oauth2.Credential)1 IOException (java.io.IOException)1 RemoteException (java.rmi.RemoteException)1