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);
}
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;
}
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);
}
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);
}
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;
}
Aggregations