Search in sources :

Example 91 with BasicDBList

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

the class MappingMongoConverterUnitTests method readsEnumCollectionsCorrectly.

// DATAMONGO-209
@Test
void readsEnumCollectionsCorrectly() {
    BasicDBList enums = new BasicDBList();
    enums.add("FIRST");
    org.bson.Document document = new org.bson.Document("enums", enums);
    ClassWithEnumProperty result = converter.read(ClassWithEnumProperty.class, document);
    assertThat(result.enums).isInstanceOf(List.class);
    assertThat(result.enums.size()).isEqualTo(1);
    assertThat(result.enums).contains(SampleEnum.FIRST);
}
Also used : BasicDBList(com.mongodb.BasicDBList) Document(org.springframework.data.mongodb.core.mapping.Document) Test(org.junit.jupiter.api.Test)

Example 92 with BasicDBList

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

the class MappingMongoConverterUnitTests method resolvesNestedComplexTypeForConstructorCorrectly.

@Test
void resolvesNestedComplexTypeForConstructorCorrectly() {
    org.bson.Document address = new org.bson.Document("street", "110 Southwark Street");
    address.put("city", "London");
    BasicDBList addresses = new BasicDBList();
    addresses.add(address);
    org.bson.Document person = new org.bson.Document("firstname", "Oliver");
    person.put("addresses", addresses);
    Person result = converter.read(Person.class, person);
    assertThat(result.addresses).isNotNull();
}
Also used : BasicDBList(com.mongodb.BasicDBList) Document(org.springframework.data.mongodb.core.mapping.Document) Test(org.junit.jupiter.api.Test)

Example 93 with BasicDBList

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

the class MappingMongoConverterUnitTests method readsMapOfObjectsListValuesCorrectly.

// DATAMONGO-235
@Test
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).isNotNull();
}
Also used : BasicDBList(com.mongodb.BasicDBList) Document(org.springframework.data.mongodb.core.mapping.Document) Test(org.junit.jupiter.api.Test)

Example 94 with BasicDBList

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

the class MappingMongoConverterUnitTests method readsEnumSetCorrectly.

// DATAMONGO-833
@Test
void readsEnumSetCorrectly() {
    BasicDBList enumSet = new BasicDBList();
    enumSet.add("SECOND");
    org.bson.Document document = new org.bson.Document("enumSet", enumSet);
    ClassWithEnumProperty result = converter.read(ClassWithEnumProperty.class, document);
    assertThat(result.enumSet).isInstanceOf(EnumSet.class);
    assertThat(result.enumSet.size()).isEqualTo(1);
    assertThat(result.enumSet).contains(SampleEnum.SECOND);
}
Also used : BasicDBList(com.mongodb.BasicDBList) Document(org.springframework.data.mongodb.core.mapping.Document) Test(org.junit.jupiter.api.Test)

Example 95 with BasicDBList

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

the class MappingMongoConverterUnitTests method readsMapListValuesCorrectly.

// DATAMONGO-235
@Test
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).isNotNull();
}
Also used : BasicDBList(com.mongodb.BasicDBList) Document(org.springframework.data.mongodb.core.mapping.Document) Test(org.junit.jupiter.api.Test)

Aggregations

BasicDBList (com.mongodb.BasicDBList)108 BasicDBObject (com.mongodb.BasicDBObject)69 DBObject (com.mongodb.DBObject)50 Test (org.junit.jupiter.api.Test)17 Document (org.springframework.data.mongodb.core.mapping.Document)14 DBCollection (com.mongodb.DBCollection)11 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)11 DBCursor (com.mongodb.DBCursor)8 DBRef (com.mongodb.DBRef)8 List (java.util.List)7 Document (org.bson.Document)7 HashMap (java.util.HashMap)6 ObjectId (org.bson.types.ObjectId)6 MongoClient (com.mongodb.MongoClient)4 Map (java.util.Map)4 NotFoundException (org.graylog2.database.NotFoundException)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 MongoInputSplit (com.mongodb.hadoop.input.MongoInputSplit)3 IOException (java.io.IOException)3