Search in sources :

Example 6 with EntityProtoComparator

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);
}
Also used : Order(com.google.apphosting.datastore.DatastoreV3Pb.Query.Order) EntityProtoComparator(com.google.appengine.api.datastore.EntityProtoComparators.EntityProtoComparator) Filter(com.google.apphosting.datastore.DatastoreV3Pb.Query.Filter) Test(org.junit.Test)

Aggregations

EntityProtoComparator (com.google.appengine.api.datastore.EntityProtoComparators.EntityProtoComparator)6 Order (com.google.apphosting.datastore.DatastoreV3Pb.Query.Order)5 Test (org.junit.Test)4 OnestoreEntity (com.google.storage.onestore.v3.OnestoreEntity)3 Filter (com.google.apphosting.datastore.DatastoreV3Pb.Query.Filter)2 Utils.getLastElement (com.google.appengine.api.datastore.dev.Utils.getLastElement)1 QueryResult (com.google.apphosting.datastore.DatastoreV3Pb.QueryResult)1 InvalidConversionException (com.google.cloud.datastore.core.exception.InvalidConversionException)1 Predicate (com.google.common.base.Predicate)1 ImmutableList (com.google.common.collect.ImmutableList)1 ByteString (com.google.protobuf.ByteString)1 CompositeIndex (com.google.storage.onestore.v3.OnestoreEntity.CompositeIndex)1 EntityProto (com.google.storage.onestore.v3.OnestoreEntity.EntityProto)1 Index (com.google.storage.onestore.v3.OnestoreEntity.Index)1 Path (com.google.storage.onestore.v3.OnestoreEntity.Path)1 Element (com.google.storage.onestore.v3.OnestoreEntity.Path.Element)1 Reference (com.google.storage.onestore.v3.OnestoreEntity.Reference)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1