Ensure configuration classes can be used with @Import

This commit adds tests that verify that all Spring Session configuration classes can be used with @Import, and fixes JDBC and Hazelcast HttpSession configurations and Redis WebSession configuration.
This commit is contained in:
Vedran Pavic
2022-09-26 10:47:56 +02:00
committed by Rob Winch
parent 4b34f35b82
commit da8e5fbbac
10 changed files with 149 additions and 0 deletions

View File

@@ -194,6 +194,13 @@ public class MongoHttpSessionConfigurationTest {
indexResolver);
}
@Test
void importConfigAndCustomize() {
registerAndRefresh(ImportConfigAndCustomizeConfiguration.class);
MongoIndexedSessionRepository sessionRepository = this.context.getBean(MongoIndexedSessionRepository.class);
assertThat(sessionRepository).extracting("maxInactiveIntervalInSeconds").isEqualTo(0);
}
private void registerAndRefresh(Class<?>... annotatedClasses) {
this.context.register(annotatedClasses);
@@ -333,4 +340,15 @@ public class MongoHttpSessionConfigurationTest {
}
@Configuration(proxyBeanMethods = false)
@Import(MongoHttpSessionConfiguration.class)
static class ImportConfigAndCustomizeConfiguration extends BaseConfiguration {
@Bean
SessionRepositoryCustomizer<MongoIndexedSessionRepository> sessionRepositoryCustomizer() {
return (sessionRepository) -> sessionRepository.setMaxInactiveIntervalInSeconds(0);
}
}
}

View File

@@ -27,6 +27,7 @@ import org.springframework.beans.factory.UnsatisfiedDependencyException;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.ReactiveMongoOperations;
import org.springframework.data.mongodb.core.index.IndexOperations;
@@ -220,6 +221,15 @@ public class ReactiveMongoWebSessionConfigurationTest {
indexResolver);
}
@Test
void importConfigAndCustomize() {
this.context = new AnnotationConfigApplicationContext();
this.context.register(ImportConfigAndCustomizeConfiguration.class);
this.context.refresh();
ReactiveMongoSessionRepository sessionRepository = this.context.getBean(ReactiveMongoSessionRepository.class);
assertThat(sessionRepository).extracting("maxInactiveIntervalInSeconds").isEqualTo(0);
}
/**
* Reflectively extract the {@link AbstractMongoSessionConverter} from the
* {@link ReactiveMongoSessionRepository}. This is to avoid expanding the surface area
@@ -393,4 +403,20 @@ public class ReactiveMongoWebSessionConfigurationTest {
}
@Configuration(proxyBeanMethods = false)
@Import(ReactiveMongoWebSessionConfiguration.class)
static class ImportConfigAndCustomizeConfiguration {
@Bean
ReactiveMongoOperations operations() {
return mock(ReactiveMongoOperations.class);
}
@Bean
ReactiveSessionRepositoryCustomizer<ReactiveMongoSessionRepository> sessionRepositoryCustomizer() {
return (sessionRepository) -> sessionRepository.setMaxInactiveIntervalInSeconds(0);
}
}
}