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));
}
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));
}
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));
}
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));
}
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));
}
Aggregations