Search in sources :

Example 41 with Selector

use of com.google.api.ads.adwords.axis.v201809.cm.Selector in project googleads-java-lib by googleads.

the class SelectorBuilderTest method testOrderBySubstitution.

/**
 * Tests that when a repeated ORDER BY clause is added to the selector, it is actually ignored.
 */
@Test
public void testOrderBySubstitution() {
    SelectorBuilder builder = new SelectorBuilder();
    builder = builder.orderAscBy(CampaignField.AdvertisingChannelType).orderDescBy(CampaignField.Amount);
    Selector selector = builder.build();
    assertNotNull(selector.getOrdering());
    assertEquals(2, selector.getOrdering().size());
    builder.orderAscBy(CampaignField.AdvertisingChannelType);
    selector = builder.build();
    assertNotNull(selector.getOrdering());
    assertEquals(2, selector.getOrdering().size());
    OrderBy orderBy = selector.getOrdering().get(0);
    assertEquals("AdvertisingChannelType", orderBy.getField());
    assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder());
    orderBy = selector.getOrdering().get(1);
    assertEquals("Amount", orderBy.getField());
    assertEquals(SortOrder.DESCENDING, orderBy.getSortOrder());
    checkUtilitiesState(true);
}
Also used : OrderBy(com.google.api.ads.adwords.jaxws.v201809.cm.OrderBy) Selector(com.google.api.ads.adwords.jaxws.v201809.cm.Selector) Test(org.junit.Test)

Example 42 with Selector

use of com.google.api.ads.adwords.axis.v201809.cm.Selector in project googleads-java-lib by googleads.

the class SelectorBuilderTest method testUniqueInternalOrderByState.

/**
 * Tests that the built selectors don't share internal OrderBy state.
 */
@Test
public void testUniqueInternalOrderByState() {
    SelectorBuilder builder = new SelectorBuilder();
    Selector selectorOne = builder.orderAscBy("Id").build();
    Selector selectorTwo = builder.build();
    OrderBy orderTwo = selectorTwo.getOrdering().get(0);
    orderTwo.setField("Status");
    assertEquals("Id", selectorOne.getOrdering().get(0).getField());
    assertEquals("Status", selectorTwo.getOrdering().get(0).getField());
    checkUtilitiesState(false);
}
Also used : OrderBy(com.google.api.ads.adwords.jaxws.v201809.cm.OrderBy) Selector(com.google.api.ads.adwords.jaxws.v201809.cm.Selector) Test(org.junit.Test)

Example 43 with Selector

use of com.google.api.ads.adwords.axis.v201809.cm.Selector in project googleads-java-lib by googleads.

the class SelectorBuilderTest method testPredicatesBuild.

/**
 * Tests the predicate build for the ID field.
 */
@Test
public void testPredicatesBuild() {
    SelectorBuilder builder = new SelectorBuilder();
    builder = builder.equalsId(10L);
    Selector selector = builder.build();
    assertNotNull(selector.getPredicates());
    assertEquals(1, selector.getPredicates().size());
    Predicate predicate = selector.getPredicates().get(0);
    assertEquals("Id", predicate.getField());
    assertEquals(PredicateOperator.EQUALS, predicate.getOperator());
    assertNotNull(predicate.getValues());
    assertEquals(1, predicate.getValues().size());
    assertEquals("10", predicate.getValues().get(0));
    checkUtilitiesState(false);
}
Also used : Selector(com.google.api.ads.adwords.jaxws.v201809.cm.Selector) Predicate(com.google.api.ads.adwords.jaxws.v201809.cm.Predicate) Test(org.junit.Test)

Example 44 with Selector

use of com.google.api.ads.adwords.axis.v201809.cm.Selector in project googleads-java-lib by googleads.

the class SelectorBuilderTest method testUniqueInternalPagingState.

/**
 * Tests that the built selectors don't share internal Paging state.
 */
@Test
public void testUniqueInternalPagingState() {
    SelectorBuilder builder = new SelectorBuilder();
    Selector selectorOne = builder.fields("Id").offset(10).build();
    Selector selectorTwo = builder.fields("Status").offset(345).build();
    assertEquals(10, selectorOne.getPaging().getStartIndex().intValue());
    assertEquals(345, selectorTwo.getPaging().getStartIndex().intValue());
    checkUtilitiesState(false);
}
Also used : Selector(com.google.api.ads.adwords.jaxws.v201809.cm.Selector) Test(org.junit.Test)

Example 45 with Selector

use of com.google.api.ads.adwords.axis.v201809.cm.Selector in project googleads-java-lib by googleads.

the class SelectorBuilderTest method testPagingAndLimits.

/**
 * Tests the offset, limit and paging logic of the builder.
 */
@Test
public void testPagingAndLimits() {
    SelectorBuilder builder = new SelectorBuilder();
    builder = builder.offset(10);
    Selector selector = builder.build();
    assertNotNull(selector.getPaging());
    assertNotNull(selector.getPaging().getStartIndex());
    assertNull(selector.getPaging().getNumberResults());
    assertEquals(10, selector.getPaging().getStartIndex().intValue());
    selector = builder.offset(10).limit(20).build();
    assertNotNull(selector.getPaging());
    assertNotNull(selector.getPaging().getStartIndex());
    assertNotNull(selector.getPaging().getNumberResults());
    assertEquals(10, selector.getPaging().getStartIndex().intValue());
    assertEquals(20, selector.getPaging().getNumberResults().intValue());
    selector = builder.offset(10).limit(20).increaseOffsetBy(5).build();
    assertNotNull(selector.getPaging());
    assertNotNull(selector.getPaging().getStartIndex());
    assertNotNull(selector.getPaging().getNumberResults());
    assertEquals(15, selector.getPaging().getStartIndex().intValue());
    assertEquals(20, selector.getPaging().getNumberResults().intValue());
    selector = builder.offset(10).limit(20).removeLimitAndOffset().build();
    assertNull(selector.getPaging());
    selector = builder.offset(10).limit(20).removeLimitAndOffset().offset(55).limit(4).build();
    assertNotNull(selector.getPaging());
    assertNotNull(selector.getPaging().getStartIndex());
    assertNotNull(selector.getPaging().getNumberResults());
    assertEquals(55, selector.getPaging().getStartIndex().intValue());
    assertEquals(4, selector.getPaging().getNumberResults().intValue());
    checkUtilitiesState(false);
}
Also used : Selector(com.google.api.ads.adwords.jaxws.v201809.cm.Selector) Test(org.junit.Test)

Aggregations

Selector (com.google.api.ads.adwords.axis.v201809.cm.Selector)36 Test (org.junit.Test)27 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)22 Selector (com.google.api.ads.adwords.jaxws.v201809.cm.Selector)14 ArrayList (java.util.ArrayList)9 SimpleDateFormat (java.text.SimpleDateFormat)7 DateFormat (java.text.DateFormat)6 DateTime (org.joda.time.DateTime)6 ApiException (com.google.api.ads.adwords.axis.v201809.cm.ApiException)5 CampaignPage (com.google.api.ads.adwords.axis.v201809.cm.CampaignPage)5 CampaignServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface)5 OrderBy (com.google.api.ads.adwords.jaxws.v201809.cm.OrderBy)4 Predicate (com.google.api.ads.adwords.jaxws.v201809.cm.Predicate)4 ConfigurationLoadException (com.google.api.ads.common.lib.conf.ConfigurationLoadException)4 OAuthException (com.google.api.ads.common.lib.exception.OAuthException)4 ValidationException (com.google.api.ads.common.lib.exception.ValidationException)4 RemoteException (java.rmi.RemoteException)4 AdWordsServices (com.google.api.ads.adwords.axis.factory.AdWordsServices)3 AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)3 AdGroupAdPage (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdPage)3