use of com.google.appengine.api.datastore.EntityProtoComparators.EntityProtoComparator in project appengine-java-standard by GoogleCloudPlatform.
the class EntityComparatorTests method testDefaultSortWithInequality.
@Test
public void testDefaultSortWithInequality() {
// if no sorts provided we end up with the default sort
List<Order> orders = Lists.newArrayList();
Filter filter = new Filter().setOp(Operator.GREATER_THAN);
String ineq = "ineq";
filter.addProperty().setName(ineq).getMutableValue().setInt64Value(0);
List<Filter> filters = Arrays.asList(filter);
// Should default to having the ineq prop first that key asc
EntityProtoComparator epc = new EntityProtoComparator(orders, filters);
assertThat(epc.orders).hasSize(2);
assertThat(epc.orders.get(0).getProperty()).isEqualTo(ineq);
assertThat(epc.orders.get(0).getDirectionEnum()).isEqualTo(Direction.ASCENDING);
assertThat(epc.orders.get(1)).isEqualTo(KEY_ASC_ORDER);
// if a sort a non-key field is provided we add the default sort to the
// end.
orders.add(new Order().setProperty(ineq).setDirection(Direction.DESCENDING));
epc = new EntityProtoComparator(orders, filters);
assertThat(epc.orders).hasSize(2);
assertThat(epc.orders.get(0).getProperty()).isEqualTo(ineq);
assertThat(epc.orders.get(0).getDirectionEnum()).isEqualTo(Direction.DESCENDING);
assertThat(epc.orders.get(1)).isEqualTo(KEY_ASC_ORDER);
// if we explicitly ad the default sort to the end we don't end up with
// more than one default sort
orders.add(KEY_ASC_ORDER);
epc = new EntityProtoComparator(orders);
assertThat(epc.orders).hasSize(2);
assertThat(epc.orders.get(0).getProperty()).isEqualTo(ineq);
assertThat(epc.orders.get(0).getDirectionEnum()).isEqualTo(Direction.DESCENDING);
assertThat(epc.orders.get(1)).isEqualTo(KEY_ASC_ORDER);
}
Aggregations