diff --git a/opendj-server-legacy/pom.xml b/opendj-server-legacy/pom.xml index 02dae69702..aabad0ce9e 100644 --- a/opendj-server-legacy/pom.xml +++ b/opendj-server-legacy/pom.xml @@ -13,7 +13,7 @@ information: "Portions Copyright [year] [name of copyright owner]". Copyright 2011-2016 ForgeRock AS. - Portions Copyright 2017-2024 3A Systems, LLC. + Portions Copyright 2017-2025 3A Systems, LLC. --> @@ -281,6 +281,44 @@ 1.20.4 test + + org.testcontainers + oracle-free + 1.20.4 + test + + + org.testcontainers + mysql + 1.20.4 + test + + + org.testcontainers + mssqlserver + 1.20.4 + test + + + + + com.mysql + mysql-connector-j + 9.2.0 + test + + + com.oracle.database.jdbc + ojdbc8 + 23.6.0.24.10 + test + + + com.microsoft.sqlserver + mssql-jdbc + 12.8.1.jre8 + test + ${project.groupId}.${project.artifactId} diff --git a/opendj-server-legacy/src/test/java/org/opends/server/backends/jdbc/MsSqlTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/backends/jdbc/MsSqlTestCase.java new file mode 100644 index 0000000000..26ead45643 --- /dev/null +++ b/opendj-server-legacy/src/test/java/org/opends/server/backends/jdbc/MsSqlTestCase.java @@ -0,0 +1,51 @@ +/* + * The contents of this file are subject to the terms of the Common Development and + * Distribution License (the License). You may not use this file except in compliance with the + * License. + * + * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the + * specific language governing permission and limitations under the License. + * + * When distributing Covered Software, include this CDDL Header Notice in each file and include + * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL + * Header, with the fields enclosed by brackets [] replaced by your own identifying + * information: "Portions Copyright [year] [name of copyright owner]". + * + * Copyright 2025 3A Systems, LLC. + */ +package org.opends.server.backends.jdbc; + +import org.testcontainers.containers.JdbcDatabaseContainer; +import org.testcontainers.containers.MSSQLServerContainer; +import org.testng.annotations.Test; + +//docker run --rm --name mssql -e ACCEPT_EULA=Y -e MSSQL_SA_PASSWORD=Passw0rd -p 1433:1433 mcr.microsoft.com/mssql/server:2017-CU12 + +@Test +public class MsSqlTestCase extends TestCase { + + @Override + protected JdbcDatabaseContainer getContainer() { + return new MSSQLServerContainer<>("mcr.microsoft.com/mssql/server:2019-CU30-ubuntu-20.04") + .withExposedPorts(1433) + .acceptLicense() + .withPassword("Passw0rd"); + + } + + @Override + protected String getContainerDockerCommand() { + return "run before test: docker run --rm --name mssql -e ACCEPT_EULA=Y -e MSSQL_SA_PASSWORD=Passw0rd -p 1433:1433 mcr.microsoft.com/mssql/server:2017-CU12"; + } + + @Override + protected String getBackendId() { + return MsSqlTestCase.class.getSimpleName(); + } + + @Override + protected String getJdbcUrl() { + return "jdbc:sqlserver://localhost:" + ((container==null)?"1433":container.getMappedPort(1433)) + ";encrypt=false;user=sa;password=Passw0rd;"; + } + +} diff --git a/opendj-server-legacy/src/test/java/org/opends/server/backends/jdbc/MySqlTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/backends/jdbc/MySqlTestCase.java new file mode 100644 index 0000000000..60592ffc14 --- /dev/null +++ b/opendj-server-legacy/src/test/java/org/opends/server/backends/jdbc/MySqlTestCase.java @@ -0,0 +1,51 @@ +/* + * The contents of this file are subject to the terms of the Common Development and + * Distribution License (the License). You may not use this file except in compliance with the + * License. + * + * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the + * specific language governing permission and limitations under the License. + * + * When distributing Covered Software, include this CDDL Header Notice in each file and include + * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL + * Header, with the fields enclosed by brackets [] replaced by your own identifying + * information: "Portions Copyright [year] [name of copyright owner]". + * + * Copyright 2025 3A Systems, LLC. + */ +package org.opends.server.backends.jdbc; + +import org.testcontainers.containers.JdbcDatabaseContainer; +import org.testcontainers.containers.MySQLContainer; +import org.testng.annotations.Test; + +//docker run --rm --name mysql -p 3306:3306 -e MYSQL_DATABASE=database_name -e MYSQL_ROOT_PASSWORD=password mysql:latest + +@Test +public class MySqlTestCase extends TestCase { + + @Override + protected JdbcDatabaseContainer getContainer() { + return new MySQLContainer<>("mysql") + .withExposedPorts(3306) + .withUsername("root") + .withPassword("password") + .withDatabaseName("database_name"); + } + + @Override + protected String getContainerDockerCommand() { + return "run before test: docker run --rm --name mysql -p 3306:3306 -e MYSQL_DATABASE=database_name -e MYSQL_ROOT_PASSWORD=password mysql:latest"; + } + + @Override + protected String getBackendId() { + return MySqlTestCase.class.getSimpleName(); + } + + @Override + protected String getJdbcUrl() { + return "jdbc:mysql://root:password@localhost:" + ((container==null)?"3306":container.getMappedPort(3306)) + "/database_name"; + } + +} diff --git a/opendj-server-legacy/src/test/java/org/opends/server/backends/jdbc/OracleTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/backends/jdbc/OracleTestCase.java new file mode 100644 index 0000000000..c2232aab5f --- /dev/null +++ b/opendj-server-legacy/src/test/java/org/opends/server/backends/jdbc/OracleTestCase.java @@ -0,0 +1,51 @@ +/* + * The contents of this file are subject to the terms of the Common Development and + * Distribution License (the License). You may not use this file except in compliance with the + * License. + * + * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the + * specific language governing permission and limitations under the License. + * + * When distributing Covered Software, include this CDDL Header Notice in each file and include + * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL + * Header, with the fields enclosed by brackets [] replaced by your own identifying + * information: "Portions Copyright [year] [name of copyright owner]". + * + * Copyright 2025 3A Systems, LLC. + */ +package org.opends.server.backends.jdbc; + +import org.testcontainers.containers.JdbcDatabaseContainer; +import org.testcontainers.oracle.OracleContainer; +import org.testng.annotations.Test; + +//docker run --rm --name oracle-db -p 1521:1521 -e APP_USER=opendj -e ORACLE_DATABASE=database_name -e APP_USER_PASSWORD=password gvenzl/oracle-free:23.4-slim-faststart + +@Test +public class OracleTestCase extends TestCase { + + @Override + protected JdbcDatabaseContainer getContainer() { + return new OracleContainer("gvenzl/oracle-free:23.4-slim-faststart") + .withExposedPorts(1521) + .withUsername("opendj") + .withPassword("password") + .withDatabaseName("database_name"); + } + + @Override + protected String getContainerDockerCommand() { + return "run before test: docker run --rm --name oracle-db -p 1521:1521 -e APP_USER=opendj -e ORACLE_DATABASE=database_name -e APP_USER_PASSWORD=password gvenzl/oracle-free:23.4-slim-faststart"; + } + + @Override + protected String getBackendId() { + return OracleTestCase.class.getSimpleName(); + } + + @Override + protected String getJdbcUrl() { + return "jdbc:oracle:thin:opendj/password@localhost: " + ((container==null)?"1521":container.getMappedPort(1521)) + "/database_name"; + } + +} diff --git a/opendj-server-legacy/src/test/java/org/opends/server/backends/jdbc/PgSqlTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/backends/jdbc/PgSqlTestCase.java new file mode 100644 index 0000000000..612093e7b0 --- /dev/null +++ b/opendj-server-legacy/src/test/java/org/opends/server/backends/jdbc/PgSqlTestCase.java @@ -0,0 +1,51 @@ +/* + * The contents of this file are subject to the terms of the Common Development and + * Distribution License (the License). You may not use this file except in compliance with the + * License. + * + * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the + * specific language governing permission and limitations under the License. + * + * When distributing Covered Software, include this CDDL Header Notice in each file and include + * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL + * Header, with the fields enclosed by brackets [] replaced by your own identifying + * information: "Portions Copyright [year] [name of copyright owner]". + * + * Copyright 2025 3A Systems, LLC. + */ +package org.opends.server.backends.jdbc; + +import org.testcontainers.containers.JdbcDatabaseContainer; +import org.testcontainers.containers.PostgreSQLContainer; +import org.testng.annotations.Test; + +//docker run --rm -it -p 5432:5432 -e POSTGRES_PASSWORD=password --name postgres postgres + +@Test +public class PgSqlTestCase extends TestCase { + + @Override + protected JdbcDatabaseContainer getContainer() { + return new PostgreSQLContainer<>("postgres:latest") + .withExposedPorts(5432) + .withUsername("postgres") + .withPassword("password") + .withDatabaseName("database_name"); + } + + @Override + protected String getContainerDockerCommand() { + return "run before test: docker run --rm -it -p 5432:5432 -e POSTGRES_DB=database_name -e POSTGRES_PASSWORD=password --name postgres postgres"; + } + + @Override + protected String getBackendId() { + return PgSqlTestCase.class.getSimpleName(); + } + + @Override + protected String getJdbcUrl() { + return "jdbc:postgresql://localhost:"+ ((container==null)?"5432":container.getMappedPort(5432))+"/database_name?user=postgres&password=password"; + } + +} diff --git a/opendj-server-legacy/src/test/java/org/opends/server/backends/jdbc/TestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/backends/jdbc/TestCase.java index 0b01008e7b..b645ee182e 100644 --- a/opendj-server-legacy/src/test/java/org/opends/server/backends/jdbc/TestCase.java +++ b/opendj-server-legacy/src/test/java/org/opends/server/backends/jdbc/TestCase.java @@ -11,18 +11,17 @@ * Header, with the fields enclosed by brackets [] replaced by your own identifying * information: "Portions Copyright [year] [name of copyright owner]". * - * Copyright 2024 3A Systems, LLC. + * Copyright 2024-2025 3A Systems, LLC. */ package org.opends.server.backends.jdbc; import org.forgerock.opendj.server.config.server.JDBCBackendCfg; import org.opends.server.backends.pluggable.PluggableBackendImplTestCase; import org.testcontainers.DockerClientFactory; -import org.testcontainers.containers.PostgreSQLContainer; +import org.testcontainers.containers.JdbcDatabaseContainer; import org.testng.SkipException; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; import java.sql.Connection; import java.sql.DriverManager; @@ -30,27 +29,23 @@ import static org.forgerock.opendj.config.ConfigurationMock.mockCfg; import static org.mockito.Mockito.when; -//docker run --rm -it -p 5432:5432 -e POSTGRES_PASSWORD=password --name postgres postgres -@Test -public class TestCase extends PluggableBackendImplTestCase { - PostgreSQLContainer container; +public abstract class TestCase extends PluggableBackendImplTestCase { + + JdbcDatabaseContainer container; @BeforeClass @Override public void setUp() throws Exception { if(DockerClientFactory.instance().isDockerAvailable()) { - container = new PostgreSQLContainer<>("postgres:latest") - .withExposedPorts(5432) - .withUsername("postgres") - .withPassword("password") - .withDatabaseName("database_name"); + container = getContainer(); container.start(); } - try(Connection con= DriverManager.getConnection(createBackendCfg().getDBDirectory())){ + try(Connection ignored = DriverManager.getConnection(createBackendCfg().getDBDirectory())){ + } catch (Exception e) { - throw new SkipException("run before test: docker run --rm -it -p 5432:5432 -e POSTGRES_DB=database_name -e POSTGRES_PASSWORD=password --name postgres postgres"); + throw new SkipException(getContainerDockerCommand()); } super.setUp(); } @@ -63,8 +58,8 @@ protected Backend createBackend() { @Override protected JDBCBackendCfg createBackendCfg() { JDBCBackendCfg backendCfg = mockCfg(JDBCBackendCfg.class); - when(backendCfg.getBackendId()).thenReturn("PsqlTestCase"); - when(backendCfg.getDBDirectory()).thenReturn("jdbc:postgresql://localhost:"+ ((container==null)?"5432":container.getMappedPort(5432))+"/database_name?user=postgres&password=password"); + when(backendCfg.getBackendId()).thenReturn(getBackendId()); + when(backendCfg.getDBDirectory()).thenReturn(getJdbcUrl()); return backendCfg; } @@ -76,4 +71,12 @@ public void cleanUp() throws Exception { container.close(); } } + + protected abstract JdbcDatabaseContainer getContainer(); + + protected abstract String getContainerDockerCommand(); + + protected abstract String getBackendId(); + + protected abstract String getJdbcUrl(); }