Add tableName setter
Add tableName setter for JdbcHttpSessionConfiguration
This commit is contained in:
@@ -45,6 +45,7 @@ import org.springframework.util.StringUtils;
|
||||
* {@link DataSource} must be exposed as a Bean.
|
||||
*
|
||||
* @author Vedran Pavic
|
||||
* @author Eddú Meléndez
|
||||
* @since 1.2.0
|
||||
* @see EnableJdbcHttpSession
|
||||
*/
|
||||
@@ -106,6 +107,14 @@ public class JdbcHttpSessionConfiguration extends SpringHttpSessionConfiguration
|
||||
this.springSessionConversionService = conversionService;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public void setMaxInactiveIntervalInSeconds(Integer maxInactiveIntervalInSeconds) {
|
||||
this.maxInactiveIntervalInSeconds = maxInactiveIntervalInSeconds;
|
||||
}
|
||||
|
||||
private String getTableName() {
|
||||
if (StringUtils.hasText(this.tableName)) {
|
||||
return this.tableName;
|
||||
|
||||
@@ -40,6 +40,7 @@ import static org.mockito.Mockito.mock;
|
||||
* Tests for {@link JdbcHttpSessionConfiguration}.
|
||||
*
|
||||
* @author Vedran Pavic
|
||||
* @author Eddú Meléndez
|
||||
* @since 1.2.0
|
||||
*/
|
||||
public class JdbcHttpSessionConfigurationTests {
|
||||
@@ -107,6 +108,30 @@ public class JdbcHttpSessionConfigurationTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setCustomTableName() {
|
||||
registerAndRefresh(BaseConfiguration.class,
|
||||
CustomTableNameSetConfiguration.class);
|
||||
|
||||
JdbcHttpSessionConfiguration repository = this.context
|
||||
.getBean(JdbcHttpSessionConfiguration.class);
|
||||
assertThat(repository).isNotNull();
|
||||
assertThat(ReflectionTestUtils.getField(repository, "tableName")).isEqualTo(
|
||||
"custom_session");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setCustomMaxInactiveIntervalInSeconds() {
|
||||
registerAndRefresh(BaseConfiguration.class,
|
||||
CustomMaxInactiveIntervalInSecondsSetConfiguration.class);
|
||||
|
||||
JdbcHttpSessionConfiguration repository = this.context
|
||||
.getBean(JdbcHttpSessionConfiguration.class);
|
||||
assertThat(repository).isNotNull();
|
||||
assertThat(ReflectionTestUtils.getField(repository, "maxInactiveIntervalInSeconds")).isEqualTo(
|
||||
10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customMaxInactiveIntervalInSeconds() {
|
||||
registerAndRefresh(CustomMaxInactiveIntervalInSecondsConfiguration.class);
|
||||
@@ -180,6 +205,24 @@ public class JdbcHttpSessionConfigurationTests {
|
||||
static class CustomTableNameConfiguration extends BaseConfiguration {
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class CustomTableNameSetConfiguration extends JdbcHttpSessionConfiguration {
|
||||
|
||||
CustomTableNameSetConfiguration() {
|
||||
setTableName("custom_session");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class CustomMaxInactiveIntervalInSecondsSetConfiguration extends JdbcHttpSessionConfiguration {
|
||||
|
||||
CustomMaxInactiveIntervalInSecondsSetConfiguration() {
|
||||
setMaxInactiveIntervalInSeconds(10);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableJdbcHttpSession(maxInactiveIntervalInSeconds = MAX_INACTIVE_INTERVAL_IN_SECONDS)
|
||||
static class CustomMaxInactiveIntervalInSecondsConfiguration
|
||||
|
||||
Reference in New Issue
Block a user