use of org.springframework.context.event.test.TestEvent in project spring-framework by spring-projects.
the class AnnotationDrivenEventListenerTests method simpleEventJavaConfig.
@Test
public void simpleEventJavaConfig() {
load(TestEventListener.class);
TestEvent event = new TestEvent(this, "test");
TestEventListener listener = this.context.getBean(TestEventListener.class);
this.eventCollector.assertNoEventReceived(listener);
this.context.publishEvent(event);
this.eventCollector.assertEvent(listener, event);
this.eventCollector.assertTotalEventsCount(1);
this.eventCollector.clear();
this.context.publishEvent(event);
this.eventCollector.assertEvent(listener, event);
this.eventCollector.assertTotalEventsCount(1);
}
use of org.springframework.context.event.test.TestEvent in project spring-framework by spring-projects.
the class AnnotationDrivenEventListenerTests method exceptionPropagated.
@Test
public void exceptionPropagated() {
load(ExceptionEventListener.class);
TestEvent event = new TestEvent(this, "fail");
ExceptionEventListener listener = this.context.getBean(ExceptionEventListener.class);
this.eventCollector.assertNoEventReceived(listener);
try {
this.context.publishEvent(event);
fail("An exception should have thrown");
} catch (IllegalStateException e) {
assertEquals("Wrong exception", "Test exception", e.getMessage());
this.eventCollector.assertEvent(listener, event);
this.eventCollector.assertTotalEventsCount(1);
}
}
use of org.springframework.context.event.test.TestEvent in project spring-framework by spring-projects.
the class AnnotationDrivenEventListenerTests method eventListenerWorksWithCglibProxy.
@Test
public void eventListenerWorksWithCglibProxy() throws Exception {
load(CglibProxyTestBean.class);
CglibProxyTestBean proxy = this.context.getBean(CglibProxyTestBean.class);
assertTrue("bean should be a cglib proxy", AopUtils.isCglibProxy(proxy));
this.eventCollector.assertNoEventReceived(proxy.getId());
this.context.publishEvent(new ContextRefreshedEvent(this.context));
this.eventCollector.assertNoEventReceived(proxy.getId());
TestEvent event = new TestEvent();
this.context.publishEvent(event);
this.eventCollector.assertEvent(proxy.getId(), event);
this.eventCollector.assertTotalEventsCount(1);
}
use of org.springframework.context.event.test.TestEvent in project spring-framework by spring-projects.
the class AnnotationDrivenEventListenerTests method simpleReply.
@Test
public void simpleReply() {
load(TestEventListener.class, ReplyEventListener.class);
AnotherTestEvent event = new AnotherTestEvent(this, "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);
// reply
this.eventCollector.assertEvent(listener, new TestEvent(replyEventListener, event.getId(), "dummy"));
this.eventCollector.assertTotalEventsCount(2);
}
use of org.springframework.context.event.test.TestEvent in project spring-framework by spring-projects.
the class AnnotationDrivenEventListenerTests method simpleEventXmlConfig.
@Test
public void simpleEventXmlConfig() {
this.context = new ClassPathXmlApplicationContext("org/springframework/context/event/simple-event-configuration.xml");
TestEvent event = new TestEvent(this, "test");
TestEventListener listener = this.context.getBean(TestEventListener.class);
this.eventCollector = getEventCollector(this.context);
this.eventCollector.assertNoEventReceived(listener);
this.context.publishEvent(event);
this.eventCollector.assertEvent(listener, event);
this.eventCollector.assertTotalEventsCount(1);
}
Aggregations