use of dev.morphia.test.models.methods.MethodMappedFriend in project morphia by mongodb.
the class TestReferences method testMethodMapping.
@Test
public void testMethodMapping() {
Datastore datastore = createDatastore(getMongoClient(), TEST_DB_NAME, MapperOptions.builder().propertyDiscovery(PropertyDiscovery.METHODS).build());
datastore.getMapper().map(MethodMappedUser.class);
MethodMappedUser user = new MethodMappedUser();
MethodMappedFriend friend = new MethodMappedFriend();
user.setFriend(friend);
user.setFriends(MorphiaReference.wrap(List.of(friend)));
datastore.save(List.of(friend, user));
MethodMappedUser loaded = datastore.find(MethodMappedUser.class).first();
assertFalse(loaded.getFriends().isResolved());
assertEquals(loaded.getFriend(), friend);
assertEquals(loaded.getFriends().get().get(0), friend);
assertEquals(loaded, user);
}
Aggregations