Search in sources :

Example 66 with BasicDBList

use of com.mongodb.BasicDBList in project spring-data-mongodb by spring-projects.

the class MappingMongoConverterUnitTests method readsEmptyCollectionIntoConstructorCorrectly.

// DATAMONGO-497
@Test
public void readsEmptyCollectionIntoConstructorCorrectly() {
    org.bson.Document source = new org.bson.Document("attributes", new BasicDBList());
    TypWithCollectionConstructor result = converter.read(TypWithCollectionConstructor.class, source);
    assertThat(result.attributes, is(notNullValue()));
}
Also used : BasicDBList(com.mongodb.BasicDBList) Document(org.springframework.data.mongodb.core.mapping.Document) Test(org.junit.Test)

Example 67 with BasicDBList

use of com.mongodb.BasicDBList in project spring-data-mongodb by spring-projects.

the class MappingMongoConverterUnitTests method readsMapListDoublyNestedValuesCorrectly.

// DATAMONGO-245
@Test
public void readsMapListDoublyNestedValuesCorrectly() {
    BasicDBList list = new BasicDBList();
    org.bson.Document nested = new org.bson.Document();
    org.bson.Document doubly = new org.bson.Document();
    doubly.append("Hello", "World");
    nested.append("nested", doubly);
    list.add(nested);
    org.bson.Document source = new org.bson.Document("mapOfObjects", new org.bson.Document("Foo", list));
    ClassWithMapProperty result = converter.read(ClassWithMapProperty.class, source);
    Object firstObjectInFoo = ((List<?>) result.mapOfObjects.get("Foo")).get(0);
    assertThat(firstObjectInFoo, is(instanceOf(Map.class)));
    Object doublyNestedObject = ((Map<?, ?>) firstObjectInFoo).get("nested");
    assertThat(doublyNestedObject, is(instanceOf(Map.class)));
    assertThat(((Map<?, ?>) doublyNestedObject).get("Hello"), is(equalTo("World")));
}
Also used : BasicDBList(com.mongodb.BasicDBList) BasicDBList(com.mongodb.BasicDBList) List(java.util.List) ArrayList(java.util.ArrayList) Document(org.springframework.data.mongodb.core.mapping.Document) Map(java.util.Map) EnumMap(java.util.EnumMap) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 68 with BasicDBList

use of com.mongodb.BasicDBList in project spring-data-mongodb by spring-projects.

the class MappingMongoConverterUnitTests method readsMapListValuesCorrectly.

// DATAMONGO-235
@Test
public void readsMapListValuesCorrectly() {
    BasicDBList list = new BasicDBList();
    list.add("Bar");
    org.bson.Document source = new org.bson.Document("mapOfLists", new org.bson.Document("Foo", list));
    ClassWithMapProperty result = converter.read(ClassWithMapProperty.class, source);
    assertThat(result.mapOfLists, is(not(nullValue())));
}
Also used : BasicDBList(com.mongodb.BasicDBList) Document(org.springframework.data.mongodb.core.mapping.Document) Test(org.junit.Test)

Example 69 with BasicDBList

use of com.mongodb.BasicDBList in project spring-data-mongodb by spring-projects.

the class MappingMongoConverterUnitTests method readsMapOfObjectsListValuesCorrectly.

// DATAMONGO-235
@Test
public void readsMapOfObjectsListValuesCorrectly() {
    BasicDBList list = new BasicDBList();
    list.add("Bar");
    org.bson.Document source = new org.bson.Document("mapOfObjects", new org.bson.Document("Foo", list));
    ClassWithMapProperty result = converter.read(ClassWithMapProperty.class, source);
    assertThat(result.mapOfObjects, is(not(nullValue())));
}
Also used : BasicDBList(com.mongodb.BasicDBList) Document(org.springframework.data.mongodb.core.mapping.Document) Test(org.junit.Test)

Aggregations

BasicDBList (com.mongodb.BasicDBList)69 BasicDBObject (com.mongodb.BasicDBObject)40 DBObject (com.mongodb.DBObject)33 Test (org.junit.Test)27 Document (org.springframework.data.mongodb.core.mapping.Document)16 ArrayList (java.util.ArrayList)13 List (java.util.List)9 DBCollection (com.mongodb.DBCollection)8 Document (org.bson.Document)7 DBCursor (com.mongodb.DBCursor)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 DBRef (com.mongodb.DBRef)5 Collection (java.util.Collection)4 NotFoundException (org.graylog2.database.NotFoundException)4 ImmutableList (com.google.common.collect.ImmutableList)3 MongoClient (com.mongodb.MongoClient)3 MongoException (com.mongodb.MongoException)3 MongoInputSplit (com.mongodb.hadoop.input.MongoInputSplit)3 LinkedHashMap (java.util.LinkedHashMap)3