Search in sources :

Example 21 with PropertyModel

use of dev.morphia.mapping.codec.pojo.PropertyModel 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)

Example 22 with PropertyModel

use of dev.morphia.mapping.codec.pojo.PropertyModel in project morphia by mongodb.

the class TestVersioning method testVersionFieldNameContribution.

@Test
public void testVersionFieldNameContribution() {
    final PropertyModel mappedFieldByJavaField = getMapper().getEntityModel(NamedVersion.class).getProperty("v");
    assertEquals(mappedFieldByJavaField.getMappedName(), "v");
}
Also used : PropertyModel(dev.morphia.mapping.codec.pojo.PropertyModel) Test(org.testng.annotations.Test)

Aggregations

PropertyModel (dev.morphia.mapping.codec.pojo.PropertyModel)22 EntityModel (dev.morphia.mapping.codec.pojo.EntityModel)10 Test (org.testng.annotations.Test)10 Document (org.bson.Document)4 Nullable (com.mongodb.lang.Nullable)3 Datastore (dev.morphia.Datastore)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 PathTarget (dev.morphia.internal.PathTarget)2 MappingException (dev.morphia.mapping.MappingException)2 PropertyHandler (dev.morphia.mapping.codec.pojo.PropertyHandler)2 DocumentWriter (dev.morphia.mapping.codec.writer.DocumentWriter)2 OperationTarget (dev.morphia.query.OperationTarget)2 MethodMappedSpecializedEntity (dev.morphia.test.models.methods.MethodMappedSpecializedEntity)2 Key (dev.morphia.Key)1 Morphia.createDatastore (dev.morphia.Morphia.createDatastore)1 Mapper (dev.morphia.mapping.Mapper)1 NotMappableException (dev.morphia.mapping.NotMappableException)1 TestBase (dev.morphia.test.TestBase)1 CityPopulation (dev.morphia.test.models.CityPopulation)1