From 321c526bf7e5e990d16858f21e13b6f20ad73155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez?= Date: Thu, 22 Jun 2023 20:34:29 -0600 Subject: [PATCH] Add SslAutoConfiguration to slice test annotations `SslAutoConfiguration` has been added to `cassandra`, `couchbase`, `elasticsearch`, `mongo` and `redis` slice test annotations. See gh-36038 --- ...ssandra.AutoConfigureDataCassandra.imports | 1 + ...uchbase.AutoConfigureDataCouchbase.imports | 1 + ...rch.AutoConfigureDataElasticsearch.imports | 1 + ....data.mongo.AutoConfigureDataMongo.imports | 1 + ....data.redis.AutoConfigureDataRedis.imports | 3 +- .../build.gradle | 1 + ...eCassandraApplicationReactiveSslTests.java | 90 +++++++++++++++++++ .../SampleCassandraApplicationSslTests.java | 4 +- .../SampleCouchbaseApplicationSslTests.java | 3 +- .../mongo/SampleMongoApplicationSslTests.java | 5 +- .../SampleRedisApplicationJedisSslTests.java | 3 +- 11 files changed, 107 insertions(+), 6 deletions(-) create mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/test/java/smoketest/data/cassandra/SampleCassandraApplicationReactiveSslTests.java diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.data.cassandra.AutoConfigureDataCassandra.imports b/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.data.cassandra.AutoConfigureDataCassandra.imports index 890af9413d..676de9b223 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.data.cassandra.AutoConfigureDataCassandra.imports +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.data.cassandra.AutoConfigureDataCassandra.imports @@ -4,3 +4,4 @@ org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfigura org.springframework.boot.autoconfigure.data.cassandra.CassandraReactiveDataAutoConfiguration org.springframework.boot.autoconfigure.data.cassandra.CassandraReactiveRepositoriesAutoConfiguration org.springframework.boot.autoconfigure.data.cassandra.CassandraRepositoriesAutoConfiguration +org.springframework.boot.autoconfigure.ssl.SslAutoConfiguration diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.data.couchbase.AutoConfigureDataCouchbase.imports b/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.data.couchbase.AutoConfigureDataCouchbase.imports index aaae4207e9..09237e1bfa 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.data.couchbase.AutoConfigureDataCouchbase.imports +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.data.couchbase.AutoConfigureDataCouchbase.imports @@ -5,3 +5,4 @@ org.springframework.boot.autoconfigure.data.couchbase.CouchbaseDataAutoConfigura org.springframework.boot.autoconfigure.data.couchbase.CouchbaseReactiveDataAutoConfiguration org.springframework.boot.autoconfigure.data.couchbase.CouchbaseReactiveRepositoriesAutoConfiguration org.springframework.boot.autoconfigure.data.couchbase.CouchbaseRepositoriesAutoConfiguration +org.springframework.boot.autoconfigure.ssl.SslAutoConfiguration diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.data.elasticsearch.AutoConfigureDataElasticsearch.imports b/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.data.elasticsearch.AutoConfigureDataElasticsearch.imports index 9e23ddfa32..6a34f70cb3 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.data.elasticsearch.AutoConfigureDataElasticsearch.imports +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.data.elasticsearch.AutoConfigureDataElasticsearch.imports @@ -7,3 +7,4 @@ org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchRestClientAuto org.springframework.boot.autoconfigure.elasticsearch.ReactiveElasticsearchClientAutoConfiguration org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration org.springframework.boot.autoconfigure.jsonb.JsonbAutoConfiguration +org.springframework.boot.autoconfigure.ssl.SslAutoConfiguration diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.data.mongo.AutoConfigureDataMongo.imports b/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.data.mongo.AutoConfigureDataMongo.imports index d16785df68..53cff5454f 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.data.mongo.AutoConfigureDataMongo.imports +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.data.mongo.AutoConfigureDataMongo.imports @@ -6,3 +6,4 @@ org.springframework.boot.autoconfigure.data.mongo.MongoRepositoriesAutoConfigura org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration org.springframework.boot.autoconfigure.mongo.MongoReactiveAutoConfiguration org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration +org.springframework.boot.autoconfigure.ssl.SslAutoConfiguration diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.data.redis.AutoConfigureDataRedis.imports b/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.data.redis.AutoConfigureDataRedis.imports index c871e47207..3014db3633 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.data.redis.AutoConfigureDataRedis.imports +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.data.redis.AutoConfigureDataRedis.imports @@ -1,4 +1,5 @@ # AutoConfigureDataRedis auto-configuration imports org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration org.springframework.boot.autoconfigure.data.redis.RedisReactiveAutoConfiguration -org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration \ No newline at end of file +org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration +org.springframework.boot.autoconfigure.ssl.SslAutoConfiguration diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/build.gradle index 951b372187..651be2c7ee 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/build.gradle @@ -7,6 +7,7 @@ description = "Spring Boot Data Cassandra smoke test" dependencies { implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-data-cassandra")) + implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-data-cassandra-reactive")) testImplementation(project(":spring-boot-project:spring-boot-test")) testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/test/java/smoketest/data/cassandra/SampleCassandraApplicationReactiveSslTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/test/java/smoketest/data/cassandra/SampleCassandraApplicationReactiveSslTests.java new file mode 100644 index 0000000000..2362aa4e55 --- /dev/null +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/test/java/smoketest/data/cassandra/SampleCassandraApplicationReactiveSslTests.java @@ -0,0 +1,90 @@ +/* + * Copyright 2012-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.cassandra; + +import java.time.Duration; +import java.util.UUID; + +import com.datastax.oss.driver.api.core.CqlSession; +import com.datastax.oss.driver.api.core.CqlSessionBuilder; +import org.junit.jupiter.api.Test; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.boot.testcontainers.service.connection.ServiceConnection; +import org.springframework.context.annotation.Bean; +import org.springframework.data.cassandra.core.ReactiveCassandraTemplate; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Smoke tests for Cassandra with SSL. + * + * @author Eddú Meléndez + */ +@Testcontainers(disabledWithoutDocker = true) +@SpringBootTest(properties = { "spring.cassandra.schema-action=create-if-not-exists", + "spring.cassandra.connection.connect-timeout=60s", "spring.cassandra.connection.init-query-timeout=60s", + "spring.cassandra.request.timeout=60s", "spring.cassandra.ssl.bundle=client", + "spring.ssl.bundle.jks.client.keystore.location=classpath:ssl/test-client.p12", + "spring.ssl.bundle.jks.client.keystore.password=password", + "spring.ssl.bundle.jks.client.truststore.location=classpath:ssl/test-ca.p12", + "spring.ssl.bundle.jks.client.truststore.password=password" }) +class SampleCassandraApplicationReactiveSslTests { + + @Container + @ServiceConnection + static final SecureCassandraContainer secureCassandra = new SecureCassandraContainer(); + + @Autowired + private ReactiveCassandraTemplate cassandraTemplate; + + @Autowired + private SampleRepository repository; + + @Test + void testRepository() { + SampleEntity entity = new SampleEntity(); + entity.setDescription("Look, new @DataCassandraTest!"); + String id = UUID.randomUUID().toString(); + entity.setId(id); + SampleEntity savedEntity = this.repository.save(entity); + SampleEntity getEntity = this.cassandraTemplate.selectOneById(id, SampleEntity.class) + .block(Duration.ofSeconds(30)); + assertThat(getEntity).isNotNull(); + assertThat(getEntity.getId()).isNotNull(); + assertThat(getEntity.getId()).isEqualTo(savedEntity.getId()); + } + + @TestConfiguration(proxyBeanMethods = false) + static class KeyspaceTestConfiguration { + + @Bean + CqlSession cqlSession(CqlSessionBuilder cqlSessionBuilder) { + try (CqlSession session = cqlSessionBuilder.build()) { + session.execute("CREATE KEYSPACE IF NOT EXISTS boot_test" + + " WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };"); + } + return cqlSessionBuilder.withKeyspace("boot_test").build(); + } + + } + +} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/test/java/smoketest/data/cassandra/SampleCassandraApplicationSslTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/test/java/smoketest/data/cassandra/SampleCassandraApplicationSslTests.java index d54c01d4e9..e6f25c7ac2 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/test/java/smoketest/data/cassandra/SampleCassandraApplicationSslTests.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/test/java/smoketest/data/cassandra/SampleCassandraApplicationSslTests.java @@ -25,6 +25,7 @@ import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.data.cassandra.DataCassandraTest; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.boot.testcontainers.service.connection.ServiceConnection; @@ -37,9 +38,10 @@ import static org.assertj.core.api.Assertions.assertThat; * Smoke tests for Cassandra with SSL. * * @author Scott Frederick + * @author Eddú Meléndez */ @Testcontainers(disabledWithoutDocker = true) -@SpringBootTest(properties = { "spring.cassandra.schema-action=create-if-not-exists", +@DataCassandraTest(properties = { "spring.cassandra.schema-action=create-if-not-exists", "spring.cassandra.connection.connect-timeout=60s", "spring.cassandra.connection.init-query-timeout=60s", "spring.cassandra.request.timeout=60s", "spring.cassandra.ssl.bundle=client", "spring.ssl.bundle.jks.client.keystore.location=classpath:ssl/test-client.p12", diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-couchbase/src/test/java/smoketest/data/couchbase/SampleCouchbaseApplicationSslTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-couchbase/src/test/java/smoketest/data/couchbase/SampleCouchbaseApplicationSslTests.java index 9e05362c33..61a72e46c1 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-couchbase/src/test/java/smoketest/data/couchbase/SampleCouchbaseApplicationSslTests.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-couchbase/src/test/java/smoketest/data/couchbase/SampleCouchbaseApplicationSslTests.java @@ -23,6 +23,7 @@ import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.data.couchbase.DataCouchbaseTest; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.testcontainers.service.connection.ServiceConnection; import org.springframework.data.couchbase.core.CouchbaseTemplate; @@ -35,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Scott Frederick */ @Testcontainers(disabledWithoutDocker = true) -@SpringBootTest(properties = { "spring.couchbase.env.ssl.bundle=client", "spring.couchbase.env.timeouts.connect=2m", +@DataCouchbaseTest(properties = { "spring.couchbase.env.ssl.bundle=client", "spring.couchbase.env.timeouts.connect=2m", "spring.data.couchbase.bucket-name=cbbucket", "spring.ssl.bundle.pem.client.keystore.certificate=classpath:ssl/test-client.crt", "spring.ssl.bundle.pem.client.keystore.private-key=classpath:ssl/test-client.key", diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-mongo/src/test/java/smoketest/data/mongo/SampleMongoApplicationSslTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-mongo/src/test/java/smoketest/data/mongo/SampleMongoApplicationSslTests.java index 13b43c0d03..0ef3544743 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-mongo/src/test/java/smoketest/data/mongo/SampleMongoApplicationSslTests.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-mongo/src/test/java/smoketest/data/mongo/SampleMongoApplicationSslTests.java @@ -22,7 +22,7 @@ import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; import org.springframework.boot.testcontainers.service.connection.ServiceConnection; import org.springframework.data.mongodb.core.MongoTemplate; @@ -32,9 +32,10 @@ import static org.assertj.core.api.Assertions.assertThat; * Smoke tests for MongoDB with SSL. * * @author Scott Frederick + * @author Eddú Meléndez */ @Testcontainers(disabledWithoutDocker = true) -@SpringBootTest(properties = { "spring.data.mongodb.ssl.bundle=client", +@DataMongoTest(properties = { "spring.data.mongodb.ssl.bundle=client", "spring.ssl.bundle.pem.client.keystore.certificate=classpath:ssl/test-client.crt", "spring.ssl.bundle.pem.client.keystore.private-key=classpath:ssl/test-client.key", "spring.ssl.bundle.pem.client.truststore.certificate=classpath:ssl/test-ca.crt" }) diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-redis/src/test/java/smoketest/data/redis/SampleRedisApplicationJedisSslTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-redis/src/test/java/smoketest/data/redis/SampleRedisApplicationJedisSslTests.java index bb650dbc3b..af680aac0e 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-redis/src/test/java/smoketest/data/redis/SampleRedisApplicationJedisSslTests.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-redis/src/test/java/smoketest/data/redis/SampleRedisApplicationJedisSslTests.java @@ -24,6 +24,7 @@ import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.data.redis.DataRedisTest; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.testcontainers.service.connection.ServiceConnection; import org.springframework.boot.testsupport.classpath.ClassPathExclusions; @@ -39,7 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ @Testcontainers(disabledWithoutDocker = true) @ClassPathExclusions("lettuce-core-*.jar") -@SpringBootTest(properties = { "spring.data.redis.ssl.bundle=client", +@DataRedisTest(properties = { "spring.data.redis.ssl.bundle=client", "spring.ssl.bundle.pem.client.keystore.certificate=classpath:ssl/test-client.crt", "spring.ssl.bundle.pem.client.keystore.private-key=classpath:ssl/test-client.key", "spring.ssl.bundle.pem.client.truststore.certificate=classpath:ssl/test-ca.crt" })