Search in sources :

Example 1 with MethodMappedUser

use of dev.morphia.test.models.methods.MethodMappedUser in project morphia by mongodb.

the class TestVersioning 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();
    assertEquals(user.getVersion(), null);
    datastore.save(user);
    assertEquals(user.getVersion(), Long.valueOf(1L));
}
Also used : MethodMappedUser(dev.morphia.test.models.methods.MethodMappedUser) Datastore(dev.morphia.Datastore) Morphia.createDatastore(dev.morphia.Morphia.createDatastore) Test(org.testng.annotations.Test)

Example 2 with MethodMappedUser

use of dev.morphia.test.models.methods.MethodMappedUser 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)2 Morphia.createDatastore (dev.morphia.Morphia.createDatastore)2 MethodMappedUser (dev.morphia.test.models.methods.MethodMappedUser)2 Test (org.testng.annotations.Test)2 MethodMappedFriend (dev.morphia.test.models.methods.MethodMappedFriend)1