|
|
|
@ -63,6 +63,8 @@ import org.springframework.scheduling.annotation.Async; |
|
|
|
import org.springframework.scheduling.annotation.EnableAsync; |
|
|
|
import org.springframework.scheduling.annotation.EnableAsync; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
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.hamcrest.Matchers.*; |
|
|
|
import static org.junit.Assert.*; |
|
|
|
import static org.junit.Assert.*; |
|
|
|
@ -491,10 +493,20 @@ public class AnnotationDrivenEventListenerTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void conditionMatch() { |
|
|
|
public void conditionMatch() { |
|
|
|
|
|
|
|
validateConditionMatch(ConditionalEventListener.class); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void conditionMatchWithProxy() { |
|
|
|
|
|
|
|
validateConditionMatch(ConditionalEventListener.class, MethodValidationPostProcessor.class); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void validateConditionMatch(Class<?>... classes) { |
|
|
|
long timestamp = System.currentTimeMillis(); |
|
|
|
long timestamp = System.currentTimeMillis(); |
|
|
|
load(ConditionalEventListener.class); |
|
|
|
load(classes); |
|
|
|
TestEvent event = new TestEvent(this, "OK"); |
|
|
|
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.eventCollector.assertNoEventReceived(listener); |
|
|
|
|
|
|
|
|
|
|
|
this.context.publishEvent(event); |
|
|
|
this.context.publishEvent(event); |
|
|
|
@ -505,6 +517,9 @@ public class AnnotationDrivenEventListenerTests { |
|
|
|
this.eventCollector.assertEvent(listener, event, "OK"); |
|
|
|
this.eventCollector.assertEvent(listener, event, "OK"); |
|
|
|
this.eventCollector.assertTotalEventsCount(2); |
|
|
|
this.eventCollector.assertTotalEventsCount(2); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.context.publishEvent("NOT OK"); |
|
|
|
|
|
|
|
this.eventCollector.assertTotalEventsCount(2); |
|
|
|
|
|
|
|
|
|
|
|
this.context.publishEvent(timestamp); |
|
|
|
this.context.publishEvent(timestamp); |
|
|
|
this.eventCollector.assertEvent(listener, event, "OK", timestamp); |
|
|
|
this.eventCollector.assertEvent(listener, event, "OK", timestamp); |
|
|
|
this.eventCollector.assertTotalEventsCount(3); |
|
|
|
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 |
|
|
|
@Component |
|
|
|
static class ConditionalEventListener extends TestEventListener { |
|
|
|
@Validated |
|
|
|
|
|
|
|
static class ConditionalEventListener extends TestEventListener implements ConditionalEventInterface { |
|
|
|
|
|
|
|
|
|
|
|
@EventListener(condition = "'OK'.equals(#root.event.msg)") |
|
|
|
@EventListener(condition = "'OK'.equals(#root.event.msg)") |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
|