use of org.mongodb.morphia.mapping.MappedClass in project morphia by mongodb.
the class SizeOperationValidatorTest method shouldAllowSizeOperatorForListTypesAndIntValues.
@Test
public void shouldAllowSizeOperatorForListTypesAndIntValues() {
// given
MappedClass mappedClass = new MappedClass(EntityWithListsAndArrays.class, new Mapper());
MappedField mappedField = mappedClass.getMappedField("listOfIntegers");
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.MappedClass in project morphia by mongodb.
the class SizeOperationValidatorTest method shouldAllowSizeOperatorForArrayTypeAndLongValues.
@Test
public void shouldAllowSizeOperatorForArrayTypeAndLongValues() {
// 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, 3L, validationFailures);
// then
assertThat(validationApplied, is(true));
assertThat(validationFailures.size(), is(0));
}
use of org.mongodb.morphia.mapping.MappedClass 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.MappedClass 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.MappedClass 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));
}
Aggregations