1 16 package org.apache.myfaces.cactus; 17 18 import javax.faces.context.FacesContext; 19 import javax.faces.context.FacesContextFactory; 20 import javax.faces.lifecycle.LifecycleFactory; 21 import javax.faces.lifecycle.Lifecycle; 22 import javax.faces.FactoryFinder; 23 import javax.faces.webapp.FacesServlet; 24 25 import org.apache.cactus.ServletTestCase; 26 27 28 31 public class MyFacesServletTestCase extends ServletTestCase 32 { 33 34 private FacesContext context; 35 36 37 public MyFacesServletTestCase() 38 { 39 } 40 41 42 public MyFacesServletTestCase(String string) 43 { 44 super(string); 45 } 46 47 48 protected void setUp() throws Exception 49 { 50 super.setUp(); 51 context = performFacesContextConfig(); 52 } 53 54 55 protected FacesContext getContext() 56 { 57 return context; 58 } 59 60 61 protected FacesContext performFacesContextConfig() 62 { 63 LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY); 64 Lifecycle lifecycle = lifecycleFactory.getLifecycle(getLifecycleId()); 65 FacesContextFactory facesCtxFactory = (FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); 66 FacesContext ctx = facesCtxFactory.getFacesContext(config.getServletContext(), request, response, lifecycle); 67 return ctx; 68 } 69 70 71 protected String getLifecycleId() 72 { 73 String lifecycleId = this.config.getServletContext().getInitParameter(FacesServlet.LIFECYCLE_ID_ATTR); 74 return lifecycleId != null ? lifecycleId : LifecycleFactory.DEFAULT_LIFECYCLE; 75 } 76 77 } 78 | Popular Tags |