Polish contribution

Closes gh-919
This commit is contained in:
Vedran Pavic
2017-11-10 22:55:14 +01:00
parent 5f23a41674
commit 36d349f328
8 changed files with 36 additions and 60 deletions

View File

@@ -85,7 +85,8 @@ public class ReactiveRedisOperationsSessionRepositoryTests {
public void customRedisKeyNamespace() {
this.repository.setRedisKeyNamespace("test");
assertThat(ReflectionTestUtils.getField(this.repository, "keyPrefix")).isEqualTo("test:");
assertThat(ReflectionTestUtils.getField(this.repository, "namespace"))
.isEqualTo("test:");
}
@Test

View File

@@ -16,7 +16,6 @@
package org.springframework.session.data.redis;
import java.text.MessageFormat;
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
@@ -710,26 +709,8 @@ public class RedisOperationsSessionRepositoryTests {
this.redisRepository.setRedisFlushMode(null);
}
@Test
public void testDefaultRedisNamespace() {
RedisSession session = this.redisRepository.new RedisSession(new MapSession());
session.setMaxInactiveInterval(Duration.ZERO);
given(this.redisOperations.boundHashOps(anyString()))
.willReturn(this.boundHashOperations);
given(this.redisOperations.boundSetOps(anyString()))
.willReturn(this.boundSetOperations);
this.redisRepository.save(session);
String id = session.getId();
verify(this.redisOperations, atLeastOnce())
.delete(getKey("expires:" + id));
verify(this.redisOperations, never()).boundValueOps(getKey("expires:" + id));
}
@Test
public void testRedisNamespaceChange() {
public void changeRedisNamespace() {
String namespace = "foo:bar";
this.redisRepository.setRedisKeyNamespace(namespace);
RedisSession session = this.redisRepository.new RedisSession(new MapSession());
@@ -743,29 +724,23 @@ public class RedisOperationsSessionRepositoryTests {
String id = session.getId();
verify(this.redisOperations, atLeastOnce())
.delete(getKeyWithinNamespace(namespace, "expires:" + id));
verify(this.redisOperations, never()).boundValueOps(getKeyWithinNamespace(namespace, "expires:" + id));
.delete(namespace + ":sessions:expires:" + id);
verify(this.redisOperations, never())
.boundValueOps(namespace + ":sessions:expires:" + id);
}
@Test(expected = IllegalArgumentException.class)
public void testLaunchExceptionOnNullNamespace() {
public void setRedisKeyNamespaceNullNamespace() {
this.redisRepository.setRedisKeyNamespace(null);
}
@Test(expected = IllegalArgumentException.class)
public void testLaunchExceptionOnEmptyNamespace() {
this.redisRepository.setRedisKeyNamespace("");
public void setRedisKeyNamespaceEmptyNamespace() {
this.redisRepository.setRedisKeyNamespace(" ");
}
private String getKey(String id) {
return getKeyWithinNamespace("spring:session", id);
}
private String getKeyWithinNamespace(String prefix, String id) {
if (prefix.endsWith(":")) {
prefix = prefix.substring(0, prefix.length());
}
return MessageFormat.format("{0}:sessions:{1}", prefix, id);
return "spring:session:sessions:" + id;
}
private Map map(Object... objects) {

View File

@@ -81,7 +81,7 @@ public class RedisWebSessionConfigurationTests {
ReactiveRedisOperationsSessionRepository repository = this.context
.getBean(ReactiveRedisOperationsSessionRepository.class);
assertThat(repository).isNotNull();
assertThat(ReflectionTestUtils.getField(repository, "keyPrefix"))
assertThat(ReflectionTestUtils.getField(repository, "namespace"))
.isEqualTo(REDIS_NAMESPACE + ":");
}