-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat, test : redis 전체 삭제 기능 구현 및 테스트 코드 추가 (#175)
* feat, test : redis 전체 삭제 기능 구현 및 테스트 코드 추가 * fix: 레디스 포트 명시적으로 배포서버로 변경 * deploy: 보안상 속성파일 위치 변경 --------- Co-authored-by: gitjiho <[email protected]>
- Loading branch information
Showing
4 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,9 @@ | |
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.mockito.junit.jupiter.MockitoSettings; | ||
import org.springframework.data.redis.connection.RedisConnection; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.data.redis.connection.RedisServerCommands; | ||
import org.springframework.data.redis.core.HashOperations; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
|
||
|
@@ -23,6 +26,15 @@ public class TokenServiceTest { | |
@Mock | ||
private HashOperations<String, Object, Object> hashOperations; | ||
|
||
@Mock | ||
private RedisConnectionFactory redisConnectionFactory; | ||
|
||
@Mock | ||
private RedisConnection redisConnection; | ||
|
||
@Mock | ||
private RedisServerCommands redisServerCommands; | ||
|
||
private TokenService tokenService; | ||
|
||
@BeforeEach | ||
|
@@ -65,4 +77,31 @@ void generateRefreshTokenTest() { | |
assertTrue(token.startsWith("ey")); | ||
assertEquals(email, resultEmail); | ||
} | ||
|
||
@Test | ||
@DisplayName("deleteAllDataFromRedis 메소드 테스트") | ||
void deleteAllDataFromRedisTest(){ | ||
//given | ||
String email = "[email protected]"; | ||
String refreshToken = "test.Refresh.Token"; | ||
|
||
when(redisTemplate.opsForHash()).thenReturn(hashOperations); | ||
when(redisTemplate.getConnectionFactory()).thenReturn(redisConnectionFactory); | ||
when(redisConnectionFactory.getConnection()).thenReturn(redisConnection); | ||
when(redisConnection.serverCommands()).thenReturn(redisServerCommands); | ||
|
||
redisTemplate.opsForHash().put(email, "refreshToken1", refreshToken); | ||
redisTemplate.opsForHash().put(email, "refreshToken2", refreshToken); | ||
redisTemplate.opsForHash().put(email, "refreshToken3", refreshToken); | ||
redisTemplate.opsForHash().put(email, "refreshToken4", refreshToken); | ||
|
||
//when | ||
tokenService.deleteAllDataFromRedis(); | ||
|
||
//then | ||
assertNull(redisTemplate.opsForHash().get(email, "refreshToken1")); | ||
assertNull(redisTemplate.opsForHash().get(email, "refreshToken2")); | ||
assertNull(redisTemplate.opsForHash().get(email, "refreshToken3")); | ||
assertNull(redisTemplate.opsForHash().get(email, "refreshToken4")); | ||
} | ||
} |