diff --git a/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/InjectableObserverMethod.java b/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/InjectableObserverMethod.java index 2ecc487e587c9f..1fc8598b139bb5 100644 --- a/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/InjectableObserverMethod.java +++ b/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/InjectableObserverMethod.java @@ -6,6 +6,7 @@ import jakarta.enterprise.event.Reception; import jakarta.enterprise.event.TransactionPhase; +import jakarta.enterprise.inject.spi.Bean; import jakarta.enterprise.inject.spi.ObserverMethod; /** @@ -32,6 +33,11 @@ default TransactionPhase getTransactionPhase() { return TransactionPhase.IN_PROGRESS; } + @Override + default Bean getDeclaringBean() { + return Arc.container().bean(getDeclaringBeanIdentifier()); + } + /** * * @return the identifier or null for synthetic observers diff --git a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/observers/SimpleObserverTest.java b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/observers/SimpleObserverTest.java index c9a6da10accded..aef36126df7c02 100644 --- a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/observers/SimpleObserverTest.java +++ b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/observers/SimpleObserverTest.java @@ -1,14 +1,18 @@ package io.quarkus.arc.test.observers; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.util.List; +import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; import jakarta.annotation.PostConstruct; import jakarta.enterprise.context.Dependent; import jakarta.enterprise.event.Event; import jakarta.enterprise.event.Observes; +import jakarta.enterprise.inject.spi.Bean; +import jakarta.enterprise.inject.spi.ObserverMethod; import jakarta.inject.Inject; import jakarta.inject.Singleton; @@ -31,6 +35,15 @@ public void testObserver() { producer.produce("ping"); List events = observer.getEvents(); assertEquals(2, events.size()); + + // verify we can resolve OM and check some of its metadata + Set> foundOms = Arc.container().beanManager().resolveObserverMethods("someString"); + assertEquals(1, foundOms.size()); + ObserverMethod om = foundOms.iterator().next(); + Bean declaringBean = om.getDeclaringBean(); + assertNotNull(declaringBean); + assertEquals(StringObserver.class, declaringBean.getBeanClass()); + assertEquals(Singleton.class, declaringBean.getScope()); } @Singleton