Reliably detect event listener conditions on proxied beans
Issue: SPR-15678
This commit is contained in:
@@ -63,6 +63,8 @@ import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.validation.beanvalidation.MethodValidationPostProcessor;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
@@ -491,10 +493,20 @@ public class AnnotationDrivenEventListenerTests {
|
||||
|
||||
@Test
|
||||
public void conditionMatch() {
|
||||
validateConditionMatch(ConditionalEventListener.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void conditionMatchWithProxy() {
|
||||
validateConditionMatch(ConditionalEventListener.class, MethodValidationPostProcessor.class);
|
||||
}
|
||||
|
||||
private void validateConditionMatch(Class<?>... classes) {
|
||||
long timestamp = System.currentTimeMillis();
|
||||
load(ConditionalEventListener.class);
|
||||
load(classes);
|
||||
TestEvent event = new TestEvent(this, "OK");
|
||||
TestEventListener listener = this.context.getBean(ConditionalEventListener.class);
|
||||
|
||||
ConditionalEventInterface listener = this.context.getBean(ConditionalEventInterface.class);
|
||||
this.eventCollector.assertNoEventReceived(listener);
|
||||
|
||||
this.context.publishEvent(event);
|
||||
@@ -505,6 +517,9 @@ public class AnnotationDrivenEventListenerTests {
|
||||
this.eventCollector.assertEvent(listener, event, "OK");
|
||||
this.eventCollector.assertTotalEventsCount(2);
|
||||
|
||||
this.context.publishEvent("NOT OK");
|
||||
this.eventCollector.assertTotalEventsCount(2);
|
||||
|
||||
this.context.publishEvent(timestamp);
|
||||
this.eventCollector.assertEvent(listener, event, "OK", timestamp);
|
||||
this.eventCollector.assertTotalEventsCount(3);
|
||||
@@ -896,8 +911,21 @@ public class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
|
||||
interface ConditionalEventInterface extends Identifiable {
|
||||
|
||||
void handle(TestEvent event);
|
||||
|
||||
void handleString(String payload);
|
||||
|
||||
void handleTimestamp(Long timestamp);
|
||||
|
||||
void handleRatio(Double ratio);
|
||||
}
|
||||
|
||||
|
||||
@Component
|
||||
static class ConditionalEventListener extends TestEventListener {
|
||||
@Validated
|
||||
static class ConditionalEventListener extends TestEventListener implements ConditionalEventInterface {
|
||||
|
||||
@EventListener(condition = "'OK'.equals(#root.event.msg)")
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user