Search in sources :

Example 1 with DateRange

use of com.google.api.ads.adwords.axis.v201809.cm.DateRange 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.axis.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.axis.v201809.cm.Selector) Test(org.junit.Test)

Example 2 with DateRange

use of com.google.api.ads.adwords.axis.v201809.cm.DateRange 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 3 with DateRange

use of com.google.api.ads.adwords.axis.v201809.cm.DateRange 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)

Example 4 with DateRange

use of com.google.api.ads.adwords.axis.v201809.cm.DateRange 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.axis.v201809.cm.Selector) Test(org.junit.Test)

Example 5 with DateRange

use of com.google.api.ads.adwords.axis.v201809.cm.DateRange 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.getFields().addAll(Sets.newLinkedHashSet(this.fields));
    selectorCopy.getOrdering().addAll(orderingCopy);
    selectorCopy.getPredicates().addAll(predicatesCopy);
    if (this.dateRange != null) {
        DateRange newDateRange = new DateRange();
        newDateRange.setMin(this.dateRange.getMin());
        newDateRange.setMax(this.dateRange.getMax());
        selectorCopy.setDateRange(newDateRange);
    }
    if (this.paging != null) {
        Paging newPaging = new Paging();
        newPaging.setStartIndex(this.paging.getStartIndex());
        newPaging.setNumberResults(this.paging.getNumberResults());
        selectorCopy.setPaging(newPaging);
    }
    return selectorCopy;
}
Also used : OrderBy(com.google.api.ads.adwords.jaxws.v201809.cm.OrderBy) DateRange(com.google.api.ads.adwords.jaxws.v201809.cm.DateRange) Paging(com.google.api.ads.adwords.jaxws.v201809.cm.Paging) Selector(com.google.api.ads.adwords.jaxws.v201809.cm.Selector) Predicate(com.google.api.ads.adwords.jaxws.v201809.cm.Predicate)

Aggregations

Selector (com.google.api.ads.adwords.axis.v201809.cm.Selector)3 DateFormat (java.text.DateFormat)3 SimpleDateFormat (java.text.SimpleDateFormat)3 DateTime (org.joda.time.DateTime)3 Test (org.junit.Test)3 DateRange (com.google.api.ads.adwords.axis.v201809.cm.DateRange)2 DateRange (com.google.api.ads.adwords.jaxws.v201809.cm.DateRange)2 Selector (com.google.api.ads.adwords.jaxws.v201809.cm.Selector)2 OrderBy (com.google.api.ads.adwords.axis.v201809.cm.OrderBy)1 Paging (com.google.api.ads.adwords.axis.v201809.cm.Paging)1 Predicate (com.google.api.ads.adwords.axis.v201809.cm.Predicate)1 OrderBy (com.google.api.ads.adwords.jaxws.v201809.cm.OrderBy)1 Paging (com.google.api.ads.adwords.jaxws.v201809.cm.Paging)1 Predicate (com.google.api.ads.adwords.jaxws.v201809.cm.Predicate)1