org.springframework.context.TestListener Java Examples
The following examples show how to use
org.springframework.context.TestListener.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EventPublicationInterceptorTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testExpectedBehavior() throws Exception { TestBean target = new TestBean(); final TestListener listener = new TestListener(); class TestContext extends StaticApplicationContext { @Override protected void onRefresh() throws BeansException { addApplicationListener(listener); } } StaticApplicationContext ctx = new TestContext(); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("applicationEventClass", TestEvent.class.getName()); // should automatically receive applicationEventPublisher reference ctx.registerSingleton("publisher", EventPublicationInterceptor.class, pvs); ctx.registerSingleton("otherListener", FactoryBeanTestListener.class); ctx.refresh(); EventPublicationInterceptor interceptor = (EventPublicationInterceptor) ctx.getBean("publisher"); ProxyFactory factory = new ProxyFactory(target); factory.addAdvice(0, interceptor); ITestBean testBean = (ITestBean) factory.getProxy(); // invoke any method on the advised proxy to see if the interceptor has been invoked testBean.getAge(); // two events: ContextRefreshedEvent and TestEvent assertTrue("Interceptor must have published 2 events", listener.getEventCount() == 2); TestListener otherListener = (TestListener) ctx.getBean("&otherListener"); assertTrue("Interceptor must have published 2 events", otherListener.getEventCount() == 2); }
Example #2
Source File: ProxyFactoryBeanTests.java From spring-analysis-note with MIT License | 5 votes |
@Before public void setUp() throws Exception { DefaultListableBeanFactory parent = new DefaultListableBeanFactory(); parent.registerBeanDefinition("target2", new RootBeanDefinition(TestListener.class)); this.factory = new DefaultListableBeanFactory(parent); new XmlBeanDefinitionReader((BeanDefinitionRegistry) this.factory).loadBeanDefinitions( new ClassPathResource(CONTEXT, getClass())); }
Example #3
Source File: XmlWebApplicationContextTests.java From spring-analysis-note with MIT License | 5 votes |
/** * Overridden as we can't trust superclass method * @see org.springframework.context.AbstractApplicationContextTests#testEvents() */ @Override protected void doTestEvents(TestListener listener, TestListener parentListener, MyEvent event) { TestListener listenerBean = (TestListener) this.applicationContext.getBean("testListener"); TestListener parentListenerBean = (TestListener) this.applicationContext.getParent().getBean("parentListener"); super.doTestEvents(listenerBean, parentListenerBean, event); }
Example #4
Source File: EventPublicationInterceptorTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testExpectedBehavior() throws Exception { TestBean target = new TestBean(); final TestListener listener = new TestListener(); class TestContext extends StaticApplicationContext { @Override protected void onRefresh() throws BeansException { addApplicationListener(listener); } } StaticApplicationContext ctx = new TestContext(); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("applicationEventClass", TestEvent.class.getName()); // should automatically receive applicationEventPublisher reference ctx.registerSingleton("publisher", EventPublicationInterceptor.class, pvs); ctx.registerSingleton("otherListener", FactoryBeanTestListener.class); ctx.refresh(); EventPublicationInterceptor interceptor = (EventPublicationInterceptor) ctx.getBean("publisher"); ProxyFactory factory = new ProxyFactory(target); factory.addAdvice(0, interceptor); ITestBean testBean = (ITestBean) factory.getProxy(); // invoke any method on the advised proxy to see if the interceptor has been invoked testBean.getAge(); // two events: ContextRefreshedEvent and TestEvent assertTrue("Interceptor must have published 2 events", listener.getEventCount() == 2); TestListener otherListener = (TestListener) ctx.getBean("&otherListener"); assertTrue("Interceptor must have published 2 events", otherListener.getEventCount() == 2); }
Example #5
Source File: ProxyFactoryBeanTests.java From java-technology-stack with MIT License | 5 votes |
@Before public void setUp() throws Exception { DefaultListableBeanFactory parent = new DefaultListableBeanFactory(); parent.registerBeanDefinition("target2", new RootBeanDefinition(TestListener.class)); this.factory = new DefaultListableBeanFactory(parent); new XmlBeanDefinitionReader((BeanDefinitionRegistry) this.factory).loadBeanDefinitions( new ClassPathResource(CONTEXT, getClass())); }
Example #6
Source File: XmlWebApplicationContextTests.java From java-technology-stack with MIT License | 5 votes |
/** * Overridden as we can't trust superclass method * @see org.springframework.context.AbstractApplicationContextTests#testEvents() */ @Override protected void doTestEvents(TestListener listener, TestListener parentListener, MyEvent event) { TestListener listenerBean = (TestListener) this.applicationContext.getBean("testListener"); TestListener parentListenerBean = (TestListener) this.applicationContext.getParent().getBean("parentListener"); super.doTestEvents(listenerBean, parentListenerBean, event); }
Example #7
Source File: AbstractXmlWebApplicationContextTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Overridden as we can't trust superclass method * @see org.springframework.context.AbstractApplicationContextTests#testEvents() */ @Override protected void doTestEvents(TestListener listener, TestListener parentListener, MyEvent event) { TestListener listenerBean = (TestListener) this.applicationContext.getBean("testListener"); TestListener parentListenerBean = (TestListener) this.applicationContext.getParent().getBean("parentListener"); super.doTestEvents(listenerBean, parentListenerBean, event); }
Example #8
Source File: EventPublicationInterceptorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testExpectedBehavior() throws Exception { TestBean target = new TestBean(); final TestListener listener = new TestListener(); class TestContext extends StaticApplicationContext { @Override protected void onRefresh() throws BeansException { addApplicationListener(listener); } } StaticApplicationContext ctx = new TestContext(); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("applicationEventClass", TestEvent.class.getName()); // should automatically receive applicationEventPublisher reference ctx.registerSingleton("publisher", EventPublicationInterceptor.class, pvs); ctx.registerSingleton("otherListener", FactoryBeanTestListener.class); ctx.refresh(); EventPublicationInterceptor interceptor = (EventPublicationInterceptor) ctx.getBean("publisher"); ProxyFactory factory = new ProxyFactory(target); factory.addAdvice(0, interceptor); ITestBean testBean = (ITestBean) factory.getProxy(); // invoke any method on the advised proxy to see if the interceptor has been invoked testBean.getAge(); // two events: ContextRefreshedEvent and TestEvent assertTrue("Interceptor must have published 2 events", listener.getEventCount() == 2); TestListener otherListener = (TestListener) ctx.getBean("&otherListener"); assertTrue("Interceptor must have published 2 events", otherListener.getEventCount() == 2); }
Example #9
Source File: ProxyFactoryBeanTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { DefaultListableBeanFactory parent = new DefaultListableBeanFactory(); parent.registerBeanDefinition("target2", new RootBeanDefinition(TestListener.class)); this.factory = new DefaultListableBeanFactory(parent); new XmlBeanDefinitionReader((BeanDefinitionRegistry) this.factory).loadBeanDefinitions( new ClassPathResource(CONTEXT, getClass())); }
Example #10
Source File: XmlWebApplicationContextTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Overridden as we can't trust superclass method * @see org.springframework.context.AbstractApplicationContextTests#testEvents() */ @Override protected void doTestEvents(TestListener listener, TestListener parentListener, MyEvent event) { TestListener listenerBean = (TestListener) this.applicationContext.getBean("testListener"); TestListener parentListenerBean = (TestListener) this.applicationContext.getParent().getBean("parentListener"); super.doTestEvents(listenerBean, parentListenerBean, event); }