mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Polish "Detect Persistent and RelationshipProperties with Neo4j"
See gh-24239
This commit is contained in:
parent
ab4b1c4e61
commit
0691ba600f
@ -20,10 +20,10 @@ 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.data.neo4j.scan.TestNode;
|
||||
import org.springframework.boot.autoconfigure.data.neo4j.scan.TestNonAnnotated;
|
||||
import org.springframework.boot.autoconfigure.data.neo4j.scan.TestPersistent;
|
||||
import org.springframework.boot.autoconfigure.data.neo4j.scan.TestRelationshipProperties;
|
||||
import org.springframework.boot.autoconfigure.neo4j.Neo4jAutoConfiguration;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@ -145,12 +145,12 @@ class Neo4jDataAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
void shouldFilterInitialEntityScanWithKnownAnnotations() {
|
||||
this.contextRunner.withUserConfiguration(PackageConfig.class).run((context) -> {
|
||||
this.contextRunner.withUserConfiguration(EntityScanConfig.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();
|
||||
assertThat(mappingContext.hasPersistentEntityFor(TestNode.class)).isTrue();
|
||||
assertThat(mappingContext.hasPersistentEntityFor(TestPersistent.class)).isTrue();
|
||||
assertThat(mappingContext.hasPersistentEntityFor(TestRelationshipProperties.class)).isTrue();
|
||||
assertThat(mappingContext.hasPersistentEntityFor(TestNonAnnotated.class)).isFalse();
|
||||
});
|
||||
}
|
||||
|
||||
@ -165,8 +165,8 @@ class Neo4jDataAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@TestAutoConfigurationPackage(AnnotatedWithPersistent.class)
|
||||
static class PackageConfig {
|
||||
@TestAutoConfigurationPackage(TestPersistent.class)
|
||||
static class EntityScanConfig {
|
||||
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,11 @@ import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage;
|
||||
import org.springframework.boot.autoconfigure.data.neo4j.scan.TestNode;
|
||||
import org.springframework.boot.autoconfigure.data.neo4j.scan.TestNonAnnotated;
|
||||
import org.springframework.boot.autoconfigure.data.neo4j.scan.TestPersistent;
|
||||
import org.springframework.boot.autoconfigure.data.neo4j.scan.TestRelationshipProperties;
|
||||
import org.springframework.boot.autoconfigure.neo4j.Neo4jAutoConfiguration;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@ -30,6 +35,7 @@ import org.springframework.data.neo4j.core.ReactiveDatabaseSelectionProvider;
|
||||
import org.springframework.data.neo4j.core.ReactiveNeo4jClient;
|
||||
import org.springframework.data.neo4j.core.ReactiveNeo4jOperations;
|
||||
import org.springframework.data.neo4j.core.ReactiveNeo4jTemplate;
|
||||
import org.springframework.data.neo4j.core.mapping.Neo4jMappingContext;
|
||||
import org.springframework.transaction.ReactiveTransactionManager;
|
||||
import org.springframework.transaction.TransactionManager;
|
||||
|
||||
@ -121,6 +127,17 @@ class Neo4jReactiveDataAutoConfigurationTests {
|
||||
.hasSingleBean(TransactionManager.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFilterInitialEntityScanWithKnownAnnotations() {
|
||||
this.contextRunner.withUserConfiguration(EntityScanConfig.class).run((context) -> {
|
||||
Neo4jMappingContext mappingContext = context.getBean(Neo4jMappingContext.class);
|
||||
assertThat(mappingContext.hasPersistentEntityFor(TestNode.class)).isTrue();
|
||||
assertThat(mappingContext.hasPersistentEntityFor(TestPersistent.class)).isTrue();
|
||||
assertThat(mappingContext.hasPersistentEntityFor(TestRelationshipProperties.class)).isTrue();
|
||||
assertThat(mappingContext.hasPersistentEntityFor(TestNonAnnotated.class)).isFalse();
|
||||
});
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class CustomReactiveDatabaseSelectionProviderConfiguration {
|
||||
|
||||
@ -131,4 +148,10 @@ class Neo4jReactiveDataAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@TestAutoConfigurationPackage(TestPersistent.class)
|
||||
static class EntityScanConfig {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,14 +26,9 @@ import org.springframework.boot.autoconfigure.data.neo4j.city.CityRepository;
|
||||
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;
|
||||
|
||||
@ -89,17 +84,6 @@ public class Neo4jReactiveRepositoriesAutoConfigurationTests {
|
||||
.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 {
|
||||
@ -125,10 +109,4 @@ public class Neo4jReactiveRepositoriesAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@TestAutoConfigurationPackage(AnnotatedWithPersistent.class)
|
||||
static class PackageConfig {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,11 +20,8 @@ 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 {
|
||||
public class TestNode {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
@ -19,10 +19,7 @@ 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 {
|
||||
public class TestNonAnnotated {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
@ -20,11 +20,8 @@ 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 {
|
||||
public class TestPersistent {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
@ -18,10 +18,7 @@ package org.springframework.boot.autoconfigure.data.neo4j.scan;
|
||||
|
||||
import org.springframework.data.neo4j.core.schema.RelationshipProperties;
|
||||
|
||||
/**
|
||||
* @author Gerrit Meier
|
||||
*/
|
||||
@RelationshipProperties
|
||||
public class AnnotatedWithRelationshipProperties {
|
||||
public class TestRelationshipProperties {
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user