From 995d1e5aac997ee006abac4d239308563c448307 Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Tue, 12 May 2015 11:19:47 +0200 Subject: [PATCH] DATAMONGO-1202 - Polishing. Moved and renamed types into test class. Added collection cleanup and missing author information. Original pull request: #293. --- .../mongodb/core/index/ConcreteCustomer.java | 26 ---------- .../mongodb/core/index/GenericCustomer.java | 49 ------------------- ...entEntityIndexCreatorIntegrationTests.java | 49 ++++++++++++++----- 3 files changed, 37 insertions(+), 87 deletions(-) delete mode 100644 spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/ConcreteCustomer.java delete mode 100644 spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/GenericCustomer.java diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/ConcreteCustomer.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/ConcreteCustomer.java deleted file mode 100644 index 1f123b192..000000000 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/ConcreteCustomer.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2015 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.mongodb.core.index; - -/** - * @author Thomas Darimont - */ -public class ConcreteCustomer extends GenericCustomer { - - public ConcreteCustomer(Long id, String firstName, ConcreteCustomer referrer) { - super(id, firstName, referrer); - } -} diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/GenericCustomer.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/GenericCustomer.java deleted file mode 100644 index 374762401..000000000 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/GenericCustomer.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2015 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.mongodb.core.index; - -import org.springframework.data.annotation.Id; -import org.springframework.data.mongodb.core.mapping.Document; - -/** - * @author Thomas Darimont - * - * @param - */ -@Document -public abstract class GenericCustomer> { - - @Id private Long id; - - @org.springframework.data.mongodb.core.mapping.DBRef private RC referrer; - - @Indexed private String firstName; - - public GenericCustomer(Long id, String firstName, RC referrer) { - this.firstName = firstName; - this.id = id; - this.referrer = referrer; - } - - public RC getReferrer() { - return referrer; - } - - @Override - public String toString() { - return "GenericCustomer{" + "id=" + id + ", referrer=" + referrer + ", firstName='" + firstName + '\'' + '}'; - } -} diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexCreatorIntegrationTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexCreatorIntegrationTests.java index 34d7810a6..0d6fc90fe 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexCreatorIntegrationTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexCreatorIntegrationTests.java @@ -18,17 +18,20 @@ package org.springframework.data.mongodb.core.index; import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; +import java.util.Arrays; import java.util.List; import org.hamcrest.Matchers; -import org.junit.After; -import org.junit.Before; import org.junit.ClassRule; import org.junit.Test; +import org.junit.rules.RuleChain; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.MongoOperations; +import org.springframework.data.mongodb.core.mapping.Document; +import org.springframework.data.mongodb.test.util.CleanMongoDB; import org.springframework.data.mongodb.test.util.MongoVersionRule; import org.springframework.data.util.Version; import org.springframework.test.context.ContextConfiguration; @@ -39,23 +42,22 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * * @author Oliver Gierke * @author Christoph Strobl + * @author Thomas Darimont */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration public class MongoPersistentEntityIndexCreatorIntegrationTests { - public static @ClassRule MongoVersionRule version = MongoVersionRule.atLeast(new Version(2, 6)); + static final String SAMPLE_TYPE_COLLECTION_NAME = "sampleEntity"; + static final String RECURSIVE_TYPE_COLLECTION_NAME = "recursiveGenericTypes"; + + public static @ClassRule RuleChain rules = RuleChain.outerRule(MongoVersionRule.atLeast(new Version(2, 6))).around( + CleanMongoDB.indexes(Arrays.asList(SAMPLE_TYPE_COLLECTION_NAME, RECURSIVE_TYPE_COLLECTION_NAME))); @Autowired @Qualifier("mongo1") MongoOperations templateOne; @Autowired @Qualifier("mongo2") MongoOperations templateTwo; - @After - public void cleanUp() { - templateOne.dropCollection(SampleEntity.class); - templateTwo.dropCollection(SampleEntity.class); - } - @Test public void createsIndexForConfiguredMappingContextOnly() { @@ -63,7 +65,7 @@ public class MongoPersistentEntityIndexCreatorIntegrationTests { assertThat(indexInfo, hasSize(greaterThan(0))); assertThat(indexInfo, Matchers. hasItem(hasProperty("name", is("prop")))); - indexInfo = templateTwo.indexOps("sampleEntity").getIndexInfo(); + indexInfo = templateTwo.indexOps(SAMPLE_TYPE_COLLECTION_NAME).getIndexInfo(); assertThat(indexInfo, hasSize(0)); } @@ -73,9 +75,32 @@ public class MongoPersistentEntityIndexCreatorIntegrationTests { @Test public void shouldHonorIndexedPropertiesWithRecursiveMappings() { - List indexInfo = templateOne.indexOps(ConcreteCustomer.class).getIndexInfo(); - + List indexInfo = templateOne.indexOps(RecursiveConcreteType.class).getIndexInfo(); + assertThat(indexInfo, hasSize(greaterThan(0))); assertThat(indexInfo, Matchers. hasItem(hasProperty("name", is("firstName")))); } + + @Document(collection = RECURSIVE_TYPE_COLLECTION_NAME) + static abstract class RecursiveGenericType> { + + @Id Long id; + + @org.springframework.data.mongodb.core.mapping.DBRef RGT referrer; + + @Indexed String firstName; + + public RecursiveGenericType(Long id, String firstName, RGT referrer) { + this.firstName = firstName; + this.id = id; + this.referrer = referrer; + } + } + + static class RecursiveConcreteType extends RecursiveGenericType { + + public RecursiveConcreteType(Long id, String firstName, RecursiveConcreteType referrer) { + super(id, firstName, referrer); + } + } }