Using TCCL while looking for Integrators

Add Integrator tests

Fixes #7189
This commit is contained in:
George Gastaldi
2020-02-13 19:15:21 -03:00
parent f5063a092d
commit 2cfb4bfb50
5 changed files with 71 additions and 3 deletions

View File

@@ -222,16 +222,16 @@ public final class HibernateOrmProcessor {
recorderContext.registerNonDefaultConstructor(ParsedPersistenceXmlDescriptor.class.getDeclaredConstructor(URL.class),
(i) -> Collections.singletonList(i.getPersistenceUnitRootUrl()));
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
// inspect service files for additional integrators
Collection<Class<? extends Integrator>> integratorClasses = new LinkedHashSet<>();
for (String integratorClassName : ServiceUtil.classNamesNamedIn(getClass().getClassLoader(),
for (String integratorClassName : ServiceUtil.classNamesNamedIn(classLoader,
"META-INF/services/org.hibernate.integrator.spi.Integrator")) {
integratorClasses.add((Class<? extends Integrator>) recorderContext.classProxy(integratorClassName));
}
// inspect service files for service contributors
Collection<Class<? extends ServiceContributor>> serviceContributorClasses = new LinkedHashSet<>();
for (String serviceContributorClassName : ServiceUtil.classNamesNamedIn(getClass().getClassLoader(),
for (String serviceContributorClassName : ServiceUtil.classNamesNamedIn(classLoader,
"META-INF/services/org.hibernate.service.spi.ServiceContributor")) {
serviceContributorClasses
.add((Class<? extends ServiceContributor>) recorderContext.classProxy(serviceContributorClassName));

View File

@@ -0,0 +1,24 @@
package io.quarkus.it.jpa.integrator;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/integrator")
@ApplicationScoped
public class IntegratorResource {
@Inject
EntityManager em;
@GET
@Produces(MediaType.TEXT_PLAIN)
public int create() {
return TestIntegrator.COUNTER.get();
}
}

View File

@@ -0,0 +1,23 @@
package io.quarkus.it.jpa.integrator;
import java.util.concurrent.atomic.AtomicInteger;
import org.hibernate.boot.Metadata;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
public class TestIntegrator implements Integrator {
public static final AtomicInteger COUNTER = new AtomicInteger();
@Override
public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory,
SessionFactoryServiceRegistry serviceRegistry) {
COUNTER.incrementAndGet();
}
@Override
public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
COUNTER.decrementAndGet();
}
}

View File

@@ -0,0 +1 @@
io.quarkus.it.jpa.integrator.TestIntegrator

View File

@@ -0,0 +1,20 @@
package io.quarkus.it.jpa.integrator;
import static io.restassured.RestAssured.when;
import static org.hamcrest.core.Is.is;
import org.junit.jupiter.api.Test;
import io.quarkus.test.junit.QuarkusTest;
@QuarkusTest
public class JPAIntegratorTest {
@Test
public void testInjection() {
when().get("/jpa-test/integrator").then()
.statusCode(200)
.body(is("1"));
}
}