Skip to content

Commit

Permalink
Arc - implement ObserverMethod#getReception()
Browse files Browse the repository at this point in the history
  • Loading branch information
manovotn authored and gsmet committed Feb 7, 2023
1 parent 568ec0a commit a6cf32f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ Collection<Resource> generate(ObserverInfo observer) {

implementGetBeanClass(observerCreator, observer.getBeanClass());
implementNotify(observer, observerCreator, injectionPointToProviderField, reflectionRegistration, isApplicationClass);
implementGetReception(observerCreator, observer);
if (observer.getPriority() != ObserverMethod.DEFAULT_PRIORITY) {
implementGetPriority(observerCreator, observer);
}
Expand Down Expand Up @@ -258,6 +259,12 @@ protected void initMaps(ObserverInfo observer, Map<InjectionPointInfo, String> i
}
}

protected void implementGetReception(ClassCreator observerCreator, ObserverInfo observer) {
MethodCreator getObservedType = observerCreator.getMethodCreator("getReception", Reception.class)
.setModifiers(ACC_PUBLIC);
getObservedType.returnValue(getObservedType.load(observer.getReception()));
}

protected void implementGetObservedType(ClassCreator observerCreator, FieldDescriptor observedTypeField) {
MethodCreator getObservedType = observerCreator.getMethodCreator("getObservedType", Type.class)
.setModifiers(ACC_PUBLIC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.Collections;
import java.util.Set;

import jakarta.enterprise.event.Reception;
import jakarta.enterprise.event.TransactionPhase;
import jakarta.enterprise.inject.spi.Bean;
import jakarta.enterprise.inject.spi.ObserverMethod;
Expand All @@ -23,11 +22,6 @@ default Set<Annotation> getObservedQualifiers() {
return Collections.emptySet();
}

@Override
default Reception getReception() {
return Reception.ALWAYS;
}

@Override
default TransactionPhase getTransactionPhase() {
return TransactionPhase.IN_PROGRESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;

import jakarta.annotation.Priority;
import jakarta.enterprise.context.Dependent;
import jakarta.enterprise.context.RequestScoped;
import jakarta.enterprise.event.Observes;
import jakarta.enterprise.event.Reception;
import jakarta.enterprise.inject.spi.ObserverMethod;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand Down Expand Up @@ -50,6 +52,17 @@ public void testObserver() {
assertEquals(RequestScopedObserver.class.getName() + "foo", EVENTS.get(0));
assertEquals(DependentObserver.class.getName() + "foo", EVENTS.get(1));
container.requestContext().deactivate();

// TODO check reception metadata
Set<ObserverMethod<? super String>> foundOm = Arc.container().beanManager().resolveObserverMethods("eventString");
assertEquals(2, foundOm.size());
for (ObserverMethod<? super String> om : foundOm) {
if (om.getDeclaringBean().getBeanClass().equals(RequestScopedObserver.class)) {
assertEquals(Reception.IF_EXISTS, om.getReception());
} else {
assertEquals(Reception.ALWAYS, om.getReception());
}
}
}

@RequestScoped
Expand Down

0 comments on commit a6cf32f

Please sign in to comment.