1 16 package org.apache.myfaces; 17 18 import junit.framework.TestCase; 19 import org.apache.myfaces.context.servlet.ServletContextMockImpl; 20 import org.apache.myfaces.context.servlet.ServletFacesContextImpl; 21 import org.apache.myfaces.context.servlet.ServletRequestMockImpl; 22 import org.apache.myfaces.context.servlet.ServletResponseMockImpl; 23 import org.apache.myfaces.webapp.StartupServletContextListener; 24 25 import javax.faces.application.Application; 26 import javax.faces.context.FacesContext; 27 import javax.faces.lifecycle.Lifecycle; 28 import javax.servlet.ServletContext ; 29 import javax.servlet.http.Cookie ; 30 import javax.servlet.http.HttpServletRequest ; 31 import javax.servlet.http.HttpServletResponse ; 32 33 38 public class MyFacesBaseTest 39 extends TestCase 40 { 41 43 private static final String RESOURCE_PATH = "org.apache.myfaces.resource".replace('.', '/'); 44 45 protected Application _application; 46 protected ServletContext _servletContext; 47 protected HttpServletRequest _httpServletRequest; 48 protected HttpServletResponse _httpServletResponse; 49 protected Lifecycle _lifecycle; 50 protected FacesContext _facesContext; 51 52 53 public MyFacesBaseTest(String name) 54 { 55 super(name); 56 } 57 58 protected void setUp() throws Exception 59 { 60 super.setUp(); 61 62 _servletContext = setUpServletContext(); 63 StartupServletContextListener.initFaces(_servletContext); 64 65 _httpServletRequest = new ServletRequestMockImpl(getCookies()); 66 _httpServletResponse = new ServletResponseMockImpl(); 67 68 _facesContext = new ServletFacesContextImpl(_servletContext, 69 _httpServletRequest, 70 _httpServletResponse); 71 _application = _facesContext.getApplication(); 72 } 73 74 75 protected ServletContext setUpServletContext() 76 { 77 ServletContextMockImpl servletContext = new ServletContextMockImpl(); 78 servletContext.addResource("/WEB-INF/faces-config.xml", 79 RESOURCE_PATH + "/junit-faces-config.xml"); 80 servletContext.addResource("/WEB-INF/web.xml", 81 RESOURCE_PATH + "/junit-web.xml"); 82 return servletContext; 83 } 84 85 protected void tearDown() throws Exception 86 { 87 super.tearDown(); 88 _application = null; 89 _servletContext = null; 90 _httpServletRequest = null; 91 _httpServletResponse = null; 92 _lifecycle = null; 93 _facesContext = null; 94 } 95 96 97 protected Cookie [] getCookies() 98 { 99 return new Cookie [0]; 100 } 101 } 102 | Popular Tags |