KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > cactus > MyFacesServletTestCase


1 /*
2  * Copyright 2002,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.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 /**
29  * @author <a HREF="mailto:oliver@rossmueller.com">Oliver Rossmueller</a>
30  */

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 JavaDoc string)
43     {
44         super(string);
45     }
46
47
48     protected void setUp() throws Exception JavaDoc
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 JavaDoc getLifecycleId()
72     {
73         String JavaDoc lifecycleId = this.config.getServletContext().getInitParameter(FacesServlet.LIFECYCLE_ID_ATTR);
74         return lifecycleId != null ? lifecycleId : LifecycleFactory.DEFAULT_LIFECYCLE;
75     }
76
77 }
78
Popular Tags