Add tableName setter

Add tableName setter for JdbcHttpSessionConfiguration
This commit is contained in:
Rob Winch
2016-04-18 23:18:58 -05:00
2 changed files with 52 additions and 0 deletions

View File

@@ -45,6 +45,7 @@ import org.springframework.util.StringUtils;
* {@link DataSource} must be exposed as a Bean. * {@link DataSource} must be exposed as a Bean.
* *
* @author Vedran Pavic * @author Vedran Pavic
* @author Eddú Meléndez
* @since 1.2.0 * @since 1.2.0
* @see EnableJdbcHttpSession * @see EnableJdbcHttpSession
*/ */
@@ -106,6 +107,14 @@ public class JdbcHttpSessionConfiguration extends SpringHttpSessionConfiguration
this.springSessionConversionService = conversionService; this.springSessionConversionService = conversionService;
} }
public void setTableName(String tableName) {
this.tableName = tableName;
}
public void setMaxInactiveIntervalInSeconds(Integer maxInactiveIntervalInSeconds) {
this.maxInactiveIntervalInSeconds = maxInactiveIntervalInSeconds;
}
private String getTableName() { private String getTableName() {
if (StringUtils.hasText(this.tableName)) { if (StringUtils.hasText(this.tableName)) {
return this.tableName; return this.tableName;

View File

@@ -40,6 +40,7 @@ import static org.mockito.Mockito.mock;
* Tests for {@link JdbcHttpSessionConfiguration}. * Tests for {@link JdbcHttpSessionConfiguration}.
* *
* @author Vedran Pavic * @author Vedran Pavic
* @author Eddú Meléndez
* @since 1.2.0 * @since 1.2.0
*/ */
public class JdbcHttpSessionConfigurationTests { 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 @Test
public void customMaxInactiveIntervalInSeconds() { public void customMaxInactiveIntervalInSeconds() {
registerAndRefresh(CustomMaxInactiveIntervalInSecondsConfiguration.class); registerAndRefresh(CustomMaxInactiveIntervalInSecondsConfiguration.class);
@@ -180,6 +205,24 @@ public class JdbcHttpSessionConfigurationTests {
static class CustomTableNameConfiguration extends BaseConfiguration { 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 @Configuration
@EnableJdbcHttpSession(maxInactiveIntervalInSeconds = MAX_INACTIVE_INTERVAL_IN_SECONDS) @EnableJdbcHttpSession(maxInactiveIntervalInSeconds = MAX_INACTIVE_INTERVAL_IN_SECONDS)
static class CustomMaxInactiveIntervalInSecondsConfiguration static class CustomMaxInactiveIntervalInSecondsConfiguration