Search in sources :

Example 1 with UserAgentCombiner

use of com.google.api.ads.common.lib.useragent.UserAgentCombiner in project googleads-java-lib by googleads.

the class UserAgentCombinerTest method testUserAgent.

/**
 * Tests that the user agent is generated correctly.
 */
@Test
public void testUserAgent() throws Exception {
    Injector injector = Guice.createInjector(new AdManagerJaxWsModule());
    String userAgent = USER_AGENT;
    UserAgentCombiner userAgentCombiner = injector.getInstance(UserAgentCombiner.class);
    assertEquals(userAgent, userAgentCombiner.getUserAgent("userAgent"));
}
Also used : Injector(com.google.inject.Injector) UserAgentCombiner(com.google.api.ads.common.lib.useragent.UserAgentCombiner) Test(org.junit.Test)

Example 2 with UserAgentCombiner

use of com.google.api.ads.common.lib.useragent.UserAgentCombiner in project googleads-java-lib by googleads.

the class UserAgentCombinerTest method testUserAgent.

/**
 * Tests that the user agent is generated correctly.
 */
@Test
public void testUserAgent() throws Exception {
    Injector injector = Guice.createInjector(new AdWordsAxisModule());
    String userAgent = USER_AGENT;
    UserAgentCombiner userAgentCombiner = injector.getInstance(UserAgentCombiner.class);
    assertEquals(userAgent, userAgentCombiner.getUserAgent("userAgent"));
}
Also used : Injector(com.google.inject.Injector) UserAgentCombiner(com.google.api.ads.common.lib.useragent.UserAgentCombiner) Test(org.junit.Test)

Example 3 with UserAgentCombiner

use of com.google.api.ads.common.lib.useragent.UserAgentCombiner in project googleads-java-lib by googleads.

the class UserAgentCombinerTest method testUserAgent.

/**
 * Tests that the user agent is generated correctly.
 */
@Test
public void testUserAgent() throws Exception {
    Injector injector = Guice.createInjector(new AdWordsJaxWsModule());
    String userAgent = USER_AGENT;
    UserAgentCombiner userAgentCombiner = injector.getInstance(UserAgentCombiner.class);
    assertEquals(userAgent, userAgentCombiner.getUserAgent("userAgent"));
}
Also used : Injector(com.google.inject.Injector) UserAgentCombiner(com.google.api.ads.common.lib.useragent.UserAgentCombiner) Test(org.junit.Test)

Example 4 with UserAgentCombiner

use of com.google.api.ads.common.lib.useragent.UserAgentCombiner in project googleads-java-lib by googleads.

the class UserAgentCombinerTest method testUserAgent.

/**
 * Tests that the user agent is generated correctly.
 */
@Test
public void testUserAgent() throws Exception {
    Injector injector = Guice.createInjector(new AdManagerAxisModule());
    String userAgent = USER_AGENT;
    UserAgentCombiner userAgentCombiner = injector.getInstance(UserAgentCombiner.class);
    assertEquals(userAgent, userAgentCombiner.getUserAgent("userAgent"));
}
Also used : Injector(com.google.inject.Injector) UserAgentCombiner(com.google.api.ads.common.lib.useragent.UserAgentCombiner) Test(org.junit.Test)

Example 5 with UserAgentCombiner

use of com.google.api.ads.common.lib.useragent.UserAgentCombiner in project googleads-java-lib by googleads.

the class AdWordsPluginModuleTest method testCombinedUserAgentBehavior.

/**
 * Verifies that {@link UserAgentCombiner} instances behave as expected when an {@link
 * AdWordsPluginModule} is or is not provided to the injector.
 */
@Test
public void testCombinedUserAgentBehavior() {
    // Create a mock ExtensionUserAgentProvider that returns a specific string from getUserAgent.
    String pluginUserAgentSnippet = "MyCustomExtension";
    when(extensionUserAgentProvider.getUserAgent()).thenReturn(pluginUserAgentSnippet);
    // Create an AdWordsServicesInterface using an AdWordsPluginModule configured with the
    // ExtensionUserAgentProvider.
    GenericAdWordsServices genericAdWordsServices = (GenericAdWordsServices) new GenericAdWordsServices().withPluginModule(new AdWordsPluginModule(extensionUserAgentProvider));
    // Get the combined user agent from the UserAgentCombiner provided by the
    // AdWordsServicesInterface, and confirm the combined user agent it returns includes the
    // string from the mock ExtensionUserAgentProvider.
    UserAgentCombiner userAgentCombiner = genericAdWordsServices.getBootstrapper().getInstanceOf(session, UserAgentCombiner.class);
    String combinedUserAgent = userAgentCombiner.getUserAgent("foo");
    assertThat("Combined user agent does not contain the string from the plugin", combinedUserAgent, Matchers.containsString(pluginUserAgentSnippet));
    // Get a UserAgentCombiner from an AdWordsServicesInterface without a plugin and confirm the
    // combined user agent it returns does not contain the string from the mock
    // ExtensionUserAgentProvider.
    genericAdWordsServices = new GenericAdWordsServices();
    userAgentCombiner = genericAdWordsServices.getBootstrapper().getInstanceOf(session, UserAgentCombiner.class);
    combinedUserAgent = userAgentCombiner.getUserAgent("foo");
    assertThat("Combined user agent contains string from the plugin, but plugin was not provided", combinedUserAgent, Matchers.not(Matchers.containsString(pluginUserAgentSnippet)));
}
Also used : GenericAdWordsServices(com.google.api.ads.adwords.lib.utils.testing.GenericAdWordsServices) UserAgentCombiner(com.google.api.ads.common.lib.useragent.UserAgentCombiner) Test(org.junit.Test)

Aggregations

UserAgentCombiner (com.google.api.ads.common.lib.useragent.UserAgentCombiner)5 Test (org.junit.Test)5 Injector (com.google.inject.Injector)4 GenericAdWordsServices (com.google.api.ads.adwords.lib.utils.testing.GenericAdWordsServices)1