Search in sources :

Example 61 with BasicDBList

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

the class MappingMongoConverterUnitTests method readsEnumSetCorrectly.

// DATAMONGO-833
@Test
public 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, is(instanceOf(EnumSet.class)));
    assertThat(result.enumSet.size(), is(1));
    assertThat(result.enumSet, hasItem(SampleEnum.SECOND));
}
Also used : BasicDBList(com.mongodb.BasicDBList) Document(org.springframework.data.mongodb.core.mapping.Document) Test(org.junit.Test)

Example 62 with BasicDBList

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

the class MappingMongoConverterUnitTests method resolvesNestedComplexTypeForConstructorCorrectly.

@Test
public 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, is(notNullValue()));
}
Also used : BasicDBList(com.mongodb.BasicDBList) Document(org.springframework.data.mongodb.core.mapping.Document) Test(org.junit.Test)

Example 63 with BasicDBList

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

the class MappingMongoConverterUnitTests method readsEnumCollectionsCorrectly.

// DATAMONGO-209
@Test
public 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, is(instanceOf(List.class)));
    assertThat(result.enums.size(), is(1));
    assertThat(result.enums, hasItem(SampleEnum.FIRST));
}
Also used : BasicDBList(com.mongodb.BasicDBList) Document(org.springframework.data.mongodb.core.mapping.Document) Test(org.junit.Test)

Example 64 with BasicDBList

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

the class MappingMongoConverterUnitTests method writesPlainMapOfCollectionsCorrectly.

// DATAMONGO-259
@Test
public void writesPlainMapOfCollectionsCorrectly() {
    Map<String, List<Locale>> map = Collections.singletonMap("Foo", Arrays.asList(Locale.US));
    org.bson.Document result = new org.bson.Document();
    converter.write(map, result);
    assertThat(result.containsKey("Foo"), is(true));
    assertThat(result.get("Foo"), is(notNullValue()));
    assertThat(result.get("Foo"), is(instanceOf(BasicDBList.class)));
    BasicDBList list = (BasicDBList) result.get("Foo");
    assertThat(list.size(), is(1));
    assertThat(list.get(0), is(Locale.US.toString()));
}
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) Test(org.junit.Test)

Example 65 with BasicDBList

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

the class MappingMongoConverterUnitTests method readsCollectionOfDBRefs.

// DATAMONGO-424
@Test
public void readsCollectionOfDBRefs() {
    DBRef dbRef = new DBRef("foo", 2);
    BasicDBList refs = new BasicDBList();
    refs.add(dbRef);
    org.bson.Document document = new org.bson.Document("refs", refs);
    DBRefWrapper result = converter.read(DBRefWrapper.class, document);
    assertThat(result.refs, hasSize(1));
    assertThat(result.refs, hasItem(dbRef));
}
Also used : BasicDBList(com.mongodb.BasicDBList) DBRef(com.mongodb.DBRef) 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