use of com.google.api.ads.adwords.jaxws.v201809.cm.Selector in project googleads-java-lib by googleads.
the class SelectorBuilderTest method testPagingAndLimits.
/**
* Tests the offset, limit and paging logic of the builder.
*/
@Test
public void testPagingAndLimits() {
SelectorBuilder builder = new SelectorBuilder();
builder = builder.offset(10);
Selector selector = builder.build();
assertNotNull(selector.getPaging());
assertNotNull(selector.getPaging().getStartIndex());
assertNull(selector.getPaging().getNumberResults());
assertEquals(10, selector.getPaging().getStartIndex().intValue());
selector = builder.offset(10).limit(20).build();
assertNotNull(selector.getPaging());
assertNotNull(selector.getPaging().getStartIndex());
assertNotNull(selector.getPaging().getNumberResults());
assertEquals(10, selector.getPaging().getStartIndex().intValue());
assertEquals(20, selector.getPaging().getNumberResults().intValue());
selector = builder.offset(10).limit(20).increaseOffsetBy(5).build();
assertNotNull(selector.getPaging());
assertNotNull(selector.getPaging().getStartIndex());
assertNotNull(selector.getPaging().getNumberResults());
assertEquals(15, selector.getPaging().getStartIndex().intValue());
assertEquals(20, selector.getPaging().getNumberResults().intValue());
selector = builder.offset(10).limit(20).removeLimitAndOffset().build();
assertNull(selector.getPaging());
selector = builder.offset(10).limit(20).removeLimitAndOffset().offset(55).limit(4).build();
assertNotNull(selector.getPaging());
assertNotNull(selector.getPaging().getStartIndex());
assertNotNull(selector.getPaging().getNumberResults());
assertEquals(55, selector.getPaging().getStartIndex().intValue());
assertEquals(4, selector.getPaging().getNumberResults().intValue());
checkUtilitiesState(false);
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.Selector in project googleads-java-lib by googleads.
the class SelectorBuilderTest method testFieldsRemove.
/**
* Tests the removal of fields.
*/
@Test
public void testFieldsRemove() {
SelectorBuilder builder = new SelectorBuilder();
builder = builder.fields("Id", "Name", "Status", "StartDate", "EndDate", "ServingStatus", "Settings");
Selector selector = builder.build();
assertEquals(7, selector.getFields().size());
assertEquals("Id", selector.getFields().get(0));
assertEquals("Name", selector.getFields().get(1));
assertEquals("Status", selector.getFields().get(2));
assertEquals("StartDate", selector.getFields().get(3));
assertEquals("EndDate", selector.getFields().get(4));
assertEquals("ServingStatus", selector.getFields().get(5));
assertEquals("Settings", selector.getFields().get(6));
checkUtilitiesState(false);
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.Selector in project googleads-java-lib by googleads.
the class SelectorBuilderTest method testFieldsBuild.
/**
* Tests the adding of a new field.
*/
@Test
public void testFieldsBuild() {
SelectorBuilder builder = new SelectorBuilder();
builder = builder.fields("Id", "Name", "Status", "StartDate", "EndDate", "ServingStatus", "Settings");
Selector selector = builder.build();
assertEquals(7, selector.getFields().size());
assertEquals("Id", selector.getFields().get(0));
assertEquals("Name", selector.getFields().get(1));
assertEquals("Status", selector.getFields().get(2));
assertEquals("StartDate", selector.getFields().get(3));
assertEquals("EndDate", selector.getFields().get(4));
assertEquals("ServingStatus", selector.getFields().get(5));
assertEquals("Settings", selector.getFields().get(6));
selector = builder.fields("Id", "Name", "Status", "StartDate", "EndDate", "ServingStatus", "Settings", "Id", "AverageCpc").build();
assertEquals(8, selector.getFields().size());
assertEquals("Id", selector.getFields().get(0));
assertEquals("Name", selector.getFields().get(1));
assertEquals("Status", selector.getFields().get(2));
assertEquals("StartDate", selector.getFields().get(3));
assertEquals("EndDate", selector.getFields().get(4));
assertEquals("ServingStatus", selector.getFields().get(5));
assertEquals("Settings", selector.getFields().get(6));
assertEquals("AverageCpc", selector.getFields().get(7));
checkUtilitiesState(false);
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.Selector 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.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.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