Skip to content

Commit 9bb6f83

Browse files
committed
Add IT for bitnami/redis
1 parent e6c2bb7 commit 9bb6f83

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright 2012-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.testcontainers.service.connection.redis;
18+
19+
import org.junit.jupiter.api.Test;
20+
import org.testcontainers.containers.GenericContainer;
21+
import org.testcontainers.junit.jupiter.Container;
22+
import org.testcontainers.junit.jupiter.Testcontainers;
23+
24+
import org.springframework.beans.factory.annotation.Autowired;
25+
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
26+
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
27+
import org.springframework.boot.autoconfigure.data.redis.RedisConnectionDetails;
28+
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
29+
import org.springframework.boot.testsupport.container.TestImage;
30+
import org.springframework.context.annotation.Configuration;
31+
import org.springframework.data.redis.connection.RedisConnection;
32+
import org.springframework.data.redis.connection.RedisConnectionFactory;
33+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
34+
35+
import static org.assertj.core.api.Assertions.assertThat;
36+
37+
/**
38+
* Tests for {@link RedisContainerConnectionDetailsFactory}.
39+
*
40+
* @author Andy Wilkinson
41+
* @author Eddú Meléndez
42+
*/
43+
@SpringJUnitConfig
44+
@Testcontainers(disabledWithoutDocker = true)
45+
class BitnamiRedisContainerConnectionDetailsFactoryTests {
46+
47+
@Container
48+
@ServiceConnection
49+
static final GenericContainer<?> redis = TestImage.BITNAMI_REDIS.genericContainer()
50+
.withExposedPorts(6379)
51+
.withEnv("ALLOW_EMPTY_PASSWORD", "yes");
52+
53+
@Autowired(required = false)
54+
private RedisConnectionDetails connectionDetails;
55+
56+
@Autowired
57+
private RedisConnectionFactory connectionFactory;
58+
59+
@Test
60+
void connectionCanBeMadeToRedisContainer() {
61+
assertThat(this.connectionDetails).isNotNull();
62+
try (RedisConnection connection = this.connectionFactory.getConnection()) {
63+
assertThat(connection.commands().echo("Hello, World".getBytes())).isEqualTo("Hello, World".getBytes());
64+
}
65+
}
66+
67+
@Configuration(proxyBeanMethods = false)
68+
@ImportAutoConfiguration(RedisAutoConfiguration.class)
69+
static class TestConfiguration {
70+
71+
}
72+
73+
}

0 commit comments

Comments
 (0)