Skip to content

Commit f3d818a

Browse files
committed
DATAMONGO-1176 - Post-rebase adoptions.
Adopt changes after rebasing to 2.0.x.
1 parent 3258b5a commit f3d818a

File tree

7 files changed

+49
-45
lines changed

7 files changed

+49
-45
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -926,8 +926,8 @@ private Object readCollectionOrArray(TypeInformation<?> targetType, List sourceV
926926
Object dbObjItem = sourceValue.get(i);
927927

928928
if (dbObjItem instanceof DBRef) {
929-
items.add(
930-
DBRef.class.equals(rawComponentType) ? dbObjItem : read(componentType, readRef((DBRef) dbObjItem), path));
929+
items.add(DBRef.class.equals(rawComponentType) ? dbObjItem
930+
: readAndConvertDBRef((DBRef) dbObjItem, componentType, path, rawComponentType));
931931
} else if (dbObjItem instanceof Document) {
932932
items.add(read(componentType, (Document) dbObjItem, path));
933933
} else if (dbObjItem instanceof BasicDBObject) {
@@ -995,7 +995,8 @@ protected Map<Object, Object> readMap(TypeInformation<?> type, Bson dbObject, Ob
995995
} else if (value instanceof BasicDBObject) {
996996
map.put(key, read(valueType, (BasicDBObject) value, path));
997997
} else if (value instanceof DBRef) {
998-
map.put(key, DBRef.class.equals(rawValueType) ? value : read(valueType, readRef((DBRef) value)));
998+
map.put(key, DBRef.class.equals(rawValueType) ? value
999+
: readAndConvertDBRef((DBRef) value, valueType, ObjectPath.ROOT, rawValueType));
9991000
} else if (value instanceof List) {
10001001
map.put(key, readCollectionOrArray(valueType, (List) value, path));
10011002
} else {

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/AggregationTests.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,10 @@ public void shouldUnwindWithIndex() {
246246

247247
assumeTrue(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO));
248248

249-
DBCollection coll = mongoTemplate.getCollection(INPUT_COLLECTION);
249+
MongoCollection<Document> coll = mongoTemplate.getCollection(INPUT_COLLECTION);
250250

251-
coll.insert(createDocument("Doc1", "spring", "mongodb", "nosql"));
252-
coll.insert(createDocument("Doc2"));
251+
coll.insertOne(createDocument("Doc1", "spring", "mongodb", "nosql"));
252+
coll.insertOne(createDocument("Doc2"));
253253

254254
Aggregation agg = newAggregation( //
255255
project("tags"), //
@@ -277,22 +277,22 @@ public void shouldUnwindPreserveEmpty() {
277277

278278
assumeTrue(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO));
279279

280-
DBCollection coll = mongoTemplate.getCollection(INPUT_COLLECTION);
280+
MongoCollection<Document> coll = mongoTemplate.getCollection(INPUT_COLLECTION);
281281

282-
coll.insert(createDocument("Doc1", "spring", "mongodb", "nosql"));
283-
coll.insert(createDocument("Doc2"));
282+
coll.insertOne(createDocument("Doc1", "spring", "mongodb", "nosql"));
283+
coll.insertOne(createDocument("Doc2"));
284284

285285
Aggregation agg = newAggregation( //
286286
project("tags"), //
287287
unwind("tags", "n", true), //
288288
sort(DESC, "n") //
289289
);
290290

291-
AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, INPUT_COLLECTION, DBObject.class);
291+
AggregationResults<Document> results = mongoTemplate.aggregate(agg, INPUT_COLLECTION, Document.class);
292292

293293
assertThat(results, is(notNullValue()));
294294

295-
List<DBObject> tagCount = results.getMappedResults();
295+
List<Document> tagCount = results.getMappedResults();
296296

297297
assertThat(tagCount, is(notNullValue()));
298298
assertThat(tagCount.size(), is(4));

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/AggregationUnitTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,12 @@ public void unwindOperationWithIndexShouldAddIndexField() {
125125
@Test
126126
public void fullUnwindOperationShouldBuildCorrectClause() {
127127

128-
DBObject agg = newAggregation( //
128+
Document agg = newAggregation( //
129129
unwind("a", "x", true)).toDbObject("foo", Aggregation.DEFAULT_CONTEXT);
130130

131131
@SuppressWarnings("unchecked")
132-
DBObject unwind = ((List<DBObject>) agg.get("pipeline")).get(0);
133-
assertThat((DBObject) unwind.get("$unwind"),
132+
Document unwind = ((List<Document>) agg.get("pipeline")).get(0);
133+
assertThat((Document) unwind.get("$unwind"),
134134
isBsonObject(). //
135135
containing("includeArrayIndex", "x").//
136136
containing("preserveNullAndEmptyArrays", true));
@@ -142,11 +142,11 @@ public void fullUnwindOperationShouldBuildCorrectClause() {
142142
@Test
143143
public void unwindOperationWithPreserveNullShouldBuildCorrectClause() {
144144

145-
DBObject agg = newAggregation( //
145+
Document agg = newAggregation( //
146146
unwind("a", true)).toDbObject("foo", Aggregation.DEFAULT_CONTEXT);
147147

148148
@SuppressWarnings("unchecked")
149-
DBObject unwind = ((List<DBObject>) agg.get("pipeline")).get(0);
149+
Document unwind = ((List<Document>) agg.get("pipeline")).get(0);
150150
assertThat(unwind,
151151
isBsonObject().notContaining("includeArrayIndex").containing("preserveNullAndEmptyArrays", true));
152152
}

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/UnwindOperationUnitTests.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@
1919
import static org.junit.Assert.*;
2020
import static org.springframework.data.mongodb.test.util.IsBsonObject.*;
2121

22+
import org.bson.Document;
2223
import org.junit.Test;
2324
import org.springframework.data.mongodb.core.DBObjectTestUtils;
2425

25-
import com.mongodb.DBObject;
26-
2726
/**
2827
* Unit tests for {@link UnwindOperation}.
2928
*
@@ -40,7 +39,7 @@ public void unwindWithPathOnlyShouldUsePreMongo32Syntax() {
4039

4140
UnwindOperation unwindOperation = Aggregation.unwind("a");
4241

43-
DBObject pipeline = unwindOperation.toDBObject(Aggregation.DEFAULT_CONTEXT);
42+
Document pipeline = unwindOperation.toDocument(Aggregation.DEFAULT_CONTEXT);
4443

4544
assertThat(pipeline, isBsonObject().containing("$unwind", "$a"));
4645
}
@@ -53,7 +52,7 @@ public void unwindWithArrayIndexShouldUseMongo32Syntax() {
5352

5453
UnwindOperation unwindOperation = Aggregation.unwind("a", "index");
5554

56-
DBObject unwindClause = extractDbObjectFromUnwindOperation(unwindOperation);
55+
Document unwindClause = extractDbObjectFromUnwindOperation(unwindOperation);
5756

5857
assertThat(unwindClause,
5958
isBsonObject().containing("path", "$a").//
@@ -91,7 +90,7 @@ public void unwindWithPreserveNullShouldUseMongo32Syntax() {
9190

9291
UnwindOperation unwindOperation = Aggregation.unwind("a", true);
9392

94-
DBObject unwindClause = extractDbObjectFromUnwindOperation(unwindOperation);
93+
Document unwindClause = extractDbObjectFromUnwindOperation(unwindOperation);
9594

9695
assertThat(unwindClause,
9796
isBsonObject().containing("path", "$a").//
@@ -106,7 +105,7 @@ public void unwindWithPreserveNullShouldUseMongo32Syntax() {
106105
public void lookupBuilderBuildsCorrectClause() {
107106

108107
UnwindOperation unwindOperation = UnwindOperation.newUnwind().path("$foo").noArrayIndex().skipNullAndEmptyArrays();
109-
DBObject pipeline = unwindOperation.toDBObject(Aggregation.DEFAULT_CONTEXT);
108+
Document pipeline = unwindOperation.toDocument(Aggregation.DEFAULT_CONTEXT);
110109

111110
assertThat(pipeline, isBsonObject().containing("$unwind", "$foo"));
112111
}
@@ -120,18 +119,18 @@ public void lookupBuilderBuildsCorrectClauseForMongo32() {
120119
UnwindOperation unwindOperation = UnwindOperation.newUnwind().path("$foo").arrayIndex("myindex")
121120
.preserveNullAndEmptyArrays();
122121

123-
DBObject unwindClause = extractDbObjectFromUnwindOperation(unwindOperation);
122+
Document unwindClause = extractDbObjectFromUnwindOperation(unwindOperation);
124123

125124
assertThat(unwindClause,
126125
isBsonObject().containing("path", "$foo").//
127126
containing("preserveNullAndEmptyArrays", true).//
128127
containing("includeArrayIndex", "myindex"));
129128
}
130129

131-
private DBObject extractDbObjectFromUnwindOperation(UnwindOperation unwindOperation) {
130+
private Document extractDbObjectFromUnwindOperation(UnwindOperation unwindOperation) {
132131

133-
DBObject dbObject = unwindOperation.toDBObject(Aggregation.DEFAULT_CONTEXT);
134-
DBObject unwindClause = DBObjectTestUtils.getAsDBObject(dbObject, "$unwind");
132+
Document dbObject = unwindOperation.toDocument(Aggregation.DEFAULT_CONTEXT);
133+
Document unwindClause = DBObjectTestUtils.getAsDocument(dbObject, "$unwind");
135134
return unwindClause;
136135
}
137136
}

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/UpdateMapperUnitTests.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -890,10 +890,10 @@ public void mapsAtomicIntegerToPrimitiveIntegerCorrectly() {
890890
public void mapsMinCorrectly() {
891891

892892
Update update = new Update().min("minfield", 10);
893-
DBObject mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
893+
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
894894
context.getPersistentEntity(SimpleValueHolder.class));
895895

896-
assertThat(mappedUpdate, isBsonObject().containing("$min", new BasicDBObject("minfield", 10)));
896+
assertThat(mappedUpdate, isBsonObject().containing("$min", new Document("minfield", 10)));
897897
}
898898

899899
/**
@@ -903,10 +903,10 @@ public void mapsMinCorrectly() {
903903
public void mapsMaxCorrectly() {
904904

905905
Update update = new Update().max("maxfield", 999);
906-
DBObject mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
906+
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
907907
context.getPersistentEntity(SimpleValueHolder.class));
908908

909-
assertThat(mappedUpdate, isBsonObject().containing("$max", new BasicDBObject("maxfield", 999)));
909+
assertThat(mappedUpdate, isBsonObject().containing("$max", new Document("maxfield", 999)));
910910
}
911911

912912
/**
@@ -930,10 +930,14 @@ public void mappingShouldConsiderCustomConvertersForEnumMapKeys() {
930930
UpdateMapper mapper = new UpdateMapper(converter);
931931

932932
Update update = new Update().set("enumAsMapKey", Collections.singletonMap(Allocation.AVAILABLE, 100));
933-
DBObject result = mapper.getMappedObject(update.getUpdateObject(),
933+
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
934934
mappingContext.getPersistentEntity(ClassWithEnum.class));
935+
936+
Document $set = DBObjectTestUtils.getAsDocument(mappedUpdate, "$set");
937+
assertThat($set.containsKey("enumAsMapKey"), is(true));
935938

936-
assertThat(result, isBsonObject().containing("$set.enumAsMapKey.V", 100));
939+
Document enumAsMapKey = $set.get("enumAsMapKey", Document.class);
940+
assertThat(enumAsMapKey.get("AVAILABLE"), is(100));
937941
}
938942

939943
static class DomainTypeWrappingConcreteyTypeHavingListOfInterfaceTypeAttributes {

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/UpdateTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ public void getUpdateObjectShouldReturnCorrectRepresentationForMax() {
521521
Update update = new Update().max("key", 10);
522522

523523
assertThat(update.getUpdateObject(),
524-
equalTo(new BasicDBObjectBuilder().add("$max", new BasicDBObject("key", 10)).get()));
524+
equalTo(new Document("$max", new Document("key", 10))));
525525
}
526526

527527
/**
@@ -533,7 +533,7 @@ public void getUpdateObjectShouldReturnCorrectRepresentationForMin() {
533533
Update update = new Update().min("key", 10);
534534

535535
assertThat(update.getUpdateObject(),
536-
equalTo(new BasicDBObjectBuilder().add("$min", new BasicDBObject("key", 10)).get()));
536+
equalTo(new Document("$min", new Document("key", 10))));
537537
}
538538

539539
/**
@@ -546,7 +546,7 @@ public void shouldSuppressPreviousValueForMax() {
546546
update.max("key", 99);
547547

548548
assertThat(update.getUpdateObject(),
549-
equalTo(new BasicDBObjectBuilder().add("$max", new BasicDBObject("key", 99)).get()));
549+
equalTo(new Document("$max", new Document("key", 99))));
550550
}
551551

552552
/**
@@ -559,7 +559,7 @@ public void shouldSuppressPreviousValueForMin() {
559559
update.min("key", 99);
560560

561561
assertThat(update.getUpdateObject(),
562-
equalTo(new BasicDBObjectBuilder().add("$min", new BasicDBObject("key", 99)).get()));
562+
equalTo(new Document("$min", new Document("key", 99))));
563563
}
564564

565565
/**
@@ -572,7 +572,7 @@ public void getUpdateObjectShouldReturnCorrectDateRepresentationForMax() {
572572
Update update = new Update().max("key", date);
573573

574574
assertThat(update.getUpdateObject(),
575-
equalTo(new BasicDBObjectBuilder().add("$max", new BasicDBObject("key", date)).get()));
575+
equalTo(new Document("$max", new Document("key", date))));
576576
}
577577

578578
/**
@@ -585,6 +585,6 @@ public void getUpdateObjectShouldReturnCorrectDateRepresentationForMin() {
585585
Update update = new Update().min("key", date);
586586

587587
assertThat(update.getUpdateObject(),
588-
equalTo(new BasicDBObjectBuilder().add("$min", new BasicDBObject("key", date)).get()));
588+
equalTo(new Document("$min", new Document("key", date))));
589589
}
590590
}

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/MongoQueryCreatorUnitTests.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ public void shouldCreateRegexWhenUsingNotContainsOnStringProperty() {
463463
MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, "thew"), context);
464464
Query query = creator.createQuery();
465465

466-
assertThat(query.getQueryObject(), is(query(where("username").not().regex(".*thew.*")).getQueryObject()));
466+
assertThat(query.getQueryObject().toJson(), is(query(where("username").not().regex(".*thew.*")).getQueryObject().toJson()));
467467
}
468468

469469
/**
@@ -680,8 +680,8 @@ public void notLikeShouldEscapeSourceWhenUsedWithLeadingAndTrailingWildcard() {
680680

681681
Query query = new MongoQueryCreator(tree, accessor, context).createQuery();
682682

683-
assertThat(query.getQueryObject(),
684-
is(query(where("username").not().regex(".*\\Qfire.fight+\\E.*")).getQueryObject()));
683+
assertThat(query.getQueryObject().toJson(),
684+
is(query(where("username").not().regex(".*\\Qfire.fight+\\E.*")).getQueryObject().toJson()));
685685
}
686686

687687
/**
@@ -695,8 +695,8 @@ public void notLikeShouldEscapeSourceWhenUsedWithLeadingWildcard() {
695695

696696
Query query = new MongoQueryCreator(tree, accessor, context).createQuery();
697697

698-
assertThat(query.getQueryObject(),
699-
is(query(where("username").not().regex(".*\\Qsteel.heart+\\E")).getQueryObject()));
698+
assertThat(query.getQueryObject().toJson(),
699+
is(query(where("username").not().regex(".*\\Qsteel.heart+\\E")).getQueryObject().toJson()));
700700
}
701701

702702
/**
@@ -709,7 +709,7 @@ public void notLikeShouldEscapeSourceWhenUsedWithTrailingWildcard() {
709709
MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, "cala.mity+*"), context);
710710
Query query = creator.createQuery();
711711

712-
assertThat(query.getQueryObject(), is(query(where("username").not().regex("\\Qcala.mity+\\E.*")).getQueryObject()));
712+
assertThat(query.getQueryObject().toJson(), is(query(where("username").not().regex("\\Qcala.mity+\\E.*")).getQueryObject().toJson()));
713713
}
714714

715715
/**
@@ -722,7 +722,7 @@ public void notLikeShouldBeTreatedCorrectlyWhenUsedWithWildcardOnly() {
722722
ConvertingParameterAccessor accessor = getAccessor(converter, "*");
723723

724724
Query query = new MongoQueryCreator(tree, accessor, context).createQuery();
725-
assertThat(query.getQueryObject(), is(query(where("username").not().regex(".*")).getQueryObject()));
725+
assertThat(query.getQueryObject().toJson(), is(query(where("username").not().regex(".*")).getQueryObject().toJson()));
726726
}
727727

728728
interface PersonRepository extends Repository<Person, Long> {

0 commit comments

Comments
 (0)