use of dev.morphia.test.models.FacebookUser in project morphia by mongodb.
the class TestQuery 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(fbUserKeys.get(0).getId(), fbUser1.getId());
assertEquals(fbUserKeys.get(1).getId(), fbUser2.getId());
assertEquals(fbUserKeys.get(2).getId(), fbUser3.getId());
assertEquals(fbUserKeys.get(3).getId(), fbUser4.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(eq("_id", k1.getId())).first();
for (Key<FacebookUser> key : k1Loaded.getUsers()) {
assertNotNull(key.getId());
}
assertNotNull(k1Loaded.getRect().getId());
}
Aggregations