Search in sources :

Example 41 with Mapper

use of org.mongodb.morphia.mapping.Mapper 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."));
}
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 42 with Mapper

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

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

use of org.mongodb.morphia.mapping.Mapper 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"));
}
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 45 with Mapper

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

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