Skip to content

Commit

Permalink
Move tests that are not specific to H2 out of integration-tests/jpa-h2
Browse files Browse the repository at this point in the history
  • Loading branch information
yrodiere committed Dec 4, 2023
1 parent 36bb87a commit 25588d8
Show file tree
Hide file tree
Showing 22 changed files with 103 additions and 73 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
quarkus.datasource.jdbc.max-size=8
quarkus.hibernate-orm.database.generation=drop-and-create

dummy.transaction.timeout=30
transaction.timeout.1s=1
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,4 @@ public void testJPAFunctionalityFromServlet() throws Exception {
RestAssured.when().get("/jpa-h2/testfunctionality").then().body(is("OK"));
}

@Test
public void testHibernateEnhancedProxies() throws Exception {
RestAssured.when().get("/jpa-h2/testproxy").then().body(is("OK"));
}

@Test
public void testHibernateEnhancedBasicProxies() throws Exception {
RestAssured.when().get("/jpa-h2/testbasicproxy").then().body(is("OK"));
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.jpa.h2.generics;
package io.quarkus.it.jpa.generics;

import jakarta.persistence.Basic;
import jakarta.persistence.Lob;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.jpa.h2.generics;
package io.quarkus.it.jpa.generics;

import java.io.Serializable;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.jpa.h2.generics;
package io.quarkus.it.jpa.generics;

import jakarta.persistence.Entity;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.jpa.h2.basicproxy;
package io.quarkus.it.jpa.proxy;

import java.io.Serializable;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.jpa.h2.proxy;
package io.quarkus.it.jpa.proxy;

import jakarta.persistence.DiscriminatorValue;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.jpa.h2;
package io.quarkus.it.jpa.proxy;

import jakarta.persistence.Entity;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.jpa.h2.basicproxy;
package io.quarkus.it.jpa.proxy;

import jakarta.persistence.DiscriminatorValue;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.jpa.h2;
package io.quarkus.it.jpa.proxy;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.jpa.h2.proxy;
package io.quarkus.it.jpa.proxy;

import jakarta.persistence.DiscriminatorValue;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.jpa.h2.proxy;
package io.quarkus.it.jpa.proxy;

public interface DogProxy {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.jpa.h2;
package io.quarkus.it.jpa.proxy;

import jakarta.persistence.Entity;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.jpa.h2.proxy;
package io.quarkus.it.jpa.proxy;

import jakarta.persistence.DiscriminatorColumn;
import jakarta.persistence.DiscriminatorValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.jpa.h2.proxy;
package io.quarkus.it.jpa.proxy;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.jpa.h2.proxy;
package io.quarkus.it.jpa.proxy;

public interface PetProxy {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.jpa.h2;
package io.quarkus.it.jpa.proxy;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
package io.quarkus.it.jpa.h2.proxy;
package io.quarkus.it.jpa.proxy;

import java.io.IOException;
import java.util.List;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.event.Observes;
import jakarta.inject.Inject;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.transaction.Transactional;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

import org.wildfly.common.Assert;

import io.quarkus.narayana.jta.QuarkusTransaction;
import io.quarkus.narayana.jta.runtime.TransactionConfiguration;
import io.quarkus.runtime.StartupEvent;

@ApplicationScoped
@Path("/jpa-h2/testproxy")
@Path("/jpa/proxy")
@Produces(MediaType.TEXT_PLAIN)
public class ProxyTestEndpoint {

Expand All @@ -26,6 +30,11 @@ public class ProxyTestEndpoint {
@Transactional
@TransactionConfiguration(timeoutFromConfigProperty = "dummy.transaction.timeout")
public void setup(@Observes StartupEvent startupEvent) {
ConcreteEntity entity = new ConcreteEntity();
entity.id = "1";
entity.type = "Concrete";
entityManager.persist(entity);

Pet pet = new Pet();
pet.setId(1);
pet.setName("Goose");
Expand Down Expand Up @@ -59,7 +68,17 @@ public void setup(@Observes StartupEvent startupEvent) {
petOwner.setPet(pet);

entityManager.persist(petOwner);
}

@GET
@Path("basic")
@Transactional
public String testBasic() {
final List list = entityManager.createQuery("from ConcreteEntity").getResultList();
if (list.size() != 1) {
throw new RuntimeException("Expected 1 result, got " + list.size());
}
return "OK";
}

/**
Expand All @@ -68,7 +87,9 @@ public void setup(@Observes StartupEvent startupEvent) {
* We need to do our own proxy generation at build time, so this tests that the logic matches what hibernate expects
*/
@GET
public String test() throws IOException {
@Path("inheritance")
@Transactional
public String inheritance() {
PetOwner owner = entityManager.find(PetOwner.class, 1);
expectEquals("Stuart", owner.getName());
expectEquals("Generic pet noises", owner.getPet().makeNoise());
Expand Down Expand Up @@ -99,6 +120,27 @@ public String test() throws IOException {
return "OK";
}

@GET
@Path("enhanced")
private void testEnhanced(EntityManagerFactory emf) {
//Define the test data:
CompanyCustomer company = new CompanyCustomer();
company.companyname = "Quarked consulting, inc.";
Project project = new Project();
project.name = "Hibernate RX";
project.customer = company;

//Store the test model:
QuarkusTransaction.requiringNew()
.run(() -> entityManager.persist(project));
final Integer testId = project.id;
Assert.assertNotNull(testId);

//Now try to load it, should trigger the use of enhanced proxies:
QuarkusTransaction.requiringNew()
.run(() -> entityManager.find(Project.class, testId));
}

void expectEquals(Object expected, Object actual) {
if (!expected.equals(actual)) {
throw new RuntimeException("Expected " + expected + " but was " + actual);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ quarkus.hibernate-orm.database.generation=drop-and-create

quarkus.hibernate-orm.metadata-builder-contributor=io.quarkus.it.jpa.defaultcatalogandschema.Schema1MetadataBuilderContributor

quarkus.hibernate-orm.multitenant=DISCRIMINATOR
quarkus.hibernate-orm.multitenant=DISCRIMINATOR

dummy.transaction.timeout=30
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.quarkus.it.jpa.proxy;

import io.quarkus.test.junit.QuarkusIntegrationTest;

/**
* Test various JPA operations running in native mode
*/
@QuarkusIntegrationTest
public class ProxyInGraalITCase extends ProxyTest {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.quarkus.it.jpa.proxy;

import static org.hamcrest.Matchers.is;

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;

@QuarkusTest
public class ProxyTest {

@Test
public void testBasicProxies() {
RestAssured.when().get("/jpa/proxy/basic").then().body(is("OK"));
}

@Test
public void testProxyInheritance() {
RestAssured.when().get("/jpa/proxy/inheritance").then().body(is("OK"));
}

@Test
public void testEnhancedProxies() {
RestAssured.when().get("/jpa/proxy/enhanced").then().body(is("OK"));
}

}

0 comments on commit 25588d8

Please sign in to comment.