Search in sources :

Example 21 with Rectangle

use of org.mongodb.morphia.testmodel.Rectangle in project morphia by mongodb.

the class TestQuery method testCompoundSort.

@Test
public void testCompoundSort() {
    getDs().save(asList(new Rectangle(1, 10), new Rectangle(3, 8), new Rectangle(6, 10), new Rectangle(10, 10), new Rectangle(10, 1)));
    Rectangle r1 = getDs().find(Rectangle.class).order("width,-height").get();
    assertNotNull(r1);
    assertEquals(1, r1.getWidth(), 0);
    assertEquals(10, r1.getHeight(), 0);
    r1 = getDs().find(Rectangle.class).order("-height,-width").get();
    assertNotNull(r1);
    assertEquals(10, r1.getWidth(), 0);
    assertEquals(10, r1.getHeight(), 0);
}
Also used : Rectangle(org.mongodb.morphia.testmodel.Rectangle) Test(org.junit.Test)

Example 22 with Rectangle

use of org.mongodb.morphia.testmodel.Rectangle in project morphia by mongodb.

the class TestQuery method testSimpleSort.

@Test
public void testSimpleSort() {
    getDs().save(asList(new Rectangle(1, 10), new Rectangle(3, 8), new Rectangle(6, 10), new Rectangle(10, 10), new Rectangle(10, 1)));
    Rectangle r1 = getDs().find(Rectangle.class).order("width").get();
    assertNotNull(r1);
    assertEquals(1, r1.getWidth(), 0);
    r1 = getDs().find(Rectangle.class).order("-width").get();
    assertNotNull(r1);
    assertEquals(10, r1.getWidth(), 0);
}
Also used : Rectangle(org.mongodb.morphia.testmodel.Rectangle) Test(org.junit.Test)

Example 23 with Rectangle

use of org.mongodb.morphia.testmodel.Rectangle in project morphia by mongodb.

the class TestQuery method testAliasedFieldSort.

@Test
public void testAliasedFieldSort() {
    getDs().save(asList(new Rectangle(1, 10), new Rectangle(3, 8), new Rectangle(6, 10), new Rectangle(10, 10), new Rectangle(10, 1)));
    Rectangle r1 = getDs().find(Rectangle.class).order("w").get(new FindOptions().limit(1));
    assertNotNull(r1);
    assertEquals(1, r1.getWidth(), 0);
    r1 = getDs().find(Rectangle.class).order("-w").get(new FindOptions().limit(1));
    assertNotNull(r1);
    assertEquals(10, r1.getWidth(), 0);
}
Also used : Rectangle(org.mongodb.morphia.testmodel.Rectangle) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)23 Rectangle (org.mongodb.morphia.testmodel.Rectangle)23 BasicDBObject (com.mongodb.BasicDBObject)9 ObjectId (org.bson.types.ObjectId)5 Circle (org.mongodb.morphia.testmodel.Circle)4 DBObject (com.mongodb.DBObject)3 Shape (org.mongodb.morphia.testmodel.Shape)3 DBCollection (com.mongodb.DBCollection)2 Random (java.util.Random)2 Key (org.mongodb.morphia.Key)2 FacebookUser (org.mongodb.morphia.TestDatastore.FacebookUser)2 DefaultEntityCache (org.mongodb.morphia.mapping.cache.DefaultEntityCache)2 DBRef (com.mongodb.DBRef)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 KeysKeysKeys (org.mongodb.morphia.TestDatastore.KeysKeysKeys)1 UsesCustomIdObject (org.mongodb.morphia.TestMapper.UsesCustomIdObject)1 UpdateResults (org.mongodb.morphia.query.UpdateResults)1 ShapeShifter (org.mongodb.morphia.testmodel.ShapeShifter)1