|
32 | 32 | import org.junit.runner.RunWith;
|
33 | 33 | import org.junit.runners.Suite;
|
34 | 34 | import org.junit.runners.Suite.SuiteClasses;
|
| 35 | + |
35 | 36 | import org.springframework.core.annotation.AliasFor;
|
36 | 37 | import org.springframework.dao.InvalidDataAccessApiUsageException;
|
37 | 38 | import org.springframework.data.annotation.Id;
|
38 | 39 | import org.springframework.data.geo.Point;
|
| 40 | +import org.springframework.data.mapping.MappingException; |
39 | 41 | import org.springframework.data.mongodb.core.DocumentTestUtils;
|
40 | 42 | import org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver.IndexDefinitionHolder;
|
41 | 43 | import org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolverUnitTests.CompoundIndexResolutionTests;
|
@@ -1333,6 +1335,20 @@ public void resolvesWildcardOnRoot() {
|
1333 | 1335 | assertThat(indices).hasSize(1);
|
1334 | 1336 | assertThat(indices.get(0)).satisfies(it -> {
|
1335 | 1337 | assertThat(it.getIndexKeys()).containsEntry("$**", 1);
|
| 1338 | + assertThat(it.getIndexOptions()).isEmpty(); |
| 1339 | + }); |
| 1340 | + } |
| 1341 | + |
| 1342 | + @Test // GH-3225 |
| 1343 | + public void resolvesWildcardWithProjectionOnRoot() { |
| 1344 | + |
| 1345 | + List<IndexDefinitionHolder> indices = prepareMappingContextAndResolveIndexForType( |
| 1346 | + WithWildCardIndexHavingProjectionOnEntity.class); |
| 1347 | + assertThat(indices).hasSize(1); |
| 1348 | + assertThat(indices.get(0)).satisfies(it -> { |
| 1349 | + assertThat(it.getIndexKeys()).containsEntry("$**", 1); |
| 1350 | + assertThat(it.getIndexOptions()).containsEntry("wildcardProjection", |
| 1351 | + org.bson.Document.parse("{'_id' : 1, 'value' : 0}")); |
1336 | 1352 | });
|
1337 | 1353 | }
|
1338 | 1354 |
|
@@ -1365,6 +1381,15 @@ public void resolvesWildcardTypeOfNestedProperty() {
|
1365 | 1381 | assertThat(indices).hasSize(1);
|
1366 | 1382 | assertThat(indices.get(0)).satisfies(it -> {
|
1367 | 1383 | assertThat(it.getIndexKeys()).containsEntry("value.$**", 1);
|
| 1384 | + assertThat(it.getIndexOptions()).hasSize(1).containsKey("name"); |
| 1385 | + }); |
| 1386 | + } |
| 1387 | + |
| 1388 | + @Test // GH-3225 |
| 1389 | + public void rejectsWildcardProjectionOnNestedPaths() { |
| 1390 | + |
| 1391 | + assertThatExceptionOfType(MappingException.class).isThrownBy(() -> { |
| 1392 | + prepareMappingContextAndResolveIndexForType(WildcardIndexedProjectionOnNestedPath.class); |
1368 | 1393 | });
|
1369 | 1394 | }
|
1370 | 1395 |
|
@@ -1647,10 +1672,16 @@ class WithWildCardIndexOnProperty {
|
1647 | 1672 |
|
1648 | 1673 | }
|
1649 | 1674 |
|
| 1675 | + @Document |
| 1676 | + class WildcardIndexedProjectionOnNestedPath { |
| 1677 | + |
| 1678 | + @WildcardIndexed(wildcardProjection = "{}") String foo; |
| 1679 | + } |
| 1680 | + |
1650 | 1681 | @Document
|
1651 | 1682 | class WithWildCardOnEntityOfNested {
|
1652 | 1683 |
|
1653 |
| - WithWildCardIndexOnEntity value; |
| 1684 | + WithWildCardIndexHavingProjectionOnEntity value; |
1654 | 1685 |
|
1655 | 1686 | }
|
1656 | 1687 |
|
|
0 commit comments