use of org.springframework.beans.testfixture.beans.LifecycleBean in project spring-framework by spring-projects.
the class XmlListableBeanFactoryTests method lifecycleMethods.
@Test
public void lifecycleMethods() {
LifecycleBean bean = (LifecycleBean) getBeanFactory().getBean("lifecycle");
bean.businessMethod();
}
use of org.springframework.beans.testfixture.beans.LifecycleBean in project spring-framework by spring-projects.
the class ContextLoaderTests method contextLoaderListenerWithDefaultContext.
@Test
void contextLoaderListenerWithDefaultContext() {
MockServletContext sc = new MockServletContext("");
sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, "/org/springframework/web/context/WEB-INF/applicationContext.xml " + "/org/springframework/web/context/WEB-INF/context-addition.xml");
ServletContextListener listener = new ContextLoaderListener();
ServletContextEvent event = new ServletContextEvent(sc);
listener.contextInitialized(event);
String contextAttr = WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE;
WebApplicationContext context = (WebApplicationContext) sc.getAttribute(contextAttr);
boolean condition1 = context instanceof XmlWebApplicationContext;
assertThat(condition1).as("Correct WebApplicationContext exposed in ServletContext").isTrue();
assertThat(WebApplicationContextUtils.getRequiredWebApplicationContext(sc) instanceof XmlWebApplicationContext).isTrue();
LifecycleBean lb = (LifecycleBean) context.getBean("lifecycle");
assertThat(context.containsBean("father")).as("Has father").isTrue();
assertThat(context.containsBean("rod")).as("Has rod").isTrue();
assertThat(context.containsBean("kerry")).as("Has kerry").isTrue();
boolean condition = !lb.isDestroyed();
assertThat(condition).as("Not destroyed").isTrue();
assertThat(context.containsBean("beans1.bean1")).isFalse();
assertThat(context.containsBean("beans1.bean2")).isFalse();
listener.contextDestroyed(event);
assertThat(lb.isDestroyed()).as("Destroyed").isTrue();
assertThat(sc.getAttribute(contextAttr)).isNull();
assertThat(WebApplicationContextUtils.getWebApplicationContext(sc)).isNull();
}
use of org.springframework.beans.testfixture.beans.LifecycleBean in project spring-framework by spring-projects.
the class AbstractApplicationContextTests method closeTriggersDestroy.
@Test
public void closeTriggersDestroy() {
LifecycleBean lb = (LifecycleBean) applicationContext.getBean("lifecycle");
boolean condition = !lb.isDestroyed();
assertThat(condition).as("Not destroyed").isTrue();
applicationContext.close();
if (applicationContext.getParent() != null) {
((ConfigurableApplicationContext) applicationContext.getParent()).close();
}
assertThat(lb.isDestroyed()).as("Destroyed").isTrue();
applicationContext.close();
if (applicationContext.getParent() != null) {
((ConfigurableApplicationContext) applicationContext.getParent()).close();
}
assertThat(lb.isDestroyed()).as("Destroyed").isTrue();
}
Aggregations