Search in sources :

Example 46 with MappedClass

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

the class IndexHelperTest method calculateBadKeys.

@Test
public void calculateBadKeys() {
    MappedClass mappedClass = getMorphia().getMapper().getMappedClass(IndexedClass.class);
    IndexBuilder index = new IndexBuilder().fields(new FieldBuilder().value("texting").type(IndexType.TEXT).weight(1), new FieldBuilder().value("nest").type(IndexType.DESC));
    try {
        indexHelper.calculateKeys(mappedClass, index);
        fail("Validation should have failed on the bad key");
    } catch (MappingException e) {
    // all good
    }
    index.options(new IndexOptionsBuilder().disableValidation(true));
    indexHelper.calculateKeys(mappedClass, index);
}
Also used : MappedClass(org.mongodb.morphia.mapping.MappedClass) MappingException(org.mongodb.morphia.mapping.MappingException) Test(org.junit.Test)

Example 47 with MappedClass

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

the class QueryValidatorTest method shouldNotAllowOtherValuesForInOperator.

@Test
public void shouldNotAllowOtherValuesForInOperator() {
    // expect
    MappedClass mappedClass = new MappedClass(SimpleEntity.class, new Mapper());
    MappedField mappedField = mappedClass.getMappedField("name");
    assertThat(QueryValidator.isCompatibleForOperator(mappedClass, mappedField, String.class, IN, "value", 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 48 with MappedClass

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

the class QueryValidatorTest method shouldNotAllowOtherValuesForAllOperator.

@Test
public void shouldNotAllowOtherValuesForAllOperator() {
    // given
    MappedClass mappedClass = new MappedClass(SimpleEntity.class, new Mapper());
    MappedField mappedField = mappedClass.getMappedField("name");
    // expect
    assertThat(QueryValidator.isCompatibleForOperator(mappedClass, mappedField, SimpleEntity.class, ALL, "value", new ArrayList<ValidationFailure>()), is(false));
}
Also used : MappedField(org.mongodb.morphia.mapping.MappedField) Mapper(org.mongodb.morphia.mapping.Mapper) SimpleEntity(org.mongodb.morphia.entities.SimpleEntity) ArrayList(java.util.ArrayList) MappedClass(org.mongodb.morphia.mapping.MappedClass) Test(org.junit.Test)

Example 49 with MappedClass

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

the class QueryValidatorTest method shouldNotAllowNonIntegerTypeIfValueIsInt.

@Test
public void shouldNotAllowNonIntegerTypeIfValueIsInt() {
    // expect
    MappedClass mappedClass = new MappedClass(SimpleEntity.class, new Mapper());
    MappedField mappedField = mappedClass.getMappedField("name");
    assertThat(QueryValidator.isCompatibleForOperator(mappedClass, mappedField, SimpleEntity.class, EQUAL, 1, new ArrayList<ValidationFailure>()), is(false));
}
Also used : MappedField(org.mongodb.morphia.mapping.MappedField) Mapper(org.mongodb.morphia.mapping.Mapper) SimpleEntity(org.mongodb.morphia.entities.SimpleEntity) ArrayList(java.util.ArrayList) MappedClass(org.mongodb.morphia.mapping.MappedClass) Test(org.junit.Test)

Example 50 with MappedClass

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

the class QueryValidatorTest method shouldNotAllowGeoOperatorIfValueDoesNotContainCorrectField.

@Test
public void shouldNotAllowGeoOperatorIfValueDoesNotContainCorrectField() {
    // expect
    MappedClass mappedClass = new MappedClass(GeoEntity.class, new Mapper());
    MappedField mappedField = mappedClass.getMappedField("array");
    assertThat(QueryValidator.isCompatibleForOperator(mappedClass, mappedField, List.class, GEO_WITHIN, new BasicDBObject("name", "value"), new ArrayList<ValidationFailure>()), is(false));
}
Also used : MappedField(org.mongodb.morphia.mapping.MappedField) Mapper(org.mongodb.morphia.mapping.Mapper) BasicDBObject(com.mongodb.BasicDBObject) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) 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