Search in sources :

Example 36 with EntityModel

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());
}
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 37 with EntityModel

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

Example 38 with EntityModel

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

Example 39 with EntityModel

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

Example 40 with EntityModel

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

Aggregations

EntityModel (dev.morphia.mapping.codec.pojo.EntityModel)94 Test (org.testng.annotations.Test)56 Document (org.bson.Document)36 PropertyModel (dev.morphia.mapping.codec.pojo.PropertyModel)22 ArrayList (java.util.ArrayList)16 Datastore (dev.morphia.Datastore)14 Entity (dev.morphia.annotations.Entity)14 PathTarget (dev.morphia.internal.PathTarget)12 Mapper (dev.morphia.mapping.Mapper)12 Nullable (com.mongodb.lang.Nullable)10 Index (dev.morphia.annotations.Index)10 Morphia.createDatastore (dev.morphia.Morphia.createDatastore)8 VersionedChildEntity (dev.morphia.test.models.versioned.VersionedChildEntity)8 List (java.util.List)8 ExternalEntity (dev.morphia.annotations.experimental.ExternalEntity)6 WriteConcern (com.mongodb.WriteConcern)4 Key (dev.morphia.Key)4 IndexOptions (dev.morphia.annotations.IndexOptions)4 MappingException (dev.morphia.mapping.MappingException)4 EntityModelBuilder (dev.morphia.mapping.codec.pojo.EntityModelBuilder)4