Search in sources :

Example 31 with Mapper

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

the class GeoWithinOperationValidatorTest method shouldAllowGeoWithinOperatorForGeoEntityWithListOfIntegers.

@Test
public void shouldAllowGeoWithinOperatorForGeoEntityWithListOfIntegers() {
    // given
    List<ValidationFailure> validationFailures = new ArrayList<ValidationFailure>();
    MappedClass mappedClass = new MappedClass(GeoEntity.class, new Mapper());
    MappedField mappedField = mappedClass.getMappedField("list");
    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 32 with Mapper

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

the class GeoWithinOperationValidatorTest method shouldRejectGeoWithinWhenValueIsNotADBObject.

@Test
public void shouldRejectGeoWithinWhenValueIsNotADBObject() {
    // given
    List<ValidationFailure> validationFailures = new ArrayList<ValidationFailure>();
    MappedClass mappedClass = new MappedClass(GeoEntity.class, new Mapper());
    MappedField mappedField = mappedClass.getMappedField("array");
    // when
    boolean validationApplied = GeoWithinOperationValidator.getInstance().apply(mappedField, GEO_WITHIN, "NotAGeoQuery", validationFailures);
    // then
    assertThat(validationApplied, is(true));
    assertThat(validationFailures.size(), is(1));
    assertThat(validationFailures.get(0).toString(), containsString("For a $geoWithin operation, the value should be a valid geo query"));
}
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 33 with Mapper

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

the class GeoWithinOperationValidatorTest method shouldRejectGeoWithinWhenValueDoesNotContainKeyword.

@Test
public void shouldRejectGeoWithinWhenValueDoesNotContainKeyword() {
    // given
    List<ValidationFailure> validationFailures = new ArrayList<ValidationFailure>();
    MappedClass mappedClass = new MappedClass(GeoEntity.class, new Mapper());
    MappedField mappedField = mappedClass.getMappedField("array");
    // when
    boolean validationApplied = GeoWithinOperationValidator.getInstance().apply(mappedField, GEO_WITHIN, new BasicDBObject("notValidKey", 1), validationFailures);
    // then
    assertThat(validationApplied, is(true));
    assertThat(validationFailures.size(), is(1));
    assertThat(validationFailures.get(0).toString(), containsString("For a $geoWithin operation, the value should be a valid geo query"));
}
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 34 with Mapper

use of org.mongodb.morphia.mapping.Mapper 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 35 with Mapper

use of org.mongodb.morphia.mapping.Mapper 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)

Aggregations

Test (org.junit.Test)61 Mapper (org.mongodb.morphia.mapping.Mapper)61 MappedClass (org.mongodb.morphia.mapping.MappedClass)53 MappedField (org.mongodb.morphia.mapping.MappedField)46 ArrayList (java.util.ArrayList)41 BasicDBObject (com.mongodb.BasicDBObject)9 DBObject (com.mongodb.DBObject)5 List (java.util.List)5 ObjectId (org.bson.types.ObjectId)5 SimpleEntity (org.mongodb.morphia.entities.SimpleEntity)5 Key (org.mongodb.morphia.Key)4 ParentType (org.mongodb.morphia.entities.ParentType)2 DefaultEntityCache (org.mongodb.morphia.mapping.cache.DefaultEntityCache)2 BsonDocument (org.bson.BsonDocument)1 BsonString (org.bson.BsonString)1 Document (org.bson.Document)1 BasicDAO (org.mongodb.morphia.dao.BasicDAO)1 AnotherNested (org.mongodb.morphia.mapping.EmbeddedMappingTest.AnotherNested)1 Nested (org.mongodb.morphia.mapping.EmbeddedMappingTest.Nested)1 MappingException (org.mongodb.morphia.mapping.MappingException)1