diff --git a/src/main/java/org/springframework/data/couchbase/repository/config/CouchbaseRepositoryConfigurationExtension.java b/src/main/java/org/springframework/data/couchbase/repository/config/CouchbaseRepositoryConfigurationExtension.java index e86d705d..b50cbf90 100644 --- a/src/main/java/org/springframework/data/couchbase/repository/config/CouchbaseRepositoryConfigurationExtension.java +++ b/src/main/java/org/springframework/data/couchbase/repository/config/CouchbaseRepositoryConfigurationExtension.java @@ -15,19 +15,25 @@ */ package org.springframework.data.couchbase.repository.config; -import org.w3c.dom.Element; +import java.lang.annotation.Annotation; +import java.util.Collection; +import java.util.Collections; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.data.config.ParsingUtils; import org.springframework.data.couchbase.config.BeanNames; +import org.springframework.data.couchbase.core.mapping.Document; +import org.springframework.data.couchbase.repository.CouchbaseRepository; import org.springframework.data.couchbase.repository.support.CouchbaseRepositoryFactoryBean; import org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource; import org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport; import org.springframework.data.repository.config.XmlRepositoryConfigurationSource; +import org.w3c.dom.Element; /** * @author Michael Nitschinger * @author Mark Paluch + * @author Oliver Gierke */ public class CouchbaseRepositoryConfigurationExtension extends RepositoryConfigurationExtensionSupport { @@ -60,4 +66,22 @@ public class CouchbaseRepositoryConfigurationExtension extends RepositoryConfigu builder.addPropertyReference("couchbaseOperationsMapping", BeanNames.COUCHBASE_OPERATIONS_MAPPING); builder.addPropertyReference("indexManager", BeanNames.COUCHBASE_INDEX_MANAGER); } + + /* + * (non-Javadoc) + * @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#getIdentifyingAnnotations() + */ + @Override + protected Collection> getIdentifyingAnnotations() { + return Collections.singleton(Document.class); + } + + /* + * (non-Javadoc) + * @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#getIdentifyingTypes() + */ + @Override + protected Collection> getIdentifyingTypes() { + return Collections.singleton(CouchbaseRepository.class); + } } diff --git a/src/test/java/org/springframework/data/couchbase/repository/config/CouchbaseRepositoryConfigurationExtensionUnitTests.java b/src/test/java/org/springframework/data/couchbase/repository/config/CouchbaseRepositoryConfigurationExtensionUnitTests.java new file mode 100644 index 00000000..1d6f93d4 --- /dev/null +++ b/src/test/java/org/springframework/data/couchbase/repository/config/CouchbaseRepositoryConfigurationExtensionUnitTests.java @@ -0,0 +1,72 @@ +/* + * Copyright 2017 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.couchbase.repository.config; + +import static org.assertj.core.api.Assertions.*; + +import java.io.Serializable; + +import org.junit.Test; +import org.springframework.data.couchbase.core.mapping.Document; +import org.springframework.data.couchbase.repository.CouchbaseRepository; +import org.springframework.data.repository.Repository; +import org.springframework.data.repository.core.RepositoryMetadata; +import org.springframework.data.repository.core.support.DefaultRepositoryMetadata; + +/** + * Unit tests for {@link CouchbaseRepositoryConfigurationExtension}. + * + * @author Oliver Gierke + */ +public class CouchbaseRepositoryConfigurationExtensionUnitTests { + + @Test // DATACOUCH-330 + public void atDocumentIsIdentifyingAnnotation() { + + CustomCouchbaseRepositoryConfigurationExtension extension = new CustomCouchbaseRepositoryConfigurationExtension(); + RepositoryMetadata metadata = DefaultRepositoryMetadata.getMetadata(ByAggregateRootAnnotationRepository.class); + + assertThat(extension.isStrictRepositoryCandidate(metadata)).isTrue(); + } + + @Test // DATACOUCH-330 + public void couchbaseRepositoryIsIdentifyingAnnotation() { + + CustomCouchbaseRepositoryConfigurationExtension extension = new CustomCouchbaseRepositoryConfigurationExtension(); + RepositoryMetadata metadata = DefaultRepositoryMetadata.getMetadata(ByRepository.class); + + assertThat(extension.isStrictRepositoryCandidate(metadata)).isTrue(); + } + + @Document + static class AggregateRoot {} + + interface ByAggregateRootAnnotationRepository extends Repository {} + + interface ByRepository extends CouchbaseRepository {}; + + static class CustomCouchbaseRepositoryConfigurationExtension extends CouchbaseRepositoryConfigurationExtension { + + /* + * (non-Javadoc) + * @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#isStrictRepositoryCandidate(org.springframework.data.repository.core.RepositoryMetadata) + */ + @Override + protected boolean isStrictRepositoryCandidate(RepositoryMetadata metadata) { + return super.isStrictRepositoryCandidate(metadata); + } + } +}