Search in sources :

Example 26 with MappedField

use of org.mongodb.morphia.mapping.MappedField in project morphia by mongodb.

the class GeoWithinOperationValidatorTest method shouldAllowGeoWithinOperatorWithAllAppropriateTrimmings.

@Test
public void shouldAllowGeoWithinOperatorWithAllAppropriateTrimmings() {
    // given
    List<ValidationFailure> validationFailures = new ArrayList<ValidationFailure>();
    MappedClass mappedClass = new MappedClass(GeoEntity.class, new Mapper());
    MappedField mappedField = mappedClass.getMappedField("array");
    // when
    assertThat(GeoWithinOperationValidator.getInstance().apply(mappedField, GEO_WITHIN, new BasicDBObject("$box", 1), validationFailures), is(true));
}
Also used : MappedField(org.mongodb.morphia.mapping.MappedField) Mapper(org.mongodb.morphia.mapping.Mapper) BasicDBObject(com.mongodb.BasicDBObject) ArrayList(java.util.ArrayList) MappedClass(org.mongodb.morphia.mapping.MappedClass) Test(org.junit.Test)

Example 27 with MappedField

use of org.mongodb.morphia.mapping.MappedField in project morphia by mongodb.

the class MappedFieldTypeValidatorTest method shouldAllowAListThatDoesNotContainNumbers.

@Test
public void shouldAllowAListThatDoesNotContainNumbers() {
    // given
    MappedClass mappedClass = new MappedClass(EntityWithListsAndArrays.class, new Mapper());
    MappedField mappedField = mappedClass.getMappedField("listOfIntegers");
    // expect
    assertThat(MappedFieldTypeValidator.isIterableOfNumbers(mappedField), is(true));
}
Also used : MappedField(org.mongodb.morphia.mapping.MappedField) Mapper(org.mongodb.morphia.mapping.Mapper) MappedClass(org.mongodb.morphia.mapping.MappedClass) Test(org.junit.Test)

Example 28 with MappedField

use of org.mongodb.morphia.mapping.MappedField in project morphia by mongodb.

the class MappedFieldTypeValidatorTest method shouldAllowArraysOfNumbers.

@Test
public void shouldAllowArraysOfNumbers() {
    // given
    MappedClass mappedClass = new MappedClass(EntityWithListsAndArrays.class, new Mapper());
    MappedField mappedField = mappedClass.getMappedField("arrayOfInts");
    // expect
    assertThat(MappedFieldTypeValidator.isArrayOfNumbers(mappedField), is(true));
}
Also used : MappedField(org.mongodb.morphia.mapping.MappedField) Mapper(org.mongodb.morphia.mapping.Mapper) MappedClass(org.mongodb.morphia.mapping.MappedClass) Test(org.junit.Test)

Example 29 with MappedField

use of org.mongodb.morphia.mapping.MappedField in project morphia by mongodb.

the class SizeOperationValidatorTest method shouldAllowSizeOperatorForIterableTypesAndIntegerValues.

@Test
public void shouldAllowSizeOperatorForIterableTypesAndIntegerValues() {
    // given
    MappedClass mappedClass = new MappedClass(EntityWithListsAndArrays.class, new Mapper());
    MappedField mappedField = mappedClass.getMappedField("setOfIntegers");
    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));
}
Also used : MappedField(org.mongodb.morphia.mapping.MappedField) Mapper(org.mongodb.morphia.mapping.Mapper) ArrayList(java.util.ArrayList) MappedClass(org.mongodb.morphia.mapping.MappedClass) Test(org.junit.Test)

Example 30 with MappedField

use of org.mongodb.morphia.mapping.MappedField in project morphia by mongodb.

the class IgnoreFieldsAnnotationTest method processIgnoreFieldsAnnotations.

//remove any MappedField specified in @IgnoreFields on the class.
private void processIgnoreFieldsAnnotations() {
    for (final MappedClass mc : getMorphia().getMapper().getMappedClasses()) {
        final IgnoreFields ignores = (IgnoreFields) mc.getAnnotation(IgnoreFields.class);
        if (ignores != null) {
            for (final String field : ignores.value().split(",")) {
                final MappedField mf = mc.getMappedFieldByJavaField(field);
                mc.getPersistenceFields().remove(mf);
            }
        }
    }
}
Also used : MappedField(org.mongodb.morphia.mapping.MappedField) MappedClass(org.mongodb.morphia.mapping.MappedClass)

Aggregations

MappedField (org.mongodb.morphia.mapping.MappedField)68 MappedClass (org.mongodb.morphia.mapping.MappedClass)56 Test (org.junit.Test)50 ArrayList (java.util.ArrayList)47 Mapper (org.mongodb.morphia.mapping.Mapper)46 BasicDBObject (com.mongodb.BasicDBObject)13 DBObject (com.mongodb.DBObject)8 List (java.util.List)7 Key (org.mongodb.morphia.Key)6 SimpleEntity (org.mongodb.morphia.entities.SimpleEntity)5 ObjectId (org.bson.types.ObjectId)4 ValidationFailure (org.mongodb.morphia.query.validation.ValidationFailure)4 UpdateResults (org.mongodb.morphia.query.UpdateResults)3 DBCollection (com.mongodb.DBCollection)2 Index (org.mongodb.morphia.annotations.Index)2 NotSaved (org.mongodb.morphia.annotations.NotSaved)2 Version (org.mongodb.morphia.annotations.Version)2 MappingException (org.mongodb.morphia.mapping.MappingException)2 DBRef (com.mongodb.DBRef)1 WriteResult (com.mongodb.WriteResult)1