use of com.google.api.ads.adwords.jaxws.v201809.cm.OrderBy 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);
}
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().length);
OrderBy orderBy = selector.getOrdering()[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().length);
orderBy = selector.getOrdering()[0];
assertEquals("AdvertisingChannelType", orderBy.getField());
assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder());
orderBy = selector.getOrdering()[1];
assertEquals("Amount", orderBy.getField());
assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder());
orderBy = selector.getOrdering()[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().length);
orderBy = selector.getOrdering()[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 orderDescBy.
@Override
public SelectorBuilderImpl orderDescBy(String field) {
OrderBy orderBy = new OrderBy();
orderBy.setField(field);
orderBy.setSortOrder(SortOrder.DESCENDING);
this.ordering.add(orderBy);
return this;
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.OrderBy in project googleads-java-lib by googleads.
the class SelectorBuilderImpl method copyOrderingSet.
/**
* Copies the whole set of OrderBy objects, by creating new instances of each one in the given
* set.
*
* @return the new set of OrderBy objects with different instance for each of the OrderBy
*/
private Set<OrderBy> copyOrderingSet() {
Set<OrderBy> orderingCopy = Sets.newLinkedHashSet();
for (OrderBy order : this.ordering) {
OrderBy copyOrder = new OrderBy();
copyOrder.setField(order.getField());
copyOrder.setSortOrder(order.getSortOrder());
orderingCopy.add(copyOrder);
}
return orderingCopy;
}
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.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;
}
Aggregations