use of org.mongodb.morphia.mapping.MappedClass 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.MappedClass 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));
}
use of org.mongodb.morphia.mapping.MappedClass in project morphia by mongodb.
the class GeoWithinOperationValidatorTest method shouldAllowGeoWithinOperatorForGeoEntityWithListOfIntegers.
@Test
public void shouldAllowGeoWithinOperatorForGeoEntityWithListOfIntegers() {
// given
List<ValidationFailure> validationFailures = new ArrayList<ValidationFailure>();
MappedClass mappedClass = new MappedClass(GeoEntity.class, new Mapper());
MappedField mappedField = mappedClass.getMappedField("list");
assertThat(GeoWithinOperationValidator.getInstance().apply(mappedField, GEO_WITHIN, new BasicDBObject("$box", 1), validationFailures), is(true));
}
use of org.mongodb.morphia.mapping.MappedClass in project morphia by mongodb.
the class GeoWithinOperationValidatorTest method shouldRejectGeoWithinWhenValueIsNotADBObject.
@Test
public void shouldRejectGeoWithinWhenValueIsNotADBObject() {
// given
List<ValidationFailure> validationFailures = new ArrayList<ValidationFailure>();
MappedClass mappedClass = new MappedClass(GeoEntity.class, new Mapper());
MappedField mappedField = mappedClass.getMappedField("array");
// when
boolean validationApplied = GeoWithinOperationValidator.getInstance().apply(mappedField, GEO_WITHIN, "NotAGeoQuery", validationFailures);
// then
assertThat(validationApplied, is(true));
assertThat(validationFailures.size(), is(1));
assertThat(validationFailures.get(0).toString(), containsString("For a $geoWithin operation, the value should be a valid geo query"));
}
use of org.mongodb.morphia.mapping.MappedClass in project morphia by mongodb.
the class GeoWithinOperationValidatorTest method shouldRejectGeoWithinWhenValueDoesNotContainKeyword.
@Test
public void shouldRejectGeoWithinWhenValueDoesNotContainKeyword() {
// given
List<ValidationFailure> validationFailures = new ArrayList<ValidationFailure>();
MappedClass mappedClass = new MappedClass(GeoEntity.class, new Mapper());
MappedField mappedField = mappedClass.getMappedField("array");
// when
boolean validationApplied = GeoWithinOperationValidator.getInstance().apply(mappedField, GEO_WITHIN, new BasicDBObject("notValidKey", 1), validationFailures);
// then
assertThat(validationApplied, is(true));
assertThat(validationFailures.size(), is(1));
assertThat(validationFailures.get(0).toString(), containsString("For a $geoWithin operation, the value should be a valid geo query"));
}
Aggregations