|
21 | 21 | import java.util.Collections;
|
22 | 22 | import java.util.HashSet;
|
23 | 23 |
|
| 24 | +import org.assertj.core.api.ThrowableAssert; |
24 | 25 | import org.junit.jupiter.api.Test;
|
25 | 26 |
|
26 | 27 | import org.springframework.mock.env.MockPropertySource;
|
|
32 | 33 | * @author Christoph Strobl
|
33 | 34 | * @author Mark Paluch
|
34 | 35 | * @author Vikas Garg
|
| 36 | + * @author Samuel Klose |
| 37 | + * @author Mustapha Zorgati |
35 | 38 | */
|
36 | 39 | class RedisSentinelConfigurationUnitTests {
|
37 | 40 |
|
@@ -186,4 +189,56 @@ void readSentinelUsernameFromConfigProperty() {
|
186 | 189 | assertThat(config.getSentinelPassword()).isEqualTo(RedisPassword.of("foo"));
|
187 | 190 | assertThat(config.getSentinels()).hasSize(1).contains(new RedisNode("127.0.0.1", 123));
|
188 | 191 | }
|
| 192 | + |
| 193 | + @Test // GH-2860 |
| 194 | + void readSentinelDataNodeUsernameFromConfigProperty() { |
| 195 | + MockPropertySource propertySource = new MockPropertySource(); |
| 196 | + propertySource.setProperty("spring.redis.sentinel.dataNode.username", "datanode-user"); |
| 197 | + |
| 198 | + RedisSentinelConfiguration config = new RedisSentinelConfiguration(propertySource); |
| 199 | + |
| 200 | + assertThat(config.getDataNodeUsername()).isEqualTo("datanode-user"); |
| 201 | + } |
| 202 | + |
| 203 | + @Test // GH-2860 |
| 204 | + void readSentinelDataNodePasswordFromConfigProperty() { |
| 205 | + MockPropertySource propertySource = new MockPropertySource(); |
| 206 | + propertySource.setProperty("spring.redis.sentinel.dataNode.password", "datanode-password"); |
| 207 | + |
| 208 | + RedisSentinelConfiguration config = new RedisSentinelConfiguration(propertySource); |
| 209 | + |
| 210 | + assertThat(config.getDataNodePassword()).isEqualTo(RedisPassword.of("datanode-password")); |
| 211 | + } |
| 212 | + |
| 213 | + @Test // GH-2860 |
| 214 | + void readSentinelDataNodeDatabaseFromConfigProperty() { |
| 215 | + MockPropertySource propertySource = new MockPropertySource(); |
| 216 | + propertySource.setProperty("spring.redis.sentinel.dataNode.database", "5"); |
| 217 | + |
| 218 | + RedisSentinelConfiguration config = new RedisSentinelConfiguration(propertySource); |
| 219 | + |
| 220 | + assertThat(config.getDatabase()).isEqualTo(5); |
| 221 | + } |
| 222 | + |
| 223 | + @Test // GH-2860 |
| 224 | + void shouldThrowErrorWhen() { |
| 225 | + MockPropertySource propertySource = new MockPropertySource(); |
| 226 | + propertySource.setProperty("spring.redis.sentinel.dataNode.database", "thisIsNotAnInteger"); |
| 227 | + |
| 228 | + ThrowableAssert.ThrowingCallable call = () -> new RedisSentinelConfiguration(propertySource); |
| 229 | + |
| 230 | + assertThatThrownBy(call).isInstanceOf(IllegalArgumentException.class) |
| 231 | + .hasMessage("Invalid DB index '%s'; integer required", "thisIsNotAnInteger"); |
| 232 | + } |
| 233 | + |
| 234 | + @Test // GH-2860 |
| 235 | + void shouldThrowErrorWhen2() { |
| 236 | + MockPropertySource propertySource = new MockPropertySource(); |
| 237 | + propertySource.setProperty("spring.redis.sentinel.dataNode.database", "null"); |
| 238 | + |
| 239 | + ThrowableAssert.ThrowingCallable call = () -> new RedisSentinelConfiguration(propertySource); |
| 240 | + |
| 241 | + assertThatThrownBy(call).isInstanceOf(IllegalArgumentException.class) |
| 242 | + .hasMessage("Invalid DB index '%s'; integer required", "null"); |
| 243 | + } |
189 | 244 | }
|
0 commit comments