Search in sources :

Example 26 with Rectangle

use of dev.morphia.test.models.Rectangle in project morphia by mongodb.

the class TestQuery method testSimpleSort.

@Test
public void testSimpleSort() {
    getMapper().map(Rectangle.class);
    getDs().ensureIndexes();
    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).iterator(new FindOptions().sort(ascending("width")).limit(1)).next();
    assertNotNull(r1);
    assertEquals(r1.getWidth(), 1, 0);
    r1 = getDs().find(Rectangle.class).iterator(new FindOptions().sort(descending("width")).limit(1)).next();
    assertNotNull(r1);
    assertEquals(r1.getWidth(), 10, 0);
}
Also used : FindOptions(dev.morphia.query.FindOptions) Rectangle(dev.morphia.test.models.Rectangle) Test(org.testng.annotations.Test)

Aggregations

Rectangle (dev.morphia.test.models.Rectangle)26 Test (org.testng.annotations.Test)25 FindOptions (dev.morphia.query.FindOptions)12 Datastore (dev.morphia.Datastore)2 Key (dev.morphia.Key)2 User (dev.morphia.test.models.User)2 ArrayList (java.util.ArrayList)2 MongoQueryException (com.mongodb.MongoQueryException)1 UpdateResult (com.mongodb.client.result.UpdateResult)1 UpdateOptions (dev.morphia.UpdateOptions)1 MorphiaSession (dev.morphia.experimental.MorphiaSession)1 FacebookUser (dev.morphia.test.models.FacebookUser)1 Keys (dev.morphia.test.models.Keys)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 BeforeMethod (org.testng.annotations.BeforeMethod)1