Skip to content

Commit ac1c445

Browse files
committed
Add tests to verify behaviour.
1 parent a9462c9 commit ac1c445

File tree

6 files changed

+169
-0
lines changed

6 files changed

+169
-0
lines changed

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java

+23
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
import org.junit.jupiter.api.Test;
2020

2121
import org.springframework.boot.autoconfigure.AutoConfigurations;
22+
import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage;
23+
import org.springframework.boot.autoconfigure.data.neo4j.scan.AnnotatedWithNode;
24+
import org.springframework.boot.autoconfigure.data.neo4j.scan.AnnotatedWithPersistent;
25+
import org.springframework.boot.autoconfigure.data.neo4j.scan.AnnotatedWithRelationshipProperties;
26+
import org.springframework.boot.autoconfigure.data.neo4j.scan.NotAnnotatedEntity;
2227
import org.springframework.boot.autoconfigure.neo4j.Neo4jAutoConfiguration;
2328
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
2429
import org.springframework.context.annotation.Bean;
@@ -29,6 +34,7 @@
2934
import org.springframework.data.neo4j.core.Neo4jOperations;
3035
import org.springframework.data.neo4j.core.Neo4jTemplate;
3136
import org.springframework.data.neo4j.core.convert.Neo4jConversions;
37+
import org.springframework.data.neo4j.core.mapping.Neo4jMappingContext;
3238
import org.springframework.data.neo4j.core.transaction.Neo4jTransactionManager;
3339
import org.springframework.transaction.PlatformTransactionManager;
3440
import org.springframework.transaction.ReactiveTransactionManager;
@@ -137,6 +143,17 @@ void shouldReuseExistingTransactionManager() {
137143
.hasBean("myCustomTransactionManager"));
138144
}
139145

146+
@Test
147+
void shouldFilterInitialEntityScanWithKnownAnnotations() {
148+
this.contextRunner.withUserConfiguration(PackageConfig.class).run((context) -> {
149+
Neo4jMappingContext mappingContext = context.getBean(Neo4jMappingContext.class);
150+
assertThat(mappingContext.hasPersistentEntityFor(AnnotatedWithNode.class)).isTrue();
151+
assertThat(mappingContext.hasPersistentEntityFor(AnnotatedWithPersistent.class)).isTrue();
152+
assertThat(mappingContext.hasPersistentEntityFor(AnnotatedWithRelationshipProperties.class)).isTrue();
153+
assertThat(mappingContext.hasPersistentEntityFor(NotAnnotatedEntity.class)).isFalse();
154+
});
155+
}
156+
140157
@Configuration(proxyBeanMethods = false)
141158
static class CustomDatabaseSelectionProviderConfiguration {
142159

@@ -147,4 +164,10 @@ DatabaseSelectionProvider databaseSelectionProvider() {
147164

148165
}
149166

167+
@Configuration(proxyBeanMethods = false)
168+
@TestAutoConfigurationPackage(AnnotatedWithPersistent.class)
169+
static class PackageConfig {
170+
171+
}
172+
150173
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jReactiveRepositoriesAutoConfigurationTests.java

+22
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,14 @@
2626
import org.springframework.boot.autoconfigure.data.neo4j.city.ReactiveCityRepository;
2727
import org.springframework.boot.autoconfigure.data.neo4j.country.CountryRepository;
2828
import org.springframework.boot.autoconfigure.data.neo4j.country.ReactiveCountryRepository;
29+
import org.springframework.boot.autoconfigure.data.neo4j.scan.AnnotatedWithNode;
30+
import org.springframework.boot.autoconfigure.data.neo4j.scan.AnnotatedWithPersistent;
31+
import org.springframework.boot.autoconfigure.data.neo4j.scan.AnnotatedWithRelationshipProperties;
32+
import org.springframework.boot.autoconfigure.data.neo4j.scan.NotAnnotatedEntity;
2933
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
3034
import org.springframework.context.annotation.Configuration;
3135
import org.springframework.data.neo4j.core.ReactiveNeo4jTemplate;
36+
import org.springframework.data.neo4j.core.mapping.Neo4jMappingContext;
3237
import org.springframework.data.neo4j.repository.ReactiveNeo4jRepository;
3338
import org.springframework.data.neo4j.repository.config.EnableReactiveNeo4jRepositories;
3439

@@ -84,6 +89,17 @@ void shouldRespectAtEnableReactiveNeo4jRepositories() {
8489
.hasSingleBean(ReactiveCountryRepository.class));
8590
}
8691

92+
@Test
93+
void shouldFilterInitialEntityScanWithKnownAnnotations() {
94+
this.contextRunner.withUserConfiguration(PackageConfig.class).run((context) -> {
95+
Neo4jMappingContext mappingContext = context.getBean(Neo4jMappingContext.class);
96+
assertThat(mappingContext.hasPersistentEntityFor(AnnotatedWithNode.class)).isTrue();
97+
assertThat(mappingContext.hasPersistentEntityFor(AnnotatedWithPersistent.class)).isTrue();
98+
assertThat(mappingContext.hasPersistentEntityFor(AnnotatedWithRelationshipProperties.class)).isTrue();
99+
assertThat(mappingContext.hasPersistentEntityFor(NotAnnotatedEntity.class)).isFalse();
100+
});
101+
}
102+
87103
@Configuration(proxyBeanMethods = false)
88104
@TestAutoConfigurationPackage(City.class)
89105
static class TestConfiguration {
@@ -109,4 +125,10 @@ static class WithCustomReactiveRepositoryScan {
109125

110126
}
111127

128+
@Configuration(proxyBeanMethods = false)
129+
@TestAutoConfigurationPackage(AnnotatedWithPersistent.class)
130+
static class PackageConfig {
131+
132+
}
133+
112134
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2012-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.autoconfigure.data.neo4j.scan;
18+
19+
import org.springframework.data.neo4j.core.schema.GeneratedValue;
20+
import org.springframework.data.neo4j.core.schema.Id;
21+
import org.springframework.data.neo4j.core.schema.Node;
22+
23+
/**
24+
* @author Gerrit Meier
25+
*/
26+
@Node
27+
public class AnnotatedWithNode {
28+
29+
@Id
30+
@GeneratedValue
31+
private Long id;
32+
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2012-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.autoconfigure.data.neo4j.scan;
18+
19+
import org.springframework.data.annotation.Persistent;
20+
import org.springframework.data.neo4j.core.schema.GeneratedValue;
21+
import org.springframework.data.neo4j.core.schema.Id;
22+
23+
/**
24+
* @author Gerrit Meier
25+
*/
26+
@Persistent
27+
public class AnnotatedWithPersistent {
28+
29+
@Id
30+
@GeneratedValue
31+
private Long id;
32+
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2012-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.autoconfigure.data.neo4j.scan;
18+
19+
import org.springframework.data.neo4j.core.schema.RelationshipProperties;
20+
21+
/**
22+
* @author Gerrit Meier
23+
*/
24+
@RelationshipProperties
25+
public class AnnotatedWithRelationshipProperties {
26+
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2012-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.autoconfigure.data.neo4j.scan;
18+
19+
import org.springframework.data.neo4j.core.schema.GeneratedValue;
20+
import org.springframework.data.neo4j.core.schema.Id;
21+
22+
/**
23+
* @author Gerrit Meier
24+
*/
25+
public class NotAnnotatedEntity {
26+
27+
@Id
28+
@GeneratedValue
29+
private Long id;
30+
31+
}

0 commit comments

Comments
 (0)