Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace QuarkusTest and Hibernate with OpenJPA #3064

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions build/optaplanner-build-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
<version.io.quarkus>3.2.10.Final</version.io.quarkus>
<version.org.apache.commons.math3>3.6.1</version.org.apache.commons.math3>
<version.org.apache.commons.text>1.10.0</version.org.apache.commons.text>
<version.org.apache.derby>10.16.1.1</version.org.apache.derby>
<version.org.apache.openjpa>4.0.0</version.org.apache.openjpa>
<version.org.apache.poi>5.2.3</version.org.apache.poi>
<version.org.assertj>3.24.2</version.org.assertj>
<version.org.freemarker>2.3.32</version.org.freemarker>
Expand Down Expand Up @@ -178,6 +180,21 @@
<artifactId>jfreechart</artifactId>
<version>${version.org.jfree.jfreechart}</version>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're using H2 everywhere and it seems to work fine with OpenJPA (at least in Drools), if possible I would give a try to use H2 also here and avoid adding another dependency.

<version>${version.org.apache.derby}</version>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbytools</artifactId>
<version>${version.org.apache.derby}</version>
</dependency>
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa</artifactId>
<version>${version.org.apache.openjpa}</version>
</dependency>
<!-- optaplanner-operator -->
<dependency>
<groupId>io.quarkiverse.operatorsdk</groupId>
Expand Down
33 changes: 17 additions & 16 deletions optaplanner-persistence/optaplanner-persistence-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,18 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm</artifactId>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-narayana-jta</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-h2</artifactId>
<groupId>org.apache.derby</groupId>
<artifactId>derbytools</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -113,6 +103,17 @@
<filtering>false</filtering>
</testResource>
</testResources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-javaagent:${settings.localRepository}/org/apache/openjpa/openjpa/${version.org.apache.openjpa}/openjpa-${version.org.apache.openjpa}.jar</argLine>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
import org.optaplanner.core.api.score.buildin.bendable.BendableScore;
import org.optaplanner.persistence.jpa.impl.AbstractScoreJpaTest;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
class BendableScoreConverterTest extends AbstractScoreJpaTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
import org.optaplanner.core.api.score.buildin.bendablebigdecimal.BendableBigDecimalScore;
import org.optaplanner.persistence.jpa.impl.AbstractScoreJpaTest;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
class BendableBigDecimalScoreConverterTest extends AbstractScoreJpaTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,25 @@
import org.optaplanner.core.api.score.buildin.bendablelong.BendableLongScore;
import org.optaplanner.persistence.jpa.impl.AbstractScoreJpaTest;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
class BendableLongScoreConverterTest extends AbstractScoreJpaTest {

@Test
void persistAndMerge() {
persistAndMerge(new BendaleLongScoreConverterTestJpaEntity(BendableLongScore.zero(3, 2)), null,
persistAndMerge(new BendableLongScoreConverterTestJpaEntity(BendableLongScore.zero(3, 2)), null,
BendableLongScore.of(new long[] { 10000L, 2000L, 300L }, new long[] { 40L, 5L }),
BendableLongScore.ofUninitialized(-7, new long[] { 10000L, 2000L, 300L }, new long[] { 40L, 5L }));
}

@Entity
static class BendaleLongScoreConverterTestJpaEntity extends AbstractTestJpaEntity<BendableLongScore> {
static class BendableLongScoreConverterTestJpaEntity extends AbstractTestJpaEntity<BendableLongScore> {

@Convert(converter = BendableLongScoreConverter.class)
protected BendableLongScore score;

BendaleLongScoreConverterTestJpaEntity() {
BendableLongScoreConverterTestJpaEntity() {
}

public BendaleLongScoreConverterTestJpaEntity(BendableLongScore score) {
public BendableLongScoreConverterTestJpaEntity(BendableLongScore score) {
this.score = score;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
import org.optaplanner.core.api.score.buildin.hardmediumsoft.HardMediumSoftScore;
import org.optaplanner.persistence.jpa.impl.AbstractScoreJpaTest;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
class HardMediumSoftScoreConverterTest extends AbstractScoreJpaTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
import org.optaplanner.core.api.score.buildin.hardmediumsoftbigdecimal.HardMediumSoftBigDecimalScore;
import org.optaplanner.persistence.jpa.impl.AbstractScoreJpaTest;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
class HardMediumSoftBigDecimalScoreConverterTest extends AbstractScoreJpaTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
import org.optaplanner.core.api.score.buildin.hardmediumsoftlong.HardMediumSoftLongScore;
import org.optaplanner.persistence.jpa.impl.AbstractScoreJpaTest;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
class HardMediumSoftLongScoreConverterTest extends AbstractScoreJpaTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
import org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore;
import org.optaplanner.persistence.jpa.impl.AbstractScoreJpaTest;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
class HardSoftScoreConverterTest extends AbstractScoreJpaTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
import org.optaplanner.core.api.score.buildin.hardsoftbigdecimal.HardSoftBigDecimalScore;
import org.optaplanner.persistence.jpa.impl.AbstractScoreJpaTest;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
class HardSoftBigDecimalScoreConverterTest extends AbstractScoreJpaTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
import org.optaplanner.core.api.score.buildin.hardsoftlong.HardSoftLongScore;
import org.optaplanner.persistence.jpa.impl.AbstractScoreJpaTest;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
class HardSoftLongScoreConverterTest extends AbstractScoreJpaTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
import org.optaplanner.core.api.score.buildin.simple.SimpleScore;
import org.optaplanner.persistence.jpa.impl.AbstractScoreJpaTest;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
class SimpleScoreConverterTest extends AbstractScoreJpaTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
import org.optaplanner.core.api.score.buildin.simplebigdecimal.SimpleBigDecimalScore;
import org.optaplanner.persistence.jpa.impl.AbstractScoreJpaTest;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
class SimpleBigDecimalScoreConverterTest extends AbstractScoreJpaTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
import org.optaplanner.core.api.score.buildin.simplelong.SimpleLongScore;
import org.optaplanner.persistence.jpa.impl.AbstractScoreJpaTest;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
class SimpleLongScoreConverterTest extends AbstractScoreJpaTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,24 @@

import static org.assertj.core.api.Assertions.assertThat;

import jakarta.inject.Inject;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;
import jakarta.persistence.Persistence;

import org.junit.jupiter.api.BeforeEach;
import org.optaplanner.core.api.score.Score;

public abstract class AbstractScoreJpaTest {

@Inject
@BeforeEach
void setUp() {
entityManagerFactory = Persistence.createEntityManagerFactory("test");
}

EntityManagerFactory entityManagerFactory;

protected <Score_ extends Score<Score_>, E extends AbstractTestJpaEntity<Score_>> Long persistAndAssert(E jpaEntity) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<persistence version="3.0" xmlns="https://jakarta.ee/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd">
<persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
<class>org.optaplanner.persistence.jpa.impl.AbstractScoreJpaTest$AbstractTestJpaEntity</class>
<class>org.optaplanner.persistence.jpa.api.score.buildin.hardsoft.HardSoftScoreConverterTest$HardSoftScoreConverterTestJpaEntity</class>
<class>org.optaplanner.persistence.jpa.api.score.buildin.hardsoftbigdecimal.HardSoftBigDecimalScoreConverterTest$HardSoftBigDecimalScoreConverterTestJpaEntity</class>
<class>org.optaplanner.persistence.jpa.api.score.buildin.hardmediumsoftbigdecimal.HardMediumSoftBigDecimalScoreConverterTest$HardMediumSoftBigDecimalScoreConverterTestJpaEntity</class>
<class>org.optaplanner.persistence.jpa.api.score.buildin.hardmediumsoftlong.HardMediumSoftLongScoreConverterTest$HardMediumSoftLongScoreConverterTestJpaEntity</class>
<class>org.optaplanner.persistence.jpa.api.score.buildin.simple.SimpleScoreConverterTest$SimpleScoreConverterTestJpaEntity</class>
<class>org.optaplanner.persistence.jpa.api.score.buildin.bendable.BendableScoreConverterTest$BendableScoreConverterTestJpaEntity</class>
<class>org.optaplanner.persistence.jpa.api.score.buildin.hardsoftlong.HardSoftLongScoreConverterTest$HardSoftLongScoreConverterTestJpaEntity</class>
<class>org.optaplanner.persistence.jpa.api.score.buildin.simplelong.SimpleLongScoreConverterTest$SimpleLongScoreConverterTestJpaEntity</class>
<class>org.optaplanner.persistence.jpa.api.score.buildin.hardmediumsoft.HardMediumSoftScoreConverterTest$HardMediumSoftScoreConverterTestJpaEntity</class>
<class>org.optaplanner.persistence.jpa.api.score.buildin.bendablebigdecimal.BendableBigDecimalScoreConverterTest$BendableBigDecimalScoreConverterTestJpaEntity</class>
<class>org.optaplanner.persistence.jpa.api.score.buildin.bendablelong.BendableLongScoreConverterTest$BendableLongScoreConverterTestJpaEntity</class>
<class>org.optaplanner.persistence.jpa.api.score.buildin.simplebigdecimal.SimpleBigDecimalScoreConverterTest$SimpleBigDecimalScoreConverterTestJpaEntity</class>
<properties>
<property name="jakarta.persistence.schema-generation.database.action"
value="drop-and-create"/>
<property name="jakarta.persistence.jdbc.driver"
value="org.apache.derby.jdbc.EmbeddedDriver"/>
<property name="jakarta.persistence.jdbc.url"
value="jdbc:derby:db;create=true"/>
</properties>
</persistence-unit>
</persistence>
Loading