use of dev.morphia.mapping.Mapper in project morphia by mongodb.
the class PathTargetTest method subClasses.
@Test
public void subClasses() {
getMapper().map(FatherEntity.class, ChildEntity.class, Another.class);
Mapper mapper = getMapper();
PathTarget pathTarget = new PathTarget(mapper, FatherEntity.class, "embedded.anotherField");
Assert.assertEquals(pathTarget.translatedPath(), "embedded.anotherField");
Assert.assertEquals(mapper.getEntityModel(Another.class).getProperty("anotherField"), pathTarget.getTarget());
}
use of dev.morphia.mapping.Mapper in project morphia by mongodb.
the class PathTargetTest method dottedPath.
@Test
public void dottedPath() {
getMapper().map(State.class, CityPopulation.class);
Mapper mapper = getMapper();
PathTarget pathTarget = new PathTarget(mapper, State.class, "biggestCity.population");
Assert.assertEquals(pathTarget.translatedPath(), "biggestCity.pop");
Assert.assertEquals(mapper.getEntityModel(CityPopulation.class).getProperty("population"), pathTarget.getTarget());
}
use of dev.morphia.mapping.Mapper in project morphia by mongodb.
the class PathTargetTest method interfaces.
@Test
public void interfaces() {
getMapper().map(HoldsAnInterface.class, MappedInterface.class, InterfaceTypeA.class, InterfaceTypeB.class);
Mapper mapper = getMapper();
EntityModel entityModel = mapper.getEntityModel(HoldsAnInterface.class);
PathTarget pathTarget = new PathTarget(mapper, entityModel, "mapped.value");
Assert.assertEquals(pathTarget.translatedPath(), "mapped.value");
Assert.assertEquals(mapper.getEntityModel(InterfaceTypeB.class).getProperty("value"), pathTarget.getTarget());
pathTarget = new PathTarget(mapper, entityModel, "mapped.field");
Assert.assertEquals(pathTarget.translatedPath(), "mapped.field");
Assert.assertEquals(mapper.getEntityModel(InterfaceTypeA.class).getProperty("field"), pathTarget.getTarget());
}
use of dev.morphia.mapping.Mapper in project morphia by mongodb.
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.Mapper in project morphia by mongodb.
the class PathTargetTest method disableValidation.
@Test
public void disableValidation() {
getMapper().map(FatherEntity.class);
Mapper mapper = getMapper();
final PathTarget pathTarget = new PathTarget(mapper, FatherEntity.class, "nested.field.fail", false);
Assert.assertEquals(pathTarget.translatedPath(), "nested.field.fail");
Assert.assertNull(pathTarget.getTarget());
}
Aggregations