Package org.springframework.tests.sample.beans

Examples of org.springframework.tests.sample.beans.LifecycleBean$PostProcessor


  public void testTestBeanCount() {
    assertTestBeanCount(13);
  }

  public void testLifecycleMethods() throws Exception {
    LifecycleBean bean = (LifecycleBean) getBeanFactory().getBean("lifecycle");
    bean.businessMethod();
  }
View Full Code Here


    TestBean dad = applicationContext.getBean("father", TestBean.class);
    assertTrue("Dad has correct name", dad.getName().equals("Albert"));
  }

  public void testCloseTriggersDestroy() {
    LifecycleBean lb = (LifecycleBean) applicationContext.getBean("lifecycle");
    assertTrue("Not destroyed", !lb.isDestroyed());
    applicationContext.close();
    if (applicationContext.getParent() != null) {
      ((ConfigurableApplicationContext) applicationContext.getParent()).close();
    }
    assertTrue("Destroyed", lb.isDestroyed());
    applicationContext.close();
    if (applicationContext.getParent() != null) {
      ((ConfigurableApplicationContext) applicationContext.getParent()).close();
    }
    assertTrue("Destroyed", lb.isDestroyed());
  }
View Full Code Here

    ServletContextEvent event = new ServletContextEvent(sc);
    listener.contextInitialized(event);
    WebApplicationContext context = (WebApplicationContext) sc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
    assertTrue("Correct WebApplicationContext exposed in ServletContext", context instanceof XmlWebApplicationContext);
    assertTrue(WebApplicationContextUtils.getRequiredWebApplicationContext(sc) instanceof XmlWebApplicationContext);
    LifecycleBean lb = (LifecycleBean) context.getBean("lifecycle");
    assertTrue("Has father", context.containsBean("father"));
    assertTrue("Has rod", context.containsBean("rod"));
    assertTrue("Has kerry", context.containsBean("kerry"));
    assertTrue("Not destroyed", !lb.isDestroyed());
    assertFalse(context.containsBean("beans1.bean1"));
    assertFalse(context.containsBean("beans1.bean2"));
    listener.contextDestroyed(event);
    assertTrue("Destroyed", lb.isDestroyed());
    assertNull(sc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE));
    assertNull(WebApplicationContextUtils.getWebApplicationContext(sc));
  }
View Full Code Here

    ServletContextEvent event = new ServletContextEvent(sc);
    listener.contextInitialized(event);
    WebApplicationContext context = (WebApplicationContext) sc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
    assertTrue("Correct WebApplicationContext exposed in ServletContext",
        context instanceof XmlWebApplicationContext);
    LifecycleBean lb = (LifecycleBean) context.getBean("lifecycle");
    assertTrue("Has father", context.containsBean("father"));
    assertTrue("Has rod", context.containsBean("rod"));
    assertTrue("Has kerry", context.containsBean("kerry"));
    assertTrue("Not destroyed", !lb.isDestroyed());
    assertTrue(context.containsBean("beans1.bean1"));
    assertTrue(context.isTypeMatch("beans1.bean1", org.springframework.beans.factory.access.TestBean.class));
    assertTrue(context.containsBean("beans1.bean2"));
    assertTrue(context.isTypeMatch("beans1.bean2", org.springframework.beans.factory.access.TestBean.class));
    listener.contextDestroyed(event);
    assertTrue("Destroyed", lb.isDestroyed());
  }
View Full Code Here

  /**
   * Test that InitializingBean/BeanFactoryAware/DisposableBean objects receive the
   * afterPropertiesSet() callback before BeanFactoryAware callbacks
   */
  public void testLifecycleCallbacks() {
    LifecycleBean lb = (LifecycleBean) getBeanFactory().getBean("lifecycle");
    assertEquals("lifecycle", lb.getBeanName());
    // The dummy business method will throw an exception if the
    // necessary callbacks weren't invoked in the right order.
    lb.businessMethod();
    assertTrue("Not destroyed", !lb.isDestroyed());
  }
View Full Code Here

TOP

Related Classes of org.springframework.tests.sample.beans.LifecycleBean$PostProcessor

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.