From 5e8273c35c6e9b573380821eed6f2a0c767a8273 Mon Sep 17 00:00:00 2001 From: Greg Turnquist Date: Wed, 28 Jun 2017 13:06:14 -0500 Subject: [PATCH] Adapt to spring-session-core and its changes * Chief artifact changed maven coordinates * `SessionRepository` API changed --- pom.xml | 2 +- .../MongoOperationsSessionRepository.java | 11 ++++++-- .../MongoOperationsSessionRepositoryTest.java | 6 ++-- .../AbstractMongoRepositoryITest.java | 28 +++++++++---------- .../MongoRepositoryJdkSerializationITest.java | 4 +-- 5 files changed, 28 insertions(+), 23 deletions(-) diff --git a/pom.xml b/pom.xml index 54b159a..8eabe76 100644 --- a/pom.xml +++ b/pom.xml @@ -430,7 +430,7 @@ org.springframework.session - spring-session + spring-session-core ${spring-session.version} diff --git a/src/main/java/org/springframework/session/data/mongo/MongoOperationsSessionRepository.java b/src/main/java/org/springframework/session/data/mongo/MongoOperationsSessionRepository.java index de10d6d..b5a3dac 100644 --- a/src/main/java/org/springframework/session/data/mongo/MongoOperationsSessionRepository.java +++ b/src/main/java/org/springframework/session/data/mongo/MongoOperationsSessionRepository.java @@ -71,6 +71,7 @@ public class MongoOperationsSessionRepository this.mongoOperations = mongoOperations; } + @Override public MongoSession createSession() { MongoSession session = new MongoSession(); @@ -82,13 +83,15 @@ public class MongoOperationsSessionRepository return session; } + @Override public void save(MongoSession session) { DBObject sessionDbObject = convertToDBObject(session); this.mongoOperations.save(sessionDbObject, this.collectionName); } - public MongoSession getSession(String id) { + @Override + public MongoSession findById(String id) { Document sessionWrapper = findSession(id); @@ -99,7 +102,7 @@ public class MongoOperationsSessionRepository MongoSession session = convertToSession(sessionWrapper); if (session.isExpired()) { - delete(id); + deleteById(id); return null; } @@ -115,6 +118,7 @@ public class MongoOperationsSessionRepository * @param indexValue the value of the index to search for. * @return sessions map */ + @Override public Map findByIndexNameAndIndexValue(String indexName, String indexValue) { HashMap result = new HashMap(); @@ -135,7 +139,8 @@ public class MongoOperationsSessionRepository return result; } - public void delete(String id) { + @Override + public void deleteById(String id) { this.mongoOperations.remove(findSession(id), this.collectionName); } diff --git a/src/test/java/org/springframework/session/data/mongo/MongoOperationsSessionRepositoryTest.java b/src/test/java/org/springframework/session/data/mongo/MongoOperationsSessionRepositoryTest.java index c325bbd..6279b3c 100644 --- a/src/test/java/org/springframework/session/data/mongo/MongoOperationsSessionRepositoryTest.java +++ b/src/test/java/org/springframework/session/data/mongo/MongoOperationsSessionRepositoryTest.java @@ -121,7 +121,7 @@ public class MongoOperationsSessionRepositoryTest { TypeDescriptor.valueOf(MongoSession.class))).willReturn(session); // when - MongoSession retrievedSession = this.repository.getSession(sessionId); + MongoSession retrievedSession = this.repository.findById(sessionId); // then assertThat(retrievedSession).isEqualTo(session); @@ -143,7 +143,7 @@ public class MongoOperationsSessionRepositoryTest { TypeDescriptor.valueOf(MongoSession.class))).willReturn(session); // when - this.repository.getSession(sessionId); + this.repository.findById(sessionId); // then verify(this.mongoOperations).remove(any(Document.class), @@ -161,7 +161,7 @@ public class MongoOperationsSessionRepositoryTest { eq(MongoOperationsSessionRepository.DEFAULT_COLLECTION_NAME))).willReturn(sessionDocument); // when - this.repository.delete(sessionId); + this.repository.deleteById(sessionId); // then verify(this.mongoOperations).remove(any(Document.class), diff --git a/src/test/java/org/springframework/session/data/mongo/integration/AbstractMongoRepositoryITest.java b/src/test/java/org/springframework/session/data/mongo/integration/AbstractMongoRepositoryITest.java index 00eb87f..ce799c6 100644 --- a/src/test/java/org/springframework/session/data/mongo/integration/AbstractMongoRepositoryITest.java +++ b/src/test/java/org/springframework/session/data/mongo/integration/AbstractMongoRepositoryITest.java @@ -79,17 +79,17 @@ abstract public class AbstractMongoRepositoryITest extends AbstractITest { this.repository.save(toSave); - Session session = this.repository.getSession(toSave.getId()); + Session session = this.repository.findById(toSave.getId()); assertThat(session.getId()).isEqualTo(toSave.getId()); assertThat(session.getAttributeNames()).isEqualTo(toSave.getAttributeNames()); assertThat(session.getAttribute(expectedAttributeName)) .isEqualTo(toSave.getAttribute(expectedAttributeName)); - this.repository.delete(toSave.getId()); + this.repository.deleteById(toSave.getId()); String id = toSave.getId(); - assertThat(this.repository.getSession(id)).isNull(); + assertThat(this.repository.findById(id)).isNull(); } @Test @@ -99,19 +99,19 @@ abstract public class AbstractMongoRepositoryITest extends AbstractITest { toSave.setAttribute("a", "b"); this.repository.save(toSave); - toSave = this.repository.getSession(toSave.getId()); + toSave = this.repository.findById(toSave.getId()); toSave.setAttribute("1", "2"); this.repository.save(toSave); - toSave = this.repository.getSession(toSave.getId()); + toSave = this.repository.findById(toSave.getId()); - Session session = this.repository.getSession(toSave.getId()); + Session session = this.repository.findById(toSave.getId()); assertThat(session.getAttributeNames().size()).isEqualTo(2); assertThat(session.getAttribute("a")).isEqualTo(Optional.of("b")); assertThat(session.getAttribute("1")).isEqualTo(Optional.of("2")); - this.repository.delete(toSave.getId()); + this.repository.deleteById(toSave.getId()); } @Test @@ -129,7 +129,7 @@ abstract public class AbstractMongoRepositoryITest extends AbstractITest { assertThat(findByPrincipalName).hasSize(1); assertThat(findByPrincipalName.keySet()).containsOnly(toSave.getId()); - this.repository.delete(toSave.getId()); + this.repository.deleteById(toSave.getId()); findByPrincipalName = this.repository.findByIndexNameAndIndexValue(INDEX_NAME, principalName); @@ -168,7 +168,7 @@ abstract public class AbstractMongoRepositoryITest extends AbstractITest { this.repository.save(toSave); - toSave = this.repository.getSession(toSave.getId()); + toSave = this.repository.findById(toSave.getId()); toSave.setAttribute("other", "value"); this.repository.save(toSave); @@ -231,7 +231,7 @@ abstract public class AbstractMongoRepositoryITest extends AbstractITest { this.repository.save(toSave); - MongoSession getSession = this.repository.getSession(toSave.getId()); + MongoSession getSession = this.repository.findById(toSave.getId()); getSession.setAttribute(INDEX_NAME, null); this.repository.save(getSession); @@ -251,7 +251,7 @@ abstract public class AbstractMongoRepositoryITest extends AbstractITest { this.repository.save(toSave); - MongoSession getSession = this.repository.getSession(toSave.getId()); + MongoSession getSession = this.repository.findById(toSave.getId()); getSession.setAttribute(INDEX_NAME, principalNameChanged); this.repository.save(getSession); @@ -281,7 +281,7 @@ abstract public class AbstractMongoRepositoryITest extends AbstractITest { assertThat(findByPrincipalName).hasSize(1); assertThat(findByPrincipalName.keySet()).containsOnly(toSave.getId()); - this.repository.delete(toSave.getId()); + this.repository.deleteById(toSave.getId()); findByPrincipalName = this.repository.findByIndexNameAndIndexValue(INDEX_NAME, getSecurityName()); @@ -355,7 +355,7 @@ abstract public class AbstractMongoRepositoryITest extends AbstractITest { this.repository.save(toSave); - MongoSession getSession = this.repository.getSession(toSave.getId()); + MongoSession getSession = this.repository.findById(toSave.getId()); getSession.setAttribute(SPRING_SECURITY_CONTEXT, this.changedContext); this.repository.save(getSession); @@ -382,7 +382,7 @@ abstract public class AbstractMongoRepositoryITest extends AbstractITest { // then MongoSession expiredSessionFromDb = this.repository - .getSession(expiredSession.getId()); + .findById(expiredSession.getId()); assertThat(expiredSessionFromDb).isNull(); } diff --git a/src/test/java/org/springframework/session/data/mongo/integration/MongoRepositoryJdkSerializationITest.java b/src/test/java/org/springframework/session/data/mongo/integration/MongoRepositoryJdkSerializationITest.java index 202a993..507fad8 100644 --- a/src/test/java/org/springframework/session/data/mongo/integration/MongoRepositoryJdkSerializationITest.java +++ b/src/test/java/org/springframework/session/data/mongo/integration/MongoRepositoryJdkSerializationITest.java @@ -48,7 +48,7 @@ public class MongoRepositoryJdkSerializationITest extends AbstractMongoRepositor this.repository.save(toSave); - MongoSession getSession = this.repository.getSession(toSave.getId()); + MongoSession getSession = this.repository.findById(toSave.getId()); getSession.setAttribute(INDEX_NAME, null); this.repository.save(getSession); @@ -66,7 +66,7 @@ public class MongoRepositoryJdkSerializationITest extends AbstractMongoRepositor this.repository.save(toSave); - toSave = this.repository.getSession(toSave.getId()); + toSave = this.repository.findById(toSave.getId()); toSave.setAttribute("other", "value"); this.repository.save(toSave);