use of org.mongodb.morphia.mapping.MappedClass 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.MappedClass 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));
}
use of org.mongodb.morphia.mapping.MappedClass in project morphia by mongodb.
the class SizeOperationValidatorTest method shouldAllowSizeOperatorForListTypesAndLongValues.
@Test
public void shouldAllowSizeOperatorForListTypesAndLongValues() {
// 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, 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 TestDocumentValidation method validationDocuments.
@Test
public void validationDocuments() {
Document validator = Document.parse("{ jelly : { $ne : 'rhubarb' } }");
getMorphia().map(DocumentValidation.class);
MappedClass mappedClass = getMorphia().getMapper().getMappedClass(DocumentValidation.class);
for (ValidationLevel level : EnumSet.allOf(ValidationLevel.class)) {
for (ValidationAction action : EnumSet.allOf(ValidationAction.class)) {
checkValidation(validator, mappedClass, level, action);
}
}
}
use of org.mongodb.morphia.mapping.MappedClass in project morphia by mongodb.
the class TestMapper method subTypes.
@Test
public void subTypes() {
getMorphia().map(NestedImpl.class, AnotherNested.class);
Mapper mapper = getMorphia().getMapper();
List<MappedClass> subTypes = mapper.getSubTypes(mapper.getMappedClass(Nested.class));
Assert.assertTrue(subTypes.contains(mapper.getMappedClass(NestedImpl.class)));
Assert.assertTrue(subTypes.contains(mapper.getMappedClass(AnotherNested.class)));
}
Aggregations