Search in sources :

Example 26 with Mapper

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

the class QueryValidatorTest method shouldNotAllowOtherValuesForInOperator.

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

Example 27 with Mapper

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

the class QueryValidatorTest method shouldReferToMappedClassInExceptionWhenQueryingPastReferenceField.

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

Example 28 with Mapper

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

the class QueryValidatorTest method shouldNotAllowOtherValuesForAllOperator.

@Test
public void shouldNotAllowOtherValuesForAllOperator() {
    // given
    MappedClass mappedClass = new MappedClass(SimpleEntity.class, new Mapper());
    MappedField mappedField = mappedClass.getMappedField("name");
    // expect
    assertThat(QueryValidator.isCompatibleForOperator(mappedClass, mappedField, SimpleEntity.class, ALL, "value", new ArrayList<ValidationFailure>()), is(false));
}
Also used : MappedField(org.mongodb.morphia.mapping.MappedField) Mapper(org.mongodb.morphia.mapping.Mapper) SimpleEntity(org.mongodb.morphia.entities.SimpleEntity) ArrayList(java.util.ArrayList) MappedClass(org.mongodb.morphia.mapping.MappedClass) Test(org.junit.Test)

Example 29 with Mapper

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

the class QueryValidatorTest method shouldNotAllowNonIntegerTypeIfValueIsInt.

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

Example 30 with Mapper

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

the class QueryValidatorTest method shouldNotAllowGeoOperatorIfValueDoesNotContainCorrectField.

@Test
public void shouldNotAllowGeoOperatorIfValueDoesNotContainCorrectField() {
    // 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("name", "value"), 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)

Aggregations

Test (org.junit.Test)61 Mapper (org.mongodb.morphia.mapping.Mapper)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 BsonDocument (org.bson.BsonDocument)1 BsonString (org.bson.BsonString)1 Document (org.bson.Document)1 BasicDAO (org.mongodb.morphia.dao.BasicDAO)1 AnotherNested (org.mongodb.morphia.mapping.EmbeddedMappingTest.AnotherNested)1 Nested (org.mongodb.morphia.mapping.EmbeddedMappingTest.Nested)1 MappingException (org.mongodb.morphia.mapping.MappingException)1