KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > application > jsp > JspViewHandlerImplTest


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 JavaDoc;
24
25 /**
26  * @author Thomas Spiegl (latest modification by $Author: matze $)
27  * @version $Revision: 1.5 $ $Date: 2004/10/13 11:50:59 $
28  */

29 public class JspViewHandlerImplTest
30     extends MyFacesBaseTest
31 {
32     private static final String JavaDoc WEB_XML_SYSTEM_ID = "/WEB-INF/web.xml";
33     private static final String JavaDoc WEB_XML_PATH_TEST =
34         "org.apache.myfaces.resource".replace('.','/') + "/servletmapping_web.xml";
35
36     public JspViewHandlerImplTest(String JavaDoc name)
37     {
38         super(name);
39     }
40
41     protected ServletContext JavaDoc 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 JavaDoc
50     {
51         testViewIdPath("/myfaces", "/test", "/abc.jsp", "/myfaces/abc.jsp");
52     }
53
54     public void testViewIdPathNoServletPath() throws Exception JavaDoc {
55         testViewIdPath("", "/test.jsf", "/xyz.jsp", "/xyz.jsp");
56     }
57
58     public void testViewIdPathJSFExtensionWithJSP() throws Exception JavaDoc {
59         testViewIdPath("/extension/test.jsf", null, "/myfaces/abc.jsp", "/myfaces/abc.jsf");
60     }
61
62     public void testViewIdPathJSFExtension() throws Exception JavaDoc {
63         testViewIdPath("/extension/test.jsf", null, "/extension/bde", "/extension/bde.jsf");
64     }
65
66     /*
67     public void testStrutsPath() throws Exception {
68         testViewIdPath("/start.do", null, "/abc.jsp", "/extension/bde.jsf");
69     }
70     */

71
72     private void testViewIdPath(String JavaDoc servletPath,
73                                 String JavaDoc pathInfo,
74                                 String JavaDoc viewId,
75                                 String JavaDoc expectedViewIdPath)
76     {
77         ((ServletRequestMockImpl)_httpServletRequest).setServletPath(servletPath);
78         ((ServletRequestMockImpl)_httpServletRequest).setPathInfo(pathInfo);
79
80         //Standard implementation caches servlet path, so we must create a new FacesContext
81
//for each test:
82
_facesContext = new ServletFacesContextImpl(_servletContext,
83                                                     _httpServletRequest,
84                                                     _httpServletResponse);
85
86         JspViewHandlerImpl viewHandler = new JspViewHandlerImpl();
87         String JavaDoc viewpath = viewHandler.getViewIdPath(_facesContext, viewId);
88         assertEquals(expectedViewIdPath, viewpath);
89     }
90
91
92
93 }
94
Popular Tags