Search in sources :

Example 66 with MappedClass

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"));
}
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 67 with MappedClass

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));
}
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 68 with MappedClass

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));
}
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 69 with MappedClass

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);
        }
    }
}
Also used : ValidationAction(com.mongodb.client.model.ValidationAction) ValidationLevel(com.mongodb.client.model.ValidationLevel) MappedClass(org.mongodb.morphia.mapping.MappedClass) Document(org.bson.Document) Test(org.junit.Test)

Example 70 with MappedClass

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)));
}
Also used : Mapper(org.mongodb.morphia.mapping.Mapper) AnotherNested(org.mongodb.morphia.mapping.EmbeddedMappingTest.AnotherNested) Nested(org.mongodb.morphia.mapping.EmbeddedMappingTest.Nested) 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