use of org.mongodb.morphia.mapping.MappedClass in project morphia by mongodb.
the class TestIndexed method testIndexedRecursiveEntity.
@Test
public void testIndexedRecursiveEntity() throws Exception {
final MappedClass mc = getMorphia().getMapper().getMappedClass(CircularEmbeddedEntity.class);
getDs().ensureIndexes();
assertThat(getDb().getCollection(mc.getCollectionName()).getIndexInfo(), hasIndexNamed("a_1"));
}
use of org.mongodb.morphia.mapping.MappedClass in project morphia by mongodb.
the class PathTargetTest method arrays.
@Test
public void arrays() {
getMorphia().map(EntityWithListsAndArrays.class, EmbeddedType.class, Student.class);
Mapper mapper = getMorphia().getMapper();
MappedClass mappedClass = mapper.getMappedClass(EntityWithListsAndArrays.class);
PathTarget pathTarget = new PathTarget(mapper, mappedClass, "listEmbeddedType.1.number");
Assert.assertEquals("listEmbeddedType.1.number", pathTarget.translatedPath());
Assert.assertEquals(mapper.getMappedClass(EmbeddedType.class).getMappedFieldByJavaField("number"), pathTarget.getTarget());
assertEquals("listEmbeddedType.$", new PathTarget(mapper, mappedClass, "listEmbeddedType.$").translatedPath());
assertEquals("listEmbeddedType.1", new PathTarget(mapper, mappedClass, "listEmbeddedType.1").translatedPath());
}
use of org.mongodb.morphia.mapping.MappedClass in project morphia by mongodb.
the class PathTargetTest method interfaces.
@Test
public void interfaces() {
getMorphia().map(WithNested.class, Nested.class, NestedImpl.class, AnotherNested.class);
Mapper mapper = getMorphia().getMapper();
MappedClass mappedClass = mapper.getMappedClass(WithNested.class);
PathTarget pathTarget = new PathTarget(mapper, mappedClass, "nested.value");
Assert.assertEquals("nested.value", pathTarget.translatedPath());
Assert.assertEquals(mapper.getMappedClass(AnotherNested.class).getMappedFieldByJavaField("value"), pathTarget.getTarget());
pathTarget = new PathTarget(mapper, mappedClass, "nested.field");
Assert.assertEquals("nested.field", pathTarget.translatedPath());
Assert.assertEquals(mapper.getMappedClass(NestedImpl.class).getMappedFieldByJavaField("field"), pathTarget.getTarget());
}
use of org.mongodb.morphia.mapping.MappedClass 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.MappedClass 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)));
}
Aggregations