|
| 1 | +/* |
| 2 | + * Copyright 2012-2023 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 smoketest.data.redis; |
| 18 | + |
| 19 | +import java.nio.charset.Charset; |
| 20 | +import java.nio.charset.StandardCharsets; |
| 21 | + |
| 22 | +import org.junit.jupiter.api.Test; |
| 23 | +import org.testcontainers.junit.jupiter.Container; |
| 24 | +import org.testcontainers.junit.jupiter.Testcontainers; |
| 25 | + |
| 26 | +import org.springframework.beans.factory.annotation.Autowired; |
| 27 | +import org.springframework.boot.test.context.SpringBootTest; |
| 28 | +import org.springframework.boot.testcontainers.service.connection.ServiceConnection; |
| 29 | +import org.springframework.boot.testsupport.classpath.ClassPathExclusions; |
| 30 | +import org.springframework.boot.testsupport.testcontainers.RedisContainer; |
| 31 | +import org.springframework.data.redis.core.RedisOperations; |
| 32 | + |
| 33 | +import static org.assertj.core.api.Assertions.assertThat; |
| 34 | + |
| 35 | +/** |
| 36 | + * Smoke tests for Redis using Jedis with SSL. |
| 37 | + * |
| 38 | + * @author Scott Frederick |
| 39 | + */ |
| 40 | +@Testcontainers(disabledWithoutDocker = true) |
| 41 | +@ClassPathExclusions("lettuce-core-*.jar") |
| 42 | +@SpringBootTest(properties = { "spring.data.redis.ssl.bundle=client", |
| 43 | + "spring.ssl.bundle.pem.client.keystore.certificate=classpath:ssl/test-client.crt", |
| 44 | + "spring.ssl.bundle.pem.client.keystore.private-key=classpath:ssl/test-client.key", |
| 45 | + "spring.ssl.bundle.pem.client.truststore.certificate=classpath:ssl/test-ca.crt" }) |
| 46 | +class SampleRedisApplicationJedisSslTests { |
| 47 | + |
| 48 | + private static final Charset CHARSET = StandardCharsets.UTF_8; |
| 49 | + |
| 50 | + @Container |
| 51 | + @ServiceConnection |
| 52 | + static RedisContainer redis = new SecureRedisContainer(); |
| 53 | + |
| 54 | + @Autowired |
| 55 | + private RedisOperations<Object, Object> operations; |
| 56 | + |
| 57 | + @Autowired |
| 58 | + private SampleRepository exampleRepository; |
| 59 | + |
| 60 | + @Test |
| 61 | + void testRepository() { |
| 62 | + PersonHash personHash = new PersonHash(); |
| 63 | + personHash.setDescription("Look, new @DataRedisTest!"); |
| 64 | + assertThat(personHash.getId()).isNull(); |
| 65 | + PersonHash savedEntity = this.exampleRepository.save(personHash); |
| 66 | + assertThat(savedEntity.getId()).isNotNull(); |
| 67 | + assertThat(this.operations |
| 68 | + .execute((org.springframework.data.redis.connection.RedisConnection connection) -> connection.keyCommands() |
| 69 | + .exists(("persons:" + savedEntity.getId()).getBytes(CHARSET)))) |
| 70 | + .isTrue(); |
| 71 | + this.exampleRepository.deleteAll(); |
| 72 | + } |
| 73 | + |
| 74 | +} |
0 commit comments