Search in sources :

Example 11 with Selector

use of com.google.api.ads.adwords.jaxws.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().length);
    builder.orderAscBy(CampaignField.AdvertisingChannelType);
    selector = builder.build();
    assertNotNull(selector.getOrdering());
    assertEquals(2, selector.getOrdering().length);
    OrderBy orderBy = selector.getOrdering()[0];
    assertEquals("AdvertisingChannelType", orderBy.getField());
    assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder());
    orderBy = selector.getOrdering()[1];
    assertEquals("Amount", orderBy.getField());
    assertEquals(SortOrder.DESCENDING, orderBy.getSortOrder());
    checkUtilitiesState(true);
}
Also used : OrderBy(com.google.api.ads.adwords.axis.v201809.cm.OrderBy) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector) Test(org.junit.Test)

Example 12 with Selector

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

the class SelectorBuilderTest method testDateRangeBuild.

/**
 * Tests the date range setting.
 */
@Test
public void testDateRangeBuild() {
    DateFormat dateFormat = new SimpleDateFormat(SelectorBuilderImpl.DEFAULT_DATE_FORMAT);
    SelectorBuilder builder = new SelectorBuilder();
    DateTime start = new DateTime(2013, 3, 25, 0, 0, 0, 0);
    DateTime end = new DateTime(2013, 3, 26, 0, 0, 0, 0);
    String formatStart = dateFormat.format(start.toDate());
    String formatEnd = dateFormat.format(end.toDate());
    builder = builder.forDateRange(start, end);
    Selector selector = builder.build();
    assertEquals(formatStart, selector.getDateRange().getMin());
    assertEquals(formatEnd, selector.getDateRange().getMax());
    checkUtilitiesState(false);
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) DateTime(org.joda.time.DateTime) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector) Test(org.junit.Test)

Example 13 with Selector

use of com.google.api.ads.adwords.jaxws.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(CampaignField.Status).offset(345).build();
    assertEquals(10, selectorOne.getPaging().getStartIndex().intValue());
    assertEquals(345, selectorTwo.getPaging().getStartIndex().intValue());
    checkUtilitiesState(true);
}
Also used : Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector) Test(org.junit.Test)

Example 14 with Selector

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

the class SelectorBuilderTest method testPredicatesInBuild.

/**
 * Tests the predicate with the IN clause.
 */
@Test
public void testPredicatesInBuild() {
    SelectorBuilder builder = new SelectorBuilder();
    builder = builder.in(CampaignField.Status, CampaignStatus.ENABLED.toString(), CampaignStatus.REMOVED.toString());
    Selector selector = builder.build();
    assertNotNull(selector.getPredicates());
    assertEquals(1, selector.getPredicates().length);
    Predicate predicate = selector.getPredicates()[0];
    assertEquals("Status", predicate.getField());
    assertEquals(PredicateOperator.IN, predicate.getOperator());
    assertNotNull(predicate.getValues());
    assertEquals(2, predicate.getValues().length);
    assertEquals(CampaignStatus.ENABLED.toString(), predicate.getValues()[0]);
    assertEquals(CampaignStatus.REMOVED.toString(), predicate.getValues()[1]);
    checkUtilitiesState(true);
}
Also used : Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector) Predicate(com.google.api.ads.adwords.axis.v201809.cm.Predicate) Test(org.junit.Test)

Example 15 with Selector

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

the class SelectorBuilderTest method testUniqueInternalPredicateState.

/**
 * Tests that the built selectors don't share internal Predicate state.
 */
@Test
public void testUniqueInternalPredicateState() {
    SelectorBuilder builder = new SelectorBuilder();
    Selector selectorOne = builder.equals("Id", "test").build();
    Selector selectorTwo = builder.build();
    Predicate predicateTwo = selectorTwo.getPredicates(0);
    predicateTwo.setField("Status");
    assertEquals("Id", selectorOne.getPredicates(0).getField());
    assertEquals("Status", selectorTwo.getPredicates(0).getField());
    checkUtilitiesState(false);
}
Also used : Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector) Predicate(com.google.api.ads.adwords.axis.v201809.cm.Predicate) Test(org.junit.Test)

Aggregations

Selector (com.google.api.ads.adwords.axis.v201809.cm.Selector)36 Test (org.junit.Test)26 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)21 Selector (com.google.api.ads.adwords.jaxws.v201809.cm.Selector)14 SimpleDateFormat (java.text.SimpleDateFormat)7 DateFormat (java.text.DateFormat)6 DateTime (org.joda.time.DateTime)6 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.axis.v201809.cm.OrderBy)4 Predicate (com.google.api.ads.adwords.axis.v201809.cm.Predicate)4 OrderBy (com.google.api.ads.adwords.jaxws.v201809.cm.OrderBy)4 Predicate (com.google.api.ads.adwords.jaxws.v201809.cm.Predicate)4 ArrayList (java.util.ArrayList)4 AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)3 AdGroupAdPage (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdPage)3 AdGroupAdServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface)3 ApiException (com.google.api.ads.adwords.axis.v201809.cm.ApiException)3 Campaign (com.google.api.ads.adwords.axis.v201809.cm.Campaign)3 Parameter (com.beust.jcommander.Parameter)2