Search in sources :

Example 21 with Selector

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

the class SelectorBuilderImpl method build.

@Override
public Selector build() {
    Selector selectorCopy = new Selector();
    Set<OrderBy> orderingCopy = this.copyOrderingSet();
    Set<Predicate> predicatesCopy = this.copyPredicatesSet();
    selectorCopy.setFields(this.fields.toArray(new String[this.fields.size()]));
    selectorCopy.setOrdering(orderingCopy.toArray(new OrderBy[this.ordering.size()]));
    selectorCopy.setPredicates(predicatesCopy.toArray(new Predicate[this.predicates.size()]));
    if (this.dateRange != null) {
        selectorCopy.setDateRange(new DateRange(this.dateRange.getMin(), this.dateRange.getMax()));
    }
    if (this.paging != null) {
        selectorCopy.setPaging(new Paging(this.paging.getStartIndex(), this.paging.getNumberResults()));
    }
    return selectorCopy;
}
Also used : OrderBy(com.google.api.ads.adwords.axis.v201809.cm.OrderBy) DateRange(com.google.api.ads.adwords.axis.v201809.cm.DateRange) Paging(com.google.api.ads.adwords.axis.v201809.cm.Paging) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector) Predicate(com.google.api.ads.adwords.axis.v201809.cm.Predicate)

Example 22 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().get(0);
    predicateTwo.setField("Status");
    assertEquals("Id", selectorOne.getPredicates().get(0).getField());
    assertEquals("Status", selectorTwo.getPredicates().get(0).getField());
    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 23 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("Status", CampaignStatus.ENABLED.toString(), CampaignStatus.REMOVED.toString());
    Selector selector = builder.build();
    assertNotNull(selector.getPredicates());
    assertEquals(1, selector.getPredicates().size());
    Predicate predicate = selector.getPredicates().get(0);
    assertEquals("Status", predicate.getField());
    assertEquals(PredicateOperator.IN, predicate.getOperator());
    assertNotNull(predicate.getValues());
    assertEquals(2, predicate.getValues().size());
    assertEquals(CampaignStatus.ENABLED.toString(), predicate.getValues().get(0));
    assertEquals(CampaignStatus.REMOVED.toString(), predicate.getValues().get(1));
    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 24 with Selector

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

the class SelectorBuilderTest method testUniqueInternalDateRangeState.

/**
 * Tests that the built selectors don't share internal DateRange state.
 */
@Test
public void testUniqueInternalDateRangeState() {
    SelectorBuilder builder = new SelectorBuilder();
    DateFormat dateFormat = new SimpleDateFormat(SelectorBuilderImpl.DEFAULT_DATE_FORMAT);
    DateTime startOne = new DateTime(2013, 1, 1, 0, 0, 0, 0);
    DateTime endOne = new DateTime(2013, 1, 31, 0, 0, 0, 0);
    DateTime startTwo = new DateTime(2013, 2, 1, 0, 0, 0, 0);
    DateTime endTwo = new DateTime(2013, 2, 28, 0, 0, 0, 0);
    Selector selectorOne = builder.forDateRange(startOne, endOne).build();
    Selector selectorTwo = builder.forDateRange(startTwo, endTwo).build();
    assertEquals(dateFormat.format(startOne.toDate()), selectorOne.getDateRange().getMin());
    assertEquals(dateFormat.format(endOne.toDate()), selectorOne.getDateRange().getMax());
    assertEquals(dateFormat.format(startTwo.toDate()), selectorTwo.getDateRange().getMin());
    assertEquals(dateFormat.format(endTwo.toDate()), selectorTwo.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.jaxws.v201809.cm.Selector) Test(org.junit.Test)

Example 25 with Selector

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

the class SelectorBuilderTest method testSelectorBuilderImmutability.

/**
 * Tests the immutability of the selector.
 */
@Test
public void testSelectorBuilderImmutability() {
    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.fields("Id", "Name", "Status").forDateRange(start, end);
    Selector selector = builder.build();
    assertEquals(formatStart, selector.getDateRange().getMin());
    assertEquals(formatEnd, selector.getDateRange().getMax());
    String formatEndPlusOne = dateFormat.format(end.plusDays(1).toDate());
    DateRange dateRange = new DateRange();
    dateRange.setMin(formatStart);
    dateRange.setMax(formatEndPlusOne);
    selector.setDateRange(dateRange);
    assertEquals(formatStart, selector.getDateRange().getMin());
    assertEquals(formatEndPlusOne, selector.getDateRange().getMax());
    Selector selectorRebuilt = builder.fields("Id", "Name", "Status").forDateRange(start, end).build();
    assertEquals(formatStart, selectorRebuilt.getDateRange().getMin());
    assertEquals(formatEnd, selectorRebuilt.getDateRange().getMax());
    checkUtilitiesState(false);
}
Also used : DateRange(com.google.api.ads.adwords.jaxws.v201809.cm.DateRange) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) DateTime(org.joda.time.DateTime) 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)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