Formatting
This commit is contained in:
parent
faba7a9514
commit
c68e5f12ff
|
|
@ -55,7 +55,8 @@ import org.springframework.data.neo4j.repository.support.GraphRepositoryFactoryB
|
|||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass({ Neo4jSession.class, GraphRepository.class })
|
||||
@ConditionalOnMissingBean({ GraphRepositoryFactoryBean.class, Neo4jRepositoryConfigurationExtension.class })
|
||||
@ConditionalOnMissingBean({ GraphRepositoryFactoryBean.class,
|
||||
Neo4jRepositoryConfigurationExtension.class })
|
||||
@ConditionalOnProperty(prefix = "spring.data.neo4j.repositories", name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@Import(Neo4jRepositoriesAutoConfigureRegistrar.class)
|
||||
@AutoConfigureAfter(Neo4jAutoConfiguration.class)
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ import org.springframework.data.repository.config.RepositoryConfigurationExtensi
|
|||
*
|
||||
* @author Michael Hunger
|
||||
*/
|
||||
class Neo4jRepositoriesAutoConfigureRegistrar extends
|
||||
AbstractRepositoryConfigurationSourceSupport {
|
||||
class Neo4jRepositoriesAutoConfigureRegistrar
|
||||
extends AbstractRepositoryConfigurationSourceSupport {
|
||||
|
||||
@Override
|
||||
protected Class<? extends Annotation> getAnnotation() {
|
||||
|
|
|
|||
|
|
@ -45,8 +45,7 @@ import org.springframework.data.neo4j.template.Neo4jTemplate;
|
|||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for Spring Data's Neo4j support.
|
||||
* <p>
|
||||
* Registers a {@link Neo4jTemplate} bean if no other bean of
|
||||
* the same type is configured.
|
||||
* Registers a {@link Neo4jTemplate} bean if no other bean of the same type is configured.
|
||||
*
|
||||
* @author Michael Hunger
|
||||
* @author Josh Long
|
||||
|
|
@ -55,7 +54,7 @@ import org.springframework.data.neo4j.template.Neo4jTemplate;
|
|||
* @since 1.4.0
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass({Neo4jSession.class, Neo4jOperations.class})
|
||||
@ConditionalOnClass({ Neo4jSession.class, Neo4jOperations.class })
|
||||
@ConditionalOnMissingBean(Neo4jOperations.class)
|
||||
@EnableConfigurationProperties(Neo4jProperties.class)
|
||||
public class Neo4jAutoConfiguration {
|
||||
|
|
@ -66,7 +65,8 @@ public class Neo4jAutoConfiguration {
|
|||
|
||||
private final ObjectProvider<SessionFactoryProvider> sessionFactoryProvider;
|
||||
|
||||
public SpringBootNeo4jConfiguration(ObjectProvider<SessionFactoryProvider> sessionFactoryProvider) {
|
||||
public SpringBootNeo4jConfiguration(
|
||||
ObjectProvider<SessionFactoryProvider> sessionFactoryProvider) {
|
||||
this.sessionFactoryProvider = sessionFactoryProvider;
|
||||
}
|
||||
|
||||
|
|
@ -77,8 +77,7 @@ public class Neo4jAutoConfiguration {
|
|||
}
|
||||
|
||||
@Bean
|
||||
@Scope(scopeName = "${spring.data.neo4j.session.scope:singleton}",
|
||||
proxyMode = ScopedProxyMode.TARGET_CLASS)
|
||||
@Scope(scopeName = "${spring.data.neo4j.session.scope:singleton}", proxyMode = ScopedProxyMode.TARGET_CLASS)
|
||||
@Override
|
||||
public Session getSession() throws Exception {
|
||||
return getSessionFactory().openSession();
|
||||
|
|
@ -94,7 +93,8 @@ public class Neo4jAutoConfiguration {
|
|||
|
||||
private ConfigurableListableBeanFactory beanFactory;
|
||||
|
||||
SessionFactoryProviderConfiguration(org.neo4j.ogm.config.Configuration configuration) {
|
||||
SessionFactoryProviderConfiguration(
|
||||
org.neo4j.ogm.config.Configuration configuration) {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
|
|
@ -114,7 +114,8 @@ public class Neo4jAutoConfiguration {
|
|||
|
||||
protected String[] getPackagesToScan() {
|
||||
if (AutoConfigurationPackages.has(this.beanFactory)) {
|
||||
List<String> basePackages = AutoConfigurationPackages.get(this.beanFactory);
|
||||
List<String> basePackages = AutoConfigurationPackages
|
||||
.get(this.beanFactory);
|
||||
return basePackages.toArray(new String[basePackages.size()]);
|
||||
}
|
||||
return new String[0];
|
||||
|
|
|
|||
|
|
@ -131,7 +131,8 @@ public class Neo4jProperties implements ApplicationContextAware {
|
|||
}
|
||||
|
||||
if (this.username != null && this.password != null) {
|
||||
configuration.driverConfiguration().setCredentials(this.username, this.password);
|
||||
configuration.driverConfiguration().setCredentials(this.username,
|
||||
this.password);
|
||||
}
|
||||
if (this.compiler != null) {
|
||||
configuration.compilerConfiguration().setCompilerClassName(this.compiler);
|
||||
|
|
@ -150,15 +151,16 @@ public class Neo4jProperties implements ApplicationContextAware {
|
|||
return HTTP_DRIVER;
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Could not deduce driver to use based on URI '" + uri + "'");
|
||||
throw new IllegalArgumentException(
|
||||
"Could not deduce driver to use based on URI '" + uri + "'");
|
||||
}
|
||||
}
|
||||
catch (URISyntaxException ex) {
|
||||
throw new IllegalArgumentException("Invalid URI for spring.data.neo4j.uri '" + this.uri + "'", ex);
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid URI for spring.data.neo4j.uri '" + this.uri + "'", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class Embedded {
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -20,4 +20,5 @@ import org.springframework.boot.autoconfigure.data.neo4j.city.City;
|
|||
import org.springframework.data.neo4j.repository.GraphRepository;
|
||||
|
||||
public interface CityNeo4jRepository extends GraphRepository<City> {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,8 +56,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
*/
|
||||
public class MixedNeo4jRepositoriesAutoConfigurationTests {
|
||||
|
||||
private AnnotationConfigApplicationContext context =
|
||||
new AnnotationConfigApplicationContext();
|
||||
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
|
|
@ -66,7 +65,8 @@ public class MixedNeo4jRepositoriesAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void testDefaultRepositoryConfiguration() throws Exception {
|
||||
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.initialize:false");
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.datasource.initialize:false");
|
||||
this.context.register(TestConfiguration.class, BaseConfiguration.class);
|
||||
this.context.refresh();
|
||||
assertThat(this.context.getBean(CountryRepository.class)).isNotNull();
|
||||
|
|
@ -74,7 +74,8 @@ public class MixedNeo4jRepositoriesAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void testMixedRepositoryConfiguration() throws Exception {
|
||||
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.initialize:false");
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.datasource.initialize:false");
|
||||
this.context.register(MixedConfiguration.class, BaseConfiguration.class);
|
||||
this.context.refresh();
|
||||
assertThat(this.context.getBean(CountryRepository.class)).isNotNull();
|
||||
|
|
@ -83,7 +84,8 @@ public class MixedNeo4jRepositoriesAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void testJpaRepositoryConfigurationWithNeo4jTemplate() throws Exception {
|
||||
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.initialize:false");
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.datasource.initialize:false");
|
||||
this.context.register(JpaConfiguration.class, BaseConfiguration.class);
|
||||
this.context.refresh();
|
||||
assertThat(this.context.getBean(CityRepository.class)).isNotNull();
|
||||
|
|
@ -92,14 +94,16 @@ public class MixedNeo4jRepositoriesAutoConfigurationTests {
|
|||
@Test
|
||||
@Ignore
|
||||
public void testJpaRepositoryConfigurationWithNeo4jOverlap() throws Exception {
|
||||
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.initialize:false");
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.datasource.initialize:false");
|
||||
this.context.register(OverlapConfiguration.class, BaseConfiguration.class);
|
||||
this.context.refresh();
|
||||
assertThat(this.context.getBean(CityRepository.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJpaRepositoryConfigurationWithNeo4jOverlapDisabled() throws Exception {
|
||||
public void testJpaRepositoryConfigurationWithNeo4jOverlapDisabled()
|
||||
throws Exception {
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.datasource.initialize:false",
|
||||
"spring.data.neo4j.repositories.enabled:false");
|
||||
|
|
@ -153,11 +157,10 @@ public class MixedNeo4jRepositoriesAutoConfigurationTests {
|
|||
@Override
|
||||
public String[] selectImports(AnnotationMetadata importingClassMetadata) {
|
||||
List<String> names = new ArrayList<String>();
|
||||
for (Class<?> type : new Class<?>[] {DataSourceAutoConfiguration.class,
|
||||
for (Class<?> type : new Class<?>[] { DataSourceAutoConfiguration.class,
|
||||
HibernateJpaAutoConfiguration.class,
|
||||
JpaRepositoriesAutoConfiguration.class,
|
||||
Neo4jAutoConfiguration.class,
|
||||
Neo4jRepositoriesAutoConfiguration.class}) {
|
||||
JpaRepositoriesAutoConfiguration.class, Neo4jAutoConfiguration.class,
|
||||
Neo4jRepositoriesAutoConfiguration.class }) {
|
||||
names.add(type.getName());
|
||||
}
|
||||
return names.toArray(new String[names.size()]);
|
||||
|
|
|
|||
|
|
@ -57,8 +57,7 @@ public class Neo4jDataAutoConfigurationTests {
|
|||
City.class);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private static void assertDomainTypesDiscovered(Neo4jMappingContext mappingContext,
|
||||
Class<?>... types) {
|
||||
for (Class<?> type : types) {
|
||||
|
|
|
|||
|
|
@ -59,7 +59,8 @@ public class Neo4jRepositoriesAutoConfigurationTests {
|
|||
prepareApplicationContext(TestConfiguration.class);
|
||||
|
||||
assertThat(this.context.getBean(CityRepository.class)).isNotNull();
|
||||
Neo4jMappingContext mappingContext = this.context.getBean(Neo4jMappingContext.class);
|
||||
Neo4jMappingContext mappingContext = this.context
|
||||
.getBean(Neo4jMappingContext.class);
|
||||
assertThat(mappingContext.getPersistentEntity(City.class)).isNotNull();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Tests for {@link Neo4jAutoConfiguration}. Tests can't use the embedded driver
|
||||
* as we use lucene 4 and Neo4j still requires 3.
|
||||
* Tests for {@link Neo4jAutoConfiguration}. Tests can't use the embedded driver as we use
|
||||
* lucene 4 and Neo4j still requires 3.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Michael Hunger
|
||||
|
|
@ -55,16 +55,19 @@ public class Neo4jAutoConfigurationTests {
|
|||
public void defaultConfiguration() {
|
||||
load(null, "spring.data.neo4j.uri=http://localhost:8989");
|
||||
assertThat(this.context.getBeansOfType(Neo4jOperations.class)).hasSize(1);
|
||||
assertThat(this.context.getBeansOfType(org.neo4j.ogm.config.Configuration.class)).hasSize(1);
|
||||
assertThat(this.context.getBeansOfType(org.neo4j.ogm.config.Configuration.class))
|
||||
.hasSize(1);
|
||||
assertThat(this.context.getBeansOfType(SessionFactory.class)).hasSize(1);
|
||||
assertThat(this.context.getBeanDefinition("scopedTarget.getSession").getScope()).isEqualTo("singleton");
|
||||
assertThat(this.context.getBeanDefinition("scopedTarget.getSession").getScope())
|
||||
.isEqualTo("singleton");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customScope() {
|
||||
load(null, "spring.data.neo4j.uri=http://localhost:8989",
|
||||
"spring.data.neo4j.session.scope=prototype");
|
||||
assertThat(this.context.getBeanDefinition("scopedTarget.getSession").getScope()).isEqualTo("prototype");
|
||||
assertThat(this.context.getBeanDefinition("scopedTarget.getSession").getScope())
|
||||
.isEqualTo("prototype");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -72,7 +75,8 @@ public class Neo4jAutoConfigurationTests {
|
|||
load(CustomNeo4jOperations.class);
|
||||
assertThat(this.context.getBean(Neo4jOperations.class))
|
||||
.isSameAs(this.context.getBean("myNeo4jOperations"));
|
||||
assertThat(this.context.getBeansOfType(org.neo4j.ogm.config.Configuration.class)).hasSize(0);
|
||||
assertThat(this.context.getBeansOfType(org.neo4j.ogm.config.Configuration.class))
|
||||
.hasSize(0);
|
||||
assertThat(this.context.getBeansOfType(SessionFactory.class)).hasSize(0);
|
||||
assertThat(this.context.getBeansOfType(Session.class)).hasSize(0);
|
||||
}
|
||||
|
|
@ -83,7 +87,8 @@ public class Neo4jAutoConfigurationTests {
|
|||
assertThat(this.context.getBean(org.neo4j.ogm.config.Configuration.class))
|
||||
.isSameAs(this.context.getBean("myConfiguration"));
|
||||
assertThat(this.context.getBeansOfType(Neo4jOperations.class)).hasSize(1);
|
||||
assertThat(this.context.getBeansOfType(org.neo4j.ogm.config.Configuration.class)).hasSize(1);
|
||||
assertThat(this.context.getBeansOfType(org.neo4j.ogm.config.Configuration.class))
|
||||
.hasSize(1);
|
||||
assertThat(this.context.getBeansOfType(SessionFactory.class)).hasSize(1);
|
||||
}
|
||||
|
||||
|
|
@ -109,14 +114,14 @@ public class Neo4jAutoConfigurationTests {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class CustomConfiguration {
|
||||
|
||||
@Bean
|
||||
public org.neo4j.ogm.config.Configuration myConfiguration() {
|
||||
org.neo4j.ogm.config.Configuration configuration = new org.neo4j.ogm.config.Configuration();
|
||||
configuration.driverConfiguration().setDriverClassName(HttpDriver.class.getName());
|
||||
configuration.driverConfiguration()
|
||||
.setDriverClassName(HttpDriver.class.getName());
|
||||
return configuration;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -68,8 +68,7 @@ public class Neo4jPropertiesTests {
|
|||
Neo4jProperties properties = load(true,
|
||||
"spring.data.neo4j.uri=http://localhost:7474");
|
||||
Configuration configuration = properties.createConfiguration();
|
||||
assertDriver(configuration, Neo4jProperties.HTTP_DRIVER,
|
||||
"http://localhost:7474");
|
||||
assertDriver(configuration, Neo4jProperties.HTTP_DRIVER, "http://localhost:7474");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -85,11 +84,9 @@ public class Neo4jPropertiesTests {
|
|||
public void credentialsAreSet() {
|
||||
Neo4jProperties properties = load(true,
|
||||
"spring.data.neo4j.uri=http://localhost:7474",
|
||||
"spring.data.neo4j.username=user",
|
||||
"spring.data.neo4j.password=secret");
|
||||
"spring.data.neo4j.username=user", "spring.data.neo4j.password=secret");
|
||||
Configuration configuration = properties.createConfiguration();
|
||||
assertDriver(configuration, Neo4jProperties.HTTP_DRIVER,
|
||||
"http://localhost:7474");
|
||||
assertDriver(configuration, Neo4jProperties.HTTP_DRIVER, "http://localhost:7474");
|
||||
assertCredentials(configuration, "user", "secret");
|
||||
}
|
||||
|
||||
|
|
@ -121,15 +118,15 @@ public class Neo4jPropertiesTests {
|
|||
"target/neo4j/my.db");
|
||||
}
|
||||
|
||||
private static void assertDriver(Configuration actual, String driver,
|
||||
String uri) {
|
||||
private static void assertDriver(Configuration actual, String driver, String uri) {
|
||||
assertThat(actual).isNotNull();
|
||||
DriverConfiguration driverConfig = actual.driverConfiguration();
|
||||
assertThat(driverConfig.getDriverClassName()).isEqualTo(driver);
|
||||
assertThat(driverConfig.getURI()).isEqualTo(uri);
|
||||
}
|
||||
|
||||
private static void assertCredentials(Configuration actual, String username, String password) {
|
||||
private static void assertCredentials(Configuration actual, String username,
|
||||
String password) {
|
||||
Credentials credentials = actual.driverConfiguration().getCredentials();
|
||||
if (username == null & password == null) {
|
||||
assertThat(credentials).isNull();
|
||||
|
|
@ -138,8 +135,8 @@ public class Neo4jPropertiesTests {
|
|||
assertThat(credentials).isNotNull();
|
||||
Object content = credentials.credentials();
|
||||
assertThat(content).isInstanceOf(String.class);
|
||||
String[] auth = new String(Base64.decode(((String) content)
|
||||
.getBytes())).split(":");
|
||||
String[] auth = new String(Base64.decode(((String) content).getBytes()))
|
||||
.split(":");
|
||||
assertThat(auth[0]).isEqualTo(username);
|
||||
assertThat(auth[1]).isEqualTo(password);
|
||||
assertThat(auth).hasSize(2);
|
||||
|
|
@ -148,24 +145,23 @@ public class Neo4jPropertiesTests {
|
|||
|
||||
public Neo4jProperties load(final boolean embeddedAvailable, String... environment) {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.setClassLoader(
|
||||
new URLClassLoader(new URL[0], getClass().getClassLoader()) {
|
||||
ctx.setClassLoader(new URLClassLoader(new URL[0], getClass().getClassLoader()) {
|
||||
|
||||
@Override
|
||||
protected Class<?> loadClass(String name, boolean resolve)
|
||||
throws ClassNotFoundException {
|
||||
if (name.equals(Neo4jProperties.EMBEDDED_DRIVER)) {
|
||||
if (embeddedAvailable) {
|
||||
return TestEmbeddedDriver.class;
|
||||
}
|
||||
else {
|
||||
throw new ClassNotFoundException();
|
||||
}
|
||||
}
|
||||
return super.loadClass(name, resolve);
|
||||
@Override
|
||||
protected Class<?> loadClass(String name, boolean resolve)
|
||||
throws ClassNotFoundException {
|
||||
if (name.equals(Neo4jProperties.EMBEDDED_DRIVER)) {
|
||||
if (embeddedAvailable) {
|
||||
return TestEmbeddedDriver.class;
|
||||
}
|
||||
else {
|
||||
throw new ClassNotFoundException();
|
||||
}
|
||||
}
|
||||
return super.loadClass(name, resolve);
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
EnvironmentTestUtils.addEnvironment(ctx, environment);
|
||||
ctx.register(TestConfiguration.class);
|
||||
ctx.refresh();
|
||||
|
|
|
|||
|
|
@ -3055,6 +3055,8 @@ properties:
|
|||
spring.data.neo4j.password=secret
|
||||
----
|
||||
|
||||
|
||||
|
||||
[[boot-features-connecting-to-neo4j-embedded]]
|
||||
==== Using the embedded mode
|
||||
|
||||
|
|
@ -3071,6 +3073,8 @@ persistence for the embedded mode:
|
|||
spring.data.neo4j.uri=file://var/tmp/graph.db
|
||||
----
|
||||
|
||||
|
||||
|
||||
[[boot-features-neo4j-ogm-session]]
|
||||
==== Neo4jSession
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue