From 4351a73a1357ca04187cf75ba4ca07980a718541 Mon Sep 17 00:00:00 2001 From: Michael Schnell Date: Sun, 11 Feb 2024 08:27:03 +0100 Subject: [PATCH] Removed archived units4j dependency --- jpa/pom.xml | 6 - .../jpa/AbstractPersistenceTest.java | 125 ++++++++++++++++++ .../objects4j/jpa/CurrencyAmountTest.java | 1 - .../org/fuin/objects4j/jpa/CurrencyTest.java | 1 - .../fuin/objects4j/jpa/DayOfTheWeekTest.java | 1 - .../objects4j/jpa/DayOpeningHoursTest.java | 1 - .../fuin/objects4j/jpa/EmailAddressTest.java | 1 - .../org/fuin/objects4j/jpa/HourRangeTest.java | 1 - .../fuin/objects4j/jpa/HourRangesTest.java | 1 - .../java/org/fuin/objects4j/jpa/HourTest.java | 1 - .../org/fuin/objects4j/jpa/LocaleTest.java | 1 - .../objects4j/jpa/MultiDayOfTheWeekTest.java | 1 - .../objects4j/jpa/PasswordSha512Test.java | 1 - .../java/org/fuin/objects4j/jpa/UUIDTest.java | 1 - .../org/fuin/objects4j/jpa/UserNameTest.java | 1 - .../objects4j/jpa/WeeklyOpeningHoursTest.java | 1 - pom.xml | 6 - 17 files changed, 125 insertions(+), 26 deletions(-) create mode 100644 jpa/src/test/java/org/fuin/objects4j/jpa/AbstractPersistenceTest.java diff --git a/jpa/pom.xml b/jpa/pom.xml index 04627e1..ae7ce5a 100644 --- a/jpa/pom.xml +++ b/jpa/pom.xml @@ -56,12 +56,6 @@ test - - org.fuin - units4j - test - - com.tngtech.archunit archunit diff --git a/jpa/src/test/java/org/fuin/objects4j/jpa/AbstractPersistenceTest.java b/jpa/src/test/java/org/fuin/objects4j/jpa/AbstractPersistenceTest.java new file mode 100644 index 0000000..1bc44ca --- /dev/null +++ b/jpa/src/test/java/org/fuin/objects4j/jpa/AbstractPersistenceTest.java @@ -0,0 +1,125 @@ +/** + * Copyright (C) 2015 Michael Schnell. All rights reserved. + * http://www.fuin.org/ + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see http://www.gnu.org/licenses/. + */ +package org.fuin.objects4j.jpa; + +import jakarta.persistence.EntityManager; +import jakarta.persistence.EntityManagerFactory; +import jakarta.persistence.Persistence; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Map; + +/** + * Base class for lightweight unit tests with entity manager. The tests tries to find a configuration properties file in the resource + * path:
+ * /org/fuin/units4j/AbstractPersistenceTest.properties
+ * You can use this file to configure the following properties:
+ * driver=org.hsqldb.jdbcDriver
+ * url=jdbc:hsqldb:mem:unit-testing-jpa
+ * user=sa
+ * pw=
+ * pu_name=testPU
+ * If the file is not found, the above default values are used. + */ +public abstract class AbstractPersistenceTest { + + private static EntityManagerFactory emf; + + private static EntityManager em; + + private static Connection connection; + + @BeforeAll + public static void beforeClass() throws Exception { + try { + emf = Persistence.createEntityManagerFactory("testPU"); + em = emf.createEntityManager(); + final Map props = emf.getProperties(); + final boolean shutdown = Boolean.parseBoolean("" + props.get("units4j.shutdown")); + if (shutdown) { + final String connUrl = "" + props.get("units4j.url"); + final String connUsername = "" + props.get("units4j.user"); + final String connPassword = "" + props.get("units4j.pw"); + connection = DriverManager.getConnection(connUrl, connUsername, connPassword); + } + + } catch (final SQLException ex) { + throw new RuntimeException(ex); + } + } + + @AfterAll + public static void afterClass() { + if (em != null) { + em.close(); + } + if (emf != null) { + emf.close(); + } + try { + if (connection != null) { + try (final Statement stmt = connection.createStatement()) { + stmt.execute("SHUTDOWN"); + } + } + } catch (final SQLException ex) { + throw new RuntimeException(ex); + } + } + + /** + * Returns the entity manager. + * + * @return Test entity manager. + */ + protected static EntityManager getEm() { + if (em == null) { + throw new IllegalStateException("Entity manager not available - Something went wrong..."); + } + return em; + } + + /** + * Starts a transaction. + */ + protected static void beginTransaction() { + getEm().getTransaction().begin(); + } + + /** + * Commits the current transaction. + */ + protected static void commitTransaction() { + getEm().getTransaction().commit(); + } + + /** + * Rolls back the current transaction (if active. + */ + protected static void rollbackTransaction() { + if (getEm().getTransaction().isActive()) { + getEm().getTransaction().rollback(); + } + } + +} diff --git a/jpa/src/test/java/org/fuin/objects4j/jpa/CurrencyAmountTest.java b/jpa/src/test/java/org/fuin/objects4j/jpa/CurrencyAmountTest.java index 18a5433..08ade7b 100644 --- a/jpa/src/test/java/org/fuin/objects4j/jpa/CurrencyAmountTest.java +++ b/jpa/src/test/java/org/fuin/objects4j/jpa/CurrencyAmountTest.java @@ -19,7 +19,6 @@ import jakarta.persistence.Query; import org.fuin.objects4j.core.CurrencyAmount; -import org.fuin.units4j.AbstractPersistenceTest; import org.junit.jupiter.api.Test; import java.math.BigDecimal; diff --git a/jpa/src/test/java/org/fuin/objects4j/jpa/CurrencyTest.java b/jpa/src/test/java/org/fuin/objects4j/jpa/CurrencyTest.java index 7cc1083..704d833 100644 --- a/jpa/src/test/java/org/fuin/objects4j/jpa/CurrencyTest.java +++ b/jpa/src/test/java/org/fuin/objects4j/jpa/CurrencyTest.java @@ -18,7 +18,6 @@ package org.fuin.objects4j.jpa; import jakarta.persistence.Query; -import org.fuin.units4j.AbstractPersistenceTest; import org.junit.jupiter.api.Test; import java.util.Currency; diff --git a/jpa/src/test/java/org/fuin/objects4j/jpa/DayOfTheWeekTest.java b/jpa/src/test/java/org/fuin/objects4j/jpa/DayOfTheWeekTest.java index fa3d1f3..16242a2 100644 --- a/jpa/src/test/java/org/fuin/objects4j/jpa/DayOfTheWeekTest.java +++ b/jpa/src/test/java/org/fuin/objects4j/jpa/DayOfTheWeekTest.java @@ -18,7 +18,6 @@ package org.fuin.objects4j.jpa; import org.fuin.objects4j.core.DayOfTheWeek; -import org.fuin.units4j.AbstractPersistenceTest; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/jpa/src/test/java/org/fuin/objects4j/jpa/DayOpeningHoursTest.java b/jpa/src/test/java/org/fuin/objects4j/jpa/DayOpeningHoursTest.java index 51afb27..2cbaa8b 100644 --- a/jpa/src/test/java/org/fuin/objects4j/jpa/DayOpeningHoursTest.java +++ b/jpa/src/test/java/org/fuin/objects4j/jpa/DayOpeningHoursTest.java @@ -18,7 +18,6 @@ package org.fuin.objects4j.jpa; import org.fuin.objects4j.core.DayOpeningHours; -import org.fuin.units4j.AbstractPersistenceTest; import org.junit.jupiter.api.Test; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; diff --git a/jpa/src/test/java/org/fuin/objects4j/jpa/EmailAddressTest.java b/jpa/src/test/java/org/fuin/objects4j/jpa/EmailAddressTest.java index 7813b22..e6979f7 100644 --- a/jpa/src/test/java/org/fuin/objects4j/jpa/EmailAddressTest.java +++ b/jpa/src/test/java/org/fuin/objects4j/jpa/EmailAddressTest.java @@ -18,7 +18,6 @@ package org.fuin.objects4j.jpa; import org.fuin.objects4j.core.EmailAddress; -import org.fuin.units4j.AbstractPersistenceTest; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/jpa/src/test/java/org/fuin/objects4j/jpa/HourRangeTest.java b/jpa/src/test/java/org/fuin/objects4j/jpa/HourRangeTest.java index 8153665..ed0dd4b 100644 --- a/jpa/src/test/java/org/fuin/objects4j/jpa/HourRangeTest.java +++ b/jpa/src/test/java/org/fuin/objects4j/jpa/HourRangeTest.java @@ -18,7 +18,6 @@ package org.fuin.objects4j.jpa; import org.fuin.objects4j.core.HourRange; -import org.fuin.units4j.AbstractPersistenceTest; import org.junit.jupiter.api.Test; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; diff --git a/jpa/src/test/java/org/fuin/objects4j/jpa/HourRangesTest.java b/jpa/src/test/java/org/fuin/objects4j/jpa/HourRangesTest.java index 3945b43..67f05f4 100644 --- a/jpa/src/test/java/org/fuin/objects4j/jpa/HourRangesTest.java +++ b/jpa/src/test/java/org/fuin/objects4j/jpa/HourRangesTest.java @@ -18,7 +18,6 @@ package org.fuin.objects4j.jpa; import org.fuin.objects4j.core.HourRanges; -import org.fuin.units4j.AbstractPersistenceTest; import org.junit.jupiter.api.Test; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; diff --git a/jpa/src/test/java/org/fuin/objects4j/jpa/HourTest.java b/jpa/src/test/java/org/fuin/objects4j/jpa/HourTest.java index 4b6a07c..38a0867 100644 --- a/jpa/src/test/java/org/fuin/objects4j/jpa/HourTest.java +++ b/jpa/src/test/java/org/fuin/objects4j/jpa/HourTest.java @@ -18,7 +18,6 @@ package org.fuin.objects4j.jpa; import org.fuin.objects4j.core.Hour; -import org.fuin.units4j.AbstractPersistenceTest; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/jpa/src/test/java/org/fuin/objects4j/jpa/LocaleTest.java b/jpa/src/test/java/org/fuin/objects4j/jpa/LocaleTest.java index 0ee61f9..17cc0c0 100644 --- a/jpa/src/test/java/org/fuin/objects4j/jpa/LocaleTest.java +++ b/jpa/src/test/java/org/fuin/objects4j/jpa/LocaleTest.java @@ -17,7 +17,6 @@ */ package org.fuin.objects4j.jpa; -import org.fuin.units4j.AbstractPersistenceTest; import org.junit.jupiter.api.Test; import java.util.Locale; diff --git a/jpa/src/test/java/org/fuin/objects4j/jpa/MultiDayOfTheWeekTest.java b/jpa/src/test/java/org/fuin/objects4j/jpa/MultiDayOfTheWeekTest.java index 7830101..ad1a7ec 100644 --- a/jpa/src/test/java/org/fuin/objects4j/jpa/MultiDayOfTheWeekTest.java +++ b/jpa/src/test/java/org/fuin/objects4j/jpa/MultiDayOfTheWeekTest.java @@ -18,7 +18,6 @@ package org.fuin.objects4j.jpa; import org.fuin.objects4j.core.MultiDayOfTheWeek; -import org.fuin.units4j.AbstractPersistenceTest; import org.junit.jupiter.api.Test; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; diff --git a/jpa/src/test/java/org/fuin/objects4j/jpa/PasswordSha512Test.java b/jpa/src/test/java/org/fuin/objects4j/jpa/PasswordSha512Test.java index e89286c..d2e2555 100644 --- a/jpa/src/test/java/org/fuin/objects4j/jpa/PasswordSha512Test.java +++ b/jpa/src/test/java/org/fuin/objects4j/jpa/PasswordSha512Test.java @@ -19,7 +19,6 @@ import org.fuin.objects4j.core.Password; import org.fuin.objects4j.core.PasswordSha512; -import org.fuin.units4j.AbstractPersistenceTest; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/jpa/src/test/java/org/fuin/objects4j/jpa/UUIDTest.java b/jpa/src/test/java/org/fuin/objects4j/jpa/UUIDTest.java index 8e1dda0..19e32ae 100644 --- a/jpa/src/test/java/org/fuin/objects4j/jpa/UUIDTest.java +++ b/jpa/src/test/java/org/fuin/objects4j/jpa/UUIDTest.java @@ -17,7 +17,6 @@ */ package org.fuin.objects4j.jpa; -import org.fuin.units4j.AbstractPersistenceTest; import org.junit.jupiter.api.Test; import java.util.UUID; diff --git a/jpa/src/test/java/org/fuin/objects4j/jpa/UserNameTest.java b/jpa/src/test/java/org/fuin/objects4j/jpa/UserNameTest.java index a8bae38..68cae0f 100644 --- a/jpa/src/test/java/org/fuin/objects4j/jpa/UserNameTest.java +++ b/jpa/src/test/java/org/fuin/objects4j/jpa/UserNameTest.java @@ -18,7 +18,6 @@ package org.fuin.objects4j.jpa; import org.fuin.objects4j.core.UserName; -import org.fuin.units4j.AbstractPersistenceTest; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/jpa/src/test/java/org/fuin/objects4j/jpa/WeeklyOpeningHoursTest.java b/jpa/src/test/java/org/fuin/objects4j/jpa/WeeklyOpeningHoursTest.java index 8f7275d..9011bf1 100644 --- a/jpa/src/test/java/org/fuin/objects4j/jpa/WeeklyOpeningHoursTest.java +++ b/jpa/src/test/java/org/fuin/objects4j/jpa/WeeklyOpeningHoursTest.java @@ -18,7 +18,6 @@ package org.fuin.objects4j.jpa; import org.fuin.objects4j.core.WeeklyOpeningHours; -import org.fuin.units4j.AbstractPersistenceTest; import org.junit.jupiter.api.Test; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; diff --git a/pom.xml b/pom.xml index 6ef98a1..3d4355e 100644 --- a/pom.xml +++ b/pom.xml @@ -92,12 +92,6 @@ 0.14.0-SNAPSHOT - - org.fuin - units4j - 0.12.0-SNAPSHOT - - jakarta.xml.bind jakarta.xml.bind-api