Search in sources :

Example 11 with PathTarget

use of dev.morphia.internal.PathTarget 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 12 with PathTarget

use of dev.morphia.internal.PathTarget 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)

Example 13 with PathTarget

use of dev.morphia.internal.PathTarget in project morphia by mongodb.

the class TestUpdateOperations method testPlaceholderOperators.

@Test
public void testPlaceholderOperators() {
    new PathTarget(getMapper(), DumbColl.class, "fromArray.$").translatedPath();
    new PathTarget(getMapper(), DumbColl.class, "fromArray.$[]").translatedPath();
    new PathTarget(getMapper(), DumbColl.class, "fromArray.$[element]").translatedPath();
}
Also used : PathTarget(dev.morphia.internal.PathTarget) Test(org.testng.annotations.Test)

Aggregations

PathTarget (dev.morphia.internal.PathTarget)13 Mapper (dev.morphia.mapping.Mapper)8 Test (org.testng.annotations.Test)8 EntityModel (dev.morphia.mapping.codec.pojo.EntityModel)7 Document (org.bson.Document)3 Nullable (com.mongodb.lang.Nullable)2 PropertyModel (dev.morphia.mapping.codec.pojo.PropertyModel)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 StringJoiner (java.util.StringJoiner)2 DBObject (com.mongodb.DBObject)1 Datastore (dev.morphia.Datastore)1 Entity (dev.morphia.annotations.Entity)1 PropertyHandler (dev.morphia.mapping.codec.pojo.PropertyHandler)1 OperationTarget (dev.morphia.query.OperationTarget)1 UpdateOperator (dev.morphia.query.experimental.updates.UpdateOperator)1 Sofia (dev.morphia.sofia.Sofia)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1