|
|
|
@ -20,18 +20,21 @@ import org.assertj.core.api.Assertions;
|
|
|
|
|
import org.junit.After;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
import org.neo4j.ogm.drivers.http.driver.HttpDriver;
|
|
|
|
|
import org.neo4j.ogm.session.Session;
|
|
|
|
|
import org.neo4j.ogm.session.SessionFactory;
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigurationPackages;
|
|
|
|
|
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
|
|
|
|
import org.springframework.boot.autoconfigure.data.neo4j.city.City;
|
|
|
|
|
import org.springframework.boot.test.util.EnvironmentTestUtils;
|
|
|
|
|
import org.springframework.context.ConfigurableApplicationContext;
|
|
|
|
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
import org.springframework.data.neo4j.mapping.Neo4jMappingContext;
|
|
|
|
|
import org.springframework.data.neo4j.template.Neo4jOperations;
|
|
|
|
|
import org.springframework.data.neo4j.web.support.OpenSessionInViewInterceptor;
|
|
|
|
|
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
@ -43,11 +46,12 @@ import static org.mockito.Mockito.mock;
|
|
|
|
|
* @author Stephane Nicoll
|
|
|
|
|
* @author Michael Hunger
|
|
|
|
|
* @author Vince Bickers
|
|
|
|
|
* @author Andy Wilkinson
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
|
public class Neo4jDataAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
private AnnotationConfigApplicationContext context;
|
|
|
|
|
private ConfigurableApplicationContext context;
|
|
|
|
|
|
|
|
|
|
@After
|
|
|
|
|
public void close() {
|
|
|
|
@ -59,31 +63,20 @@ public class Neo4jDataAutoConfigurationTests {
|
|
|
|
|
@Test
|
|
|
|
|
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(SessionFactory.class)).hasSize(1);
|
|
|
|
|
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.getBeansOfType(Neo4jOperations.class)).hasSize(1);
|
|
|
|
|
assertThat(this.context.getBeansOfType(OpenSessionInViewInterceptor.class))
|
|
|
|
|
.isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void customNeo4jOperations() {
|
|
|
|
|
load(CustomNeo4jOperations.class);
|
|
|
|
|
assertThat(this.context.getBean(Neo4jOperations.class))
|
|
|
|
|
.isSameAs(this.context.getBean("myNeo4jOperations"));
|
|
|
|
|
public void customSessionFactory() {
|
|
|
|
|
load(CustomSessionFactory.class);
|
|
|
|
|
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);
|
|
|
|
|
assertThat(this.context.getBeansOfType(SessionFactory.class)).hasSize(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -91,25 +84,41 @@ public class Neo4jDataAutoConfigurationTests {
|
|
|
|
|
load(CustomConfiguration.class);
|
|
|
|
|
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(SessionFactory.class)).hasSize(1);
|
|
|
|
|
assertThat(this.context.getBeansOfType(org.neo4j.ogm.config.Configuration.class))
|
|
|
|
|
.hasSize(1);
|
|
|
|
|
assertThat(this.context.getBeansOfType(SessionFactory.class)).hasSize(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void customNeo4jOperations() {
|
|
|
|
|
load(CustomNeo4jOperations.class);
|
|
|
|
|
assertThat(this.context.getBean(Neo4jOperations.class))
|
|
|
|
|
.isSameAs(this.context.getBean("myNeo4jOperations"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void usesAutoConfigurationPackageToPickUpDomainTypes() {
|
|
|
|
|
this.context = new AnnotationConfigApplicationContext();
|
|
|
|
|
String cityPackage = City.class.getPackage().getName();
|
|
|
|
|
AutoConfigurationPackages.register(this.context, cityPackage);
|
|
|
|
|
this.context.register(Neo4jDataAutoConfiguration.class);
|
|
|
|
|
AutoConfigurationPackages.register((BeanDefinitionRegistry) this.context,
|
|
|
|
|
cityPackage);
|
|
|
|
|
((AnnotationConfigApplicationContext) this.context).register(
|
|
|
|
|
Neo4jDataAutoConfiguration.class,
|
|
|
|
|
Neo4jRepositoriesAutoConfiguration.class);
|
|
|
|
|
this.context.refresh();
|
|
|
|
|
assertDomainTypesDiscovered(this.context.getBean(Neo4jMappingContext.class),
|
|
|
|
|
City.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void openSessionInViewInterceptorCanBeEnabled() {
|
|
|
|
|
load(null, "spring.data.neo4j.open-in-view=true");
|
|
|
|
|
assertThat(this.context.getBeansOfType(OpenSessionInViewInterceptor.class))
|
|
|
|
|
.hasSize(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void load(Class<?> config, String... environment) {
|
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
|
|
|
|
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
|
|
|
|
|
EnvironmentTestUtils.addEnvironment(ctx, environment);
|
|
|
|
|
if (config != null) {
|
|
|
|
|
ctx.register(config);
|
|
|
|
@ -128,11 +137,11 @@ public class Neo4jDataAutoConfigurationTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
static class CustomNeo4jOperations {
|
|
|
|
|
static class CustomSessionFactory {
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
public Neo4jOperations myNeo4jOperations() {
|
|
|
|
|
return mock(Neo4jOperations.class);
|
|
|
|
|
public SessionFactory customSessionFactory() {
|
|
|
|
|
return mock(SessionFactory.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -150,4 +159,14 @@ public class Neo4jDataAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
static class CustomNeo4jOperations {
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
public Neo4jOperations myNeo4jOperations() {
|
|
|
|
|
return mock(Neo4jOperations.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|