use of dev.morphia.mapping.codec.pojo.EntityModel in project morphia by MorphiaOrg.
the class IndexHelperTest method wildcardTextIndex.
@Test
public void wildcardTextIndex() {
MongoCollection<Document> indexes = getDatabase().getCollection("indexes");
EntityModel model = getMapper().getEntityModel(IndexedClass.class);
Index index = indexBuilder().fields(fieldBuilder().value("$**").type(IndexType.TEXT).build()).build();
getIndexHelper().createIndex(indexes, model, index);
List<Document> wildcard = getIndexInfo(IndexedClass.class);
boolean found = false;
for (Document document : wildcard) {
found |= document.get("name").equals("$**_text");
}
assertTrue(found, "Should have found the wildcard index");
}
use of dev.morphia.mapping.codec.pojo.EntityModel in project morphia by MorphiaOrg.
the class TestDocumentValidation method validationDocuments.
@Test
public void validationDocuments() {
Document validator = parse("{ \"jelly\" : { \"$ne\" : \"rhubarb\" } }");
getMapper().map(DocumentValidation.class);
EntityModel model = getMapper().getEntityModel(DocumentValidation.class);
for (ValidationLevel level : EnumSet.allOf(ValidationLevel.class)) {
for (ValidationAction action : EnumSet.allOf(ValidationAction.class)) {
checkValidation(validator, model, level, action);
}
}
}
use of dev.morphia.mapping.codec.pojo.EntityModel in project morphia by MorphiaOrg.
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());
}
use of dev.morphia.mapping.codec.pojo.EntityModel in project morphia by MorphiaOrg.
the class TestGenerics method testGenericEntities.
@Test
public void testGenericEntities() {
EntityModel entityModel = getMapper().map(SpecializedEntity.class).get(0);
PropertyModel test = entityModel.getProperty("test");
assertEquals(test.getType(), UUID.class);
SpecializedEntity beforeDB = new SpecializedEntity();
beforeDB.setId(UUID.randomUUID());
beforeDB.setTest(UUID.randomUUID());
getDs().save(beforeDB);
SpecializedEntity loaded = getDs().find(SpecializedEntity.class).filter(eq("_id", beforeDB.getId())).first();
assertEquals(loaded.getId(), beforeDB.getId());
assertEquals(loaded.getTest(), beforeDB.getTest());
}
use of dev.morphia.mapping.codec.pojo.EntityModel in project morphia by MorphiaOrg.
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");
}
Aggregations