Search in sources :

Example 36 with MappedField

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

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

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

Example 39 with MappedField

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

the class QueryValidatorTest method shouldNotAllowTypeThatDoesNotMatchKeyTypeValue.

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

Example 40 with MappedField

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

the class EntityTypeAndIdValueValidatorTest method shouldRejectValueWithATypeThatDoesNotMatchTheEntityIdFieldType.

@Test
public void shouldRejectValueWithATypeThatDoesNotMatchTheEntityIdFieldType() {
    // given
    ArrayList<ValidationFailure> validationFailures = new ArrayList<ValidationFailure>();
    // when
    MappedClass mappedClass = new MappedClass(SimpleEntity.class, new Mapper());
    MappedField mappedField = mappedClass.getMappedField("_id");
    boolean validationApplied = EntityTypeAndIdValueValidator.getInstance().apply(mappedClass, mappedField, "some non-ObjectId value", validationFailures);
    // then
    assertThat(validationApplied, is(true));
    assertThat(validationFailures.size(), is(1));
}
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

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