Search in sources :

Example 86 with MappedClass

use of org.mongodb.morphia.mapping.MappedClass 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 87 with MappedClass

use of org.mongodb.morphia.mapping.MappedClass 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 88 with MappedClass

use of org.mongodb.morphia.mapping.MappedClass 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)

Example 89 with MappedClass

use of org.mongodb.morphia.mapping.MappedClass in project morphia by mongodb.

the class QueryValidatorTest method shouldAllowValuesOfList.

@Test
public void shouldAllowValuesOfList() {
    // expect
    MappedClass mappedClass = new MappedClass(SimpleEntity.class, new Mapper());
    MappedField mappedField = mappedClass.getMappedField("name");
    assertThat(QueryValidator.isCompatibleForOperator(mappedClass, mappedField, List.class, EQUAL, new ArrayList<String>(), new ArrayList<ValidationFailure>()), is(true));
}
Also used : MappedField(org.mongodb.morphia.mapping.MappedField) Mapper(org.mongodb.morphia.mapping.Mapper) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) MappedClass(org.mongodb.morphia.mapping.MappedClass) Test(org.junit.Test)

Example 90 with MappedClass

use of org.mongodb.morphia.mapping.MappedClass in project morphia by mongodb.

the class QueryValidatorTest method shouldNotAllowSizeOperatorForNonIntegerValues.

@Test
public void shouldNotAllowSizeOperatorForNonIntegerValues() {
    // expect
    MappedClass mappedClass = new MappedClass(SimpleEntity.class, new Mapper());
    MappedField mappedField = mappedClass.getMappedField("name");
    assertThat(QueryValidator.isCompatibleForOperator(mappedClass, mappedField, ArrayList.class, SIZE, "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) Test(org.junit.Test)

Aggregations

MappedClass (org.mongodb.morphia.mapping.MappedClass)92 Test (org.junit.Test)73 MappedField (org.mongodb.morphia.mapping.MappedField)56 Mapper (org.mongodb.morphia.mapping.Mapper)53 ArrayList (java.util.ArrayList)48 BasicDBObject (com.mongodb.BasicDBObject)18 DBObject (com.mongodb.DBObject)12 BsonDocument (org.bson.BsonDocument)8 Document (org.bson.Document)8 MappingException (org.mongodb.morphia.mapping.MappingException)6 DBCollection (com.mongodb.DBCollection)5 List (java.util.List)5 SimpleEntity (org.mongodb.morphia.entities.SimpleEntity)5 ObjectId (org.bson.types.ObjectId)4 Key (org.mongodb.morphia.Key)4 Index (org.mongodb.morphia.annotations.Index)4 LinkedHashMap (java.util.LinkedHashMap)3 NotSaved (org.mongodb.morphia.annotations.NotSaved)3 UpdateResults (org.mongodb.morphia.query.UpdateResults)3 WriteResult (com.mongodb.WriteResult)2