1 16 package org.apache.myfaces.application.jsp; 17 18 import org.apache.myfaces.MyFacesBaseTest; 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 23 import javax.servlet.ServletContext ; 24 25 29 public class JspViewHandlerImplTest 30 extends MyFacesBaseTest 31 { 32 private static final String WEB_XML_SYSTEM_ID = "/WEB-INF/web.xml"; 33 private static final String WEB_XML_PATH_TEST = 34 "org.apache.myfaces.resource".replace('.','/') + "/servletmapping_web.xml"; 35 36 public JspViewHandlerImplTest(String name) 37 { 38 super(name); 39 } 40 41 protected ServletContext setUpServletContext() 42 { 43 ServletContextMockImpl servletContextMock 44 = (ServletContextMockImpl)super.setUpServletContext(); 45 servletContextMock.addResource(WEB_XML_SYSTEM_ID, WEB_XML_PATH_TEST); 46 return servletContextMock; 47 } 48 49 public void testViewIdPathSimple() throws Exception 50 { 51 testViewIdPath("/myfaces", "/test", "/abc.jsp", "/myfaces/abc.jsp"); 52 } 53 54 public void testViewIdPathNoServletPath() throws Exception { 55 testViewIdPath("", "/test.jsf", "/xyz.jsp", "/xyz.jsp"); 56 } 57 58 public void testViewIdPathJSFExtensionWithJSP() throws Exception { 59 testViewIdPath("/extension/test.jsf", null, "/myfaces/abc.jsp", "/myfaces/abc.jsf"); 60 } 61 62 public void testViewIdPathJSFExtension() throws Exception { 63 testViewIdPath("/extension/test.jsf", null, "/extension/bde", "/extension/bde.jsf"); 64 } 65 66 71 72 private void testViewIdPath(String servletPath, 73 String pathInfo, 74 String viewId, 75 String expectedViewIdPath) 76 { 77 ((ServletRequestMockImpl)_httpServletRequest).setServletPath(servletPath); 78 ((ServletRequestMockImpl)_httpServletRequest).setPathInfo(pathInfo); 79 80 _facesContext = new ServletFacesContextImpl(_servletContext, 83 _httpServletRequest, 84 _httpServletResponse); 85 86 JspViewHandlerImpl viewHandler = new JspViewHandlerImpl(); 87 String viewpath = viewHandler.getViewIdPath(_facesContext, viewId); 88 assertEquals(expectedViewIdPath, viewpath); 89 } 90 91 92 93 } 94 | Popular Tags |