use of dev.morphia.mapping.codec.pojo.EntityModel in project morphia by MorphiaOrg.
the class PathTargetTest method propertyNameResolution.
@Test
public void propertyNameResolution() {
getMapper().map(City.class, EmbeddedType.class);
Mapper mapper = getMapper();
EntityModel entityModel = mapper.getEntityModel(City.class);
PathTarget pathTarget = new PathTarget(mapper, entityModel, "name");
Assert.assertEquals(pathTarget.translatedPath(), "city");
Assert.assertEquals(entityModel.getProperty("name"), pathTarget.getTarget());
pathTarget = new PathTarget(mapper, entityModel, "city");
Assert.assertEquals(pathTarget.translatedPath(), "city");
Assert.assertEquals(entityModel.getProperty("city"), pathTarget.getTarget());
}
use of dev.morphia.mapping.codec.pojo.EntityModel in project morphia by MorphiaOrg.
the class EntityModelTest method testFindParameterization.
@Test
public void testFindParameterization() {
EntityModel model = new EntityModelBuilder(getMapper(), Child.class).build();
assertEquals(model.getProperty("someField").getType(), LocalDate.class);
}
use of dev.morphia.mapping.codec.pojo.EntityModel in project morphia by MorphiaOrg.
the class EntityModelTest method testGenericFields.
@Test
public void testGenericFields() {
EntityModel model = getDs().getMapper().map(Base.class).get(0);
assertEquals(model.getProperties().size(), 3, model.getProperties().stream().map(PropertyModel::getName).collect(joining(", ")));
model = getDs().getMapper().map(Parent.class).get(0);
assertEquals(model.getProperties().size(), 4, model.getProperties().stream().map(PropertyModel::getName).collect(joining(", ")));
model = getDs().getMapper().map(Child.class).get(0);
assertEquals(model.getProperties().size(), 5, model.getProperties().stream().map(PropertyModel::getName).collect(joining(", ")));
assertEquals(model.getProperty("t").getType(), String.class);
assertEquals(model.getProperty("someField").getType(), LocalDate.class);
}
use of dev.morphia.mapping.codec.pojo.EntityModel in project morphia by MorphiaOrg.
the class IndexHelperTest method calculateBadKeys.
@Test
public void calculateBadKeys() {
EntityModel model = getMapper().getEntityModel(IndexedClass.class);
Index index = indexBuilder().fields(fieldBuilder().value("texting").type(IndexType.TEXT).weight(1).build(), fieldBuilder().value("nest").type(IndexType.DESC).build()).build();
try {
getIndexHelper().calculateKeys(model, index);
fail("Validation should have failed on the bad key");
} catch (MappingException e) {
// all good
}
index = indexBuilder().fields(fieldBuilder().value("texting").type(IndexType.TEXT).weight(1).build(), fieldBuilder().value("nest").type(IndexType.DESC).build()).options(indexOptionsBuilder().disableValidation(true).build()).build();
getIndexHelper().calculateKeys(model, index);
}
use of dev.morphia.mapping.codec.pojo.EntityModel in project morphia by MorphiaOrg.
the class IndexHelperTest method calculateKeys.
@Test
public void calculateKeys() {
EntityModel model = getMapper().getEntityModel(IndexedClass.class);
Document keys = getIndexHelper().calculateKeys(model, indexBuilder().fields(fieldBuilder().value("text").type(IndexType.TEXT).weight(1).build(), fieldBuilder().value("nest").type(IndexType.DESC).build()).build());
assertEquals(keys, new Document().append("text", "text").append("nest", -1));
}
Aggregations