Search in sources :

Example 11 with Mapper

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());
}
Also used : Mapper(dev.morphia.mapping.Mapper) PathTarget(dev.morphia.internal.PathTarget) Test(org.testng.annotations.Test)

Example 12 with Mapper

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());
}
Also used : Mapper(dev.morphia.mapping.Mapper) PathTarget(dev.morphia.internal.PathTarget) Test(org.testng.annotations.Test)

Example 13 with Mapper

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());
}
Also used : Mapper(dev.morphia.mapping.Mapper) PathTarget(dev.morphia.internal.PathTarget) EntityModel(dev.morphia.mapping.codec.pojo.EntityModel) Test(org.testng.annotations.Test)

Example 14 with Mapper

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());
}
Also used : Mapper(dev.morphia.mapping.Mapper) PathTarget(dev.morphia.internal.PathTarget) EntityModel(dev.morphia.mapping.codec.pojo.EntityModel) Test(org.testng.annotations.Test)

Example 15 with Mapper

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());
}
Also used : Mapper(dev.morphia.mapping.Mapper) PathTarget(dev.morphia.internal.PathTarget) Test(org.testng.annotations.Test)

Aggregations

Mapper (dev.morphia.mapping.Mapper)16 Test (org.testng.annotations.Test)13 PathTarget (dev.morphia.internal.PathTarget)8 EntityModel (dev.morphia.mapping.codec.pojo.EntityModel)7 ArrayList (java.util.ArrayList)5 Datastore (dev.morphia.Datastore)3 MapperOptions (dev.morphia.mapping.MapperOptions)2 DocumentReader (dev.morphia.mapping.codec.reader.DocumentReader)2 Document (org.bson.Document)2 Nullable (com.mongodb.lang.Nullable)1 Morphia.createDatastore (dev.morphia.Morphia.createDatastore)1 Entity (dev.morphia.annotations.Entity)1 MappingException (dev.morphia.mapping.MappingException)1 PropertyModel (dev.morphia.mapping.codec.pojo.PropertyModel)1 Sofia (dev.morphia.sofia.Sofia)1 CityPopulation (dev.morphia.test.models.CityPopulation)1 State (dev.morphia.test.models.State)1 EmbeddedType (dev.morphia.test.models.generics.EmbeddedType)1 AbstractVersionedBase (dev.morphia.test.models.versioned.AbstractVersionedBase)1 VersionedChildEntity (dev.morphia.test.models.versioned.VersionedChildEntity)1