Search in sources :

Example 56 with Mapper

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

the class QueryValidatorTest method shouldReferToMappedClassInExceptionWhenQueryingPastSerializedField.

@Test
public void shouldReferToMappedClassInExceptionWhenQueryingPastSerializedField() {
    thrown.expect(ValidationException.class);
    thrown.expectMessage("Cannot use dot-notation past 'serialized' in " + "'org.mongodb.morphia.query.QueryValidatorTest$WithSerializedField'");
    validateQuery(WithSerializedField.class, new Mapper(), new StringBuilder("serialized.name"), FilterOperator.EQUAL, "", true, true);
}
Also used : Mapper(org.mongodb.morphia.mapping.Mapper) Test(org.junit.Test)

Example 57 with Mapper

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

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

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

the class QueryValidatorTest method shouldReferToMappedClassInExceptionWhenFieldNotFound.

@Test
public void shouldReferToMappedClassInExceptionWhenFieldNotFound() {
    thrown.expect(ValidationException.class);
    thrown.expectMessage("The field 'notAField' could not be found in 'org.bson.types.ObjectId'");
    validateQuery(SimpleEntity.class, new Mapper(), new StringBuilder("id.notAField"), FilterOperator.EQUAL, 1, true, true);
}
Also used : Mapper(org.mongodb.morphia.mapping.Mapper) Test(org.junit.Test)

Example 60 with Mapper

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

Mapper (org.mongodb.morphia.mapping.Mapper)62 Test (org.junit.Test)61 MappedClass (org.mongodb.morphia.mapping.MappedClass)53 MappedField (org.mongodb.morphia.mapping.MappedField)46 ArrayList (java.util.ArrayList)41 BasicDBObject (com.mongodb.BasicDBObject)9 DBObject (com.mongodb.DBObject)5 List (java.util.List)5 ObjectId (org.bson.types.ObjectId)5 SimpleEntity (org.mongodb.morphia.entities.SimpleEntity)5 Key (org.mongodb.morphia.Key)4 ParentType (org.mongodb.morphia.entities.ParentType)2 DefaultEntityCache (org.mongodb.morphia.mapping.cache.DefaultEntityCache)2 CollectionIdConverter (edu.stanford.bmir.protege.web.server.collection.CollectionIdConverter)1 CollectionItemConverter (edu.stanford.bmir.protege.web.server.collection.CollectionItemConverter)1 FormDataConverter (edu.stanford.bmir.protege.web.server.form.FormDataConverter)1 FormDataValueConverter (edu.stanford.bmir.protege.web.server.form.FormDataValueConverter)1 BsonDocument (org.bson.BsonDocument)1 BsonString (org.bson.BsonString)1 Document (org.bson.Document)1