Search in sources :

Example 56 with MappedClass

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

the class GeoWithinOperationValidatorTest method shouldRejectGeoWithinOperatorWhenMappedFieldIsArrayThatDoesNotContainNumbers.

@Test
public void shouldRejectGeoWithinOperatorWhenMappedFieldIsArrayThatDoesNotContainNumbers() {
    // given
    List<ValidationFailure> validationFailures = new ArrayList<ValidationFailure>();
    MappedClass mappedClass = new MappedClass(InvalidGeoEntity.class, new Mapper());
    MappedField mappedField = mappedClass.getMappedField("arrayOfStrings");
    // when
    boolean validationApplied = GeoWithinOperationValidator.getInstance().apply(mappedField, GEO_WITHIN, new BasicDBObject("$box", 1), validationFailures);
    // then
    assertThat(validationApplied, is(true));
    assertThat(validationFailures.size(), is(1));
    assertThat(validationFailures.get(0).toString(), containsString("is an array or iterable it should have numeric values"));
}
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 57 with MappedClass

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

the class GeoWithinOperationValidatorTest method shouldRejectGeoWithinOperatorWhenMappedFieldIsListThatDoesNotContainNumbers.

@Test
public void shouldRejectGeoWithinOperatorWhenMappedFieldIsListThatDoesNotContainNumbers() {
    // given
    List<ValidationFailure> validationFailures = new ArrayList<ValidationFailure>();
    MappedClass mappedClass = new MappedClass(InvalidGeoEntity.class, new Mapper());
    MappedField mappedField = mappedClass.getMappedField("listOfStrings");
    // when
    boolean validationApplied = GeoWithinOperationValidator.getInstance().apply(mappedField, GEO_WITHIN, new BasicDBObject("$box", 1), validationFailures);
    // then
    assertThat(validationApplied, is(true));
    assertThat(validationFailures.size(), is(1));
    assertThat(validationFailures.get(0).toString(), containsString("is an array or iterable it should have numeric values"));
}
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 58 with MappedClass

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

the class MappedFieldTypeValidatorTest method shouldRejectAListThatDoesNotContainNumbers.

@Test
public void shouldRejectAListThatDoesNotContainNumbers() {
    // given
    MappedClass mappedClass = new MappedClass(EntityWithListsAndArrays.class, new Mapper());
    MappedField mappedField = mappedClass.getMappedField("listOfStrings");
    // expect
    assertThat(MappedFieldTypeValidator.isIterableOfNumbers(mappedField), is(false));
}
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 59 with MappedClass

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

the class MappedFieldTypeValidatorTest method shouldRejectArraysOfStrings.

@Test
public void shouldRejectArraysOfStrings() {
    // given
    MappedClass mappedClass = new MappedClass(EntityWithListsAndArrays.class, new Mapper());
    MappedField mappedField = mappedClass.getMappedField("arrayOfStrings");
    // expect
    assertThat(MappedFieldTypeValidator.isArrayOfNumbers(mappedField), is(false));
}
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 60 with MappedClass

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

the class SizeOperationValidatorTest method shouldNotApplyValidationToOperatorThatIsNotSize.

@Test
public void shouldNotApplyValidationToOperatorThatIsNotSize() {
    // given
    MappedClass mappedClass = new MappedClass(EntityWithListsAndArrays.class, new Mapper());
    MappedField mappedField = mappedClass.getMappedField("list");
    List<ValidationFailure> validationFailures = new ArrayList<ValidationFailure>();
    // when
    boolean validationApplied = SizeOperationValidator.getInstance().apply(mappedField, EQUAL, 1, validationFailures);
    // then
    assertThat(validationApplied, is(false));
    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)

Aggregations

MappedClass (org.mongodb.morphia.mapping.MappedClass)92 Test (org.junit.Test)73 MappedField (org.mongodb.morphia.mapping.MappedField)56 Mapper (org.mongodb.morphia.mapping.Mapper)53 ArrayList (java.util.ArrayList)48 BasicDBObject (com.mongodb.BasicDBObject)18 DBObject (com.mongodb.DBObject)12 BsonDocument (org.bson.BsonDocument)8 Document (org.bson.Document)8 MappingException (org.mongodb.morphia.mapping.MappingException)6 DBCollection (com.mongodb.DBCollection)5 List (java.util.List)5 SimpleEntity (org.mongodb.morphia.entities.SimpleEntity)5 ObjectId (org.bson.types.ObjectId)4 Key (org.mongodb.morphia.Key)4 Index (org.mongodb.morphia.annotations.Index)4 LinkedHashMap (java.util.LinkedHashMap)3 NotSaved (org.mongodb.morphia.annotations.NotSaved)3 UpdateResults (org.mongodb.morphia.query.UpdateResults)3 WriteResult (com.mongodb.WriteResult)2