diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java index 5206a3ca5ada..9b145f0cc864 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java @@ -19,6 +19,11 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; +import org.springframework.boot.autoconfigure.data.neo4j.scan.AnnotatedWithNode; +import org.springframework.boot.autoconfigure.data.neo4j.scan.AnnotatedWithPersistent; +import org.springframework.boot.autoconfigure.data.neo4j.scan.AnnotatedWithRelationshipProperties; +import org.springframework.boot.autoconfigure.data.neo4j.scan.NotAnnotatedEntity; import org.springframework.boot.autoconfigure.neo4j.Neo4jAutoConfiguration; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.context.annotation.Bean; @@ -29,6 +34,7 @@ import org.springframework.data.neo4j.core.Neo4jOperations; import org.springframework.data.neo4j.core.Neo4jTemplate; import org.springframework.data.neo4j.core.convert.Neo4jConversions; +import org.springframework.data.neo4j.core.mapping.Neo4jMappingContext; import org.springframework.data.neo4j.core.transaction.Neo4jTransactionManager; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.ReactiveTransactionManager; @@ -137,6 +143,17 @@ void shouldReuseExistingTransactionManager() { .hasBean("myCustomTransactionManager")); } + @Test + void shouldFilterInitialEntityScanWithKnownAnnotations() { + this.contextRunner.withUserConfiguration(PackageConfig.class).run((context) -> { + Neo4jMappingContext mappingContext = context.getBean(Neo4jMappingContext.class); + assertThat(mappingContext.hasPersistentEntityFor(AnnotatedWithNode.class)).isTrue(); + assertThat(mappingContext.hasPersistentEntityFor(AnnotatedWithPersistent.class)).isTrue(); + assertThat(mappingContext.hasPersistentEntityFor(AnnotatedWithRelationshipProperties.class)).isTrue(); + assertThat(mappingContext.hasPersistentEntityFor(NotAnnotatedEntity.class)).isFalse(); + }); + } + @Configuration(proxyBeanMethods = false) static class CustomDatabaseSelectionProviderConfiguration { @@ -147,4 +164,10 @@ DatabaseSelectionProvider databaseSelectionProvider() { } + @Configuration(proxyBeanMethods = false) + @TestAutoConfigurationPackage(AnnotatedWithPersistent.class) + static class PackageConfig { + + } + } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jReactiveRepositoriesAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jReactiveRepositoriesAutoConfigurationTests.java index 66afb613f5e3..2895ff0288c6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jReactiveRepositoriesAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jReactiveRepositoriesAutoConfigurationTests.java @@ -26,9 +26,14 @@ import org.springframework.boot.autoconfigure.data.neo4j.city.ReactiveCityRepository; import org.springframework.boot.autoconfigure.data.neo4j.country.CountryRepository; import org.springframework.boot.autoconfigure.data.neo4j.country.ReactiveCountryRepository; +import org.springframework.boot.autoconfigure.data.neo4j.scan.AnnotatedWithNode; +import org.springframework.boot.autoconfigure.data.neo4j.scan.AnnotatedWithPersistent; +import org.springframework.boot.autoconfigure.data.neo4j.scan.AnnotatedWithRelationshipProperties; +import org.springframework.boot.autoconfigure.data.neo4j.scan.NotAnnotatedEntity; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.context.annotation.Configuration; import org.springframework.data.neo4j.core.ReactiveNeo4jTemplate; +import org.springframework.data.neo4j.core.mapping.Neo4jMappingContext; import org.springframework.data.neo4j.repository.ReactiveNeo4jRepository; import org.springframework.data.neo4j.repository.config.EnableReactiveNeo4jRepositories; @@ -84,6 +89,17 @@ void shouldRespectAtEnableReactiveNeo4jRepositories() { .hasSingleBean(ReactiveCountryRepository.class)); } + @Test + void shouldFilterInitialEntityScanWithKnownAnnotations() { + this.contextRunner.withUserConfiguration(PackageConfig.class).run((context) -> { + Neo4jMappingContext mappingContext = context.getBean(Neo4jMappingContext.class); + assertThat(mappingContext.hasPersistentEntityFor(AnnotatedWithNode.class)).isTrue(); + assertThat(mappingContext.hasPersistentEntityFor(AnnotatedWithPersistent.class)).isTrue(); + assertThat(mappingContext.hasPersistentEntityFor(AnnotatedWithRelationshipProperties.class)).isTrue(); + assertThat(mappingContext.hasPersistentEntityFor(NotAnnotatedEntity.class)).isFalse(); + }); + } + @Configuration(proxyBeanMethods = false) @TestAutoConfigurationPackage(City.class) static class TestConfiguration { @@ -109,4 +125,10 @@ static class WithCustomReactiveRepositoryScan { } + @Configuration(proxyBeanMethods = false) + @TestAutoConfigurationPackage(AnnotatedWithPersistent.class) + static class PackageConfig { + + } + } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/scan/AnnotatedWithNode.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/scan/AnnotatedWithNode.java new file mode 100644 index 000000000000..9c44e5479615 --- /dev/null +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/scan/AnnotatedWithNode.java @@ -0,0 +1,33 @@ +/* + * Copyright 2012-2020 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 + * + * https://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.boot.autoconfigure.data.neo4j.scan; + +import org.springframework.data.neo4j.core.schema.GeneratedValue; +import org.springframework.data.neo4j.core.schema.Id; +import org.springframework.data.neo4j.core.schema.Node; + +/** + * @author Gerrit Meier + */ +@Node +public class AnnotatedWithNode { + + @Id + @GeneratedValue + private Long id; + +} diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/scan/AnnotatedWithPersistent.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/scan/AnnotatedWithPersistent.java new file mode 100644 index 000000000000..f987df09ab65 --- /dev/null +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/scan/AnnotatedWithPersistent.java @@ -0,0 +1,33 @@ +/* + * Copyright 2012-2020 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 + * + * https://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.boot.autoconfigure.data.neo4j.scan; + +import org.springframework.data.annotation.Persistent; +import org.springframework.data.neo4j.core.schema.GeneratedValue; +import org.springframework.data.neo4j.core.schema.Id; + +/** + * @author Gerrit Meier + */ +@Persistent +public class AnnotatedWithPersistent { + + @Id + @GeneratedValue + private Long id; + +} diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/scan/AnnotatedWithRelationshipProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/scan/AnnotatedWithRelationshipProperties.java new file mode 100644 index 000000000000..062e5bf15a19 --- /dev/null +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/scan/AnnotatedWithRelationshipProperties.java @@ -0,0 +1,27 @@ +/* + * Copyright 2012-2020 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 + * + * https://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.boot.autoconfigure.data.neo4j.scan; + +import org.springframework.data.neo4j.core.schema.RelationshipProperties; + +/** + * @author Gerrit Meier + */ +@RelationshipProperties +public class AnnotatedWithRelationshipProperties { + +} diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/scan/NotAnnotatedEntity.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/scan/NotAnnotatedEntity.java new file mode 100644 index 000000000000..dd78d4cfe129 --- /dev/null +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/scan/NotAnnotatedEntity.java @@ -0,0 +1,31 @@ +/* + * Copyright 2012-2020 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 + * + * https://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.boot.autoconfigure.data.neo4j.scan; + +import org.springframework.data.neo4j.core.schema.GeneratedValue; +import org.springframework.data.neo4j.core.schema.Id; + +/** + * @author Gerrit Meier + */ +public class NotAnnotatedEntity { + + @Id + @GeneratedValue + private Long id; + +}