-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#22706 Some tests using testcontainers.
- Loading branch information
Showing
6 changed files
with
424 additions
and
5 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
39 changes: 39 additions & 0 deletions
39
tools/dotcms-cli/api-data-model/src/test/java/com/dotcms/DockerComposeResource.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,39 @@ | ||
//package com.dotcms; | ||
// | ||
//import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; | ||
//import org.testcontainers.containers.DockerComposeContainer; | ||
//import org.testcontainers.containers.wait.strategy.Wait; | ||
// | ||
//import java.io.File; | ||
//import java.time.Duration; | ||
//import java.util.Collections; | ||
//import java.util.Map; | ||
// | ||
//public class DockerComposeResource implements QuarkusTestResourceLifecycleManager { | ||
// | ||
// private static final int POSTGRES_SERVICE_PORT = 5432; | ||
// private static final int ELASTICSEARCH_SERVICE_PORT = 9200; | ||
// private static final int DOTCMS_SERVICE_PORT = 8080; | ||
// private static final int STARTUP_TIMEOUT = 120; | ||
// private static final boolean USE_LOCAL_COMPOSE = false; | ||
// | ||
// private static final DockerComposeContainer<?> DOCKER_COMPOSE_CONTAINER = | ||
// new DockerComposeContainer("dotcms-env", new File("src/test/resources/docker-compose.yaml")) | ||
// .withExposedService("postgres", POSTGRES_SERVICE_PORT, Wait.forListeningPort().withStartupTimeout(Duration.ofSeconds(STARTUP_TIMEOUT))) | ||
// .withExposedService("elasticsearch", ELASTICSEARCH_SERVICE_PORT, Wait.forHttp("/").forPort(ELASTICSEARCH_SERVICE_PORT).forStatusCode(200)) | ||
// .withExposedService("dotcms", DOTCMS_SERVICE_PORT, Wait.forListeningPort().withStartupTimeout(Duration.ofSeconds(STARTUP_TIMEOUT))) | ||
// .withLocalCompose(USE_LOCAL_COMPOSE); // need to be false to run on macOS | ||
// @Override | ||
// public Map<String, String> start() { | ||
// DOCKER_COMPOSE_CONTAINER.start(); | ||
// String dotcmsServiceHost = DOCKER_COMPOSE_CONTAINER.getServiceHost("dotcms", DOTCMS_SERVICE_PORT); | ||
// String dotcmsServicePort = DOCKER_COMPOSE_CONTAINER.getServicePort("dotcms", DOTCMS_SERVICE_PORT).toString(); | ||
// | ||
// return Collections.singletonMap("myapp.service.url", "http://" + dotcmsServiceHost + ":" + dotcmsServicePort); | ||
// } | ||
// | ||
// @Override | ||
// public void stop() { | ||
// DOCKER_COMPOSE_CONTAINER.stop(); | ||
// } | ||
//} |
63 changes: 63 additions & 0 deletions
63
tools/dotcms-cli/api-data-model/src/test/java/com/dotcms/DockerComposeTestResource.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,63 @@ | ||
//package com.dotcms; | ||
// | ||
//import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; | ||
//import org.testcontainers.containers.DockerComposeContainer; | ||
//import org.testcontainers.containers.wait.strategy.Wait; | ||
//import org.testcontainers.lifecycle.Startables; | ||
// | ||
//import java.io.File; | ||
//import java.time.Duration; | ||
//import java.util.Collections; | ||
//import java.util.Map; | ||
//import java.util.stream.Stream; | ||
// | ||
//public class DockerComposeTestResource implements QuarkusTestResourceLifecycleManager { | ||
// | ||
// private static final DockerComposeContainer<?> composeContainer = new DockerComposeContainer<>(new File("src/test/resources/docker-compose.yaml")) | ||
// .withLocalCompose(true) | ||
// | ||
// .withServices("postgres"); | ||
// | ||
// static { | ||
// Startables.deepStart(Stream.of(composeContainer)).join(); | ||
// } | ||
// @Override | ||
// public Map<String, String> start() { | ||
// return Map.of( | ||
// "quarkus.datasource.jdbc.url", composeContainer.getServiceHost("postgres", 5432) | ||
// + ":" + composeContainer.getServicePort("postgres", 5432), | ||
// "quarkus.datasource.username", "your_username", | ||
// "quarkus.datasource.password", "your_password" | ||
// ); | ||
// } | ||
// | ||
// @Override | ||
// public void stop() { | ||
// // No explicit stop needed as Testcontainers manages the lifecycle | ||
// } | ||
// | ||
// | ||
//// private static final int SERVICE_PORT = 5432; | ||
//// private static final int STARTUP_TIMEOUT = 60; | ||
//// private static final DockerComposeContainer<?> DOCKER_COMPOSE_CONTAINER = | ||
//// new DockerComposeContainer<>(new File("src/test/resources/docker-compose.yaml")) | ||
//// .withExposedService( | ||
//// "dotcms-env", | ||
//// SERVICE_PORT, | ||
//// Wait.forListeningPort().withStartupTimeout(Duration.ofSeconds(STARTUP_TIMEOUT))) | ||
//// .withLocalCompose(true); | ||
//// | ||
//// @Override | ||
//// public Map<String, String> start() { | ||
//// DOCKER_COMPOSE_CONTAINER.start(); | ||
//// String dotcmsServiceHost = DOCKER_COMPOSE_CONTAINER.getServiceHost("dotcms-env", SERVICE_PORT); | ||
//// String dotcmsServicePort = DOCKER_COMPOSE_CONTAINER.getServicePort("dotcms-env", SERVICE_PORT).toString(); | ||
//// | ||
//// return Collections.singletonMap("dotcms.service.url", "http://" + dotcmsServiceHost + ":" + dotcmsServicePort); | ||
//// } | ||
//// | ||
//// @Override | ||
//// public void stop() { | ||
//// DOCKER_COMPOSE_CONTAINER.stop(); | ||
//// } | ||
//} |
141 changes: 141 additions & 0 deletions
141
tools/dotcms-cli/api-data-model/src/test/java/com/dotcms/DummyTest.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,141 @@ | ||
package com.dotcms; | ||
|
||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.testcontainers.containers.DockerComposeContainer; | ||
import org.testcontainers.containers.wait.strategy.Wait; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
||
import java.io.File; | ||
import java.time.Duration; | ||
|
||
@Testcontainers | ||
public class DummyTest { | ||
|
||
private static final int POSTGRES_SERVICE_PORT = 5432; | ||
private static final int ELASTICSEARCH_SERVICE_PORT = 9200; | ||
private static final int DOTCMS_SERVICE_PORT = 8080; | ||
private static final int STARTUP_TIMEOUT = 120; | ||
|
||
private static final DockerComposeContainer<?> COMPOSE_CONTAINER = | ||
new DockerComposeContainer("dotcms-env", new File("src/test/resources/docker-compose.yaml")) | ||
.withExposedService("postgres", POSTGRES_SERVICE_PORT, Wait.forListeningPort().withStartupTimeout(Duration.ofSeconds(STARTUP_TIMEOUT))) | ||
.withExposedService("elasticsearch", ELASTICSEARCH_SERVICE_PORT, Wait.forHttp("/").forPort(ELASTICSEARCH_SERVICE_PORT).forStatusCode(200)) | ||
.withExposedService("dotcms", DOTCMS_SERVICE_PORT, Wait.forListeningPort().withStartupTimeout(Duration.ofSeconds(STARTUP_TIMEOUT))) | ||
.withLocalCompose(false); // need to be false to run on macOS | ||
|
||
static { | ||
COMPOSE_CONTAINER.start(); | ||
// Stream.of(GENERIC_CONTAINER, COMPOSE_CONTAINER).parallel().forEach(Startable::start); | ||
// Startables.deepStart(Stream.of(GENERIC_CONTAINER, COMPOSE_CONTAINER)).join(); | ||
} | ||
|
||
@BeforeAll | ||
public static void beforeAll() { | ||
System.out.println("beforeAll"); | ||
|
||
System.out.println("Postgres address: " + COMPOSE_CONTAINER.getServiceHost("postgres", POSTGRES_SERVICE_PORT)); | ||
System.out.println("Postgres port: " + COMPOSE_CONTAINER.getServicePort("postgres", POSTGRES_SERVICE_PORT)); | ||
|
||
System.out.println("Elasticsearch address: " + COMPOSE_CONTAINER.getServiceHost("elasticsearch", ELASTICSEARCH_SERVICE_PORT)); | ||
System.out.println("Elasticsearch port: " + COMPOSE_CONTAINER.getServicePort("elasticsearch", ELASTICSEARCH_SERVICE_PORT)); | ||
|
||
System.out.println("DotCMS address: " + COMPOSE_CONTAINER.getServiceHost("dotcms", DOTCMS_SERVICE_PORT)); | ||
System.out.println("DotCMS port: " + COMPOSE_CONTAINER.getServicePort("dotcms", DOTCMS_SERVICE_PORT)); | ||
|
||
} | ||
|
||
@Test | ||
public void myTest() { | ||
// Your test logic here | ||
System.out.println("Hello World"); | ||
} | ||
|
||
|
||
// private static final Network NETWORK = Network.newNetwork(); | ||
// | ||
// @Container | ||
// private static final ElasticsearchContainer ELASTICSEARCH_CONTAINER = | ||
// new ElasticsearchContainer(DockerImageName.parse("docker.elastic.co/elasticsearch/elasticsearch:7.10.2")) | ||
// .withEnv("discovery.type", "single-node") | ||
// .withEnv("cluster.name", "elastic-cluster") | ||
// .withEnv("bootstrap.memory_lock", "true") | ||
// .withEnv("ES_JAVA_OPTS", "-Xms512m -Xmx1G") | ||
// .withExposedPorts(ELASTICSEARCH_SERVICE_PORT, 9600) | ||
// .waitingFor(Wait.forHttp("/").forPort(ELASTICSEARCH_SERVICE_PORT).forStatusCode(200)) | ||
// .withNetwork(NETWORK) | ||
// .withLogConsumer(new Slf4jLogConsumer(org.slf4j.LoggerFactory.getLogger("elasticsearch"))) | ||
// .withReuse(true); | ||
|
||
|
||
|
||
|
||
|
||
// @Container | ||
// public static final DockerComposeContainer<?> dotCmsEnv = new DockerComposeContainer(new File("src/test/resources/docker-compose.yaml")) | ||
// .withExposedService("dotcms", POSTGRES_SERVICE_PORT, Wait.forListeningPort().withStartupTimeout(Duration.ofSeconds(STARTUP_TIMEOUT))) | ||
// .withLocalCompose(true); | ||
|
||
// @Container | ||
// private static final DockerComposeContainer<?> dotCmsEnv = new DockerComposeContainer(new File("src/test/resources/docker-compose.yaml")) | ||
// .withExposedService("dotcms", 8080, Wait.forListeningPort().withStartupTimeout(Duration.ofSeconds(60))) | ||
// .withLocalCompose(true); | ||
|
||
// @Container | ||
// private static final PostgreSQLContainer<?> POSTGRES_CONTAINER = | ||
// new PostgreSQLContainer<>(DockerImageName.parse("postgres:15")) | ||
//// .withDatabaseName("dotcms") | ||
//// .withUsername("dotcms") | ||
//// .withPassword("dotcms") | ||
// .withEnv("POSTGRES_USER", "dotcms") | ||
// .withEnv("POSTGRES_PASSWORD", "dotcms") | ||
// .withEnv("POSTGRES_DB", "dotcms") | ||
// .withCommand("postgres -c 'max_connections=400' -c 'shared_buffers=128MB'") | ||
// .withExposedPorts(POSTGRES_SERVICE_PORT) | ||
// .waitingFor(Wait.forListeningPort().withStartupTimeout(Duration.ofSeconds(STARTUP_TIMEOUT))) | ||
// .withNetwork(NETWORK) | ||
// .withReuse(true); | ||
|
||
|
||
// @BeforeAll | ||
// public static void setup() { | ||
// | ||
//// System.out.println("Postgres address: " + POSTGRES_CONTAINER.getHost()); | ||
//// System.out.println("Postgres port: " + POSTGRES_CONTAINER.getFirstMappedPort()); | ||
//// | ||
//// System.out.println("Elasticsearch address: " + ELASTICSEARCH_CONTAINER.getHost()); | ||
//// System.out.println("Elasticsearch port: " + ELASTICSEARCH_CONTAINER.getFirstMappedPort()); | ||
//// | ||
//// GenericContainer<?> DOTCMS_CONTAINER = new GenericContainer<>(DockerImageName.parse("dotcms/dotcms:latest")) | ||
//// .withEnv("CMS_JAVA_OPTS", "-Xmx1G") | ||
//// .withEnv("TZ", "UTC") | ||
//// .withEnv("DB_BASE_URL", "jdbc:postgresql://" + POSTGRES_CONTAINER.getHost() + ":5432/dotcms") | ||
////// .withEnv("DB_BASE_URL", "jdbc:postgresql://" + POSTGRES_CONTAINER.getHost() + ":" + POSTGRES_CONTAINER.getFirstMappedPort() + "/dotcms") | ||
//// .withEnv("DB_USERNAME", "dotcms") | ||
//// .withEnv("DB_PASSWORD", "dotcms") | ||
//// .withEnv("DOT_ES_AUTH_BASIC_PASSWORD", "admin") | ||
//// .withEnv("DOT_INITIAL_ADMIN_PASSWORD", "admin") | ||
//// .withEnv("DOT_ES_ENDPOINTS", "https://" + ELASTICSEARCH_CONTAINER.getHost() + ":9200") | ||
////// .withEnv("DOT_ES_ENDPOINTS", "https://" + ELASTICSEARCH_CONTAINER.getHost() + ":" + ELASTICSEARCH_CONTAINER.getFirstMappedPort()) | ||
////// .withEnv("CUSTOM_STARTER_URL", "https://repo.dotcms.com/artifactory/libs-release-local/com/dotcms/starter/20211201/starter-20211201.zip") | ||
//// .withExposedPorts(8080, 8443) | ||
//// .waitingFor(Wait.forHttp("/dotAdmin").forPort(8080).forStatusCode(200)) | ||
//// .dependsOn(POSTGRES_CONTAINER, ELASTICSEARCH_CONTAINER) | ||
//// .withNetwork(NETWORK) | ||
//// .withLogConsumer(logger -> System.out.print(logger.getUtf8String())) | ||
//// .withReuse(true); | ||
//// | ||
//// DOTCMS_CONTAINER.start(); | ||
// | ||
//// System.out.println("DotCMS address: " + DOTCMS_CONTAINER.getHost()); | ||
//// System.out.println("DotCMS port: " + DOTCMS_CONTAINER.getFirstMappedPort()); | ||
// | ||
// System.out.println("DummyTest.setup"); | ||
// | ||
// } | ||
|
||
// @Test | ||
// public void should_launch_containers_test() { | ||
// System.out.println("DummyTest.test"); | ||
// } | ||
} |
Oops, something went wrong.