Search in sources :

Example 56 with ObjectId

use of org.bson.types.ObjectId in project morphia by mongodb.

the class QueryValidatorTest method shouldNotAllowNonKeyTypeWithKeyValue.

@Test
public void shouldNotAllowNonKeyTypeWithKeyValue() {
    // expect
    MappedClass mappedClass = new MappedClass(EntityWithListsAndArrays.class, new Mapper());
    MappedField mappedField = mappedClass.getMappedField("listOfIntegers");
    assertThat(QueryValidator.isCompatibleForOperator(mappedClass, mappedField, SimpleEntity.class, EQUAL, new Key<String>(String.class, "kind", new ObjectId()), new ArrayList<ValidationFailure>()), is(false));
}
Also used : MappedField(org.mongodb.morphia.mapping.MappedField) Mapper(org.mongodb.morphia.mapping.Mapper) ObjectId(org.bson.types.ObjectId) SimpleEntity(org.mongodb.morphia.entities.SimpleEntity) ArrayList(java.util.ArrayList) MappedClass(org.mongodb.morphia.mapping.MappedClass) Key(org.mongodb.morphia.Key) Test(org.junit.Test)

Example 57 with ObjectId

use of org.bson.types.ObjectId in project morphia by mongodb.

the class QueryValidatorTest method shouldAllowTypeThatMatchesKeyTypeValue.

@Test
public void shouldAllowTypeThatMatchesKeyTypeValue() {
    // expect
    MappedClass mappedClass = new MappedClass(SimpleEntity.class, new Mapper());
    MappedField mappedField = mappedClass.getMappedField("integer");
    assertThat(QueryValidator.isCompatibleForOperator(mappedClass, mappedField, Integer.class, EQUAL, new Key<Number>(Integer.class, "Integer", new ObjectId()), new ArrayList<ValidationFailure>()), is(true));
}
Also used : MappedField(org.mongodb.morphia.mapping.MappedField) Mapper(org.mongodb.morphia.mapping.Mapper) ObjectId(org.bson.types.ObjectId) ArrayList(java.util.ArrayList) MappedClass(org.mongodb.morphia.mapping.MappedClass) Key(org.mongodb.morphia.Key) Test(org.junit.Test)

Example 58 with ObjectId

use of org.bson.types.ObjectId in project morphia by mongodb.

the class TestQuery method testComplexIdQuery.

@Test
public void testComplexIdQuery() {
    final CustomId cId = new CustomId();
    cId.setId(new ObjectId());
    cId.setType("banker");
    final UsesCustomIdObject object = new UsesCustomIdObject();
    object.setId(cId);
    object.setText("hllo");
    getDs().save(object);
    assertNotNull(getDs().find(UsesCustomIdObject.class).filter("_id.type", "banker").get());
    assertNotNull(getDs().find(UsesCustomIdObject.class).field("_id").hasAnyOf(singletonList(cId)).get());
}
Also used : ObjectId(org.bson.types.ObjectId) CustomId(org.mongodb.morphia.TestMapper.CustomId) UsesCustomIdObject(org.mongodb.morphia.TestMapper.UsesCustomIdObject) Test(org.junit.Test)

Example 59 with ObjectId

use of org.bson.types.ObjectId in project morphia by mongodb.

the class TestQuery method testComplexIdQueryWithRenamedField.

@Test
public void testComplexIdQueryWithRenamedField() {
    final CustomId cId = new CustomId();
    cId.setId(new ObjectId());
    cId.setType("banker");
    final UsesCustomIdObject object = new UsesCustomIdObject();
    object.setId(cId);
    object.setText("hllo");
    getDs().save(object);
    assertNotNull(getDs().find(UsesCustomIdObject.class).filter("_id.t", "banker").get());
}
Also used : ObjectId(org.bson.types.ObjectId) CustomId(org.mongodb.morphia.TestMapper.CustomId) UsesCustomIdObject(org.mongodb.morphia.TestMapper.UsesCustomIdObject) Test(org.junit.Test)

Example 60 with ObjectId

use of org.bson.types.ObjectId in project morphia by mongodb.

the class EntityTypeAndIdValueValidatorTest method shouldAllowTypeThatIsAMappedEntityAndAValueWithSameClassAsIdOfMappedEntity.

@Test
public void shouldAllowTypeThatIsAMappedEntityAndAValueWithSameClassAsIdOfMappedEntity() {
    // given
    ArrayList<ValidationFailure> validationFailures = new ArrayList<ValidationFailure>();
    // when
    MappedClass mappedClass = new MappedClass(SimpleEntity.class, new Mapper());
    MappedField mappedField = mappedClass.getMappedField("_id");
    boolean validationApplied = EntityTypeAndIdValueValidator.getInstance().apply(mappedClass, mappedField, new ObjectId(), 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) ObjectId(org.bson.types.ObjectId) ArrayList(java.util.ArrayList) MappedClass(org.mongodb.morphia.mapping.MappedClass) Test(org.junit.Test)

Aggregations

ObjectId (org.bson.types.ObjectId)249 Test (org.junit.Test)157 BasicDBObject (com.mongodb.BasicDBObject)54 Document (org.bson.Document)38 DBObject (com.mongodb.DBObject)35 ArrayList (java.util.ArrayList)28 BsonObjectId (org.bson.BsonObjectId)27 Date (java.util.Date)24 DBRef (com.mongodb.DBRef)15 List (java.util.List)15 StreamRuleMock (org.graylog2.streams.matchers.StreamRuleMock)14 Message (org.graylog2.plugin.Message)13 BasicBSONObject (org.bson.BasicBSONObject)12 Query (org.springframework.data.mongodb.core.query.Query)11 GridFSFile (com.mongodb.client.gridfs.model.GridFSFile)10 Map (java.util.Map)10 Binary (org.bson.types.Binary)10 GridFSFindIterable (com.mongodb.client.gridfs.GridFSFindIterable)8 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)7 Code (org.bson.types.Code)7