diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..d0b6c90 --- /dev/null +++ b/pom.xml @@ -0,0 +1,88 @@ + + + 4.0.0 + + org.duckdns.owly.bugs.quarkus + quarkus-7102 + 1.0-SNAPSHOT + + + true + 11 + 11 + + UTF-8 + UTF-8 + + 1.5.1.Final + ${quarkus.platform.version} + + 2.22.2 + + + 3.8.1 + + + + + + io.quarkus + quarkus-universe-bom + ${quarkus.platform.version} + pom + import + + + + + + + + io.quarkus + quarkus-hibernate-orm-panache + + + + io.quarkus + quarkus-junit5 + test + + + io.quarkus + quarkus-jdbc-h2 + test + + + + + + + io.quarkus + quarkus-maven-plugin + ${quarkus-plugin.version} + + + + build + + + + + + maven-compiler-plugin + ${compiler-plugin.version} + + + maven-surefire-plugin + ${surefire-plugin.version} + + + org.jboss.logmanager.LogManager + + + + + + diff --git a/src/main/java/org/owly/duckdns/bugs/quarkus/entity/TestEntity.java b/src/main/java/org/owly/duckdns/bugs/quarkus/entity/TestEntity.java new file mode 100644 index 0000000..40e76f3 --- /dev/null +++ b/src/main/java/org/owly/duckdns/bugs/quarkus/entity/TestEntity.java @@ -0,0 +1,43 @@ +package org.owly.duckdns.bugs.quarkus.entity; + +import io.quarkus.hibernate.orm.panache.PanacheEntity; + +import javax.persistence.Entity; +import java.util.Objects; + +@Entity +public class TestEntity extends PanacheEntity { + private String name; + + public TestEntity() { + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public String toString() { + return "TestEntity(name=" + this.getName() + ", id=" + super.id + ")"; + } + + public boolean equals(final Object other) { + return other instanceof TestEntity && + super.equals(other) && + Objects.equals(this.id, ((TestEntity) other).id) && + Objects.equals(this.name, ((TestEntity) other).name); + } + + public int hashCode() { + final int PRIME = 59; + int result = super.hashCode(); + final String name = this.getName(); + final Long id = this.id; + result = result * PRIME + (name == null ? 43 : name.hashCode()); + result = result * PRIME + (id == null ? 43 : id.hashCode()); + return result; + } +} diff --git a/src/main/java/org/owly/duckdns/bugs/quarkus/repo/TestEntityRepo.java b/src/main/java/org/owly/duckdns/bugs/quarkus/repo/TestEntityRepo.java new file mode 100644 index 0000000..ec7b9c7 --- /dev/null +++ b/src/main/java/org/owly/duckdns/bugs/quarkus/repo/TestEntityRepo.java @@ -0,0 +1,10 @@ +package org.owly.duckdns.bugs.quarkus.repo; + +import io.quarkus.hibernate.orm.panache.PanacheRepository; +import org.owly.duckdns.bugs.quarkus.entity.TestEntity; + +import javax.enterprise.context.ApplicationScoped; + +@ApplicationScoped +public class TestEntityRepo implements PanacheRepository { +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..c89bfe1 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,3 @@ +quarkus.hibernate-orm.database.generation=create +quarkus.datasource.db-kind=h2 +quarkus.datasource.jdbc.url=jdbc:h2:mem:test diff --git a/src/test/java/org/owly/duckdns/bugs/quarkus/test/TestEntityRepoTest.java b/src/test/java/org/owly/duckdns/bugs/quarkus/test/TestEntityRepoTest.java new file mode 100644 index 0000000..30c3f96 --- /dev/null +++ b/src/test/java/org/owly/duckdns/bugs/quarkus/test/TestEntityRepoTest.java @@ -0,0 +1,49 @@ +package org.owly.duckdns.bugs.quarkus.test; + +import io.quarkus.test.junit.QuarkusTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.owly.duckdns.bugs.quarkus.entity.TestEntity; +import org.owly.duckdns.bugs.quarkus.repo.TestEntityRepo; + +import javax.inject.Inject; +import javax.transaction.Transactional; + +@QuarkusTest +public class TestEntityRepoTest { + @Inject + TestEntityRepo testEntityRepo; + + @ParameterizedTest(name = "#{index} - Executing findAll() in between: {0}") + @ValueSource(booleans = {true, false}) + public void testUpdate(boolean executeFindAll) { + // Create + TestEntity testEntity = new TestEntity(); + testEntity.setName("Start"); + create(testEntity); + + // Call getAll + if (executeFindAll) + testEntityRepo.findAll().list(); + + // Update + update(testEntity.id); + + // Compare + Assertions.assertEquals("Start Updated", testEntityRepo.findById(testEntity.id).getName()); + } + + @Transactional + void create(TestEntity testEntity) { + testEntityRepo.persist(testEntity); + } + + @Transactional + void update(long id) { + TestEntity testEntity = testEntityRepo.findById(id); + testEntity.setName(testEntity.getName() + " Updated"); + testEntityRepo.persist(testEntity); + } +}