Package org.springframework.context

Examples of org.springframework.context.TestListener


    }.runTest();
  }

  public void testExpectedBehavior() throws Exception {
    TestBean target = new TestBean();
    final TestListener listener = new TestListener();

    class TestContext extends StaticApplicationContext {
      protected void onRefresh() throws BeansException {
        addListener(listener);
      }
    }

    StaticApplicationContext ctx = new TestContext();
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("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);
  }
View Full Code Here


  }

  @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);
  }
View Full Code Here

   * @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);

  };
View Full Code Here

   * @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);
  }
View Full Code Here

TOP

Related Classes of org.springframework.context.TestListener

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.