Skip to content

Commit af8a53b

Browse files
christophstroblodrotbohm
authored andcommitted
DATAMONGO-909 - Compound index on inherited class should be created correctly.
With the overhaul of the index creation done in DATAMONGO-899 the CompoundIndex annotation is not longer just looked up at the concrete type but rather all its interfaces and super classes. So we just added an additional test to verify this behaviour.
1 parent 916b856 commit af8a53b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexResolverUnitTests.java

+19
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,29 @@ public void compoundIndexOptionsResolvedCorrectly() {
295295
assertThat(indexDefinition.getIndexKeys(), equalTo(new BasicDBObjectBuilder().add("foo", 1).add("bar", -1).get()));
296296
}
297297

298+
/**
299+
* @see DATAMONGO-909
300+
*/
301+
@Test
302+
public void compoundIndexOnSuperClassResolvedCorrectly() {
303+
304+
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(IndexDefinedOnSuperClass.class);
305+
306+
IndexDefinition indexDefinition = indexDefinitions.get(0).getIndexDefinition();
307+
assertThat(indexDefinition.getIndexOptions(),
308+
equalTo(new BasicDBObjectBuilder().add("name", "compound_index").add("unique", true).add("dropDups", true)
309+
.add("sparse", true).add("background", true).add("expireAfterSeconds", 10L).get()));
310+
assertThat(indexDefinition.getIndexKeys(), equalTo(new BasicDBObjectBuilder().add("foo", 1).add("bar", -1).get()));
311+
}
312+
298313
@Document(collection = "CompoundIndexOnLevelZero")
299314
@CompoundIndexes({ @CompoundIndex(name = "compound_index", def = "{'foo': 1, 'bar': -1}", background = true,
300315
dropDups = true, expireAfterSeconds = 10, sparse = true, unique = true) })
301316
static class CompoundIndexOnLevelZero {}
317+
318+
static class IndexDefinedOnSuperClass extends CompoundIndexOnLevelZero {
319+
320+
}
302321
}
303322

304323
public static class MixedIndexResolutionTests {

0 commit comments

Comments
 (0)