Remove Compiler Warnings

* Fixes Generics
* Remove unused imports
* Ignore serialize warnings in tests

Fixes gh-40
This commit is contained in:
Rob Winch
2014-09-29 22:00:46 -05:00
parent 52827f4a46
commit 6130a10d14
10 changed files with 1326 additions and 1311 deletions

View File

@@ -30,99 +30,97 @@ import java.net.ServerSocket;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class RedisOperationsSessionRepositoryITests {
private RedisServer redisServer;
public class RedisOperationsSessionRepositoryITests<S extends Session> {
private RedisServer redisServer;
@Autowired
private SessionRepository repository;
@Autowired
private SessionRepository<S> repository;
@Before
public void setup() throws IOException {
redisServer = new RedisServer(getPort());
redisServer.start();
}
@Before
public void setup() throws IOException {
redisServer = new RedisServer(getPort());
redisServer.start();
}
@After
public void shutdown() throws InterruptedException {
redisServer.stop();
}
@After
public void shutdown() throws InterruptedException {
redisServer.stop();
}
@Test
public void saves() {
Session toSave = repository.createSession();
toSave.setAttribute("a", "b");
Authentication toSaveToken = new UsernamePasswordAuthenticationToken("user","password", AuthorityUtils.createAuthorityList("ROLE_USER"));
SecurityContext toSaveContext = SecurityContextHolder.createEmptyContext();
toSaveContext.setAuthentication(toSaveToken);
toSave.setAttribute("SPRING_SECURITY_CONTEXT", toSaveContext);
@Test
public void saves() {
S toSave = repository.createSession();
toSave.setAttribute("a", "b");
Authentication toSaveToken = new UsernamePasswordAuthenticationToken("user","password", AuthorityUtils.createAuthorityList("ROLE_USER"));
SecurityContext toSaveContext = SecurityContextHolder.createEmptyContext();
toSaveContext.setAuthentication(toSaveToken);
toSave.setAttribute("SPRING_SECURITY_CONTEXT", toSaveContext);
repository.save(toSave);
repository.save(toSave);
Session session = repository.getSession(toSave.getId());
Session session = repository.getSession(toSave.getId());
assertThat(session.getId()).isEqualTo(toSave.getId());
assertThat(session.getAttributeNames()).isEqualTo(session.getAttributeNames());
assertThat(session.getAttribute("a")).isEqualTo(toSave.getAttribute("a"));
assertThat(session.getId()).isEqualTo(toSave.getId());
assertThat(session.getAttributeNames()).isEqualTo(session.getAttributeNames());
assertThat(session.getAttribute("a")).isEqualTo(toSave.getAttribute("a"));
SecurityContext context = (SecurityContext) session.getAttribute("SPRING_SECURITY_CONTEXT");
repository.delete(toSave.getId());
repository.delete(toSave.getId());
assertThat(repository.getSession(toSave.getId())).isNull();
}
assertThat(repository.getSession(toSave.getId())).isNull();
}
@Test
public void putAllOnSingleAttrDoesNotRemoveOld() {
S toSave = repository.createSession();
toSave.setAttribute("a", "b");
@Test
public void putAllOnSingleAttrDoesNotRemoveOld() {
Session toSave = repository.createSession();
toSave.setAttribute("a", "b");
repository.save(toSave);
toSave = repository.getSession(toSave.getId());
repository.save(toSave);
toSave = repository.getSession(toSave.getId());
toSave.setAttribute("1", "2");
toSave.setAttribute("1", "2");
repository.save(toSave);
toSave = repository.getSession(toSave.getId());
repository.save(toSave);
toSave = repository.getSession(toSave.getId());
Session session = repository.getSession(toSave.getId());
assertThat(session.getAttributeNames().size()).isEqualTo(2);
assertThat(session.getAttribute("a")).isEqualTo("b");
assertThat(session.getAttribute("1")).isEqualTo("2");
}
Session session = repository.getSession(toSave.getId());
assertThat(session.getAttributeNames().size()).isEqualTo(2);
assertThat(session.getAttribute("a")).isEqualTo("b");
assertThat(session.getAttribute("1")).isEqualTo("2");
}
@Configuration
static class Config {
@Bean
public JedisConnectionFactory connectionFactory() throws Exception {
JedisConnectionFactory factory = new JedisConnectionFactory();
factory.setPort(getPort());
factory.setUsePool(false);
return factory;
}
@Configuration
static class Config {
@Bean
public JedisConnectionFactory connectionFactory() throws Exception {
JedisConnectionFactory factory = new JedisConnectionFactory();
factory.setPort(getPort());
factory.setUsePool(false);
return factory;
}
@Bean
public RedisTemplate<String,ExpiringSession> redisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, ExpiringSession> template = new RedisTemplate<String, ExpiringSession>();
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());
template.setConnectionFactory(connectionFactory);
return template;
}
@Bean
public RedisTemplate<String,ExpiringSession> redisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, ExpiringSession> template = new RedisTemplate<String, ExpiringSession>();
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());
template.setConnectionFactory(connectionFactory);
return template;
}
@Bean
public RedisOperationsSessionRepository sessionRepository(RedisTemplate<String, ExpiringSession> redisTemplate) {
return new RedisOperationsSessionRepository(redisTemplate);
}
}
@Bean
public RedisOperationsSessionRepository sessionRepository(RedisTemplate<String, ExpiringSession> redisTemplate) {
return new RedisOperationsSessionRepository(redisTemplate);
}
}
private static Integer availablePort;
private static Integer availablePort;
private static int getPort() throws IOException {
if(availablePort == null) {
ServerSocket socket = new ServerSocket(0);
availablePort = socket.getLocalPort();
socket.close();
}
return availablePort;
}
private static int getPort() throws IOException {
if(availablePort == null) {
ServerSocket socket = new ServerSocket(0);
availablePort = socket.getLocalPort();
socket.close();
}
return availablePort;
}
}