Skip to content

Commit

Permalink
Removed archived units4j dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-schnell committed Feb 11, 2024
1 parent 26b0610 commit 4351a73
Show file tree
Hide file tree
Showing 17 changed files with 125 additions and 26 deletions.
6 changes: 0 additions & 6 deletions jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.fuin</groupId>
<artifactId>units4j</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit</artifactId>
Expand Down
125 changes: 125 additions & 0 deletions jpa/src/test/java/org/fuin/objects4j/jpa/AbstractPersistenceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/**
* Copyright (C) 2015 Michael Schnell. All rights reserved.
* http://www.fuin.org/
* <p>
* 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.
* <p>
* 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.
* <p>
* 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:<br>
* /org/fuin/units4j/AbstractPersistenceTest.properties<br>
* You can use this file to configure the following properties:<br>
* driver=org.hsqldb.jdbcDriver<br>
* url=jdbc:hsqldb:mem:unit-testing-jpa<br>
* user=sa<br>
* pw=<br>
* pu_name=testPU<br>
* 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<String, Object> 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();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion jpa/src/test/java/org/fuin/objects4j/jpa/CurrencyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion jpa/src/test/java/org/fuin/objects4j/jpa/HourTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion jpa/src/test/java/org/fuin/objects4j/jpa/LocaleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package org.fuin.objects4j.jpa;

import org.fuin.units4j.AbstractPersistenceTest;
import org.junit.jupiter.api.Test;

import java.util.Locale;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion jpa/src/test/java/org/fuin/objects4j/jpa/UUIDTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package org.fuin.objects4j.jpa;

import org.fuin.units4j.AbstractPersistenceTest;
import org.junit.jupiter.api.Test;

import java.util.UUID;
Expand Down
1 change: 0 additions & 1 deletion jpa/src/test/java/org/fuin/objects4j/jpa/UserNameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,6 @@
<version>0.14.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.fuin</groupId>
<artifactId>units4j</artifactId>
<version>0.12.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
Expand Down

0 comments on commit 4351a73

Please sign in to comment.