public class StartupListenerTest extends TestCase {
private MockServletContext sc = null;
private ServletContextListener listener = null;
private ContextLoaderListener springListener = null;
protected void setUp() throws Exception {
super.setUp();
sc = new MockServletContext("");
sc.addInitParameter(Constants.CSS_THEME, "simplicity");
// initialize Spring
sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
"classpath:/applicationContext-dao.xml, " +
"classpath:/applicationContext-service.xml, " +
"classpath:/applicationContext-resources.xml");
springListener = new ContextLoaderListener();
springListener.contextInitialized(new ServletContextEvent(sc));
listener = new StartupListener();
}
protected void tearDown() throws Exception {
super.tearDown();
springListener = null;
listener = null;
sc = null;
}
public void testContextInitialized() {
listener.contextInitialized(new ServletContextEvent(sc));
assertTrue(sc.getAttribute(Constants.CONFIG) != null);
Map config = (Map) sc.getAttribute(Constants.CONFIG);
assertEquals(config.get(Constants.CSS_THEME), "simplicity");
assertTrue(sc.getAttribute(WebApplicationContext
.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE) != null);
assertTrue(sc.getAttribute(Constants.AVAILABLE_ROLES) != null);
}
}
On Wed, May 5, 2010 at 12:36 AM, Tony Luo <[email protected]> wrote:
> Hi All,
>
> I need to put a list of object in memory when application start.
> The object is quite simple so I generate the service by Generic
> Manager and configured it in applicationContext.xml
>
> <bean id="personManager"
> class="org.appfuse.service.impl.GenericManagerImpl">
> <constructor-arg>
> <bean class="org.appfuse.dao.hibernate.GenericDaoHibernate"
> autowire="byType">
> <constructor-arg
> value="org.appfuse.tutorial.model.Person"/>
> </bean>
> </constructor-arg>
> </bean>
>
> The cod in StartupListener is like the following code
>
> GenericManager<Person,Long> mgr = (GenericManager<Person,Long>)
> ctx.getBean("personManager");
>
> Unfortunately, It failed in the testing and the log says can't find
> this bean when do StartupListenerTest. What shall I do now?
>
> Regards
> Tony Luo
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>