Search in sources :

Example 61 with MappedField

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)));
}
Also used : MappedField(org.mongodb.morphia.mapping.MappedField) Mapper(org.mongodb.morphia.mapping.Mapper) ArrayList(java.util.ArrayList) DBObject(com.mongodb.DBObject) MappedClass(org.mongodb.morphia.mapping.MappedClass) Test(org.junit.Test)

Example 62 with MappedField

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));
}
Also used : MappedField(org.mongodb.morphia.mapping.MappedField) ValidationFailure(org.mongodb.morphia.query.validation.ValidationFailure) Test(org.junit.Test)

Example 63 with MappedField

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));
}
Also used : MappedField(org.mongodb.morphia.mapping.MappedField) Key(org.mongodb.morphia.Key) ValidationFailure(org.mongodb.morphia.query.validation.ValidationFailure) Test(org.junit.Test)

Example 64 with MappedField

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));
}
Also used : MappedField(org.mongodb.morphia.mapping.MappedField) Mapper(org.mongodb.morphia.mapping.Mapper) BasicDBObject(com.mongodb.BasicDBObject) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) MappedClass(org.mongodb.morphia.mapping.MappedClass) Test(org.junit.Test)

Example 65 with MappedField

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));
}
Also used : MappedField(org.mongodb.morphia.mapping.MappedField) Mapper(org.mongodb.morphia.mapping.Mapper) ArrayList(java.util.ArrayList) MappedClass(org.mongodb.morphia.mapping.MappedClass) Key(org.mongodb.morphia.Key) Test(org.junit.Test)

Aggregations

MappedField (org.mongodb.morphia.mapping.MappedField)68 MappedClass (org.mongodb.morphia.mapping.MappedClass)56 Test (org.junit.Test)50 ArrayList (java.util.ArrayList)47 Mapper (org.mongodb.morphia.mapping.Mapper)46 BasicDBObject (com.mongodb.BasicDBObject)13 DBObject (com.mongodb.DBObject)8 List (java.util.List)7 Key (org.mongodb.morphia.Key)6 SimpleEntity (org.mongodb.morphia.entities.SimpleEntity)5 ObjectId (org.bson.types.ObjectId)4 ValidationFailure (org.mongodb.morphia.query.validation.ValidationFailure)4 UpdateResults (org.mongodb.morphia.query.UpdateResults)3 DBCollection (com.mongodb.DBCollection)2 Index (org.mongodb.morphia.annotations.Index)2 NotSaved (org.mongodb.morphia.annotations.NotSaved)2 Version (org.mongodb.morphia.annotations.Version)2 MappingException (org.mongodb.morphia.mapping.MappingException)2 DBRef (com.mongodb.DBRef)1 WriteResult (com.mongodb.WriteResult)1