Make reactive session settings configurable through setters
Resolves #11
This commit is contained in:
@@ -145,10 +145,18 @@ public class ReactiveMongoOperationsSessionRepository implements ReactorSessionR
|
||||
this.maxInactiveIntervalInSeconds = maxInactiveIntervalInSeconds;
|
||||
}
|
||||
|
||||
public Integer getMaxInactiveIntervalInSeconds() {
|
||||
return maxInactiveIntervalInSeconds;
|
||||
}
|
||||
|
||||
public void setCollectionName(String collectionName) {
|
||||
this.collectionName = collectionName;
|
||||
}
|
||||
|
||||
public String getCollectionName() {
|
||||
return collectionName;
|
||||
}
|
||||
|
||||
public MongoOperations getBlockingMongoOperations() {
|
||||
return this.blockingMongoOperations;
|
||||
}
|
||||
|
||||
@@ -93,4 +93,19 @@ public class ReactiveMongoWebSessionConfiguration implements EmbeddedValueResolv
|
||||
public void setEmbeddedValueResolver(StringValueResolver embeddedValueResolver) {
|
||||
this.embeddedValueResolver = embeddedValueResolver;
|
||||
}
|
||||
public Integer getMaxInactiveIntervalInSeconds() {
|
||||
return maxInactiveIntervalInSeconds;
|
||||
}
|
||||
|
||||
public void setMaxInactiveIntervalInSeconds(Integer maxInactiveIntervalInSeconds) {
|
||||
this.maxInactiveIntervalInSeconds = maxInactiveIntervalInSeconds;
|
||||
}
|
||||
|
||||
public String getCollectionName() {
|
||||
return collectionName;
|
||||
}
|
||||
|
||||
public void setCollectionName(String collectionName) {
|
||||
this.collectionName = collectionName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ package org.springframework.session.data.mongo.config.annotation.web.reactive;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
import static org.mockito.BDDMockito.times;
|
||||
import static org.mockito.BDDMockito.verify;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@@ -155,6 +157,18 @@ public class ReactiveMongoWebSessionConfigurationTest {
|
||||
verify(indexOperations, times(1)).ensureIndex(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void overrideCollectionAndInactiveIntervalThroughConfigurationOptions() {
|
||||
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.register(CustomizedReactiveConfiguration.class);
|
||||
this.context.refresh();
|
||||
|
||||
ReactiveMongoOperationsSessionRepository repository = this.context.getBean(ReactiveMongoOperationsSessionRepository.class);
|
||||
assertThat(repository.getCollectionName()).isEqualTo("custom-collection");
|
||||
assertThat(repository.getMaxInactiveIntervalInSeconds()).isEqualTo(123);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reflectively extract the {@link AbstractMongoSessionConverter} from the {@link ReactiveMongoOperationsSessionRepository}.
|
||||
* This is to avoid expanding the surface area of the API.
|
||||
@@ -240,4 +254,19 @@ public class ReactiveMongoWebSessionConfigurationTest {
|
||||
return mongoOperations;
|
||||
}
|
||||
}
|
||||
|
||||
@EnableSpringWebSession
|
||||
static class CustomizedReactiveConfiguration extends ReactiveMongoWebSessionConfiguration {
|
||||
|
||||
@Bean
|
||||
ReactiveMongoOperations reactiveMongoOperations() {
|
||||
return mock(ReactiveMongoOperations.class);
|
||||
}
|
||||
|
||||
public CustomizedReactiveConfiguration() {
|
||||
|
||||
this.setCollectionName("custom-collection");
|
||||
this.setMaxInactiveIntervalInSeconds(123);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user