|
1 | 1 | /*
|
2 |
| - * Copyright 2014-2022 the original author or authors. |
| 2 | + * Copyright 2014-2025 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
16 | 16 |
|
17 | 17 | package sample;
|
18 | 18 |
|
| 19 | +import com.redis.testcontainers.RedisContainer; |
19 | 20 | import org.junit.jupiter.api.AfterEach;
|
20 | 21 | import org.junit.jupiter.api.BeforeEach;
|
21 | 22 | import org.junit.jupiter.api.Test;
|
22 | 23 | import org.junit.jupiter.api.extension.ExtendWith;
|
23 | 24 | import org.openqa.selenium.WebDriver;
|
24 |
| -import org.testcontainers.containers.GenericContainer; |
25 | 25 | import sample.pages.HomePage;
|
26 | 26 | import sample.pages.LoginPage;
|
27 | 27 |
|
|
30 | 30 | import org.springframework.boot.test.context.SpringBootTest;
|
31 | 31 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
32 | 32 | import org.springframework.boot.test.context.TestConfiguration;
|
| 33 | +import org.springframework.boot.testcontainers.service.connection.ServiceConnection; |
33 | 34 | import org.springframework.context.annotation.Bean;
|
34 |
| -import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; |
35 | 35 | import org.springframework.test.context.junit.jupiter.SpringExtension;
|
36 | 36 | import org.springframework.test.web.servlet.MockMvc;
|
37 | 37 | import org.springframework.test.web.servlet.htmlunit.webdriver.MockMvcHtmlUnitDriverBuilder;
|
|
40 | 40 | * @author Eddú Meléndez
|
41 | 41 | * @author Rob Winch
|
42 | 42 | * @author Vedran Pavic
|
| 43 | + * @author Yanming Zhou |
43 | 44 | */
|
44 | 45 | @ExtendWith(SpringExtension.class)
|
45 | 46 | @AutoConfigureMockMvc
|
@@ -107,15 +108,9 @@ private static HomePage home(WebDriver driver) {
|
107 | 108 | static class Config {
|
108 | 109 |
|
109 | 110 | @Bean
|
110 |
| - GenericContainer redisContainer() { |
111 |
| - GenericContainer redisContainer = new GenericContainer(DOCKER_IMAGE).withExposedPorts(6379); |
112 |
| - redisContainer.start(); |
113 |
| - return redisContainer; |
114 |
| - } |
115 |
| - |
116 |
| - @Bean |
117 |
| - LettuceConnectionFactory redisConnectionFactory() { |
118 |
| - return new LettuceConnectionFactory(redisContainer().getHost(), redisContainer().getFirstMappedPort()); |
| 111 | + @ServiceConnection |
| 112 | + RedisContainer redisContainer() { |
| 113 | + return new RedisContainer(DOCKER_IMAGE); |
119 | 114 | }
|
120 | 115 |
|
121 | 116 | }
|
|
0 commit comments