@Override public Mono<Void> deleteById(String id) { String sessionKey = getSessionKey(id); return this.sessionRedisOperations.delete(sessionKey).then(); }
@Test public void delete() { given(this.redisOperations.delete(anyString())).willReturn(Mono.just(1L)); StepVerifier.create(this.repository.deleteById("test")).verifyComplete(); verify(this.redisOperations).delete(anyString()); verifyZeroInteractions(this.redisOperations); verifyZeroInteractions(this.hashOperations); }
@Test public void getSessionNotFound() { given(this.redisOperations.opsForHash()).willReturn(this.hashOperations); given(this.hashOperations.entries(anyString())).willReturn(Flux.empty()); given(this.redisOperations.delete(anyString())).willReturn(Mono.just(0L)); StepVerifier.create(this.repository.findById("test")).verifyComplete(); verify(this.redisOperations).opsForHash(); verify(this.hashOperations).entries(anyString()); verify(this.redisOperations).delete(anyString()); verifyZeroInteractions(this.redisOperations); verifyZeroInteractions(this.hashOperations); }
@Test @SuppressWarnings("unchecked") public void getSessionExpired() { given(this.redisOperations.opsForHash()).willReturn(this.hashOperations); Map map = map(ReactiveRedisOperationsSessionRepository.CREATION_TIME_KEY, 0L, ReactiveRedisOperationsSessionRepository.MAX_INACTIVE_INTERVAL_KEY, 1, ReactiveRedisOperationsSessionRepository.LAST_ACCESSED_TIME_KEY, Instant.now().minus(5, ChronoUnit.MINUTES).toEpochMilli()); given(this.hashOperations.entries(anyString())) .willReturn(Flux.fromIterable(map.entrySet())); given(this.redisOperations.delete(anyString())).willReturn(Mono.just(0L)); StepVerifier.create(this.repository.findById("test")).verifyComplete(); verify(this.redisOperations).opsForHash(); verify(this.hashOperations).entries(anyString()); verify(this.redisOperations).delete(anyString()); verifyZeroInteractions(this.redisOperations); verifyZeroInteractions(this.hashOperations); }