Polish Neo4J BookmarkManager auto-configuration
Closes gh-14568
This commit is contained in:
parent
b7847d98a7
commit
2add65fe15
|
@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.data.neo4j;
|
|||
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
|
@ -41,7 +40,7 @@ import org.springframework.web.context.WebApplicationContext;
|
|||
* bound to the application or the request, as recommend by Spring Data Neo4j.
|
||||
*
|
||||
* @author Michael Simons
|
||||
* @since 2.1
|
||||
* @since 2.1.0
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass({ Caffeine.class, CaffeineCacheManager.class })
|
||||
|
@ -50,17 +49,16 @@ import org.springframework.web.context.WebApplicationContext;
|
|||
BookmarkInterceptor.class })
|
||||
class Neo4jBookmarkManagementConfiguration {
|
||||
|
||||
static final String BOOKMARK_MANAGER_BEAN_NAME = "bookmarkManager";
|
||||
private static final String BOOKMARK_MANAGER_BEAN_NAME = "bookmarkManager";
|
||||
|
||||
@Bean(BOOKMARK_MANAGER_BEAN_NAME)
|
||||
@Scope(value = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.INTERFACES)
|
||||
@ConditionalOnWebApplication
|
||||
@Scope(value = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.INTERFACES)
|
||||
public BookmarkManager requestScopedBookmarkManager() {
|
||||
return new CaffeineBookmarkManager();
|
||||
}
|
||||
|
||||
@Bean(BOOKMARK_MANAGER_BEAN_NAME)
|
||||
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
|
||||
@ConditionalOnNotWebApplication
|
||||
public BookmarkManager singletonScopedBookmarkManager() {
|
||||
return new CaffeineBookmarkManager();
|
||||
|
|
|
@ -53,7 +53,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|||
* @author Vince Bickers
|
||||
* @author Stephane Nicoll
|
||||
* @author Kazuki Shimizu
|
||||
* @author Michael Simons
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Configuration
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,10 +16,7 @@
|
|||
|
||||
package org.springframework.boot.autoconfigure.data.neo4j;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.junit.Test;
|
||||
import org.neo4j.ogm.session.Session;
|
||||
import org.neo4j.ogm.session.SessionFactory;
|
||||
|
@ -27,6 +24,7 @@ import org.neo4j.ogm.session.event.Event;
|
|||
import org.neo4j.ogm.session.event.EventListener;
|
||||
import org.neo4j.ogm.session.event.PersistenceEvent;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurationPackages;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.data.neo4j.city.City;
|
||||
|
@ -36,7 +34,6 @@ import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfigu
|
|||
import org.springframework.boot.test.context.FilteredClassLoader;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
@ -160,18 +157,14 @@ public class Neo4jDataAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void providesARequestScopedBookmarkManangerIfNecessaryAndPossible() {
|
||||
Predicate<ConfigurableApplicationContext> hasRequestScopedBookmarkManager = (
|
||||
context) -> context.getBeanFactory() //
|
||||
.getBeanDefinition("scopedTarget."
|
||||
+ Neo4jBookmarkManagementConfiguration.BOOKMARK_MANAGER_BEAN_NAME) //
|
||||
.getScope() //
|
||||
.equals(WebApplicationContext.SCOPE_REQUEST);
|
||||
|
||||
this.contextRunner
|
||||
.withUserConfiguration(BookmarkManagementEnabledConfiguration.class)
|
||||
.run((context) -> assertThat(context)
|
||||
.satisfies(new Condition<>(hasRequestScopedBookmarkManager,
|
||||
"hasRequestScopedBookmarkManager")));
|
||||
.run((context) -> {
|
||||
BeanDefinition bookmarkManagerBean = context.getBeanFactory()
|
||||
.getBeanDefinition("scopedTarget.bookmarkManager");
|
||||
assertThat(bookmarkManagerBean.getScope())
|
||||
.isEqualTo(WebApplicationContext.SCOPE_REQUEST);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -181,8 +174,11 @@ public class Neo4jDataAutoConfigurationTests {
|
|||
BookmarkManagementEnabledConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(Neo4jDataAutoConfiguration.class,
|
||||
TransactionAutoConfiguration.class))
|
||||
.run((context) -> assertThat(context)
|
||||
.hasSingleBean(BookmarkManager.class));
|
||||
.run((context) -> {
|
||||
assertThat(context).hasSingleBean(BookmarkManager.class);
|
||||
assertThat(context.getBeanDefinitionNames())
|
||||
.doesNotContain("scopedTarget.bookmarkManager");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue