I'm using the class below as a TestCase to test my Managed Beans sans Tomcat. I'm using Spring to inject some of the properties on my beans. This all works great and I have to thank you for a lot of code I "borrowed" from the Cactus tests. ;-) One thing I noticed is that I have to have jsp-api.jar and commons-el.jar in my classpath for this to work. AFAIK, these are Tomcat 5 JARs. Does this mean my app / MyFaces won't run on Tomcat 4?

Also, when I run my tests, I get the following log messages with the level set to WARN:

[junit] [appfuse] WARN [main] WebXmlParser.readServlet(218) | Ignored elemen
t 'display-name' as child of 'servlet'.
[junit] [appfuse] WARN [main] WebXmlParser.readServlet(218) | Ignored elemen
t 'init-param' as child of 'servlet'.
[junit] [appfuse] WARN [main] WebXmlParser.readServlet(218) | Ignored elemen
t 'init-param' as child of 'servlet'.
[junit] [appfuse] WARN [main] WebXmlParser.readServlet(218) | Ignored elemen
t 'init-param' as child of 'servlet'.
[junit] [appfuse] WARN [main] WebXmlParser.readServlet(218) | Ignored elemen
t 'init-param' as child of 'servlet'.
[junit] [appfuse] ERROR [main] VariableResolverImpl.resolveVariable(342) | V
ariable 'userManager' could not be resolved.
[junit] [appfuse] ERROR [main] VariableResolverImpl.resolveVariable(342) | V
ariable 'mailEngine' could not be resolved.
[junit] [appfuse] ERROR [main] VariableResolverImpl.resolveVariable(342) | V
ariable 'mailMessage' could not be resolved.


Shouldn't these messages be set to INFO or DEBUG? Everything works (including the variable resolution) - so the levels are invalid IMO. BTW, I've brought up the VariableResolver logging before with Spring's VariableResolver.

http://sourceforge.net/tracker/index.php?func=detail&aid=1012536&group_id=69709&atid=525508

In the meantime, I can set my logging to FATAL and get rid of the messages, but I'm afraid I might lose out on something important.

Thanks,

Matt

public class BasePageTestCase extends TestCase {
   protected final transient Log log = LogFactory.getLog(getClass());
   protected String MESSAGES = "ApplicationResources";
   protected FacesContext facesContext;
   protected MockServletConfig config;
   protected MockServletContext servletContext;
   protected MockHttpServletRequest request;
   protected MockHttpServletResponse response;
   protected static WebApplicationContext ctx;

   protected void setUp() throws Exception {
       super.setUp();
       servletContext = new MockServletContext("");
       servletContext.addInitParameter(BasePage.jstlBundleParam, MESSAGES);
       servletContext.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
                                       "/WEB-INF/applicationContext*.xml");

ServletContextListener contextListener = new ContextLoaderListener();
ServletContextEvent event = new ServletContextEvent(servletContext);
contextListener.contextInitialized(event);


ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);

       config = new MockServletConfig(servletContext);
       request = new MockHttpServletRequest();
       response = new MockHttpServletResponse();
       facesContext = performFacesContextConfig();
   }

   protected FacesContext performFacesContextConfig() {
       StartupServletContextListener facesListener =
           new StartupServletContextListener();
       ServletContextEvent event = new ServletContextEvent(servletContext);
       facesListener.contextInitialized(event);

LifecycleFactory lifecycleFactory =
(LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
Lifecycle lifecycle = lifecycleFactory.getLifecycle(getLifecycleId());
FacesContextFactory facesCtxFactory =
(FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
FacesContext ctx =
facesCtxFactory.getFacesContext(servletContext, request, response,
lifecycle);


       return ctx;
   }

   protected String getLifecycleId() {
       String lifecycleId =
           servletContext.getInitParameter(FacesServlet.LIFECYCLE_ID_ATTR);

       return (lifecycleId != null) ? lifecycleId
                                    : LifecycleFactory.DEFAULT_LIFECYCLE;
   }

   protected Object getManagedBean(String name) {
       return FacesUtils.getManagedBean(name);
   }
}




Reply via email to