Search in sources :

Example 11 with MappedField

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

the class VersionTest method testVersionFieldNameContribution.

@Test
public void testVersionFieldNameContribution() throws Exception {
    final MappedField mappedFieldByJavaField = getMorphia().getMapper().getMappedClass(ALong.class).getMappedFieldByJavaField("v");
    Assert.assertEquals("versionNameContributedByAnnotation", mappedFieldByJavaField.getNameToStore());
}
Also used : MappedField(org.mongodb.morphia.mapping.MappedField) Test(org.junit.Test)

Example 12 with MappedField

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

the class QueryForSubtypeTest method testIntSizeShouldBeCompatibleWithArrayList.

@Test
public void testIntSizeShouldBeCompatibleWithArrayList() {
    MappedField attributes = jobMappedClass.getMappedField("attributes");
    boolean compatible = isCompatibleForOperator(jobMappedClass, attributes, ArrayList.class, SIZE, 2, new ArrayList<ValidationFailure>());
    assertThat(compatible, is(true));
}
Also used : MappedField(org.mongodb.morphia.mapping.MappedField) ValidationFailure(org.mongodb.morphia.query.validation.ValidationFailure) Test(org.junit.Test)

Example 13 with MappedField

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

the class QueryValidatorTest method shouldAllowSizeOperatorForArrayListTypesAndIntegerValues.

@Test
public //this used to fail
void shouldAllowSizeOperatorForArrayListTypesAndIntegerValues() {
    // given
    MappedClass mappedClass = new MappedClass(EntityWithListsAndArrays.class, new Mapper());
    MappedField mappedField = mappedClass.getMappedField("arrayListOfIntegers");
    // expect
    assertThat(QueryValidator.isCompatibleForOperator(mappedClass, mappedField, NullClass.class, SIZE, 3, new ArrayList<ValidationFailure>()), is(true));
}
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 14 with MappedField

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

the class QueryValidatorTest method shouldNotAllowSizeOperatorForNonListTypes.

@Test
public void shouldNotAllowSizeOperatorForNonListTypes() {
    // given
    MappedClass mappedClass = new MappedClass(EntityWithListsAndArrays.class, new Mapper());
    MappedField mappedField = mappedClass.getMappedField("notAnArrayOrList");
    // expect
    assertThat(QueryValidator.isCompatibleForOperator(mappedClass, mappedField, NullClass.class, SIZE, 3, new ArrayList<ValidationFailure>()), is(false));
}
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 15 with MappedField

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

the class QueryValidatorTest method shouldRejectTypesAndValuesThatDoNotMatch.

@Test
public void shouldRejectTypesAndValuesThatDoNotMatch() {
    // expect
    MappedClass mappedClass = new MappedClass(SimpleEntity.class, new Mapper());
    MappedField mappedField = mappedClass.getMappedField("name");
    assertThat(QueryValidator.isCompatibleForOperator(mappedClass, mappedField, String.class, EQUAL, 1, new ArrayList<ValidationFailure>()), is(false));
}
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

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