Handle removing sessions that don't exist

Resolves #21
This commit is contained in:
Greg Turnquist
2018-01-10 15:52:45 -06:00
parent 6be92ebbfe
commit b22cc99899
2 changed files with 8 additions and 2 deletions

View File

@@ -23,11 +23,11 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import javax.annotation.PostConstruct;
import org.bson.Document;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.index.IndexOperations;
import org.springframework.data.mongodb.core.query.Query;
@@ -141,7 +141,8 @@ public class MongoOperationsSessionRepository
@Override
public void deleteById(String id) {
this.mongoOperations.remove(findSession(id), this.collectionName);
Optional.ofNullable(findSession(id))
.ifPresent(document -> this.mongoOperations.remove(document, this.collectionName));
}
@PostConstruct

View File

@@ -137,6 +137,11 @@ abstract public class AbstractMongoRepositoryITest extends AbstractITest {
assertThat(findByPrincipalName.keySet()).doesNotContain(toSave.getId());
}
@Test
public void nonExistentSessionShouldNotBreakMongo() {
this.repository.deleteById("doesn't exist");
}
@Test
public void findByPrincipalNameNoPrincipalNameChange() throws Exception {