use of com.google.apphosting.datastore.DatastoreV3Pb.Query.Order in project appengine-java-standard by GoogleCloudPlatform.
the class EntityComparatorTests method testMultiValuePropertySortWithInequality.
@Test
public void testMultiValuePropertySortWithInequality() {
OnestoreEntity.EntityProto p1 = new OnestoreEntity.EntityProto();
p1.addProperty().setMultiple(true).setName("a").setValue(new OnestoreEntity.PropertyValue().setInt64Value(1L));
p1.addProperty().setMultiple(true).setName("a").setValue(new OnestoreEntity.PropertyValue().setInt64Value(4L));
OnestoreEntity.EntityProto p2 = new OnestoreEntity.EntityProto();
p2.addProperty().setMultiple(true).setName("a").setValue(new OnestoreEntity.PropertyValue().setInt64Value(2L));
p2.addProperty().setMultiple(true).setName("a").setValue(new OnestoreEntity.PropertyValue().setInt64Value(3L));
Filter filter = new Filter().setOp(Operator.GREATER_THAN);
filter.addProperty().setName("a").getMutableValue().setInt64Value(2);
Order desc = new Order().setProperty("a").setDirection(Direction.DESCENDING);
EntityProtoComparator epc = new EntityProtoComparator(Collections.singletonList(desc), Collections.singletonList(filter));
assertThat(epc.compare(p1, p2)).isEqualTo(-1);
Order asc = new Order().setProperty("a").setDirection(Direction.ASCENDING);
epc = new EntityProtoComparator(Collections.singletonList(asc), Collections.singletonList(filter));
assertThat(epc.compare(p1, p2)).isEqualTo(1);
}
use of com.google.apphosting.datastore.DatastoreV3Pb.Query.Order 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