use of org.mongodb.morphia.mapping.MappedField 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.MappedField in project morphia by mongodb.
the class QueryForSubtypeTest method testImplementingClassIsCompatibleWithInterface.
@Test
public void testImplementingClassIsCompatibleWithInterface() {
MappedField user = jobMappedClass.getMappedField("owner");
boolean compatible = isCompatibleForOperator(jobMappedClass, user, User.class, EQUAL, new UserImpl(), new ArrayList<ValidationFailure>());
assertThat(compatible, is(true));
}
use of org.mongodb.morphia.mapping.MappedField in project morphia by mongodb.
the class QueryForSubtypeTest method testSubclassOfKeyShouldBeCompatibleWithFieldUser.
@Test
public void testSubclassOfKeyShouldBeCompatibleWithFieldUser() {
MappedField user = jobMappedClass.getMappedField("owner");
Key<User> anonymousKeySubclass = new Key<User>(User.class, "User", 212L) {
};
boolean compatible = isCompatibleForOperator(jobMappedClass, user, User.class, EQUAL, anonymousKeySubclass, new ArrayList<ValidationFailure>());
assertThat(compatible, is(true));
}
use of org.mongodb.morphia.mapping.MappedField 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));
}
use of org.mongodb.morphia.mapping.MappedField in project morphia by mongodb.
the class QueryValidatorTest method shouldNotAllowValueWithoutEntityAnnotationAndTypeOfKey.
@Test
public void shouldNotAllowValueWithoutEntityAnnotationAndTypeOfKey() {
// expect
MappedClass mappedClass = new MappedClass(SimpleEntity.class, new Mapper());
MappedField mappedField = mappedClass.getMappedField("name");
assertThat(QueryValidator.isCompatibleForOperator(mappedClass, mappedField, Key.class, EQUAL, "value", new ArrayList<ValidationFailure>()), is(false));
}
Aggregations