From 2050033a0d126dc0289c20ae2a0fc00d775e28f4 Mon Sep 17 00:00:00 2001
From: Maxim Thomas <maxim.thomas@gmail.com>
Date: Mon, 03 Feb 2025 18:31:01 +0000
Subject: [PATCH] [#466] JDBC: added tests for Oracle, MySQL, MSSQL (#472)
---
opendj-server-legacy/src/test/java/org/opends/server/backends/jdbc/MsSqlTestCase.java | 51 ++++++++++
opendj-server-legacy/pom.xml | 40 +++++++
opendj-server-legacy/src/test/java/org/opends/server/backends/jdbc/OracleTestCase.java | 51 ++++++++++
opendj-server-legacy/src/test/java/org/opends/server/backends/jdbc/TestCase.java | 35 +++---
opendj-server-legacy/src/test/java/org/opends/server/backends/jdbc/PgSqlTestCase.java | 51 ++++++++++
opendj-server-legacy/src/test/java/org/opends/server/backends/jdbc/MySqlTestCase.java | 51 ++++++++++
6 files changed, 262 insertions(+), 17 deletions(-)
diff --git a/opendj-server-legacy/pom.xml b/opendj-server-legacy/pom.xml
index 02dae69..aabad0c 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
@@ -281,6 +281,44 @@
<version>1.20.4</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>oracle-free</artifactId>
+ <version>1.20.4</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>mysql</artifactId>
+ <version>1.20.4</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>mssqlserver</artifactId>
+ <version>1.20.4</version>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- test JDBC drivers -->
+ <dependency>
+ <groupId>com.mysql</groupId>
+ <artifactId>mysql-connector-j</artifactId>
+ <version>9.2.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.oracle.database.jdbc</groupId>
+ <artifactId>ojdbc8</artifactId>
+ <version>23.6.0.24.10</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.microsoft.sqlserver</groupId>
+ <artifactId>mssql-jdbc</artifactId>
+ <version>12.8.1.jre8</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build><finalName>${project.groupId}.${project.artifactId}</finalName>
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 0000000..26ead45
--- /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 0000000..60592ff
--- /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 0000000..c2232aa
--- /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 0000000..612093e
--- /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 0b01008..b645ee1 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<JDBCBackendCfg> {
- PostgreSQLContainer container;
+public abstract class TestCase extends PluggableBackendImplTestCase<JDBCBackendCfg> {
+
+ 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 @@
@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 @@
container.close();
}
}
+
+ protected abstract JdbcDatabaseContainer<?> getContainer();
+
+ protected abstract String getContainerDockerCommand();
+
+ protected abstract String getBackendId();
+
+ protected abstract String getJdbcUrl();
}
--
Gitblit v1.10.0