KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > MyFacesBaseTest


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;
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 JavaDoc;
29 import javax.servlet.http.Cookie JavaDoc;
30 import javax.servlet.http.HttpServletRequest JavaDoc;
31 import javax.servlet.http.HttpServletResponse JavaDoc;
32
33 /**
34  * @author Manfred Geiler (latest modification by $Author: matze $)
35  * @author Anton Koinov
36  * @version $Revision: 1.4 $ $Date: 2004/10/13 11:50:59 $
37  */

38 public class MyFacesBaseTest
39     extends TestCase
40 {
41     //private static final Log log = LogFactory.getLog(MyFacesBaseTest.class);
42

43     private static final String JavaDoc RESOURCE_PATH = "org.apache.myfaces.resource".replace('.', '/');
44
45     protected Application _application;
46     protected ServletContext JavaDoc _servletContext;
47     protected HttpServletRequest JavaDoc _httpServletRequest;
48     protected HttpServletResponse JavaDoc _httpServletResponse;
49     protected Lifecycle _lifecycle;
50     protected FacesContext _facesContext;
51
52
53     public MyFacesBaseTest(String JavaDoc name)
54     {
55         super(name);
56     }
57
58     protected void setUp() throws Exception JavaDoc
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 JavaDoc 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 JavaDoc
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     /** override where necessary */
97     protected Cookie JavaDoc[] getCookies()
98     {
99         return new Cookie JavaDoc[0];
100     }
101 }
102
Popular Tags