Search in sources :

Example 1 with MethodMappedFriend

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);
}
Also used : MethodMappedFriend(dev.morphia.test.models.methods.MethodMappedFriend) MethodMappedUser(dev.morphia.test.models.methods.MethodMappedUser) Datastore(dev.morphia.Datastore) Morphia.createDatastore(dev.morphia.Morphia.createDatastore) Test(org.testng.annotations.Test)

Aggregations

Datastore (dev.morphia.Datastore)1 Morphia.createDatastore (dev.morphia.Morphia.createDatastore)1 MethodMappedFriend (dev.morphia.test.models.methods.MethodMappedFriend)1 MethodMappedUser (dev.morphia.test.models.methods.MethodMappedUser)1 Test (org.testng.annotations.Test)1