1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
package org.apache.shale.test.jmock; |
19 |
|
|
20 |
|
import java.net.URL; |
21 |
|
import java.net.URLClassLoader; |
22 |
|
|
23 |
|
import javax.faces.FactoryFinder; |
24 |
|
import javax.faces.application.ApplicationFactory; |
25 |
|
import javax.faces.component.UIViewRoot; |
26 |
|
import javax.faces.lifecycle.LifecycleFactory; |
27 |
|
import javax.faces.render.RenderKitFactory; |
28 |
|
|
29 |
|
import org.apache.shale.test.mock.MockApplication; |
30 |
|
import org.apache.shale.test.mock.MockExternalContext; |
31 |
|
import org.apache.shale.test.mock.MockFacesContext; |
32 |
|
import org.apache.shale.test.mock.MockFacesContextFactory; |
33 |
|
import org.apache.shale.test.mock.MockHttpServletRequest; |
34 |
|
import org.apache.shale.test.mock.MockHttpServletResponse; |
35 |
|
import org.apache.shale.test.mock.MockHttpSession; |
36 |
|
import org.apache.shale.test.mock.MockLifecycle; |
37 |
|
import org.apache.shale.test.mock.MockLifecycleFactory; |
38 |
|
import org.apache.shale.test.mock.MockRenderKit; |
39 |
|
import org.apache.shale.test.mock.MockServletConfig; |
40 |
|
import org.apache.shale.test.mock.MockServletContext; |
41 |
|
import org.jmock.cglib.MockObjectTestCase; |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
public abstract class AbstractJmockJsfTestCase extends MockObjectTestCase { |
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
0 |
public AbstractJmockJsfTestCase(String name) { |
81 |
0 |
setName(name); |
82 |
0 |
} |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
protected void setUp() throws Exception { |
90 |
|
|
91 |
|
|
92 |
0 |
threadContextClassLoader = Thread.currentThread().getContextClassLoader(); |
93 |
0 |
Thread.currentThread().setContextClassLoader(new URLClassLoader(new URL[0], |
94 |
|
this.getClass().getClassLoader())); |
95 |
|
|
96 |
|
|
97 |
0 |
servletContext = new MockServletContext(); |
98 |
0 |
config = new MockServletConfig(servletContext); |
99 |
0 |
session = new MockHttpSession(); |
100 |
0 |
session.setServletContext(servletContext); |
101 |
0 |
request = new MockHttpServletRequest(session); |
102 |
0 |
request.setServletContext(servletContext); |
103 |
0 |
response = new MockHttpServletResponse(); |
104 |
|
|
105 |
|
|
106 |
0 |
FactoryFinder.releaseFactories(); |
107 |
0 |
FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY, |
108 |
|
"org.apache.shale.test.mock.MockApplicationFactory"); |
109 |
0 |
FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY, |
110 |
|
"org.apache.shale.test.mock.MockFacesContextFactory"); |
111 |
0 |
FactoryFinder.setFactory(FactoryFinder.LIFECYCLE_FACTORY, |
112 |
|
"org.apache.shale.test.mock.MockLifecycleFactory"); |
113 |
0 |
FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY, |
114 |
|
"org.apache.shale.test.mock.MockRenderKitFactory"); |
115 |
|
|
116 |
0 |
externalContext = |
117 |
|
new MockExternalContext(servletContext, request, response); |
118 |
0 |
lifecycleFactory = (MockLifecycleFactory) |
119 |
|
FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY); |
120 |
0 |
lifecycle = (MockLifecycle) |
121 |
|
lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE); |
122 |
0 |
facesContextFactory = (MockFacesContextFactory) |
123 |
|
FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); |
124 |
0 |
facesContext = (MockFacesContext) |
125 |
|
facesContextFactory.getFacesContext(servletContext, |
126 |
|
request, |
127 |
|
response, |
128 |
|
lifecycle); |
129 |
0 |
externalContext = (MockExternalContext) facesContext.getExternalContext(); |
130 |
0 |
UIViewRoot root = new UIViewRoot(); |
131 |
0 |
root.setViewId("/viewId"); |
132 |
0 |
root.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT); |
133 |
0 |
facesContext.setViewRoot(root); |
134 |
0 |
ApplicationFactory applicationFactory = (ApplicationFactory) |
135 |
|
FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY); |
136 |
0 |
application = (MockApplication) applicationFactory.getApplication(); |
137 |
0 |
facesContext.setApplication(application); |
138 |
0 |
RenderKitFactory renderKitFactory = (RenderKitFactory) |
139 |
|
FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY); |
140 |
0 |
renderKit = new MockRenderKit(); |
141 |
0 |
renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT, renderKit); |
142 |
|
|
143 |
0 |
} |
144 |
|
|
145 |
|
|
146 |
|
protected void tearDown() throws Exception { |
147 |
|
|
148 |
0 |
application = null; |
149 |
0 |
config = null; |
150 |
0 |
externalContext = null; |
151 |
0 |
facesContext.release(); |
152 |
0 |
facesContext = null; |
153 |
0 |
lifecycle = null; |
154 |
0 |
lifecycleFactory = null; |
155 |
0 |
renderKit = null; |
156 |
0 |
request = null; |
157 |
0 |
response = null; |
158 |
0 |
servletContext = null; |
159 |
0 |
session = null; |
160 |
0 |
FactoryFinder.releaseFactories(); |
161 |
|
|
162 |
0 |
Thread.currentThread().setContextClassLoader(threadContextClassLoader); |
163 |
0 |
threadContextClassLoader = null; |
164 |
|
|
165 |
0 |
} |
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
0 |
protected MockApplication application = null; |
173 |
0 |
protected MockServletConfig config = null; |
174 |
0 |
protected MockExternalContext externalContext = null; |
175 |
0 |
protected MockFacesContext facesContext = null; |
176 |
0 |
protected MockFacesContextFactory facesContextFactory = null; |
177 |
0 |
protected MockLifecycle lifecycle = null; |
178 |
0 |
protected MockLifecycleFactory lifecycleFactory = null; |
179 |
0 |
protected MockRenderKit renderKit = null; |
180 |
0 |
protected MockHttpServletRequest request = null; |
181 |
0 |
protected MockHttpServletResponse response = null; |
182 |
0 |
protected MockServletContext servletContext = null; |
183 |
0 |
protected MockHttpSession session = null; |
184 |
|
|
185 |
|
|
186 |
0 |
private ClassLoader threadContextClassLoader = null; |
187 |
|
|
188 |
|
} |