forked from spring-projects/spring-boot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
533 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...tainers/service/connection/cassandra/CassandraContainerConnectionDetailsFactoryTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2012-2024 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 org.springframework.boot.testcontainers.service.connection.cassandra; | ||
|
||
import com.datastax.oss.driver.api.core.CqlSession; | ||
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.autoconfigure.ImportAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.cassandra.CassandraConnectionDetails; | ||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection; | ||
import org.springframework.boot.testsupport.testcontainers.CassandraContainer; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Tests for {@link CassandraContainerConnectionDetailsFactory}. | ||
* | ||
* @author Andy Wilkinson | ||
*/ | ||
@SpringJUnitConfig | ||
@Testcontainers(disabledWithoutDocker = true) | ||
class CassandraContainerConnectionDetailsFactoryTests { | ||
|
||
@Container | ||
@ServiceConnection | ||
static final CassandraContainer cassandra = new CassandraContainer(); | ||
|
||
@Autowired(required = false) | ||
private CassandraConnectionDetails connectionDetails; | ||
|
||
@Autowired | ||
private CqlSession cqlSession; | ||
|
||
@Test | ||
void connectionCanBeMadeToCassandraContainer() { | ||
assertThat(this.connectionDetails).isNotNull(); | ||
assertThat(this.cqlSession.getMetadata().getNodes()).hasSize(1); | ||
} | ||
|
||
@Configuration(proxyBeanMethods = false) | ||
@ImportAutoConfiguration(CassandraAutoConfiguration.class) | ||
static class TestConfiguration { | ||
|
||
} | ||
|
||
} |
75 changes: 75 additions & 0 deletions
75
...tainers/service/connection/couchbase/CouchbaseContainerConnectionDetailsFactoryTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright 2012-2024 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 org.springframework.boot.testcontainers.service.connection.couchbase; | ||
|
||
import java.time.Duration; | ||
|
||
import com.couchbase.client.java.Cluster; | ||
import org.junit.jupiter.api.Test; | ||
import org.testcontainers.couchbase.BucketDefinition; | ||
import org.testcontainers.couchbase.CouchbaseContainer; | ||
import org.testcontainers.couchbase.CouchbaseService; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.couchbase.CouchbaseConnectionDetails; | ||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection; | ||
import org.springframework.boot.testsupport.testcontainers.DockerImageNames; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Tests for {@link CouchbaseContainerConnectionDetailsFactory}. | ||
* | ||
* @author Andy Wilkinson | ||
*/ | ||
@SpringJUnitConfig | ||
@Testcontainers(disabledWithoutDocker = true) | ||
class CouchbaseContainerConnectionDetailsFactoryTests { | ||
|
||
@Container | ||
@ServiceConnection | ||
static final CouchbaseContainer couchbase = new CouchbaseContainer(DockerImageNames.couchbase()) | ||
.withEnabledServices(CouchbaseService.KV, CouchbaseService.INDEX, CouchbaseService.QUERY) | ||
.withStartupAttempts(5) | ||
.withStartupTimeout(Duration.ofMinutes(10)) | ||
.withBucket(new BucketDefinition("cbbucket")); | ||
|
||
@Autowired(required = false) | ||
private CouchbaseConnectionDetails connectionDetails; | ||
|
||
@Autowired | ||
private Cluster cluster; | ||
|
||
@Test | ||
void connectionCanBeMadeToCouchbaseContainer() { | ||
assertThat(this.connectionDetails).isNotNull(); | ||
assertThat(this.cluster.diagnostics().endpoints()).hasSize(1); | ||
} | ||
|
||
@Configuration(proxyBeanMethods = false) | ||
@ImportAutoConfiguration(CouchbaseAutoConfiguration.class) | ||
static class TestConfiguration { | ||
|
||
} | ||
|
||
} |
75 changes: 75 additions & 0 deletions
75
...service/connection/elasticsearch/ElasticsearchContainerConnectionDetailsFactoryTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright 2012-2024 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 org.springframework.boot.testcontainers.service.connection.elasticsearch; | ||
|
||
import java.io.IOException; | ||
import java.time.Duration; | ||
|
||
import co.elastic.clients.elasticsearch.ElasticsearchClient; | ||
import org.junit.jupiter.api.Test; | ||
import org.testcontainers.elasticsearch.ElasticsearchContainer; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchClientAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchConnectionDetails; | ||
import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchRestClientAutoConfiguration; | ||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection; | ||
import org.springframework.boot.testsupport.testcontainers.DockerImageNames; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Tests for {@link ElasticsearchContainerConnectionDetailsFactory}. | ||
* | ||
* @author Andy Wilkinson | ||
*/ | ||
@SpringJUnitConfig | ||
@Testcontainers(disabledWithoutDocker = true) | ||
class ElasticsearchContainerConnectionDetailsFactoryTests { | ||
|
||
@Container | ||
@ServiceConnection | ||
static final ElasticsearchContainer elasticsearch = new ElasticsearchContainer(DockerImageNames.elasticsearch()) | ||
.withEnv("ES_JAVA_OPTS", "-Xms32m -Xmx512m") | ||
.withStartupAttempts(5) | ||
.withStartupTimeout(Duration.ofMinutes(10)); | ||
|
||
@Autowired(required = false) | ||
private ElasticsearchConnectionDetails connectionDetails; | ||
|
||
@Autowired | ||
private ElasticsearchClient client; | ||
|
||
@Test | ||
void connectionCanBeMadeToElasticsearchContainer() throws IOException { | ||
assertThat(this.connectionDetails).isNotNull(); | ||
assertThat(this.client.cluster().health().numberOfNodes()).isEqualTo(1); | ||
} | ||
|
||
@Configuration(proxyBeanMethods = false) | ||
@ImportAutoConfiguration({ ElasticsearchClientAutoConfiguration.class, | ||
ElasticsearchRestClientAutoConfiguration.class }) | ||
static class TestConfiguration { | ||
|
||
} | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
...estcontainers/service/connection/flyway/FlywayContainerConnectionDetailsFactoryTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright 2012-2024 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 org.springframework.boot.testcontainers.service.connection.flyway; | ||
|
||
import org.flywaydb.core.Flyway; | ||
import org.junit.jupiter.api.Test; | ||
import org.testcontainers.containers.PostgreSQLContainer; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.jdbc.JdbcConnectionDetails; | ||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection; | ||
import org.springframework.boot.testsupport.testcontainers.DockerImageNames; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatNoException; | ||
|
||
/** | ||
* Tests for {@link FlywayContainerConnectionDetailsFactory}. | ||
* | ||
* @author Andy Wilkinson | ||
*/ | ||
@SpringJUnitConfig | ||
@Testcontainers(disabledWithoutDocker = true) | ||
class FlywayContainerConnectionDetailsFactoryTests { | ||
|
||
@Container | ||
@ServiceConnection | ||
static final PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>(DockerImageNames.postgresql()); | ||
|
||
@Autowired(required = false) | ||
private JdbcConnectionDetails connectionDetails; | ||
|
||
@Autowired | ||
private Flyway flyway; | ||
|
||
@Test | ||
void connectionCanBeMadeToJdbcContainer() { | ||
assertThat(this.connectionDetails).isNotNull(); | ||
JdbcTemplate jdbc = new JdbcTemplate(this.flyway.getConfiguration().getDataSource()); | ||
assertThatNoException().isThrownBy(() -> jdbc.execute("SELECT * from public.flyway_schema_history")); | ||
} | ||
|
||
@Configuration(proxyBeanMethods = false) | ||
@ImportAutoConfiguration(FlywayAutoConfiguration.class) | ||
static class TestConfiguration { | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.