Skip to content

Commit

Permalink
#22706 Another test configuration using testcontainers.
Browse files Browse the repository at this point in the history
  • Loading branch information
dcolina committed Jul 11, 2023
1 parent 74b0094 commit 4582b53
Show file tree
Hide file tree
Showing 4 changed files with 249 additions and 190 deletions.
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.HashMap;
//import java.util.Map;
//
//public class ContainerResource 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 LOCAL_COMPOSE = false;
//
// static 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(LOCAL_COMPOSE); // need to be false to run on macOS
// @Override
// public Map<String, String> start() {
// COMPOSE_CONTAINER.start();
// final Map<String, String> conf = new HashMap<>();
// conf.put("%test.dotcms.url", COMPOSE_CONTAINER.getServiceHost("dotcms", DOTCMS_SERVICE_PORT) + ":" + COMPOSE_CONTAINER.getServicePort("dotcms", DOTCMS_SERVICE_PORT));
//
// return conf;
// }
//
// @Override
// public void stop() {
// COMPOSE_CONTAINER.stop();
// }
//}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//package com.dotcms;
//
//import com.dotcms.api.AssetAPI;
//import com.dotcms.api.AuthenticationContext;
//import com.dotcms.api.client.RestClientFactory;
//import com.dotcms.api.client.ServiceManager;
//import com.dotcms.model.asset.SearchByPathRequest;
//import com.dotcms.model.config.ServiceBean;
//import io.quarkus.test.common.QuarkusTestResource;
//import io.quarkus.test.junit.QuarkusTest;
//import org.eclipse.microprofile.config.inject.ConfigProperty;
//import org.junit.jupiter.api.Assertions;
//import org.junit.jupiter.api.BeforeEach;
//import org.junit.jupiter.api.Test;
//
//import javax.inject.Inject;
//import javax.ws.rs.NotFoundException;
//import java.io.IOException;
//
//@QuarkusTest
//@QuarkusTestResource(ContainerResource.class)
//public class ContainerTest {
//
// @ConfigProperty(name = "com.dotcms.starter.site", defaultValue = "default")
// String siteName;
//
// @Inject
// AuthenticationContext authenticationContext;
//
// @Inject
// RestClientFactory clientFactory;
//
// @Inject
// ServiceManager serviceManager;
//
// @BeforeEach
// public void setupTest() throws IOException {
// serviceManager.removeAll().persist(
// ServiceBean.builder().
// name("default").
// active(true).
// build()
// );
//
// final String user = "[email protected]";
// final char[] passwd = "admin".toCharArray();
// authenticationContext.login(user, passwd);
// }
//
// /**
// * Check for the proper response when a folder is not found
// */
// @Test
// void Test_Asset_By_Path_Not_Found() {
//
// final AssetAPI assetAPI = clientFactory.getClient(AssetAPI.class);
//
// var folderByPath = SearchByPathRequest.builder().
// assetPath(String.format("//%s/%s", siteName, "folderDoesNotExist")).build();
//
// try {
// assetAPI.folderByPath(folderByPath);
// Assertions.fail(" 404 Exception should have been thrown here.");
// } catch (Exception e) {
// e.printStackTrace();
// Assertions.assertTrue(e instanceof NotFoundException);
// }
// }
//
// @Test
// void test_docker_containers_up() {
// System.out.println("test_docker_containers_up");
// }
//}
266 changes: 133 additions & 133 deletions tools/dotcms-cli/api-data-model/src/test/java/com/dotcms/DummyTest.java
Original file line number Diff line number Diff line change
@@ -1,141 +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);


//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 setup() {
// public static void beforeAll() {
// System.out.println("beforeAll");
//
//// 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("Postgres address: " + COMPOSE_CONTAINER.getServiceHost("postgres", POSTGRES_SERVICE_PORT));
// System.out.println("Postgres port: " + COMPOSE_CONTAINER.getServicePort("postgres", POSTGRES_SERVICE_PORT));
//
//// System.out.println("DotCMS address: " + DOTCMS_CONTAINER.getHost());
//// System.out.println("DotCMS port: " + DOTCMS_CONTAINER.getFirstMappedPort());
// 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("DummyTest.setup");
// 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 should_launch_containers_test() {
// System.out.println("DummyTest.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");
//// }
//}
Loading

0 comments on commit 4582b53

Please sign in to comment.