use of org.mongodb.morphia.mapping.MappedField in project morphia by mongodb.
the class SizeOperationValidatorTest method shouldRejectSizeOperatorForNonListTypes.
@Test
public void shouldRejectSizeOperatorForNonListTypes() {
// given
MappedClass mappedClass = new MappedClass(EntityWithListsAndArrays.class, new Mapper());
MappedField mappedField = mappedClass.getMappedField("notAnArrayOrList");
List<ValidationFailure> validationFailures = new ArrayList<ValidationFailure>();
// when
boolean validationApplied = SizeOperationValidator.getInstance().apply(mappedField, SIZE, 3, validationFailures);
// then
assertThat(validationApplied, is(true));
assertThat(validationFailures.size(), is(1));
assertThat(validationFailures.get(0).toString(), containsString("should be a List or array."));
}
use of org.mongodb.morphia.mapping.MappedField in project morphia by mongodb.
the class SizeOperationValidatorTest method shouldAllowSizeOperatorForArrayTypeAndIntValues.
@Test
public void shouldAllowSizeOperatorForArrayTypeAndIntValues() {
// given
MappedClass mappedClass = new MappedClass(EntityWithListsAndArrays.class, new Mapper());
MappedField mappedField = mappedClass.getMappedField("arrayOfInts");
List<ValidationFailure> validationFailures = new ArrayList<ValidationFailure>();
// when
boolean validationApplied = SizeOperationValidator.getInstance().apply(mappedField, SIZE, 3, validationFailures);
// then
assertThat(validationApplied, is(true));
assertThat(validationFailures.size(), is(0));
}
use of org.mongodb.morphia.mapping.MappedField in project morphia by mongodb.
the class SizeOperationValidatorTest method shouldContainValidationFailuresForBothErrorsWhenTypeIsWrongAndValueIsWrong.
@Test
public void shouldContainValidationFailuresForBothErrorsWhenTypeIsWrongAndValueIsWrong() {
// given
MappedClass mappedClass = new MappedClass(EntityWithListsAndArrays.class, new Mapper());
MappedField mappedField = mappedClass.getMappedField("notAnArrayOrList");
List<ValidationFailure> validationFailures = new ArrayList<ValidationFailure>();
// when
boolean validationApplied = SizeOperationValidator.getInstance().apply(mappedField, SIZE, "value", validationFailures);
// then
assertThat(validationApplied, is(true));
assertThat(validationFailures.size(), is(2));
}
use of org.mongodb.morphia.mapping.MappedField in project morphia by mongodb.
the class SizeOperationValidatorTest method shouldRejectSizeOperatorForNonIntegerValues.
@Test
public void shouldRejectSizeOperatorForNonIntegerValues() {
// given
MappedClass mappedClass = new MappedClass(EntityWithListsAndArrays.class, new Mapper());
MappedField mappedField = mappedClass.getMappedField("listOfStrings");
List<ValidationFailure> validationFailures = new ArrayList<ValidationFailure>();
// when
boolean validationApplied = SizeOperationValidator.getInstance().apply(mappedField, SIZE, "value", validationFailures);
// then
assertThat(validationApplied, is(true));
assertThat(validationFailures.size(), is(1));
assertThat(validationFailures.get(0).toString(), Matchers.containsString("should be an integer type"));
}
use of org.mongodb.morphia.mapping.MappedField in project morphia by mongodb.
the class SizeOperationValidatorTest method shouldAllowSizeOperatorForArrayListTypesAndIntegerValues.
@Test
public void shouldAllowSizeOperatorForArrayListTypesAndIntegerValues() {
// given
MappedClass mappedClass = new MappedClass(EntityWithListsAndArrays.class, new Mapper());
MappedField mappedField = mappedClass.getMappedField("arrayListOfIntegers");
List<ValidationFailure> validationFailures = new ArrayList<ValidationFailure>();
// when
boolean validationApplied = SizeOperationValidator.getInstance().apply(mappedField, SIZE, 3, validationFailures);
// then
assertThat(validationApplied, is(true));
assertThat(validationFailures.size(), is(0));
}
Aggregations