use of dev.morphia.test.models.Rectangle in project morphia by mongodb.
the class TestQuery method testNaturalSortAscending.
@Test
public void testNaturalSortAscending() {
getDs().save(asList(new Rectangle(6, 10), new Rectangle(3, 8), new Rectangle(10, 10), new Rectangle(10, 1)));
List<Rectangle> results = getDs().find(Rectangle.class).iterator(new FindOptions().sort(naturalAscending())).toList();
assertEquals(results.size(), 4);
Rectangle r;
r = results.get(0);
assertNotNull(r);
assertEquals(r.getHeight(), 6, 0);
assertEquals(r.getWidth(), 10, 0);
r = results.get(1);
assertNotNull(r);
assertEquals(r.getHeight(), 3, 0);
assertEquals(r.getWidth(), 8, 0);
r = results.get(2);
assertNotNull(r);
assertEquals(r.getHeight(), 10, 0);
assertEquals(r.getWidth(), 10, 0);
}
use of dev.morphia.test.models.Rectangle in project morphia by mongodb.
the class TestLegacyQuery method testNaturalSortAscending.
@Test
public void testNaturalSortAscending() {
getDs().save(asList(new Rectangle(6, 10), new Rectangle(3, 8), new Rectangle(10, 10), new Rectangle(10, 1)));
List<Rectangle> results = getDs().find(Rectangle.class).execute(new FindOptions().sort(naturalAscending())).toList();
assertEquals(results.size(), 4);
Rectangle r;
r = results.get(0);
assertNotNull(r);
assertEquals(r.getHeight(), 6, 0);
assertEquals(r.getWidth(), 10, 0);
r = results.get(1);
assertNotNull(r);
assertEquals(r.getHeight(), 3, 0);
assertEquals(r.getWidth(), 8, 0);
r = results.get(2);
assertNotNull(r);
assertEquals(r.getHeight(), 10, 0);
assertEquals(r.getWidth(), 10, 0);
}
use of dev.morphia.test.models.Rectangle in project morphia by mongodb.
the class TestLegacyQuery 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).execute(new FindOptions().sort(ascending("width")).limit(1)).next();
assertNotNull(r1);
assertEquals(r1.getWidth(), 1, 0);
r1 = getDs().find(Rectangle.class).execute(new FindOptions().sort(descending("width")).limit(1)).next();
assertNotNull(r1);
assertEquals(r1.getWidth(), 10, 0);
}
use of dev.morphia.test.models.Rectangle in project morphia by mongodb.
the class TestLegacyQuery method testKeyList.
@Test
public void testKeyList() {
final Rectangle rect = new Rectangle(1000, 1);
Rectangle rectangle = getDs().save(rect);
assertEquals(rectangle.getId(), rect.getId());
final FacebookUser fbUser1 = new FacebookUser(1, "scott");
final FacebookUser fbUser2 = new FacebookUser(2, "tom");
final FacebookUser fbUser3 = new FacebookUser(3, "oli");
final FacebookUser fbUser4 = new FacebookUser(4, "frank");
final List<FacebookUser> users = getDs().save(asList(fbUser1, fbUser2, fbUser3, fbUser4));
assertEquals(fbUser1.getId(), 1);
final List<Key<FacebookUser>> fbUserKeys = new ArrayList<>();
for (FacebookUser user : users) {
fbUserKeys.add(getMapper().getKey(user));
}
assertEquals(fbUser1.getId(), fbUserKeys.get(0).getId());
assertEquals(fbUser2.getId(), fbUserKeys.get(1).getId());
assertEquals(fbUser3.getId(), fbUserKeys.get(2).getId());
assertEquals(fbUser4.getId(), fbUserKeys.get(3).getId());
final Keys k1 = new Keys(getMapper().getKey(rectangle), fbUserKeys);
final Keys keys = getDs().save(k1);
assertEquals(k1.getId(), keys.getId());
final Datastore datastore = getDs();
final Keys k1Loaded = datastore.find(Keys.class).filter("_id", k1.getId()).first();
for (Key<FacebookUser> key : k1Loaded.getUsers()) {
assertNotNull(key.getId());
}
assertNotNull(k1Loaded.getRect().getId());
}
use of dev.morphia.test.models.Rectangle in project morphia by mongodb.
the class TestLegacyQuery method testNaturalSortDescending.
@Test
public void testNaturalSortDescending() {
getDs().save(asList(new Rectangle(6, 10), new Rectangle(3, 8), new Rectangle(10, 10), new Rectangle(10, 1)));
List<Rectangle> results = getDs().find(Rectangle.class).execute(new FindOptions().sort(naturalDescending())).toList();
assertEquals(results.size(), 4);
Rectangle r;
r = results.get(0);
assertNotNull(r);
assertEquals(r.getHeight(), 10, 0);
assertEquals(r.getWidth(), 1, 0);
r = results.get(1);
assertNotNull(r);
assertEquals(r.getHeight(), 10, 0);
assertEquals(r.getWidth(), 10, 0);
r = results.get(2);
assertNotNull(r);
assertEquals(r.getHeight(), 3, 0);
assertEquals(r.getWidth(), 8, 0);
}
Aggregations