@ -25,6 +25,7 @@ import java.util.Arrays;
@@ -25,6 +25,7 @@ import java.util.Arrays;
import java.util.LinkedHashSet ;
import java.util.List ;
import java.util.Set ;
import java.util.concurrent.CompletableFuture ;
import java.util.concurrent.CountDownLatch ;
import java.util.concurrent.TimeUnit ;
import javax.annotation.PostConstruct ;
@ -32,6 +33,8 @@ import javax.annotation.PostConstruct;
@@ -32,6 +33,8 @@ import javax.annotation.PostConstruct;
import org.junit.After ;
import org.junit.Ignore ;
import org.junit.Test ;
import reactor.core.publisher.Flux ;
import reactor.core.publisher.Mono ;
import org.springframework.aop.framework.Advised ;
import org.springframework.aop.support.AopUtils ;
@ -61,6 +64,7 @@ import org.springframework.scheduling.annotation.Async;
@@ -61,6 +64,7 @@ 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.util.concurrent.SettableListenableFuture ;
import org.springframework.validation.annotation.Validated ;
import org.springframework.validation.beanvalidation.MethodValidationPostProcessor ;
@ -243,7 +247,69 @@ public class AnnotationDrivenEventListenerTests {
@@ -243,7 +247,69 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void eventListenerWorksWithSimpleInterfaceProxy ( ) throws Exception {
public void listenableFutureReply ( ) {
load ( TestEventListener . class , ReplyEventListener . class ) ;
SettableListenableFuture < String > future = new SettableListenableFuture < > ( ) ;
future . set ( "dummy" ) ;
AnotherTestEvent event = new AnotherTestEvent ( this , future ) ;
ReplyEventListener replyEventListener = this . context . getBean ( ReplyEventListener . class ) ;
TestEventListener listener = this . context . getBean ( TestEventListener . class ) ;
this . eventCollector . assertNoEventReceived ( listener ) ;
this . eventCollector . assertNoEventReceived ( replyEventListener ) ;
this . context . publishEvent ( event ) ;
this . eventCollector . assertEvent ( replyEventListener , event ) ;
this . eventCollector . assertEvent ( listener , "dummy" ) ; // reply
this . eventCollector . assertTotalEventsCount ( 2 ) ;
}
@Test
public void completableFutureReply ( ) {
load ( TestEventListener . class , ReplyEventListener . class ) ;
AnotherTestEvent event = new AnotherTestEvent ( this , CompletableFuture . completedFuture ( "dummy" ) ) ;
ReplyEventListener replyEventListener = this . context . getBean ( ReplyEventListener . class ) ;
TestEventListener listener = this . context . getBean ( TestEventListener . class ) ;
this . eventCollector . assertNoEventReceived ( listener ) ;
this . eventCollector . assertNoEventReceived ( replyEventListener ) ;
this . context . publishEvent ( event ) ;
this . eventCollector . assertEvent ( replyEventListener , event ) ;
this . eventCollector . assertEvent ( listener , "dummy" ) ; // reply
this . eventCollector . assertTotalEventsCount ( 2 ) ;
}
@Test
public void monoReply ( ) {
load ( TestEventListener . class , ReplyEventListener . class ) ;
AnotherTestEvent event = new AnotherTestEvent ( this , Mono . just ( "dummy" ) ) ;
ReplyEventListener replyEventListener = this . context . getBean ( ReplyEventListener . class ) ;
TestEventListener listener = this . context . getBean ( TestEventListener . class ) ;
this . eventCollector . assertNoEventReceived ( listener ) ;
this . eventCollector . assertNoEventReceived ( replyEventListener ) ;
this . context . publishEvent ( event ) ;
this . eventCollector . assertEvent ( replyEventListener , event ) ;
this . eventCollector . assertEvent ( listener , "dummy" ) ; // reply
this . eventCollector . assertTotalEventsCount ( 2 ) ;
}
@Test
public void fluxReply ( ) {
load ( TestEventListener . class , ReplyEventListener . class ) ;
AnotherTestEvent event = new AnotherTestEvent ( this , Flux . just ( "dummy1" , "dummy2" ) ) ;
ReplyEventListener replyEventListener = this . context . getBean ( ReplyEventListener . class ) ;
TestEventListener listener = this . context . getBean ( TestEventListener . class ) ;
this . eventCollector . assertNoEventReceived ( listener ) ;
this . eventCollector . assertNoEventReceived ( replyEventListener ) ;
this . context . publishEvent ( event ) ;
this . eventCollector . assertEvent ( replyEventListener , event ) ;
this . eventCollector . assertEvent ( listener , "dummy1" , "dummy2" ) ; // reply
this . eventCollector . assertTotalEventsCount ( 3 ) ;
}
@Test
public void eventListenerWorksWithSimpleInterfaceProxy ( ) {
load ( ScopedProxyTestBean . class ) ;
SimpleService proxy = this . context . getBean ( SimpleService . class ) ;
@ -260,7 +326,7 @@ public class AnnotationDrivenEventListenerTests {
@@ -260,7 +326,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void eventListenerWorksWithAnnotatedInterfaceProxy ( ) throws Exception {
public void eventListenerWorksWithAnnotatedInterfaceProxy ( ) {
load ( AnnotatedProxyTestBean . class ) ;
AnnotatedSimpleService proxy = this . context . getBean ( AnnotatedSimpleService . class ) ;
@ -277,7 +343,7 @@ public class AnnotationDrivenEventListenerTests {
@@ -277,7 +343,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void eventListenerWorksWithCglibProxy ( ) throws Exception {
public void eventListenerWorksWithCglibProxy ( ) {
load ( CglibProxyTestBean . class ) ;
CglibProxyTestBean proxy = this . context . getBean ( CglibProxyTestBean . class ) ;
@ -294,14 +360,14 @@ public class AnnotationDrivenEventListenerTests {
@@ -294,14 +360,14 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void privateMethodOnCglibProxyFails ( ) throws Exception {
public void privateMethodOnCglibProxyFails ( ) {
assertThatExceptionOfType ( BeanInitializationException . class ) . isThrownBy ( ( ) - >
load ( CglibProxyWithPrivateMethod . class ) )
. withCauseInstanceOf ( IllegalStateException . class ) ;
}
@Test
public void eventListenerWorksWithCustomScope ( ) throws Exception {
public void eventListenerWorksWithCustomScope ( ) {
load ( CustomScopeTestBean . class ) ;
CustomScope customScope = new CustomScope ( ) ;
this . context . getBeanFactory ( ) . registerScope ( "custom" , customScope ) ;