Skip to content

Commit

Permalink
Polish "Detect Persistent and RelationshipProperties with Neo4j"
Browse files Browse the repository at this point in the history
  • Loading branch information
snicoll committed Dec 22, 2020
1 parent ab4b1c4 commit 0691ba6
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 49 deletions.
Expand Up @@ -20,10 +20,10 @@

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;
Expand Down Expand Up @@ -145,12 +145,12 @@ void shouldReuseExistingTransactionManager() {

@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();
});
}

Expand All @@ -165,8 +165,8 @@ DatabaseSelectionProvider databaseSelectionProvider() {
}

@Configuration(proxyBeanMethods = false)
@TestAutoConfigurationPackage(AnnotatedWithPersistent.class)
static class PackageConfig {
@TestAutoConfigurationPackage(TestPersistent.class)
static class EntityScanConfig {

}

Expand Down
Expand Up @@ -21,6 +21,11 @@
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;
Expand All @@ -30,6 +35,7 @@
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;

Expand Down Expand Up @@ -121,6 +127,17 @@ void shouldUseExistingReactiveTransactionManager() {
.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 {

Expand All @@ -131,4 +148,10 @@ ReactiveDatabaseSelectionProvider databaseNameProvider() {

}

@Configuration(proxyBeanMethods = false)
@TestAutoConfigurationPackage(TestPersistent.class)
static class EntityScanConfig {

}

}
Expand Up @@ -26,14 +26,9 @@
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;

Expand Down Expand Up @@ -89,17 +84,6 @@ 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 {
Expand All @@ -125,10 +109,4 @@ static class WithCustomReactiveRepositoryScan {

}

@Configuration(proxyBeanMethods = false)
@TestAutoConfigurationPackage(AnnotatedWithPersistent.class)
static class PackageConfig {

}

}
Expand Up @@ -20,11 +20,8 @@
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
Expand Down
Expand Up @@ -19,10 +19,7 @@
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
Expand Down
Expand Up @@ -20,11 +20,8 @@
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
Expand Down
Expand Up @@ -18,10 +18,7 @@

import org.springframework.data.neo4j.core.schema.RelationshipProperties;

/**
* @author Gerrit Meier
*/
@RelationshipProperties
public class AnnotatedWithRelationshipProperties {
public class TestRelationshipProperties {

}

0 comments on commit 0691ba6

Please sign in to comment.