Fix Neo4J Tests

Update Neo4J tests following SPR-17333 which has broken our previous
method of simulating Embedded Neo4J.

Closes gh-14779
pull/14783/head
Phillip Webb 6 years ago
parent 33c2d24560
commit b1d4cf4ea8

@ -785,6 +785,11 @@
<artifactId>neo4j-ogm-http-driver</artifactId> <artifactId>neo4j-ogm-http-driver</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-embedded-driver</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId> <artifactId>log4j-over-slf4j</artifactId>

@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.data.neo4j;
import org.junit.After; import org.junit.After;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver;
import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage;
import org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration; import org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration;
@ -30,6 +31,7 @@ import org.springframework.boot.autoconfigure.data.neo4j.empty.EmptyMarker;
import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.util.TestPropertyValues; import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -92,6 +94,7 @@ public class MixedNeo4jRepositoriesAutoConfigurationTests {
private void load(Class<?> config, String... environment) { private void load(Class<?> config, String... environment) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.setClassLoader(new FilteredClassLoader(EmbeddedDriver.class));
TestPropertyValues.of(environment) TestPropertyValues.of(environment)
.and("spring.datasource.initialization-mode=never").applyTo(context); .and("spring.datasource.initialization-mode=never").applyTo(context);
context.register(config); context.register(config);

@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.data.neo4j;
import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.Caffeine;
import org.junit.Test; import org.junit.Test;
import org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver;
import org.neo4j.ogm.session.Session; import org.neo4j.ogm.session.Session;
import org.neo4j.ogm.session.SessionFactory; import org.neo4j.ogm.session.SessionFactory;
import org.neo4j.ogm.session.event.Event; import org.neo4j.ogm.session.event.Event;
@ -63,6 +64,7 @@ import static org.mockito.Mockito.verify;
public class Neo4jDataAutoConfigurationTests { public class Neo4jDataAutoConfigurationTests {
private WebApplicationContextRunner contextRunner = new WebApplicationContextRunner() private WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
.withClassLoader(new FilteredClassLoader(EmbeddedDriver.class))
.withUserConfiguration(TestConfiguration.class) .withUserConfiguration(TestConfiguration.class)
.withConfiguration(AutoConfigurations.of(Neo4jDataAutoConfiguration.class, .withConfiguration(AutoConfigurations.of(Neo4jDataAutoConfiguration.class,
TransactionAutoConfiguration.class)); TransactionAutoConfiguration.class));
@ -120,6 +122,7 @@ public class Neo4jDataAutoConfigurationTests {
@Test @Test
public void usesAutoConfigurationPackageToPickUpDomainTypes() { public void usesAutoConfigurationPackageToPickUpDomainTypes() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.setClassLoader(new FilteredClassLoader(EmbeddedDriver.class));
String cityPackage = City.class.getPackage().getName(); String cityPackage = City.class.getPackage().getName();
AutoConfigurationPackages.register(context, cityPackage); AutoConfigurationPackages.register(context, cityPackage);
context.register(Neo4jDataAutoConfiguration.class, context.register(Neo4jDataAutoConfiguration.class,
@ -170,6 +173,7 @@ public class Neo4jDataAutoConfigurationTests {
@Test @Test
public void providesASingletonScopedBookmarkManagerIfNecessaryAndPossible() { public void providesASingletonScopedBookmarkManagerIfNecessaryAndPossible() {
new ApplicationContextRunner() new ApplicationContextRunner()
.withClassLoader(new FilteredClassLoader(EmbeddedDriver.class))
.withUserConfiguration(TestConfiguration.class, .withUserConfiguration(TestConfiguration.class,
BookmarkManagementEnabledConfiguration.class) BookmarkManagementEnabledConfiguration.class)
.withConfiguration(AutoConfigurations.of(Neo4jDataAutoConfiguration.class, .withConfiguration(AutoConfigurations.of(Neo4jDataAutoConfiguration.class,
@ -183,7 +187,9 @@ public class Neo4jDataAutoConfigurationTests {
@Test @Test
public void doesNotProvideABookmarkManagerIfNotPossible() { public void doesNotProvideABookmarkManagerIfNotPossible() {
this.contextRunner.withClassLoader(new FilteredClassLoader(Caffeine.class)) this.contextRunner
.withClassLoader(
new FilteredClassLoader(Caffeine.class, EmbeddedDriver.class))
.withUserConfiguration(BookmarkManagementEnabledConfiguration.class) .withUserConfiguration(BookmarkManagementEnabledConfiguration.class)
.run((context) -> assertThat(context) .run((context) -> assertThat(context)
.doesNotHaveBean(BookmarkManager.class)); .doesNotHaveBean(BookmarkManager.class));

@ -16,17 +16,16 @@
package org.springframework.boot.autoconfigure.data.neo4j; package org.springframework.boot.autoconfigure.data.neo4j;
import java.net.URL;
import java.net.URLClassLoader;
import com.hazelcast.util.Base64; import com.hazelcast.util.Base64;
import org.junit.After; import org.junit.After;
import org.junit.Test; import org.junit.Test;
import org.neo4j.ogm.config.AutoIndexMode; import org.neo4j.ogm.config.AutoIndexMode;
import org.neo4j.ogm.config.Configuration; import org.neo4j.ogm.config.Configuration;
import org.neo4j.ogm.config.Credentials; import org.neo4j.ogm.config.Credentials;
import org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.util.TestPropertyValues; import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@ -174,23 +173,9 @@ public class Neo4jPropertiesTests {
public Neo4jProperties load(boolean embeddedAvailable, String... environment) { public Neo4jProperties load(boolean embeddedAvailable, String... environment) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.setClassLoader(new URLClassLoader(new URL[0], getClass().getClassLoader()) { if (!embeddedAvailable) {
ctx.setClassLoader(new FilteredClassLoader(EmbeddedDriver.class));
@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);
}
});
TestPropertyValues.of(environment).applyTo(ctx); TestPropertyValues.of(environment).applyTo(ctx);
ctx.register(TestConfiguration.class); ctx.register(TestConfiguration.class);
ctx.refresh(); ctx.refresh();
@ -204,8 +189,4 @@ public class Neo4jPropertiesTests {
} }
private static class TestEmbeddedDriver {
}
} }

Loading…
Cancel
Save