Search in sources :

Example 46 with EntityModel

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

the class TestMapping method collectionNaming.

@Test
public void collectionNaming() {
    MapperOptions options = MapperOptions.builder().collectionNaming(NamingStrategy.lowerCase()).build();
    Datastore datastore = createDatastore(TestBase.TEST_DB_NAME, options);
    List<EntityModel> map = datastore.getMapper().map(ContainsMapWithEmbeddedInterface.class, ContainsIntegerList.class);
    assertEquals(map.get(0).getCollectionName(), "containsmapwithembeddedinterface");
    assertEquals(map.get(1).getCollectionName(), "cil");
    options = MapperOptions.builder().collectionNaming(NamingStrategy.kebabCase()).build();
    datastore = createDatastore(TestBase.TEST_DB_NAME, options);
    map = datastore.getMapper().map(ContainsMapWithEmbeddedInterface.class, ContainsIntegerList.class);
    assertEquals(map.get(0).getCollectionName(), "contains-map-with-embedded-interface");
    assertEquals(map.get(1).getCollectionName(), "cil");
}
Also used : MapperOptions(dev.morphia.mapping.MapperOptions) Datastore(dev.morphia.Datastore) Morphia.createDatastore(dev.morphia.Morphia.createDatastore) EntityModel(dev.morphia.mapping.codec.pojo.EntityModel) Test(org.testng.annotations.Test)

Example 47 with EntityModel

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

the class TestVersioning method testCanMapAPackageContainingAVersionedAbstractBaseClass.

@Test
public void testCanMapAPackageContainingAVersionedAbstractBaseClass() {
    getMapper().mapPackage("dev.morphia.test.models.versioned");
    List<EntityModel> entities = getMapper().getMappedEntities();
    assertThat(entities.size(), is(3));
    List<Class<?>> list = new ArrayList<>();
    for (EntityModel entityModel : entities) {
        list.add(entityModel.getType());
    }
    assertTrue(list.contains(VersionedChildEntity.class));
    assertTrue(list.contains(AbstractVersionedBase.class));
}
Also used : VersionedChildEntity(dev.morphia.test.models.versioned.VersionedChildEntity) EntityModel(dev.morphia.mapping.codec.pojo.EntityModel) ArrayList(java.util.ArrayList) AbstractVersionedBase(dev.morphia.test.models.versioned.AbstractVersionedBase) Test(org.testng.annotations.Test)

Aggregations

EntityModel (dev.morphia.mapping.codec.pojo.EntityModel)47 Test (org.testng.annotations.Test)28 Document (org.bson.Document)18 PropertyModel (dev.morphia.mapping.codec.pojo.PropertyModel)11 ArrayList (java.util.ArrayList)8 Datastore (dev.morphia.Datastore)7 Entity (dev.morphia.annotations.Entity)7 PathTarget (dev.morphia.internal.PathTarget)6 Mapper (dev.morphia.mapping.Mapper)6 Nullable (com.mongodb.lang.Nullable)5 Index (dev.morphia.annotations.Index)5 Morphia.createDatastore (dev.morphia.Morphia.createDatastore)4 VersionedChildEntity (dev.morphia.test.models.versioned.VersionedChildEntity)4 List (java.util.List)4 ExternalEntity (dev.morphia.annotations.experimental.ExternalEntity)3 WriteConcern (com.mongodb.WriteConcern)2 Key (dev.morphia.Key)2 IndexOptions (dev.morphia.annotations.IndexOptions)2 MappingException (dev.morphia.mapping.MappingException)2 EntityModelBuilder (dev.morphia.mapping.codec.pojo.EntityModelBuilder)2