|
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.Mock; |
38 | | -import org.mockito.junit.jupiter.MockitoExtension; |
39 | | -import org.mockito.junit.jupiter.MockitoSettings; |
40 | | -import org.mockito.quality.Strictness; |
41 | 36 |
|
42 | 37 | import org.springframework.core.convert.converter.Converter; |
43 | 38 | import org.springframework.data.annotation.Id; |
|
79 | 74 | * @author Mark Paluch |
80 | 75 | * @author David Julia |
81 | 76 | */ |
82 | | -@ExtendWith(MockitoExtension.class) |
83 | | -@MockitoSettings(strictness = Strictness.LENIENT) |
84 | 77 | public class QueryMapperUnitTests { |
85 | 78 |
|
86 | 79 | private QueryMapper mapper; |
87 | 80 | private MongoMappingContext context; |
88 | 81 | private MappingMongoConverter converter; |
89 | 82 |
|
90 | | - @Mock MongoDatabaseFactory factory; |
91 | | - |
92 | 83 | @BeforeEach |
93 | 84 | void beforeEach() { |
94 | 85 |
|
| 86 | + MongoCustomConversions conversions = new MongoCustomConversions(); |
95 | 87 | this.context = new MongoMappingContext(); |
| 88 | + this.context.setSimpleTypeHolder(conversions.getSimpleTypeHolder()); |
96 | 89 |
|
97 | | - this.converter = new MappingMongoConverter(new DefaultDbRefResolver(factory), context); |
| 90 | + this.converter = new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, context); |
| 91 | + this.converter.setCustomConversions(conversions); |
98 | 92 | this.converter.afterPropertiesSet(); |
99 | 93 |
|
100 | 94 | this.mapper = new QueryMapper(converter); |
@@ -1333,6 +1327,25 @@ void mapStringIdFieldProjection() { |
1333 | 1327 | assertThat(mappedFields).containsEntry("_id", 1); |
1334 | 1328 | } |
1335 | 1329 |
|
| 1330 | + @Test // GH-3783 |
| 1331 | + void retainsId$InWithStringArray() { |
| 1332 | + |
| 1333 | + org.bson.Document mappedQuery = mapper.getMappedObject( |
| 1334 | + org.bson.Document.parse("{ _id : { $in: [\"5b8bedceb1e0bfc07b008828\"]}}"), |
| 1335 | + context.getPersistentEntity(WithExplicitStringId.class)); |
| 1336 | + assertThat(mappedQuery.get("_id")).isEqualTo(org.bson.Document.parse("{ $in: [\"5b8bedceb1e0bfc07b008828\"]}")); |
| 1337 | + } |
| 1338 | + |
| 1339 | + @Test // GH-3783 |
| 1340 | + void mapsId$InInToObjectIds() { |
| 1341 | + |
| 1342 | + org.bson.Document mappedQuery = mapper.getMappedObject( |
| 1343 | + org.bson.Document.parse("{ _id : { $in: [\"5b8bedceb1e0bfc07b008828\"]}}"), |
| 1344 | + context.getPersistentEntity(ClassWithDefaultId.class)); |
| 1345 | + assertThat(mappedQuery.get("_id")) |
| 1346 | + .isEqualTo(org.bson.Document.parse("{ $in: [ {$oid: \"5b8bedceb1e0bfc07b008828\" } ]}")); |
| 1347 | + } |
| 1348 | + |
1336 | 1349 | class WithDeepArrayNesting { |
1337 | 1350 |
|
1338 | 1351 | List<WithNestedArray> level0; |
@@ -1402,6 +1415,12 @@ class WithStringId { |
1402 | 1415 | String name; |
1403 | 1416 | } |
1404 | 1417 |
|
| 1418 | + class WithExplicitStringId { |
| 1419 | + |
| 1420 | + @MongoId(FieldType.STRING) String id; |
| 1421 | + String name; |
| 1422 | + } |
| 1423 | + |
1405 | 1424 | class BigIntegerId { |
1406 | 1425 |
|
1407 | 1426 | @Id private BigInteger id; |
|
0 commit comments