From f82f937d14996936f69477ab697871ca8b347adf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Chicchiricc=C3=B2?= Date: Mon, 26 Aug 2024 16:52:03 +0200 Subject: [PATCH] PostgreSQL without Docker --- .../workflows/fit_Tomcat_PostgreSQL_JSON.yml | 4 +- .../workflows/fit_Tomcat_PostgreSQL_XML.yml | 4 +- .../workflows/fit_Tomcat_PostgreSQL_YAML.yml | 4 +- core/idm/logic/pom.xml | 4 +- .../syncope/core/logic/AbstractTest.java | 44 +++---- core/idrepo/logic/pom.xml | 4 +- .../syncope/core/logic/AbstractTest.java | 44 +++---- core/persistence-jpa/pom.xml | 4 +- .../core/persistence/jpa/AbstractTest.java | 111 +++++++++--------- .../src/test/resources/test.properties | 1 - core/provisioning-java/pom.xml | 4 +- .../core/provisioning/java/AbstractTest.java | 44 +++---- core/workflow-java/pom.xml | 4 +- .../core/workflow/java/AbstractTest.java | 44 +++---- fit/core-reference/pom.xml | 3 - fit/persistence-embedded/pom.xml | 12 -- pom.xml | 28 +++++ standalone/pom.xml | 5 + 18 files changed, 178 insertions(+), 190 deletions(-) diff --git a/.github/workflows/fit_Tomcat_PostgreSQL_JSON.yml b/.github/workflows/fit_Tomcat_PostgreSQL_JSON.yml index ecc9bd1b52..2d9a5b8bcb 100644 --- a/.github/workflows/fit_Tomcat_PostgreSQL_JSON.yml +++ b/.github/workflows/fit_Tomcat_PostgreSQL_JSON.yml @@ -14,7 +14,7 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License -name: "FIT Tomcat H2 JSON" +name: "FIT Tomcat PostgreSQL JSON" on: push: @@ -26,7 +26,7 @@ on: - cron: '0 13 * * 4' jobs: - fit_Tomcat_H2_JSON: + fit_Tomcat_PostgreSQL_JSON: runs-on: ubuntu-latest steps: diff --git a/.github/workflows/fit_Tomcat_PostgreSQL_XML.yml b/.github/workflows/fit_Tomcat_PostgreSQL_XML.yml index f0076dbff6..b3153d898c 100644 --- a/.github/workflows/fit_Tomcat_PostgreSQL_XML.yml +++ b/.github/workflows/fit_Tomcat_PostgreSQL_XML.yml @@ -14,7 +14,7 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License -name: "FIT Tomcat H2 XML" +name: "FIT Tomcat PostgreSQL XML" on: push: @@ -26,7 +26,7 @@ on: - cron: '0 13 * * 4' jobs: - fit_Tomcat_H2_XML: + fit_Tomcat_PostgreSQL_XML: runs-on: ubuntu-latest steps: diff --git a/.github/workflows/fit_Tomcat_PostgreSQL_YAML.yml b/.github/workflows/fit_Tomcat_PostgreSQL_YAML.yml index 520232a63b..ba19bdd2d0 100644 --- a/.github/workflows/fit_Tomcat_PostgreSQL_YAML.yml +++ b/.github/workflows/fit_Tomcat_PostgreSQL_YAML.yml @@ -14,7 +14,7 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License -name: "FIT Tomcat H2 YAML" +name: "FIT Tomcat PostgreSQL YAML" on: push: @@ -26,7 +26,7 @@ on: - cron: '0 13 * * 4' jobs: - fit_Tomcat_H2_YAML: + fit_Tomcat_PostgreSQL_YAML: runs-on: ubuntu-latest steps: diff --git a/core/idm/logic/pom.xml b/core/idm/logic/pom.xml index 2dff06b3ae..b78651d03d 100644 --- a/core/idm/logic/pom.xml +++ b/core/idm/logic/pom.xml @@ -83,8 +83,8 @@ under the License. test - org.testcontainers - postgresql + io.zonky.test + embedded-postgres test diff --git a/core/idm/logic/src/test/java/org/apache/syncope/core/logic/AbstractTest.java b/core/idm/logic/src/test/java/org/apache/syncope/core/logic/AbstractTest.java index 3813488a7e..e62a95e55b 100644 --- a/core/idm/logic/src/test/java/org/apache/syncope/core/logic/AbstractTest.java +++ b/core/idm/logic/src/test/java/org/apache/syncope/core/logic/AbstractTest.java @@ -18,57 +18,49 @@ */ package org.apache.syncope.core.logic; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; +import io.zonky.test.db.postgres.embedded.EmbeddedPostgres; import jakarta.persistence.EntityManager; -import java.io.InputStream; -import java.util.Map; -import java.util.Properties; +import java.util.function.Supplier; import org.apache.syncope.common.lib.types.EntitlementsHolder; import org.apache.syncope.common.lib.types.IdMEntitlement; import org.apache.syncope.common.lib.types.IdRepoEntitlement; import org.apache.syncope.core.persistence.jpa.MasterDomain; import org.junit.jupiter.api.BeforeAll; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.DynamicPropertyRegistry; import org.springframework.test.context.DynamicPropertySource; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -import org.testcontainers.containers.PostgreSQLContainer; @SpringJUnitConfig(classes = { MasterDomain.class, IdMLogicTestContext.class }) public abstract class AbstractTest { - private static final Logger LOG = LoggerFactory.getLogger(AbstractTest.class); + private static Supplier JDBC_URL_SUPPLIER; - private static final PostgreSQLContainer MASTER_DOMAIN; + private static final Supplier DB_CRED_SUPPLIER = () -> "syncope"; static { - String dockerPostgreSQLVersion = null; - try (InputStream propStream = AbstractTest.class.getResourceAsStream("/test.properties")) { - Properties props = new Properties(); - props.load(propStream); + try { + EmbeddedPostgres pg = EmbeddedPostgres.builder().start(); + JdbcTemplate jdbcTemplate = new JdbcTemplate(pg.getPostgresDatabase()); + jdbcTemplate.execute("CREATE DATABASE syncope"); - dockerPostgreSQLVersion = props.getProperty("docker.postgresql.version"); + jdbcTemplate.execute("CREATE USER syncope WITH PASSWORD 'syncope'"); + jdbcTemplate.execute("ALTER DATABASE syncope OWNER TO syncope"); + + JDBC_URL_SUPPLIER = () -> pg.getJdbcUrl("syncope", "syncope") + "&stringtype=unspecified"; } catch (Exception e) { - LOG.error("Could not load /test.properties", e); + fail("Could not setup PostgreSQL database", e); } - assertNotNull(dockerPostgreSQLVersion); - - MASTER_DOMAIN = new PostgreSQLContainer<>("postgres:" + dockerPostgreSQLVersion). - withTmpFs(Map.of("/var/lib/postgresql/data", "rw")). - withDatabaseName("syncope").withPassword("syncope").withUsername("syncope"). - withUrlParam("stringtype", "unspecified"). - withReuse(true); - MASTER_DOMAIN.start(); } @DynamicPropertySource static void configureProperties(final DynamicPropertyRegistry registry) { - registry.add("DB_URL", MASTER_DOMAIN::getJdbcUrl); - registry.add("DB_USER", MASTER_DOMAIN::getUsername); - registry.add("DB_PASSWORD", MASTER_DOMAIN::getPassword); + registry.add("DB_URL", JDBC_URL_SUPPLIER); + registry.add("DB_USER", DB_CRED_SUPPLIER); + registry.add("DB_PASSWORD", DB_CRED_SUPPLIER); } @BeforeAll diff --git a/core/idrepo/logic/pom.xml b/core/idrepo/logic/pom.xml index 240636d2da..630e6aec8a 100644 --- a/core/idrepo/logic/pom.xml +++ b/core/idrepo/logic/pom.xml @@ -92,8 +92,8 @@ under the License. test - org.testcontainers - postgresql + io.zonky.test + embedded-postgres test diff --git a/core/idrepo/logic/src/test/java/org/apache/syncope/core/logic/AbstractTest.java b/core/idrepo/logic/src/test/java/org/apache/syncope/core/logic/AbstractTest.java index 2f6c797c90..4f151a41bc 100644 --- a/core/idrepo/logic/src/test/java/org/apache/syncope/core/logic/AbstractTest.java +++ b/core/idrepo/logic/src/test/java/org/apache/syncope/core/logic/AbstractTest.java @@ -18,56 +18,48 @@ */ package org.apache.syncope.core.logic; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; +import io.zonky.test.db.postgres.embedded.EmbeddedPostgres; import jakarta.persistence.EntityManager; -import java.io.InputStream; -import java.util.Map; -import java.util.Properties; +import java.util.function.Supplier; import org.apache.syncope.common.lib.types.EntitlementsHolder; import org.apache.syncope.common.lib.types.IdRepoEntitlement; import org.apache.syncope.core.persistence.jpa.MasterDomain; import org.junit.jupiter.api.BeforeAll; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.DynamicPropertyRegistry; import org.springframework.test.context.DynamicPropertySource; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -import org.testcontainers.containers.PostgreSQLContainer; @SpringJUnitConfig(classes = { MasterDomain.class, IdRepoLogicTestContext.class }) public abstract class AbstractTest { - private static final Logger LOG = LoggerFactory.getLogger(AbstractTest.class); + private static Supplier JDBC_URL_SUPPLIER; - private static final PostgreSQLContainer MASTER_DOMAIN; + private static final Supplier DB_CRED_SUPPLIER = () -> "syncope"; static { - String dockerPostgreSQLVersion = null; - try (InputStream propStream = AbstractTest.class.getResourceAsStream("/test.properties")) { - Properties props = new Properties(); - props.load(propStream); + try { + EmbeddedPostgres pg = EmbeddedPostgres.builder().start(); + JdbcTemplate jdbcTemplate = new JdbcTemplate(pg.getPostgresDatabase()); + jdbcTemplate.execute("CREATE DATABASE syncope"); - dockerPostgreSQLVersion = props.getProperty("docker.postgresql.version"); + jdbcTemplate.execute("CREATE USER syncope WITH PASSWORD 'syncope'"); + jdbcTemplate.execute("ALTER DATABASE syncope OWNER TO syncope"); + + JDBC_URL_SUPPLIER = () -> pg.getJdbcUrl("syncope", "syncope") + "&stringtype=unspecified"; } catch (Exception e) { - LOG.error("Could not load /test.properties", e); + fail("Could not setup PostgreSQL database", e); } - assertNotNull(dockerPostgreSQLVersion); - - MASTER_DOMAIN = new PostgreSQLContainer<>("postgres:" + dockerPostgreSQLVersion). - withTmpFs(Map.of("/var/lib/postgresql/data", "rw")). - withDatabaseName("syncope").withPassword("syncope").withUsername("syncope"). - withUrlParam("stringtype", "unspecified"). - withReuse(true); - MASTER_DOMAIN.start(); } @DynamicPropertySource static void configureProperties(final DynamicPropertyRegistry registry) { - registry.add("DB_URL", MASTER_DOMAIN::getJdbcUrl); - registry.add("DB_USER", MASTER_DOMAIN::getUsername); - registry.add("DB_PASSWORD", MASTER_DOMAIN::getPassword); + registry.add("DB_URL", JDBC_URL_SUPPLIER); + registry.add("DB_USER", DB_CRED_SUPPLIER); + registry.add("DB_PASSWORD", DB_CRED_SUPPLIER); } @BeforeAll diff --git a/core/persistence-jpa/pom.xml b/core/persistence-jpa/pom.xml index 86cec46dc7..cb0dae80fb 100644 --- a/core/persistence-jpa/pom.xml +++ b/core/persistence-jpa/pom.xml @@ -100,8 +100,8 @@ under the License. test - org.testcontainers - postgresql + io.zonky.test + embedded-postgres test diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/AbstractTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/AbstractTest.java index 4902068408..ce7c865b48 100644 --- a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/AbstractTest.java +++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/AbstractTest.java @@ -19,31 +19,29 @@ package org.apache.syncope.core.persistence.jpa; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; +import io.zonky.test.db.postgres.embedded.EmbeddedPostgres; import jakarta.persistence.EntityManager; import java.io.InputStream; import java.util.Map; import java.util.Properties; import java.util.function.Supplier; +import java.util.stream.Stream; import org.apache.syncope.core.persistence.api.entity.AnyUtilsFactory; import org.apache.syncope.core.persistence.api.entity.EntityFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.DynamicPropertyRegistry; import org.springframework.test.context.DynamicPropertySource; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -import org.testcontainers.containers.JdbcDatabaseContainer; import org.testcontainers.containers.MariaDBContainer; import org.testcontainers.containers.MySQLContainer; -import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.oracle.OracleContainer; @SpringJUnitConfig(classes = { MasterDomain.class, PersistenceTestContext.class }) public abstract class AbstractTest { - private static final Logger LOG = LoggerFactory.getLogger(AbstractTest.class); - private static String JDBC_DRIVER; private static String DATABASE_PLATFORM; @@ -54,13 +52,17 @@ public abstract class AbstractTest { private static String VIEWS = "classpath:META-INF/views.xml"; - private static Supplier DB_USER_SUPPLIER; + private static Supplier JDBC_URL_SUPPLIER; + + private static Supplier JDBC2_URL_SUPPLIER; - private static Supplier DB2_USER_SUPPLIER; + private static Supplier DB_USER_SUPPLIER = () -> "syncope"; - private static JdbcDatabaseContainer MASTER_DOMAIN; + private static Supplier DB_PWD_SUPPLIER = () -> "syncope"; - private static JdbcDatabaseContainer TWO_DOMAIN; + private static Supplier DB2_USER_SUPPLIER = () -> "syncope"; + + private static Supplier DB2_PWD_SUPPLIER = () -> "syncope"; private static boolean classExists(final String name) { try { @@ -73,7 +75,6 @@ private static boolean classExists(final String name) { } static { - String dockerPostgreSQLVersion = null; String dockerMySQLVersion = null; String dockerMariaDBVersion = null; String dockerOracleVersion = null; @@ -81,20 +82,16 @@ private static boolean classExists(final String name) { Properties props = new Properties(); props.load(propStream); - dockerPostgreSQLVersion = props.getProperty("docker.postgresql.version"); dockerMySQLVersion = props.getProperty("docker.mysql.version"); dockerMariaDBVersion = props.getProperty("docker.mariadb.version"); dockerOracleVersion = props.getProperty("docker.oracle.version"); } catch (Exception e) { - LOG.error("Could not load /test.properties", e); + fail("Could not load /test.properties", e); } - assertNotNull(dockerPostgreSQLVersion); assertNotNull(dockerMySQLVersion); assertNotNull(dockerMariaDBVersion); assertNotNull(dockerOracleVersion); - MASTER_DOMAIN = null; - TWO_DOMAIN = null; if (classExists("org.postgresql.Driver")) { JDBC_DRIVER = "org.postgresql.Driver"; DATABASE_PLATFORM = "org.apache.openjpa.jdbc.sql.PostgresDictionary"; @@ -102,19 +99,23 @@ private static boolean classExists(final String name) { INDEXES = "classpath:META-INF/indexes.xml"; VIEWS = "classpath:META-INF/views.xml"; - MASTER_DOMAIN = new PostgreSQLContainer<>("postgres:" + dockerPostgreSQLVersion). - withTmpFs(Map.of("/var/lib/postgresql/data", "rw")). - withDatabaseName("syncope").withPassword("syncope").withUsername("syncope"). - withUrlParam("stringtype", "unspecified"). - withReuse(true); - TWO_DOMAIN = new PostgreSQLContainer<>("postgres:" + dockerPostgreSQLVersion). - withTmpFs(Map.of("/var/lib/postgresql/data", "rw")). - withDatabaseName("syncope").withPassword("syncope").withUsername("syncope"). - withUrlParam("stringtype", "unspecified"). - withReuse(true); - - DB_USER_SUPPLIER = MASTER_DOMAIN::getUsername; - DB2_USER_SUPPLIER = TWO_DOMAIN::getUsername; + try { + EmbeddedPostgres pg = EmbeddedPostgres.builder().start(); + JdbcTemplate jdbcTemplate = new JdbcTemplate(pg.getPostgresDatabase()); + Stream.of("syncope", "syncopetwo").forEach(key -> { + jdbcTemplate.execute("CREATE DATABASE " + key); + + jdbcTemplate.execute("CREATE USER " + key + " WITH PASSWORD '" + key + "'"); + jdbcTemplate.execute("ALTER DATABASE " + key + " OWNER TO " + key); + }); + + JDBC_URL_SUPPLIER = () -> pg.getJdbcUrl("syncope", "syncope") + "&stringtype=unspecified"; + JDBC2_URL_SUPPLIER = () -> pg.getJdbcUrl("syncopetwo", "syncopetwo") + "&stringtype=unspecified"; + DB2_USER_SUPPLIER = () -> "syncopetwo"; + DB2_PWD_SUPPLIER = () -> "syncopetwo"; + } catch (Exception e) { + fail("Could not setup PostgreSQL databases", e); + } } else if (classExists("com.mysql.cj.jdbc.Driver")) { JDBC_DRIVER = "com.mysql.cj.jdbc.Driver"; DATABASE_PLATFORM = "org.apache.openjpa.jdbc.sql.MySQLDictionary(" @@ -123,19 +124,21 @@ private static boolean classExists(final String name) { INDEXES = "classpath:META-INF/mysql/indexes.xml"; VIEWS = "classpath:META-INF/mysql/views.xml"; - MASTER_DOMAIN = new MySQLContainer<>("mysql:" + dockerMySQLVersion). + MySQLContainer masterDomain = new MySQLContainer<>("mysql:" + dockerMySQLVersion). withTmpFs(Map.of("/var/lib/mysql", "rw")). withDatabaseName("syncope").withPassword("syncope").withUsername("syncope"). withUrlParam("characterEncoding", "UTF-8"). withReuse(true); - TWO_DOMAIN = new MySQLContainer<>("mysql:" + dockerMySQLVersion). + masterDomain.start(); + JDBC_URL_SUPPLIER = () -> masterDomain.getJdbcUrl(); + + MySQLContainer twoDomain = new MySQLContainer<>("mysql:" + dockerMySQLVersion). withTmpFs(Map.of("/var/lib/mysql", "rw")). withDatabaseName("syncope").withPassword("syncope").withUsername("syncope"). withUrlParam("characterEncoding", "UTF-8"). withReuse(true); - - DB_USER_SUPPLIER = MASTER_DOMAIN::getUsername; - DB2_USER_SUPPLIER = TWO_DOMAIN::getUsername; + twoDomain.start(); + JDBC2_URL_SUPPLIER = () -> twoDomain.getJdbcUrl(); } else if (classExists("org.mariadb.jdbc.Driver")) { JDBC_DRIVER = "org.mariadb.jdbc.Driver"; DATABASE_PLATFORM = "org.apache.openjpa.jdbc.sql.MariaDBDictionary(" @@ -144,20 +147,27 @@ private static boolean classExists(final String name) { INDEXES = "classpath:META-INF/mariadb/indexes.xml"; VIEWS = "classpath:META-INF/mariadb/views.xml"; - MASTER_DOMAIN = new MariaDBContainer<>("mariadb:" + dockerMariaDBVersion). + MariaDBContainer masterDomain = new MariaDBContainer<>("mariadb:" + dockerMariaDBVersion). withTmpFs(Map.of("/var/lib/mysql", "rw")). withDatabaseName("syncope").withPassword("syncope").withUsername("syncope"). withUrlParam("characterEncoding", "UTF-8"). withReuse(true); - TWO_DOMAIN = new MariaDBContainer<>("mariadb:" + dockerMariaDBVersion). + masterDomain.start(); + JDBC_URL_SUPPLIER = () -> masterDomain.getJdbcUrl(); + + MariaDBContainer twoDomain = new MariaDBContainer<>("mariadb:" + dockerMariaDBVersion). withTmpFs(Map.of("/var/lib/mysql", "rw")). withDatabaseName("syncope").withPassword("syncope").withUsername("syncope"). withUrlParam("characterEncoding", "UTF-8"). withReuse(true); + twoDomain.start(); + JDBC2_URL_SUPPLIER = () -> twoDomain.getJdbcUrl(); // https://jira.mariadb.org/browse/MDEV-27898 DB_USER_SUPPLIER = () -> "root"; + DB_PWD_SUPPLIER = () -> "syncope"; DB2_USER_SUPPLIER = () -> "root"; + DB2_PWD_SUPPLIER = () -> "syncope"; } else if (classExists("oracle.jdbc.OracleDriver")) { JDBC_DRIVER = "oracle.jdbc.OracleDriver"; DATABASE_PLATFORM = "org.apache.openjpa.jdbc.sql.OracleDictionary"; @@ -165,25 +175,18 @@ private static boolean classExists(final String name) { INDEXES = "classpath:META-INF/oracle/indexes.xml"; VIEWS = "classpath:META-INF/oracle/views.xml"; - MASTER_DOMAIN = new OracleContainer("gvenzl/oracle-free:" + dockerOracleVersion). + OracleContainer masterDomain = new OracleContainer("gvenzl/oracle-free:" + dockerOracleVersion). withDatabaseName("syncope").withPassword("syncope").withUsername("syncope"). withReuse(true); - TWO_DOMAIN = new OracleContainer("gvenzl/oracle-free:" + dockerOracleVersion). + masterDomain.start(); + JDBC_URL_SUPPLIER = () -> masterDomain.getJdbcUrl(); + + OracleContainer twoDomain = new OracleContainer("gvenzl/oracle-free:" + dockerOracleVersion). withDatabaseName("syncope").withPassword("syncope").withUsername("syncope"). withReuse(true); - - DB_USER_SUPPLIER = MASTER_DOMAIN::getUsername; - DB2_USER_SUPPLIER = TWO_DOMAIN::getUsername; - } - - if (MASTER_DOMAIN == null) { - throw new IllegalStateException("Could not inizialize TestContainers for domain Master"); - } - MASTER_DOMAIN.start(); - if (TWO_DOMAIN == null) { - throw new IllegalStateException("Could not inizialize TestContainers for domain Two"); + twoDomain.start(); + JDBC2_URL_SUPPLIER = () -> twoDomain.getJdbcUrl(); } - TWO_DOMAIN.start(); } @DynamicPropertySource @@ -194,13 +197,13 @@ static void configureProperties(final DynamicPropertyRegistry registry) { registry.add("INDEXES", () -> INDEXES); registry.add("VIEWS", () -> VIEWS); - registry.add("DB_URL", MASTER_DOMAIN::getJdbcUrl); + registry.add("DB_URL", JDBC_URL_SUPPLIER::get); registry.add("DB_USER", DB_USER_SUPPLIER::get); - registry.add("DB_PASSWORD", MASTER_DOMAIN::getPassword); + registry.add("DB_PASSWORD", DB_PWD_SUPPLIER::get); - registry.add("DB2_URL", TWO_DOMAIN::getJdbcUrl); + registry.add("DB2_URL", JDBC2_URL_SUPPLIER::get); registry.add("DB2_USER", DB2_USER_SUPPLIER::get); - registry.add("DB2_PASSWORD", TWO_DOMAIN::getPassword); + registry.add("DB2_PASSWORD", DB2_PWD_SUPPLIER::get); } @Autowired diff --git a/core/persistence-jpa/src/test/resources/test.properties b/core/persistence-jpa/src/test/resources/test.properties index 68df80da91..e772d2ea88 100644 --- a/core/persistence-jpa/src/test/resources/test.properties +++ b/core/persistence-jpa/src/test/resources/test.properties @@ -14,7 +14,6 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -docker.postgresql.version=${docker.postgresql.version} docker.mysql.version=${docker.mysql.version} docker.mariadb.version=${docker.mariadb.version} docker.oracle.version=${docker.oracle.version} diff --git a/core/provisioning-java/pom.xml b/core/provisioning-java/pom.xml index c3b0acf1cc..aa2c485e8b 100644 --- a/core/provisioning-java/pom.xml +++ b/core/provisioning-java/pom.xml @@ -133,8 +133,8 @@ under the License. test - org.testcontainers - postgresql + io.zonky.test + embedded-postgres test diff --git a/core/provisioning-java/src/test/java/org/apache/syncope/core/provisioning/java/AbstractTest.java b/core/provisioning-java/src/test/java/org/apache/syncope/core/provisioning/java/AbstractTest.java index 3cfb6f2d9b..0b66606c99 100644 --- a/core/provisioning-java/src/test/java/org/apache/syncope/core/provisioning/java/AbstractTest.java +++ b/core/provisioning-java/src/test/java/org/apache/syncope/core/provisioning/java/AbstractTest.java @@ -18,12 +18,11 @@ */ package org.apache.syncope.core.provisioning.java; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; +import io.zonky.test.db.postgres.embedded.EmbeddedPostgres; import jakarta.persistence.EntityManager; -import java.io.InputStream; -import java.util.Map; -import java.util.Properties; +import java.util.function.Supplier; import org.apache.syncope.common.lib.types.AMEntitlement; import org.apache.syncope.common.lib.types.EntitlementsHolder; import org.apache.syncope.common.lib.types.IdMEntitlement; @@ -34,47 +33,40 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.MockitoAnnotations; import org.mockito.junit.jupiter.MockitoExtension; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.DynamicPropertyRegistry; import org.springframework.test.context.DynamicPropertySource; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -import org.testcontainers.containers.PostgreSQLContainer; @SpringJUnitConfig(classes = { MasterDomain.class, ProvisioningTestContext.class }) @ExtendWith(MockitoExtension.class) public abstract class AbstractTest { - private static final Logger LOG = LoggerFactory.getLogger(AbstractTest.class); + private static Supplier JDBC_URL_SUPPLIER; - private static final PostgreSQLContainer MASTER_DOMAIN; + private static final Supplier DB_CRED_SUPPLIER = () -> "syncope"; static { - String dockerPostgreSQLVersion = null; - try (InputStream propStream = AbstractTest.class.getResourceAsStream("/test.properties")) { - Properties props = new Properties(); - props.load(propStream); + try { + EmbeddedPostgres pg = EmbeddedPostgres.builder().start(); + JdbcTemplate jdbcTemplate = new JdbcTemplate(pg.getPostgresDatabase()); + jdbcTemplate.execute("CREATE DATABASE syncope"); - dockerPostgreSQLVersion = props.getProperty("docker.postgresql.version"); + jdbcTemplate.execute("CREATE USER syncope WITH PASSWORD 'syncope'"); + jdbcTemplate.execute("ALTER DATABASE syncope OWNER TO syncope"); + + JDBC_URL_SUPPLIER = () -> pg.getJdbcUrl("syncope", "syncope") + "&stringtype=unspecified"; } catch (Exception e) { - LOG.error("Could not load /test.properties", e); + fail("Could not setup PostgreSQL database", e); } - assertNotNull(dockerPostgreSQLVersion); - - MASTER_DOMAIN = new PostgreSQLContainer<>("postgres:" + dockerPostgreSQLVersion). - withTmpFs(Map.of("/var/lib/postgresql/data", "rw")). - withDatabaseName("syncope").withPassword("syncope").withUsername("syncope"). - withUrlParam("stringtype", "unspecified"). - withReuse(true); - MASTER_DOMAIN.start(); } @DynamicPropertySource static void configureProperties(final DynamicPropertyRegistry registry) { - registry.add("DB_URL", MASTER_DOMAIN::getJdbcUrl); - registry.add("DB_USER", MASTER_DOMAIN::getUsername); - registry.add("DB_PASSWORD", MASTER_DOMAIN::getPassword); + registry.add("DB_URL", JDBC_URL_SUPPLIER); + registry.add("DB_USER", DB_CRED_SUPPLIER); + registry.add("DB_PASSWORD", DB_CRED_SUPPLIER); } @BeforeAll diff --git a/core/workflow-java/pom.xml b/core/workflow-java/pom.xml index 242fd1c0a5..43311d1f0b 100644 --- a/core/workflow-java/pom.xml +++ b/core/workflow-java/pom.xml @@ -76,8 +76,8 @@ under the License. test - org.testcontainers - postgresql + io.zonky.test + embedded-postgres test diff --git a/core/workflow-java/src/test/java/org/apache/syncope/core/workflow/java/AbstractTest.java b/core/workflow-java/src/test/java/org/apache/syncope/core/workflow/java/AbstractTest.java index 3ebea6a23b..f4393ec0e9 100644 --- a/core/workflow-java/src/test/java/org/apache/syncope/core/workflow/java/AbstractTest.java +++ b/core/workflow-java/src/test/java/org/apache/syncope/core/workflow/java/AbstractTest.java @@ -18,50 +18,42 @@ */ package org.apache.syncope.core.workflow.java; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; -import java.io.InputStream; -import java.util.Map; -import java.util.Properties; +import io.zonky.test.db.postgres.embedded.EmbeddedPostgres; +import java.util.function.Supplier; import org.apache.syncope.core.persistence.jpa.MasterDomain; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.DynamicPropertyRegistry; import org.springframework.test.context.DynamicPropertySource; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -import org.testcontainers.containers.PostgreSQLContainer; @SpringJUnitConfig(classes = { MasterDomain.class, WorkflowTestContext.class }) public abstract class AbstractTest { - private static final Logger LOG = LoggerFactory.getLogger(AbstractTest.class); + private static Supplier JDBC_URL_SUPPLIER; - private static final PostgreSQLContainer MASTER_DOMAIN; + private static final Supplier DB_CRED_SUPPLIER = () -> "syncope"; static { - String dockerPostgreSQLVersion = null; - try (InputStream propStream = AbstractTest.class.getResourceAsStream("/test.properties")) { - Properties props = new Properties(); - props.load(propStream); + try { + EmbeddedPostgres pg = EmbeddedPostgres.builder().start(); + JdbcTemplate jdbcTemplate = new JdbcTemplate(pg.getPostgresDatabase()); + jdbcTemplate.execute("CREATE DATABASE syncope"); - dockerPostgreSQLVersion = props.getProperty("docker.postgresql.version"); + jdbcTemplate.execute("CREATE USER syncope WITH PASSWORD 'syncope'"); + jdbcTemplate.execute("ALTER DATABASE syncope OWNER TO syncope"); + + JDBC_URL_SUPPLIER = () -> pg.getJdbcUrl("syncope", "syncope") + "&stringtype=unspecified"; } catch (Exception e) { - LOG.error("Could not load /test.properties", e); + fail("Could not setup PostgreSQL database", e); } - assertNotNull(dockerPostgreSQLVersion); - - MASTER_DOMAIN = new PostgreSQLContainer<>("postgres:" + dockerPostgreSQLVersion). - withTmpFs(Map.of("/var/lib/postgresql/data", "rw")). - withDatabaseName("syncope").withPassword("syncope").withUsername("syncope"). - withUrlParam("stringtype", "unspecified"). - withReuse(true); - MASTER_DOMAIN.start(); } @DynamicPropertySource static void configureProperties(final DynamicPropertyRegistry registry) { - registry.add("DB_URL", MASTER_DOMAIN::getJdbcUrl); - registry.add("DB_USER", MASTER_DOMAIN::getUsername); - registry.add("DB_PASSWORD", MASTER_DOMAIN::getPassword); + registry.add("DB_URL", JDBC_URL_SUPPLIER); + registry.add("DB_USER", DB_CRED_SUPPLIER); + registry.add("DB_PASSWORD", DB_CRED_SUPPLIER); } } diff --git a/fit/core-reference/pom.xml b/fit/core-reference/pom.xml index 8798f02c1f..6f31e3c687 100644 --- a/fit/core-reference/pom.xml +++ b/fit/core-reference/pom.xml @@ -744,7 +744,6 @@ under the License. com.mysql mysql-connector-j - ${jdbc.mysql.version} test @@ -845,7 +844,6 @@ under the License. org.mariadb.jdbc mariadb-java-client - ${jdbc.mariadb.version} test @@ -946,7 +944,6 @@ under the License. com.oracle.database.jdbc ojdbc11 - ${jdbc.oracle.version} test diff --git a/fit/persistence-embedded/pom.xml b/fit/persistence-embedded/pom.xml index c3bf392aef..5b4876e22f 100644 --- a/fit/persistence-embedded/pom.xml +++ b/fit/persistence-embedded/pom.xml @@ -39,18 +39,6 @@ under the License. ${basedir}/../.. - - - - io.zonky.test.postgres - embedded-postgres-binaries-bom - ${zonky.embedded-postgres-binaries.version} - pom - import - - - - org.springframework.boot diff --git a/pom.xml b/pom.xml index 5061320695..d9d9a07cde 100644 --- a/pom.xml +++ b/pom.xml @@ -1276,6 +1276,13 @@ under the License. + + io.zonky.test.postgres + embedded-postgres-binaries-bom + ${zonky.embedded-postgres-binaries.version} + pom + import + org.jsoup @@ -1283,6 +1290,27 @@ under the License. 1.18.1 + + org.postgresql + postgresql + ${jdbc.postgresql.version} + + + com.mysql + mysql-connector-j + ${jdbc.mysql.version} + + + org.mariadb.jdbc + mariadb-java-client + ${jdbc.mariadb.version} + + + com.oracle.database.jdbc + ojdbc11 + ${jdbc.oracle.version} + + com.icegreen greenmail diff --git a/standalone/pom.xml b/standalone/pom.xml index 06d0728b4c..a6df0832c8 100644 --- a/standalone/pom.xml +++ b/standalone/pom.xml @@ -42,6 +42,11 @@ under the License. + + org.postgresql + postgresql + test + org.apache.syncope.fit syncope-fit-build-tools