public void testInitFaces() throws Exception
{
// TODO adapt this test case for MyFaces 2.0, because currently it checks nothing!
Jsp21FacesInitializer initializer = new Jsp21FacesInitializer();
IMocksControl control = EasyMock.createControl();
JspFactory jspFactory = control.createMock(JspFactory.class);
initializer.setJspFactory(jspFactory);
RuntimeConfig runtimeConfig = control.createMock(RuntimeConfig.class);
ServletContext context = control.createMock(ServletContext.class);
ExpressionFactory expressionFactory = control.createMock(ExpressionFactory.class);
runtimeConfig.setExpressionFactory(expressionFactory);
runtimeConfig.setPropertyResolverChainHead(isA(DefaultPropertyResolver.class));
runtimeConfig.setVariableResolverChainHead(isA(VariableResolverImpl.class));
expect(context.getAttribute(eq(RuntimeConfig.class.getName()))).andReturn(runtimeConfig).anyTimes();
expect(context.getInitParameter(eq(FacesServlet.CONFIG_FILES_ATTR))).andReturn(null);
expect(context.getResourceAsStream(eq("/WEB-INF/faces-config.xml"))).andReturn(null);
expect(context.getInitParameter(eq(FacesServlet.LIFECYCLE_ID_ATTR))).andReturn(null);
// TODO: add myfaces specific tests
expect(context.getResource(isA(String.class))).andReturn(null);
expect(context.getResourceAsStream(isA(String.class))).andReturn(null);
expect(context.getInitParameter(isA(String.class))).andReturn(null).anyTimes();
expect(context.getAttribute(isA(String.class))).andReturn(null).anyTimes();
context.setAttribute(isA(String.class), anyObject());
expectLastCall().anyTimes();
expect(context.getRealPath(isA(String.class))).andAnswer(new IAnswer<String>() {
public String answer() throws Throwable
{
return (String) org.easymock.EasyMock.getCurrentArguments()[0];
}
});
JspApplicationContext jspAppCtx = control.createMock(JspApplicationContext.class);
expect(jspAppCtx.getExpressionFactory()).andReturn(expressionFactory);
jspAppCtx.addELContextListener(isA(FacesELContextListener.class));
expect(jspFactory.getJspApplicationContext(eq(context))).andReturn(jspAppCtx);
jspAppCtx.addELResolver(isA(FacesCompositeELResolver.class));
control.replay();
initializer.initFaces(context);
// In MYFACES-1222: The Jsp21FacesInitializer isn't practicable anymore.
// The ServletContext-Mock won't return its WebXml instance, so Jsp21FacesInitializer will stop initializing.
// This is why the next line is commented: