mirror of
https://github.com/jlengrand/quarkus.git
synced 2026-03-10 08:41:22 +00:00
Using TCCL while looking for Integrators
Add Integrator tests Fixes #7189
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
io.quarkus.it.jpa.integrator.TestIntegrator
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user