Search in sources :

Example 1 with MethodMappedSpecializedEntity

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

the class TestGenerics method testMethodMappedGenericEntities.

@Test
public void testMethodMappedGenericEntities() {
    Datastore datastore = createDatastore(getMongoClient(), TEST_DB_NAME, MapperOptions.builder().propertyDiscovery(PropertyDiscovery.METHODS).build());
    EntityModel entityModel = datastore.getMapper().map(MethodMappedSpecializedEntity.class).get(0);
    PropertyModel test = entityModel.getProperty("test");
    assertEquals(test.getType(), UUID.class);
    MethodMappedSpecializedEntity beforeDB = new MethodMappedSpecializedEntity();
    beforeDB.setId(UUID.randomUUID());
    beforeDB.setTest(UUID.randomUUID());
    datastore.save(beforeDB);
    MethodMappedSpecializedEntity loaded = datastore.find(MethodMappedSpecializedEntity.class).filter(eq("_id", beforeDB.getId())).first();
    assertEquals(loaded.getId(), beforeDB.getId());
    assertEquals(loaded.getTest(), beforeDB.getTest());
}
Also used : Datastore(dev.morphia.Datastore) Morphia.createDatastore(dev.morphia.Morphia.createDatastore) MethodMappedSpecializedEntity(dev.morphia.test.models.methods.MethodMappedSpecializedEntity) EntityModel(dev.morphia.mapping.codec.pojo.EntityModel) PropertyModel(dev.morphia.mapping.codec.pojo.PropertyModel) Test(org.testng.annotations.Test)

Aggregations

Datastore (dev.morphia.Datastore)1 Morphia.createDatastore (dev.morphia.Morphia.createDatastore)1 EntityModel (dev.morphia.mapping.codec.pojo.EntityModel)1 PropertyModel (dev.morphia.mapping.codec.pojo.PropertyModel)1 MethodMappedSpecializedEntity (dev.morphia.test.models.methods.MethodMappedSpecializedEntity)1 Test (org.testng.annotations.Test)1