Fix build failure
Force the use of the http Neo4j driver as the bolt one attempts to connect to the server on startup by default (and there is no way to disable that behaviour). See https://github.com/neo4j/neo4j-java-driver/issues/380 Closes gh-9499
This commit is contained in:
parent
7d70b1b72a
commit
be00dfafde
|
|
@ -16,9 +16,6 @@
|
|||
|
||||
package org.springframework.boot.autoconfigure.data.neo4j;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
|
@ -36,9 +33,6 @@ import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfigurat
|
|||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.ImportSelector;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
|
||||
|
||||
|
|
@ -55,59 +49,63 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
*/
|
||||
public class MixedNeo4jRepositoriesAutoConfigurationTests {
|
||||
|
||||
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
private AnnotationConfigApplicationContext context;
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
this.context.close();
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultRepositoryConfiguration() throws Exception {
|
||||
TestPropertyValues.of("spring.datasource.initialize:false").applyTo(this.context);
|
||||
this.context.register(TestConfiguration.class, BaseConfiguration.class);
|
||||
this.context.refresh();
|
||||
load(TestConfiguration.class);
|
||||
assertThat(this.context.getBean(CountryRepository.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMixedRepositoryConfiguration() throws Exception {
|
||||
TestPropertyValues.of("spring.datasource.initialize:false").applyTo(this.context);
|
||||
this.context.register(MixedConfiguration.class, BaseConfiguration.class);
|
||||
this.context.refresh();
|
||||
load(MixedConfiguration.class);
|
||||
assertThat(this.context.getBean(CountryRepository.class)).isNotNull();
|
||||
assertThat(this.context.getBean(CityRepository.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJpaRepositoryConfigurationWithNeo4jTemplate() throws Exception {
|
||||
TestPropertyValues.of("spring.datasource.initialize:false").applyTo(this.context);
|
||||
this.context.register(JpaConfiguration.class, BaseConfiguration.class);
|
||||
this.context.refresh();
|
||||
load(JpaConfiguration.class);
|
||||
assertThat(this.context.getBean(CityRepository.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testJpaRepositoryConfigurationWithNeo4jOverlap() throws Exception {
|
||||
TestPropertyValues.of("spring.datasource.initialize:false").applyTo(this.context);
|
||||
this.context.register(OverlapConfiguration.class, BaseConfiguration.class);
|
||||
this.context.refresh();
|
||||
load(OverlapConfiguration.class);
|
||||
assertThat(this.context.getBean(CityRepository.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJpaRepositoryConfigurationWithNeo4jOverlapDisabled()
|
||||
throws Exception {
|
||||
TestPropertyValues
|
||||
.of("spring.datasource.initialize:false",
|
||||
"spring.data.neo4j.repositories.enabled:false")
|
||||
.applyTo(this.context);
|
||||
this.context.register(OverlapConfiguration.class, BaseConfiguration.class);
|
||||
this.context.refresh();
|
||||
load(OverlapConfiguration.class, "spring.data.neo4j.repositories.enabled:false");
|
||||
assertThat(this.context.getBean(CityRepository.class)).isNotNull();
|
||||
}
|
||||
|
||||
private void load(Class config, String... environment) {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
TestPropertyValues.of(environment)
|
||||
.and("spring.datasource.initialize", "false")
|
||||
.and("spring.data.neo4j.uri", "http://localhost:8989")
|
||||
.applyTo(ctx);
|
||||
ctx.register(config);
|
||||
ctx.register(DataSourceAutoConfiguration.class,
|
||||
HibernateJpaAutoConfiguration.class,
|
||||
JpaRepositoriesAutoConfiguration.class, Neo4jDataAutoConfiguration.class,
|
||||
Neo4jRepositoriesAutoConfiguration.class);
|
||||
ctx.refresh();
|
||||
this.context = ctx;
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@TestAutoConfigurationPackage(EmptyMarker.class)
|
||||
// Not this package or its parent
|
||||
|
|
@ -142,27 +140,4 @@ public class MixedNeo4jRepositoriesAutoConfigurationTests {
|
|||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@Import(Registrar.class)
|
||||
protected static class BaseConfiguration {
|
||||
|
||||
}
|
||||
|
||||
protected static class Registrar implements ImportSelector {
|
||||
|
||||
@Override
|
||||
public String[] selectImports(AnnotationMetadata importingClassMetadata) {
|
||||
List<String> names = new ArrayList<>();
|
||||
for (Class<?> type : new Class<?>[] { DataSourceAutoConfiguration.class,
|
||||
HibernateJpaAutoConfiguration.class,
|
||||
JpaRepositoriesAutoConfiguration.class,
|
||||
Neo4jDataAutoConfiguration.class,
|
||||
Neo4jRepositoriesAutoConfiguration.class }) {
|
||||
names.add(type.getName());
|
||||
}
|
||||
return names.toArray(new String[names.size()]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,7 +81,8 @@ public class Neo4jDataAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void customNeo4jTransactionManagerUsingProperties() {
|
||||
load(null, "spring.transaction.default-timeout=30",
|
||||
load(null, "spring.data.neo4j.uri=http://localhost:8989",
|
||||
"spring.transaction.default-timeout=30",
|
||||
"spring.transaction.rollback-on-commit-failure:true");
|
||||
Neo4jTransactionManager transactionManager = this.context
|
||||
.getBean(Neo4jTransactionManager.class);
|
||||
|
|
@ -110,6 +111,8 @@ public class Neo4jDataAutoConfigurationTests {
|
|||
@Test
|
||||
public void usesAutoConfigurationPackageToPickUpDomainTypes() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
TestPropertyValues.of("spring.data.neo4j.uri=http://localhost:8989")
|
||||
.applyTo(this.context);
|
||||
String cityPackage = City.class.getPackage().getName();
|
||||
AutoConfigurationPackages.register((BeanDefinitionRegistry) this.context,
|
||||
cityPackage);
|
||||
|
|
@ -123,14 +126,16 @@ public class Neo4jDataAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void openSessionInViewInterceptorCanBeDisabled() {
|
||||
load(null, "spring.data.neo4j.open-in-view:false");
|
||||
load(null, "spring.data.neo4j.uri=http://localhost:8989",
|
||||
"spring.data.neo4j.open-in-view:false");
|
||||
assertThat(this.context.getBeansOfType(OpenSessionInViewInterceptor.class))
|
||||
.isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eventListenersAreAutoRegistered() {
|
||||
load(EventListenerConfiguration.class);
|
||||
load(EventListenerConfiguration.class,
|
||||
"spring.data.neo4j.uri=http://localhost:8989");
|
||||
Session session = this.context.getBean(SessionFactory.class).openSession();
|
||||
session.notifyListeners(new PersistenceEvent(null, Event.TYPE.PRE_SAVE));
|
||||
verify(this.context.getBean("eventListenerOne", EventListener.class))
|
||||
|
|
|
|||
Loading…
Reference in New Issue