Skip to content

Commit

Permalink
Arc - add default impl for ObserverMethod#getDeclaringBean()
Browse files Browse the repository at this point in the history
  • Loading branch information
manovotn authored and gsmet committed Feb 7, 2023
1 parent 6c5a529 commit 568ec0a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -31,6 +35,15 @@ public void testObserver() {
producer.produce("ping");
List<String> events = observer.getEvents();
assertEquals(2, events.size());

// verify we can resolve OM and check some of its metadata
Set<ObserverMethod<? super String>> foundOms = Arc.container().beanManager().resolveObserverMethods("someString");
assertEquals(1, foundOms.size());
ObserverMethod<? super String> om = foundOms.iterator().next();
Bean<?> declaringBean = om.getDeclaringBean();
assertNotNull(declaringBean);
assertEquals(StringObserver.class, declaringBean.getBeanClass());
assertEquals(Singleton.class, declaringBean.getScope());
}

@Singleton
Expand Down

0 comments on commit 568ec0a

Please sign in to comment.