|
33 | 33 | import org.bson.types.ObjectId;
|
34 | 34 | import org.junit.jupiter.api.BeforeEach;
|
35 | 35 | import org.junit.jupiter.api.Test;
|
36 |
| -import org.junit.jupiter.api.extension.ExtendWith; |
37 |
| -import org.mockito.junit.jupiter.MockitoExtension; |
| 36 | + |
38 | 37 | import org.springframework.core.convert.converter.Converter;
|
39 | 38 | import org.springframework.data.annotation.Id;
|
40 | 39 | import org.springframework.data.annotation.Transient;
|
@@ -83,9 +82,12 @@ public class QueryMapperUnitTests {
|
83 | 82 | @BeforeEach
|
84 | 83 | void beforeEach() {
|
85 | 84 |
|
| 85 | + MongoCustomConversions conversions = new MongoCustomConversions(); |
86 | 86 | this.context = new MongoMappingContext();
|
| 87 | + this.context.setSimpleTypeHolder(conversions.getSimpleTypeHolder()); |
87 | 88 |
|
88 | 89 | this.converter = new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, context);
|
| 90 | + this.converter.setCustomConversions(conversions); |
89 | 91 | this.converter.afterPropertiesSet();
|
90 | 92 |
|
91 | 93 | this.mapper = new QueryMapper(converter);
|
@@ -1335,6 +1337,25 @@ void mapStringIdFieldProjection() {
|
1335 | 1337 | assertThat(mappedFields).containsEntry("_id", 1);
|
1336 | 1338 | }
|
1337 | 1339 |
|
| 1340 | + @Test // GH-3783 |
| 1341 | + void retainsId$InWithStringArray() { |
| 1342 | + |
| 1343 | + org.bson.Document mappedQuery = mapper.getMappedObject( |
| 1344 | + org.bson.Document.parse("{ _id : { $in: [\"5b8bedceb1e0bfc07b008828\"]}}"), |
| 1345 | + context.getPersistentEntity(WithExplicitStringId.class)); |
| 1346 | + assertThat(mappedQuery.get("_id")).isEqualTo(org.bson.Document.parse("{ $in: [\"5b8bedceb1e0bfc07b008828\"]}")); |
| 1347 | + } |
| 1348 | + |
| 1349 | + @Test // GH-3783 |
| 1350 | + void mapsId$InInToObjectIds() { |
| 1351 | + |
| 1352 | + org.bson.Document mappedQuery = mapper.getMappedObject( |
| 1353 | + org.bson.Document.parse("{ _id : { $in: [\"5b8bedceb1e0bfc07b008828\"]}}"), |
| 1354 | + context.getPersistentEntity(ClassWithDefaultId.class)); |
| 1355 | + assertThat(mappedQuery.get("_id")) |
| 1356 | + .isEqualTo(org.bson.Document.parse("{ $in: [ {$oid: \"5b8bedceb1e0bfc07b008828\" } ]}")); |
| 1357 | + } |
| 1358 | + |
1338 | 1359 | class WithDeepArrayNesting {
|
1339 | 1360 |
|
1340 | 1361 | List<WithNestedArray> level0;
|
@@ -1404,6 +1425,12 @@ class WithStringId {
|
1404 | 1425 | String name;
|
1405 | 1426 | }
|
1406 | 1427 |
|
| 1428 | + class WithExplicitStringId { |
| 1429 | + |
| 1430 | + @MongoId(FieldType.STRING) String id; |
| 1431 | + String name; |
| 1432 | + } |
| 1433 | + |
1407 | 1434 | class BigIntegerId {
|
1408 | 1435 |
|
1409 | 1436 | @Id private BigInteger id;
|
|
0 commit comments