use of com.google.api.ads.adwords.jaxws.v201809.cm.OrderBy in project googleads-java-lib by googleads.
the class SelectorBuilderTest method testOrderByBuild.
/**
* Tests the order by criteria.
*/
@Test
public void testOrderByBuild() {
SelectorBuilder builder = new SelectorBuilder();
builder = builder.orderAscBy(CampaignField.AdvertisingChannelType);
Selector selector = builder.build();
assertNotNull(selector.getOrdering());
assertEquals(1, selector.getOrdering().size());
OrderBy orderBy = selector.getOrdering().get(0);
assertEquals("AdvertisingChannelType", orderBy.getField());
assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder());
builder.orderAscBy(CampaignField.Amount).orderDescBy(CampaignField.AdvertisingChannelType);
selector = builder.build();
assertNotNull(selector.getOrdering());
assertEquals(3, selector.getOrdering().size());
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.ASCENDING, orderBy.getSortOrder());
orderBy = selector.getOrdering().get(2);
assertEquals("AdvertisingChannelType", orderBy.getField());
assertEquals(SortOrder.DESCENDING, orderBy.getSortOrder());
// Removing the OrderBy for AdvertisingChannelType
selector = builder.removeOrderBy("AdvertisingChannelType").build();
assertNotNull(selector.getOrdering());
assertEquals(1, selector.getOrdering().size());
orderBy = selector.getOrdering().get(0);
assertEquals("Amount", orderBy.getField());
assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder());
checkUtilitiesState(true);
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.OrderBy 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