|
1 | 1 | package org.baeldung; |
2 | 2 |
|
3 | | -import java.io.IOException; |
4 | | - |
5 | | -import org.junit.AfterClass; |
6 | | -import org.junit.BeforeClass; |
7 | 3 | import org.junit.Test; |
8 | 4 | import org.junit.runner.RunWith; |
| 5 | +import org.mockito.Mockito; |
9 | 6 | import org.springframework.boot.test.context.SpringBootTest; |
| 7 | +import org.springframework.context.annotation.Bean; |
| 8 | +import org.springframework.context.annotation.Configuration; |
| 9 | +import org.springframework.data.redis.connection.RedisConnection; |
| 10 | +import org.springframework.data.redis.connection.RedisConnectionFactory; |
| 11 | +import org.springframework.data.redis.serializer.RedisSerializer; |
| 12 | +import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; |
10 | 13 | import org.springframework.test.context.junit4.SpringRunner; |
11 | | -import redis.embedded.RedisServer; |
12 | 14 |
|
13 | 15 | @RunWith(SpringRunner.class) |
14 | 16 | @SpringBootTest |
15 | 17 | public class BookReviewsApiIntegrationTest { |
16 | | - |
17 | | - private static RedisServer redisServer; |
18 | | - private static int port; |
19 | | - |
20 | | - @BeforeClass |
21 | | - public static void setUp() throws IOException { |
22 | | - |
23 | | - redisServer = new RedisServer(6379); |
24 | | - redisServer.start(); |
25 | | - } |
26 | | - |
27 | | - @AfterClass |
28 | | - public static void destroy() { |
29 | | - redisServer.stop(); |
30 | | - } |
31 | 18 |
|
32 | 19 | @Test |
33 | 20 | public void contextLoads() { |
34 | 21 | } |
35 | 22 |
|
| 23 | + @EnableRedisHttpSession |
| 24 | + @Configuration |
| 25 | + static class Config { |
| 26 | + |
| 27 | + @Bean |
| 28 | + @SuppressWarnings("unchecked") |
| 29 | + public RedisSerializer<Object> defaultRedisSerializer() { |
| 30 | + return Mockito.mock(RedisSerializer.class); |
| 31 | + } |
| 32 | + |
| 33 | + @Bean |
| 34 | + public RedisConnectionFactory connectionFactory() { |
| 35 | + |
| 36 | + RedisConnectionFactory factory = Mockito.mock(RedisConnectionFactory.class); |
| 37 | + RedisConnection connection = Mockito.mock(RedisConnection.class); |
| 38 | + Mockito.when(factory.getConnection()).thenReturn(connection); |
| 39 | + |
| 40 | + return factory; |
| 41 | + } |
| 42 | + } |
36 | 43 | } |
0 commit comments