Search in sources :

Example 1 with TestEvent

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);
}
Also used : TestEvent(org.springframework.context.event.test.TestEvent) AnotherTestEvent(org.springframework.context.event.test.AnotherTestEvent) Test(org.junit.Test)

Example 2 with TestEvent

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);
    }
}
Also used : TestEvent(org.springframework.context.event.test.TestEvent) AnotherTestEvent(org.springframework.context.event.test.AnotherTestEvent) Test(org.junit.Test)

Example 3 with TestEvent

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);
}
Also used : TestEvent(org.springframework.context.event.test.TestEvent) AnotherTestEvent(org.springframework.context.event.test.AnotherTestEvent) Test(org.junit.Test)

Example 4 with TestEvent

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);
}
Also used : AnotherTestEvent(org.springframework.context.event.test.AnotherTestEvent) TestEvent(org.springframework.context.event.test.TestEvent) AnotherTestEvent(org.springframework.context.event.test.AnotherTestEvent) Test(org.junit.Test)

Example 5 with TestEvent

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);
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) TestEvent(org.springframework.context.event.test.TestEvent) AnotherTestEvent(org.springframework.context.event.test.AnotherTestEvent) Test(org.junit.Test)

Aggregations

TestEvent (org.springframework.context.event.test.TestEvent)12 Test (org.junit.Test)11 AnotherTestEvent (org.springframework.context.event.test.AnotherTestEvent)11 Advised (org.springframework.aop.framework.Advised)2 Test (org.junit.jupiter.api.Test)1 ProxyFactory (org.springframework.aop.framework.ProxyFactory)1 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)1 BeanCreationException (org.springframework.beans.factory.BeanCreationException)1 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)1 TestBean (org.springframework.beans.testfixture.beans.TestBean)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)1 TestApplicationListener (org.springframework.context.testfixture.beans.TestApplicationListener)1