use of org.mongodb.morphia.mapping.Mapper in project morphia by mongodb.
the class PathTargetTest method dottedPath.
@Test
public void dottedPath() {
getMorphia().map(ParentType.class, EmbeddedType.class);
Mapper mapper = getMorphia().getMapper();
PathTarget pathTarget = new PathTarget(mapper, mapper.getMappedClass(ParentType.class), "embedded.number");
Assert.assertEquals("embedded.number", pathTarget.translatedPath());
Assert.assertEquals(mapper.getMappedClass(EmbeddedType.class).getMappedFieldByJavaField("number"), pathTarget.getTarget());
}
use of org.mongodb.morphia.mapping.Mapper in project morphia by mongodb.
the class PathTargetTest method disableValidation.
@Test
public void disableValidation() {
getMorphia().map(WithNested.class, Nested.class, NestedImpl.class, AnotherNested.class);
Mapper mapper = getMorphia().getMapper();
MappedClass mappedClass = mapper.getMappedClass(WithNested.class);
final PathTarget pathTarget = new PathTarget(mapper, mappedClass, "nested.field.fail");
pathTarget.disableValidation();
Assert.assertEquals("nested.field.fail", pathTarget.translatedPath());
Assert.assertNull(pathTarget.getTarget());
}
use of org.mongodb.morphia.mapping.Mapper in project morphia by mongodb.
the class PathTargetTest method simpleResolution.
@Test
public void simpleResolution() {
getMorphia().map(ParentType.class, EmbeddedType.class);
Mapper mapper = getMorphia().getMapper();
MappedClass mappedClass = mapper.getMappedClass(ParentType.class);
PathTarget pathTarget = new PathTarget(mapper, mappedClass, "name");
Assert.assertEquals("n", pathTarget.translatedPath());
Assert.assertEquals(mappedClass.getMappedFieldByJavaField("name"), pathTarget.getTarget());
pathTarget = new PathTarget(mapper, mappedClass, "n");
Assert.assertEquals("n", pathTarget.translatedPath());
Assert.assertEquals(mappedClass.getMappedField("n"), pathTarget.getTarget());
}
use of org.mongodb.morphia.mapping.Mapper in project morphia by mongodb.
the class TestMapping method testMapping.
@Test
public void testMapping() {
final BasicDAO<User, ObjectId> messageDAO = new BasicDAO<User, ObjectId>(User.class, getDs());
Assert.assertNotNull(messageDAO);
Mapper mapper = new Mapper();
User user = new User();
user.id = 1;
user.userObject = "just a String";
DBObject dbObject = mapper.toDBObject(user);
Object object = mapper.fromDBObject(getDs(), User.class, dbObject, new DefaultEntityCache());
Assert.assertEquals(user.userObject, ((User) object).userObject);
user.userObject = 33;
dbObject = mapper.toDBObject(user);
object = mapper.fromDBObject(getDs(), User.class, dbObject, new DefaultEntityCache());
Assert.assertEquals(user.userObject, ((User) object).userObject);
user.userObject = 33.3;
dbObject = mapper.toDBObject(user);
object = mapper.fromDBObject(getDs(), User.class, dbObject, new DefaultEntityCache());
Assert.assertEquals(user.userObject, ((User) object).userObject);
}
use of org.mongodb.morphia.mapping.Mapper in project morphia by mongodb.
the class TestMapping method testCanMapSerializableObject.
@Test
public void testCanMapSerializableObject() {
// given
Mapper mapper = new Mapper();
User user = new User();
user.id = 1;
user.userObject = new SerializableObject();
// when
DBObject dbObject = mapper.toDBObject(user);
User object = mapper.fromDBObject(getDs(), User.class, dbObject, new DefaultEntityCache());
// then
assertThat(object.userObject, is(user.userObject));
}
Aggregations