use of dev.morphia.test.models.FacebookUser in project morphia by mongodb.
the class TestReferences method testSecondDatastore.
private void testSecondDatastore(Datastore datastore) {
assertNull(datastore.find(FacebookUser.class).filter(eq("id", 1)).first());
assertNull(datastore.find(FacebookUser.class).filter(eq("id", 3)).first());
final FacebookUser db2FoundUser = datastore.find(FacebookUser.class).filter(eq("id", 2)).first();
assertNotNull(db2FoundUser);
assertNotNull(datastore.find(FacebookUser.class).filter(eq("id", 4)).first());
assertEquals(db2FoundUser.friends.size(), 1, "Should find 1 friend");
assertEquals(db2FoundUser.friends.get(0).id, 4, "Should find the right friend");
}
use of dev.morphia.test.models.FacebookUser in project morphia by mongodb.
the class TestReferences method testMultipleDatabasesSingleThreaded.
@Test
public void testMultipleDatabasesSingleThreaded() {
getMapper().map(List.of(FacebookUser.class));
final Datastore ds1 = createDatastore(getMongoClient(), "db1");
final Datastore ds2 = createDatastore(getMongoClient(), "db2");
final FacebookUser db1Friend = new FacebookUser(3, "DB1 FaceBook Friend");
ds1.save(db1Friend);
final FacebookUser db1User = new FacebookUser(1, "DB1 FaceBook User");
db1User.friends.add(db1Friend);
ds1.save(db1User);
final FacebookUser db2Friend = new FacebookUser(4, "DB2 FaceBook Friend");
ds2.save(db2Friend);
final FacebookUser db2User = new FacebookUser(2, "DB2 FaceBook User");
db2User.friends.add(db2Friend);
ds2.save(db2User);
testFirstDatastore(ds1);
testSecondDatastore(ds2);
for (int i = 1; i <= 4; i++) {
assertNull(getDs().find(FacebookUser.class).filter(eq("id", i)).first());
}
}
use of dev.morphia.test.models.FacebookUser in project morphia by mongodb.
the class TestReferences method testFirstDatastore.
private void testFirstDatastore(Datastore datastore) {
final FacebookUser user = datastore.find(FacebookUser.class).filter(eq("id", 1)).first();
assertNotNull(user);
assertNotNull(datastore.find(FacebookUser.class).filter(eq("id", 3)).first());
assertEquals(user.friends.size(), 1, "Should find 1 friend");
assertEquals(user.friends.get(0).id, 3, "Should find the right friend");
assertNull(datastore.find(FacebookUser.class).filter(eq("id", 2)).first());
assertNull(datastore.find(FacebookUser.class).filter(eq("id", 4)).first());
}
use of dev.morphia.test.models.FacebookUser in project morphia by mongodb.
the class TestDatastore method testRefresh.
@Test
public void testRefresh() {
FacebookUser steve = getDs().save(new FacebookUser(1, "Steve"));
assertEquals(steve.loginCount, 0);
UpdateResult loginCount = getDs().find(FacebookUser.class).update(inc("loginCount", 10)).execute();
assertEquals(loginCount.getModifiedCount(), 1);
getDs().refresh(steve);
assertEquals(steve.loginCount, 10);
loginCount = getDs().find(FacebookUser.class).update(set("username", "Mark"), set("loginCount", 1)).execute();
assertEquals(loginCount.getModifiedCount(), 1);
getDs().refresh(steve);
assertEquals(steve.loginCount, 1);
assertEquals(steve.username, "Mark");
}
use of dev.morphia.test.models.FacebookUser in project morphia by mongodb.
the class TestDatastore method testUpdateWithCollation.
@Test
public void testUpdateWithCollation() {
getDs().save(asList(new FacebookUser(1, "John Doe"), new FacebookUser(2, "john doe")));
final Update<FacebookUser> update = getDs().find(FacebookUser.class).filter(eq("username", "john doe")).update(inc("loginCount"));
UpdateResult results = update.execute();
assertEquals(results.getModifiedCount(), 1);
assertEquals(getDs().find(FacebookUser.class).filter(eq("id", 1)).iterator(new FindOptions().limit(1)).next().loginCount, 0);
assertEquals(getDs().find(FacebookUser.class).filter(eq("id", 2)).iterator(new FindOptions().limit(1)).next().loginCount, 1);
results = update.execute(new UpdateOptions().multi(true).collation(Collation.builder().locale("en").collationStrength(SECONDARY).build()));
assertEquals(results.getModifiedCount(), 2);
assertEquals(getDs().find(FacebookUser.class).filter(eq("id", 1)).iterator(new FindOptions().limit(1)).next().loginCount, 1);
assertEquals(getDs().find(FacebookUser.class).filter(eq("id", 2)).iterator(new FindOptions().limit(1)).next().loginCount, 2);
}
Aggregations