use of org.mongodb.morphia.mapping.Mapper in project morphia by mongodb.
the class PathTargetTest method maps.
@Test
public void maps() {
getMorphia().map(Student.class, Article.class);
Mapper mapper = getMorphia().getMapper();
MappedClass mappedClass = mapper.getMappedClass(Student.class);
PathTarget pathTarget = new PathTarget(mapper, mappedClass, "grades.$.data.name");
Assert.assertEquals("grades.$.d.name", pathTarget.translatedPath());
Assert.assertEquals(mapper.getMappedClass(Grade.class).getMappedFieldByJavaField("data"), pathTarget.getTarget());
pathTarget = new PathTarget(mapper, mappedClass, "grades.$.d.name");
Assert.assertEquals("grades.$.d.name", pathTarget.translatedPath());
Assert.assertEquals(mapper.getMappedClass(Grade.class).getMappedField("d"), pathTarget.getTarget());
pathTarget = new PathTarget(mapper, mapper.getMappedClass(Article.class), "translations");
Assert.assertEquals("translations", pathTarget.translatedPath());
}
use of org.mongodb.morphia.mapping.Mapper in project morphia by mongodb.
the class PathTargetTest method subClasses.
@Test
public void subClasses() {
getMorphia().map(ParentType.class, EmbeddedType.class, EmbeddedSubtype.class);
Mapper mapper = getMorphia().getMapper();
PathTarget pathTarget = new PathTarget(mapper, mapper.getMappedClass(ParentType.class), "embedded.flag");
Assert.assertEquals("embedded.flag", pathTarget.translatedPath());
Assert.assertEquals(mapper.getMappedClass(EmbeddedSubtype.class).getMappedFieldByJavaField("flag"), pathTarget.getTarget());
}
use of org.mongodb.morphia.mapping.Mapper in project morphia by mongodb.
the class TestMapping method testToMongoObjectCorrectlyMapsSerializableFieldForIssue591.
@Test
public void testToMongoObjectCorrectlyMapsSerializableFieldForIssue591() {
// given
Mapper mapper = new Mapper();
User user = new User();
user.id = 1;
user.userObject = new SerializableObject();
MappedClass mc = new MappedClass(User.class, mapper);
MappedField mf = mc.getMappedField("userObject");
// when
Object dbValue = mapper.toMongoObject(mf, null, user.userObject);
Class<byte[]> byteArrayClass = byte[].class;
// then
assertThat(dbValue, is(instanceOf(byteArrayClass)));
}
use of org.mongodb.morphia.mapping.Mapper in project morphia by mongodb.
the class TestMapping method testToMongoObjectCorrectlyMapsSerializableListOfObjectsForIssue591.
@Test
public void testToMongoObjectCorrectlyMapsSerializableListOfObjectsForIssue591() {
// given
Mapper mapper = new Mapper();
ListEntity user = new ListEntity();
user.id = 1;
List<Object> list = new ArrayList<Object>();
list.add("value");
user.list = list;
MappedClass mc = new MappedClass(ListEntity.class, mapper);
MappedField mf = mc.getMappedField("list");
// when
Object dbValue = mapper.toMongoObject(mf, null, user.list);
Class<byte[]> byteArrayClass = byte[].class;
// then
assertThat(dbValue, is(instanceOf(byteArrayClass)));
}
use of org.mongodb.morphia.mapping.Mapper in project morphia by mongodb.
the class QueryValidatorTest method shouldNotAllowGeoWithinWhenValueDoesNotContainKeyword.
@Test
public void shouldNotAllowGeoWithinWhenValueDoesNotContainKeyword() {
// expect
MappedClass mappedClass = new MappedClass(GeoEntity.class, new Mapper());
MappedField mappedField = mappedClass.getMappedField("array");
assertThat(QueryValidator.isCompatibleForOperator(mappedClass, mappedField, List.class, GEO_WITHIN, new BasicDBObject("notValidKey", 1), new ArrayList<ValidationFailure>()), is(false));
}
Aggregations