From af8a53bef6f6a8584413a3fecfcde37b2e059560 Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Mon, 28 Apr 2014 11:13:11 +0200 Subject: [PATCH] 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. --- ...ersistentEntityIndexResolverUnitTests.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexResolverUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexResolverUnitTests.java index 91f673bea..1639488c3 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexResolverUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexResolverUnitTests.java @@ -295,10 +295,29 @@ public class MongoPersistentEntityIndexResolverUnitTests { assertThat(indexDefinition.getIndexKeys(), equalTo(new BasicDBObjectBuilder().add("foo", 1).add("bar", -1).get())); } + /** + * @see DATAMONGO-909 + */ + @Test + public void compoundIndexOnSuperClassResolvedCorrectly() { + + List indexDefinitions = prepareMappingContextAndResolveIndexForType(IndexDefinedOnSuperClass.class); + + IndexDefinition indexDefinition = indexDefinitions.get(0).getIndexDefinition(); + assertThat(indexDefinition.getIndexOptions(), + equalTo(new BasicDBObjectBuilder().add("name", "compound_index").add("unique", true).add("dropDups", true) + .add("sparse", true).add("background", true).add("expireAfterSeconds", 10L).get())); + assertThat(indexDefinition.getIndexKeys(), equalTo(new BasicDBObjectBuilder().add("foo", 1).add("bar", -1).get())); + } + @Document(collection = "CompoundIndexOnLevelZero") @CompoundIndexes({ @CompoundIndex(name = "compound_index", def = "{'foo': 1, 'bar': -1}", background = true, dropDups = true, expireAfterSeconds = 10, sparse = true, unique = true) }) static class CompoundIndexOnLevelZero {} + + static class IndexDefinedOnSuperClass extends CompoundIndexOnLevelZero { + + } } public static class MixedIndexResolutionTests {