Commit f8168bf591298d2f360cba24682890651bd710ac
Exists in
master
Merge branch 'master' of git@github.com:demoiselle/framework.git
Showing
21 changed files
with
1275 additions
and
1422 deletions
Show diff stats
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/java/view/BookmarkEditMB.java
@@ -11,7 +11,7 @@ import ${package}.business.BookmarkBC; | @@ -11,7 +11,7 @@ import ${package}.business.BookmarkBC; | ||
11 | import ${package}.domain.Bookmark; | 11 | import ${package}.domain.Bookmark; |
12 | 12 | ||
13 | @ViewController | 13 | @ViewController |
14 | -@PreviousView("/bookmark_list.xhtml") | 14 | +@PreviousView("./bookmark_list.xhtml") |
15 | public class BookmarkEditMB extends AbstractEditPageBean<Bookmark, Long> { | 15 | public class BookmarkEditMB extends AbstractEditPageBean<Bookmark, Long> { |
16 | 16 | ||
17 | private static final long serialVersionUID = 1L; | 17 | private static final long serialVersionUID = 1L; |
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/java/view/BookmarkListMB.java
@@ -15,8 +15,8 @@ import ${package}.business.BookmarkBC; | @@ -15,8 +15,8 @@ import ${package}.business.BookmarkBC; | ||
15 | import ${package}.domain.Bookmark; | 15 | import ${package}.domain.Bookmark; |
16 | 16 | ||
17 | @ViewController | 17 | @ViewController |
18 | -@NextView("/bookmark_edit.xhtml") | ||
19 | -@PreviousView("/bookmark_list.xhtml") | 18 | +@NextView("./bookmark_edit.xhtml") |
19 | +@PreviousView("./bookmark_list.xhtml") | ||
20 | public class BookmarkListMB extends AbstractListPageBean<Bookmark, Long> { | 20 | public class BookmarkListMB extends AbstractListPageBean<Bookmark, Long> { |
21 | 21 | ||
22 | private static final long serialVersionUID = 1L; | 22 | private static final long serialVersionUID = 1L; |
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityContextImplTest.java
1 | -//package br.gov.frameworkdemoiselle.internal.implementation; | ||
2 | -// | ||
3 | -//import static junit.framework.Assert.assertEquals; | ||
4 | -//import static junit.framework.Assert.assertFalse; | ||
5 | -//import static junit.framework.Assert.assertNotNull; | ||
6 | -//import static junit.framework.Assert.assertNull; | ||
7 | -//import static junit.framework.Assert.assertTrue; | ||
8 | -//import static junit.framework.Assert.fail; | ||
9 | -//import static org.easymock.EasyMock.createMock; | ||
10 | -//import static org.easymock.EasyMock.expect; | ||
11 | -//import static org.powermock.api.easymock.PowerMock.mockStatic; | ||
12 | -//import static org.powermock.api.easymock.PowerMock.replay; | ||
13 | -//import static org.powermock.api.easymock.PowerMock.replayAll; | ||
14 | -//import static org.powermock.reflect.Whitebox.setInternalState; | ||
15 | -// | ||
16 | -//import java.util.Locale; | ||
17 | -// | ||
18 | -//import javax.enterprise.inject.spi.BeanManager; | ||
19 | -// | ||
20 | -//import org.easymock.EasyMock; | ||
21 | -//import org.junit.Before; | ||
22 | -//import org.junit.Test; | ||
23 | -//import org.junit.runner.RunWith; | ||
24 | -//import org.powermock.api.easymock.PowerMock; | ||
25 | -//import org.powermock.core.classloader.annotations.PrepareForTest; | ||
26 | -//import org.powermock.modules.junit4.PowerMockRunner; | ||
27 | -// | ||
28 | -//import br.gov.frameworkdemoiselle.internal.configuration.SecurityConfig; | ||
29 | -//import br.gov.frameworkdemoiselle.security.Authenticator; | ||
30 | -//import br.gov.frameworkdemoiselle.security.Authorizer; | ||
31 | -//import br.gov.frameworkdemoiselle.security.NotLoggedInException; | ||
32 | -//import br.gov.frameworkdemoiselle.security.User; | ||
33 | -//import br.gov.frameworkdemoiselle.util.Beans; | ||
34 | -//import br.gov.frameworkdemoiselle.util.ResourceBundle; | ||
35 | -// | ||
36 | -//@RunWith(PowerMockRunner.class) | ||
37 | -//@PrepareForTest({ CoreBundle.class, Beans.class }) | ||
38 | -//public class SecurityContextImplTest { | ||
39 | -// | ||
40 | -// private SecurityContextImpl context; | ||
41 | -// | ||
42 | -// private SecurityConfig config; | ||
43 | -// | ||
44 | -// @Before | ||
45 | -// public void setUp() { | ||
46 | -// context = new SecurityContextImpl(); | ||
47 | -// | ||
48 | -// config = createMock(SecurityConfig.class); | ||
49 | -// setInternalState(context, "config", config); | ||
50 | -// } | ||
51 | -// | ||
52 | -// @Test | ||
53 | -// public void testHasPermissionWithSecurityDisabled() { | ||
54 | -// | ||
55 | -// expect(config.isEnabled()).andReturn(false); | ||
56 | -// | ||
57 | -// replay(config); | ||
58 | -// | ||
59 | -// try { | ||
60 | -// assertTrue(context.hasPermission(null, null)); | ||
61 | -// } catch (NotLoggedInException e) { | ||
62 | -// fail(); | ||
63 | -// } | ||
64 | -// | ||
65 | -// } | ||
66 | -// | ||
67 | -// @Test | ||
68 | -// public void testHasPermissionWithSecurityEnabledAndNotLoggedIn() { | ||
69 | -// Authenticator authenticator = createMock(Authenticator.class); | ||
70 | -// expect(authenticator.getUser()).andReturn(null).anyTimes(); | ||
71 | -// | ||
72 | -// ResourceBundle bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); | ||
73 | -// setInternalState(context, "bundle", bundle); | ||
74 | -// setInternalState(context, "authenticator", authenticator); | ||
75 | -// | ||
76 | -// expect(config.isEnabled()).andReturn(true).anyTimes(); | ||
77 | -// replay(config, authenticator); | ||
78 | -// | ||
79 | -// try { | ||
80 | -// context.hasPermission(null, null); | ||
81 | -// fail(); | ||
82 | -// } catch (NotLoggedInException e) { | ||
83 | -// assertTrue(e.getMessage().equals(bundle.getString("user-not-authenticated"))); | ||
84 | -// } | ||
85 | -// | ||
86 | -// } | ||
87 | -// | ||
88 | -// @Test | ||
89 | -// public void testHasPermissionWithSecurityEnabledAndLoggedIn() { | ||
90 | -// expect(config.isEnabled()).andReturn(true).anyTimes(); | ||
91 | -// replay(config); | ||
92 | -// | ||
93 | -// loginSuccessfully(); | ||
94 | -// | ||
95 | -// Authorizer authorizer = createMock(Authorizer.class); | ||
96 | -// expect(authorizer.hasPermission(null, null)).andReturn(true); | ||
97 | -// | ||
98 | -// setInternalState(context, "authorizer", authorizer); | ||
99 | -// | ||
100 | -// replay(authorizer); | ||
101 | -// | ||
102 | -// try { | ||
103 | -// assertTrue(context.hasPermission(null, null)); | ||
104 | -// } catch (NotLoggedInException e) { | ||
105 | -// fail(); | ||
106 | -// } | ||
107 | -// | ||
108 | -// } | ||
109 | -// | ||
110 | -// private void loginSuccessfully() { | ||
111 | -// Authenticator authenticator = createMock(Authenticator.class); | ||
112 | -// expect(authenticator.authenticate()).andReturn(true); | ||
113 | -// | ||
114 | -// BeanManager manager = createMock(BeanManager.class); | ||
115 | -// mockStatic(Beans.class); | ||
116 | -// expect(Beans.getBeanManager()).andReturn(manager); | ||
117 | -// manager.fireEvent(EasyMock.anyObject(Class.class)); | ||
118 | -// PowerMock.expectLastCall(); | ||
119 | -// | ||
120 | -// User user = createMock(User.class); | ||
121 | -// expect(authenticator.getUser()).andReturn(user).anyTimes(); | ||
122 | -// | ||
123 | -// setInternalState(context, "authenticator", authenticator); | ||
124 | -// | ||
125 | -// replayAll(authenticator, user, Beans.class, manager); | ||
126 | -// | ||
127 | -// context.login(); | ||
128 | -// assertTrue(context.isLoggedIn()); | ||
129 | -// } | ||
130 | -// | ||
131 | -// @Test | ||
132 | -// public void testHasRoleWithSecurityDisabled() { | ||
133 | -// | ||
134 | -// expect(config.isEnabled()).andReturn(false); | ||
135 | -// | ||
136 | -// replay(config); | ||
137 | -// | ||
138 | -// try { | ||
139 | -// assertTrue(context.hasRole(null)); | ||
140 | -// } catch (NotLoggedInException e) { | ||
141 | -// fail(); | ||
142 | -// } | ||
143 | -// | ||
144 | -// } | ||
145 | -// | ||
146 | -// @Test | ||
147 | -// public void testHasRoleWithSecurityEnabledAndNotLoggedIn() { | ||
148 | -// Authenticator authenticator = createMock(Authenticator.class); | ||
149 | -// expect(authenticator.getUser()).andReturn(null).anyTimes(); | ||
150 | -// | ||
151 | -// ResourceBundle bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); | ||
152 | -// setInternalState(context, "bundle", bundle); | ||
153 | -// expect(config.isEnabled()).andReturn(true).anyTimes(); | ||
154 | -// | ||
155 | -// setInternalState(context, "authenticator", authenticator); | ||
156 | -// | ||
157 | -// replay(config, authenticator); | ||
158 | -// | ||
159 | -// try { | ||
160 | -// context.hasRole(null); | ||
161 | -// fail(); | ||
162 | -// } catch (NotLoggedInException e) { | ||
163 | -// assertTrue(e.getMessage().equals(bundle.getString("user-not-authenticated"))); | ||
164 | -// } | ||
165 | -// | ||
166 | -// } | ||
167 | -// | ||
168 | -// @Test | ||
169 | -// public void testHasRoleWithSecurityEnabledAndLoggedIn() { | ||
170 | -// expect(config.isEnabled()).andReturn(true).anyTimes(); | ||
171 | -// replay(config); | ||
172 | -// | ||
173 | -// loginSuccessfully(); | ||
174 | -// | ||
175 | -// Authorizer authorizer = createMock(Authorizer.class); | ||
176 | -// expect(authorizer.hasRole(null)).andReturn(true); | ||
177 | -// | ||
178 | -// setInternalState(context, "authorizer", authorizer); | ||
179 | -// | ||
180 | -// replay(authorizer); | ||
181 | -// | ||
182 | -// try { | ||
183 | -// assertTrue(context.hasRole(null)); | ||
184 | -// } catch (NotLoggedInException e) { | ||
185 | -// fail(); | ||
186 | -// } | ||
187 | -// | ||
188 | -// } | ||
189 | -// | ||
190 | -// @Test | ||
191 | -// public void testIsLoggedInWithSecurityEnabled() { | ||
192 | -// Authenticator authenticator = createMock(Authenticator.class); | ||
193 | -// expect(authenticator.getUser()).andReturn(null).anyTimes(); | ||
194 | -// | ||
195 | -// expect(config.isEnabled()).andReturn(true).anyTimes(); | ||
196 | -// | ||
197 | -// setInternalState(context, "authenticator", authenticator); | ||
198 | -// | ||
199 | -// replay(config, authenticator); | ||
200 | -// | ||
201 | -// assertFalse(context.isLoggedIn()); | ||
202 | -// } | ||
203 | -// | ||
204 | -// @Test | ||
205 | -// public void testIsLoggedInWithSecurityDisabled() { | ||
206 | -// | ||
207 | -// expect(config.isEnabled()).andReturn(false); | ||
208 | -// | ||
209 | -// replay(config); | ||
210 | -// | ||
211 | -// assertTrue(context.isLoggedIn()); | ||
212 | -// | ||
213 | -// } | ||
214 | -// | ||
215 | -// @Test | ||
216 | -// public void testLoginWithSecurityDisabled() { | ||
217 | -// | ||
218 | -// expect(config.isEnabled()).andReturn(false).times(2); | ||
219 | -// | ||
220 | -// replay(config); | ||
221 | -// | ||
222 | -// context.login(); | ||
223 | -// | ||
224 | -// assertTrue(context.isLoggedIn()); | ||
225 | -// | ||
226 | -// } | ||
227 | -// | ||
228 | -// @Test | ||
229 | -// public void testLoginWithAuthenticationFail() { | ||
230 | -// | ||
231 | -// expect(config.isEnabled()).andReturn(true).anyTimes(); | ||
232 | -// | ||
233 | -// Authenticator authenticator = createMock(Authenticator.class); | ||
234 | -// expect(authenticator.authenticate()).andReturn(false); | ||
235 | -// expect(authenticator.getUser()).andReturn(null).anyTimes(); | ||
236 | -// | ||
237 | -// setInternalState(context, "authenticator", authenticator); | ||
238 | -// | ||
239 | -// replayAll(authenticator, config); | ||
240 | -// | ||
241 | -// context.login(); | ||
242 | -// | ||
243 | -// assertFalse(context.isLoggedIn()); | ||
244 | -// } | ||
245 | -// | ||
246 | -// @Test | ||
247 | -// public void testLogOutWithSecurityDisabled() { | ||
248 | -// | ||
249 | -// expect(config.isEnabled()).andReturn(false).times(2); | ||
250 | -// | ||
251 | -// replay(config); | ||
252 | -// | ||
253 | -// try { | ||
254 | -// context.logout(); | ||
255 | -// assertTrue(context.isLoggedIn()); | ||
256 | -// } catch (NotLoggedInException e) { | ||
257 | -// fail(); | ||
258 | -// } | ||
259 | -// } | ||
260 | -// | ||
261 | -// @Test | ||
262 | -// public void testLogOutWithoutPreviousLogin() { | ||
263 | -// Authenticator authenticator = createMock(Authenticator.class); | ||
264 | -// expect(authenticator.getUser()).andReturn(null).anyTimes(); | ||
265 | -// | ||
266 | -// ResourceBundle bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); | ||
267 | -// setInternalState(context, "bundle", bundle); | ||
268 | -// | ||
269 | -// expect(config.isEnabled()).andReturn(true).anyTimes(); | ||
270 | -// | ||
271 | -// setInternalState(context, "authenticator", authenticator); | ||
272 | -// | ||
273 | -// replay(config, authenticator); | ||
274 | -// | ||
275 | -// try { | ||
276 | -// context.logout(); | ||
277 | -// fail(); | ||
278 | -// } catch (NotLoggedInException e) { | ||
279 | -// assertTrue(e.getMessage().equals(bundle.getString("user-not-authenticated"))); | ||
280 | -// } | ||
281 | -// } | ||
282 | -// | ||
283 | -// @Test | ||
284 | -// public void testLogOutAfterSuccessfulLogin() { | ||
285 | -// mockStatic(Beans.class); | ||
286 | -// | ||
287 | -// expect(config.isEnabled()).andReturn(true).anyTimes(); | ||
288 | -// | ||
289 | -// Authenticator authenticator = createMock(Authenticator.class); | ||
290 | -// expect(authenticator.authenticate()).andReturn(true); | ||
291 | -// authenticator.unAuthenticate(); | ||
292 | -// PowerMock.expectLastCall(); | ||
293 | -// | ||
294 | -// User user = createMock(User.class); | ||
295 | -// expect(authenticator.getUser()).andReturn(user); | ||
296 | -// expect(authenticator.getUser()).andReturn(null); | ||
297 | -// | ||
298 | -// BeanManager manager = createMock(BeanManager.class); | ||
299 | -// expect(Beans.getBeanManager()).andReturn(manager).times(2); | ||
300 | -// manager.fireEvent(EasyMock.anyObject(Class.class)); | ||
301 | -// PowerMock.expectLastCall().times(2); | ||
302 | -// | ||
303 | -// setInternalState(context, "authenticator", authenticator); | ||
304 | -// | ||
305 | -// replayAll(Beans.class, authenticator, user, manager, config); | ||
306 | -// | ||
307 | -// context.login(); | ||
308 | -// context.logout(); | ||
309 | -// | ||
310 | -// assertFalse(context.isLoggedIn()); | ||
311 | -// } | ||
312 | -// | ||
313 | -// @Test | ||
314 | -// public void testGetUserWhenSecurityIsDisabled() { | ||
315 | -// Authenticator authenticator = createMock(Authenticator.class); | ||
316 | -// expect(authenticator.getUser()).andReturn(null).anyTimes(); | ||
317 | -// | ||
318 | -// expect(config.isEnabled()).andReturn(false).anyTimes(); | ||
319 | -// replay(config, authenticator, Beans.class); | ||
320 | -// | ||
321 | -// setInternalState(context, "authenticator", authenticator); | ||
322 | -// | ||
323 | -// assertNotNull(context.getUser()); | ||
324 | -// assertNotNull(context.getUser().getId()); | ||
325 | -// assertNull(context.getUser().getAttribute(null)); | ||
326 | -// context.getUser().setAttribute(null, null); | ||
327 | -// } | ||
328 | -// | ||
329 | -// @Test | ||
330 | -// public void testGetUserWhenSecurityIsEnabled() { | ||
331 | -// Authenticator authenticator = createMock(Authenticator.class); | ||
332 | -// expect(authenticator.getUser()).andReturn(null).anyTimes(); | ||
333 | -// | ||
334 | -// expect(config.isEnabled()).andReturn(true); | ||
335 | -// replay(config, authenticator, Beans.class); | ||
336 | -// | ||
337 | -// setInternalState(context, "authenticator", authenticator); | ||
338 | -// | ||
339 | -// assertNull(context.getUser()); | ||
340 | -// } | ||
341 | -// | ||
342 | -// @Test | ||
343 | -// public void testGetUserWhenSecurityIsEnabledAndUserIsNotNull() { | ||
344 | -// User user = createMock(User.class); | ||
345 | -// | ||
346 | -// Authenticator authenticator = createMock(Authenticator.class); | ||
347 | -// expect(authenticator.getUser()).andReturn(user).anyTimes(); | ||
348 | -// | ||
349 | -// expect(config.isEnabled()).andReturn(true).anyTimes(); | ||
350 | -// replay(config, user, authenticator, Beans.class); | ||
351 | -// | ||
352 | -// setInternalState(context, "authenticator", authenticator); | ||
353 | -// | ||
354 | -// assertEquals(context.getUser(), user); | ||
355 | -// } | ||
356 | -//} | 1 | +/* |
2 | + * Demoiselle Framework | ||
3 | + * Copyright (C) 2010 SERPRO | ||
4 | + * ---------------------------------------------------------------------------- | ||
5 | + * This file is part of Demoiselle Framework. | ||
6 | + * | ||
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + * as published by the Free Software Foundation. | ||
10 | + * | ||
11 | + * This program is distributed in the hope that it will be useful, | ||
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + * GNU General Public License for more details. | ||
15 | + * | ||
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + * ---------------------------------------------------------------------------- | ||
21 | + * Este arquivo é parte do Framework Demoiselle. | ||
22 | + * | ||
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + * do Software Livre (FSF). | ||
26 | + * | ||
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + * para maiores detalhes. | ||
31 | + * | ||
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | + */ | ||
37 | +package br.gov.frameworkdemoiselle.internal.implementation; | ||
38 | + | ||
39 | +import static junit.framework.Assert.assertEquals; | ||
40 | +import static junit.framework.Assert.assertFalse; | ||
41 | +import static junit.framework.Assert.assertNotNull; | ||
42 | +import static junit.framework.Assert.assertNull; | ||
43 | +import static junit.framework.Assert.assertTrue; | ||
44 | +import static junit.framework.Assert.fail; | ||
45 | +import static org.easymock.EasyMock.createMock; | ||
46 | +import static org.easymock.EasyMock.expect; | ||
47 | +import static org.powermock.api.easymock.PowerMock.mockStatic; | ||
48 | +import static org.powermock.api.easymock.PowerMock.replay; | ||
49 | +import static org.powermock.api.easymock.PowerMock.replayAll; | ||
50 | + | ||
51 | +import java.util.ArrayList; | ||
52 | +import java.util.List; | ||
53 | +import java.util.Locale; | ||
54 | + | ||
55 | +import static org.powermock.reflect.Whitebox.setInternalState; | ||
56 | + | ||
57 | +import javax.enterprise.inject.spi.BeanManager; | ||
58 | + | ||
59 | +import org.easymock.EasyMock; | ||
60 | +import org.junit.Before; | ||
61 | +import org.junit.Test; | ||
62 | +import org.junit.runner.RunWith; | ||
63 | +import org.powermock.api.easymock.PowerMock; | ||
64 | +import org.powermock.core.classloader.annotations.PrepareForTest; | ||
65 | +import org.powermock.modules.junit4.PowerMockRunner; | ||
66 | + | ||
67 | +import br.gov.frameworkdemoiselle.security.Authenticator; | ||
68 | +import br.gov.frameworkdemoiselle.security.User; | ||
69 | +import br.gov.frameworkdemoiselle.security.Authorizer; | ||
70 | +import br.gov.frameworkdemoiselle.security.NotLoggedInException; | ||
71 | +import br.gov.frameworkdemoiselle.internal.bootstrap.AuthenticatorBootstrap; | ||
72 | +import br.gov.frameworkdemoiselle.internal.configuration.SecurityConfigImpl; | ||
73 | +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; | ||
74 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
75 | +import br.gov.frameworkdemoiselle.util.ResourceBundle; | ||
76 | + | ||
77 | +@RunWith(PowerMockRunner.class) | ||
78 | +@PrepareForTest({ Beans.class, ResourceBundle.class }) | ||
79 | +public class SecurityContextImplTest { | ||
80 | + | ||
81 | + private SecurityContextImpl context; | ||
82 | + private SecurityConfigImpl config; | ||
83 | + private ResourceBundle bundle; | ||
84 | + | ||
85 | + @Before | ||
86 | + public void setUpConfig() { | ||
87 | + context = new SecurityContextImpl(); | ||
88 | + config = createMock(SecurityConfigImpl.class); | ||
89 | + | ||
90 | + mockStatic(Beans.class); | ||
91 | + expect(Beans.getReference(SecurityConfigImpl.class)).andReturn(config).anyTimes(); | ||
92 | + } | ||
93 | + | ||
94 | + @Test | ||
95 | + public void testHasPermissionWithSecurityDisabled() { | ||
96 | + expect(config.isEnabled()).andReturn(false); | ||
97 | + replayAll(Beans.class,config); | ||
98 | + | ||
99 | + try { | ||
100 | + assertTrue(context.hasPermission(null, null)); | ||
101 | + } catch (NotLoggedInException e) { | ||
102 | + fail(); | ||
103 | + } | ||
104 | + } | ||
105 | + | ||
106 | + public void mockGetAuthenticator() { | ||
107 | + Class<? extends Authenticator> cache = AuthenticatorImpl.class; | ||
108 | + List<Class<? extends Authenticator>> cacheList = new ArrayList<Class<? extends Authenticator>>(); | ||
109 | + cacheList.add(cache); | ||
110 | + | ||
111 | + AuthenticatorBootstrap bootstrap = PowerMock.createMock(AuthenticatorBootstrap.class); | ||
112 | + | ||
113 | + expect(Beans.getReference(AuthenticatorBootstrap.class)).andReturn(bootstrap).anyTimes(); | ||
114 | + expect(config.getAuthenticatorClass()).andReturn(null).anyTimes(); | ||
115 | + expect(bootstrap.getCache()).andReturn(cacheList); | ||
116 | + expect(Beans.getReference(AuthenticatorImpl.class)).andReturn(new AuthenticatorImpl()); | ||
117 | + expect(Beans.getReference(Locale.class)).andReturn(Locale.getDefault()).anyTimes(); | ||
118 | + } | ||
119 | + | ||
120 | + @Test | ||
121 | + public void testHasPermissionWithSecurityEnabledAndNotLoggedIn() { | ||
122 | + mockGetAuthenticator(); | ||
123 | + | ||
124 | + expect(config.isEnabled()).andReturn(true).anyTimes(); | ||
125 | + replayAll(Beans.class,config); | ||
126 | + | ||
127 | + bundle = ResourceBundleProducer.create("demoiselle-core-bundle"); | ||
128 | + | ||
129 | + try { | ||
130 | + context.hasPermission(null, null); | ||
131 | + fail(); | ||
132 | + } catch (NotLoggedInException e) { | ||
133 | + assertTrue(e.getMessage().equals(bundle.getString("user-not-authenticated"))); | ||
134 | + } | ||
135 | + } | ||
136 | + | ||
137 | + @Test | ||
138 | + public void testHasPermissionWithSecurityEnabledAndLoggedIn() { | ||
139 | + expect(config.isEnabled()).andReturn(true).anyTimes(); | ||
140 | + replay(config); | ||
141 | + | ||
142 | + loginSuccessfully(); | ||
143 | + | ||
144 | + Authorizer authorizer = createMock(Authorizer.class); | ||
145 | + expect(authorizer.hasPermission(null, null)).andReturn(true); | ||
146 | + | ||
147 | + setInternalState(context, "authorizer", authorizer); | ||
148 | + | ||
149 | + replay(authorizer); | ||
150 | + | ||
151 | + try { | ||
152 | + assertTrue(context.hasPermission(null, null)); | ||
153 | + } catch (NotLoggedInException e) { | ||
154 | + fail(); | ||
155 | + } | ||
156 | + } | ||
157 | + | ||
158 | + private void loginSuccessfully() { | ||
159 | + Authenticator authenticator = createMock(Authenticator.class); | ||
160 | + expect(authenticator.authenticate()).andReturn(true); | ||
161 | + | ||
162 | + BeanManager manager = createMock(BeanManager.class); | ||
163 | + expect(Beans.getBeanManager()).andReturn(manager); | ||
164 | + manager.fireEvent(EasyMock.anyObject(Class.class)); | ||
165 | + PowerMock.expectLastCall(); | ||
166 | + | ||
167 | + User user = createMock(User.class); | ||
168 | + expect(authenticator.getUser()).andReturn(user).anyTimes(); | ||
169 | + | ||
170 | + setInternalState(context, "authenticator", authenticator); | ||
171 | + | ||
172 | + replayAll(authenticator, user, Beans.class, manager); | ||
173 | + | ||
174 | + context.login(); | ||
175 | + assertTrue(context.isLoggedIn()); | ||
176 | + } | ||
177 | + | ||
178 | + @Test | ||
179 | + public void testHasRoleWithSecurityDisabled() { | ||
180 | + expect(config.isEnabled()).andReturn(false); | ||
181 | + replayAll(Beans.class,config); | ||
182 | + | ||
183 | + try { | ||
184 | + assertTrue(context.hasRole(null)); | ||
185 | + } catch (NotLoggedInException e) { | ||
186 | + fail(); | ||
187 | + } | ||
188 | + } | ||
189 | + | ||
190 | + @Test | ||
191 | + public void testHasRoleWithSecurityEnabledAndNotLoggedIn() { | ||
192 | + mockGetAuthenticator(); | ||
193 | + | ||
194 | + expect(config.isEnabled()).andReturn(true).anyTimes(); | ||
195 | + replayAll(Beans.class,config); | ||
196 | + | ||
197 | + bundle = ResourceBundleProducer.create("demoiselle-core-bundle"); | ||
198 | + | ||
199 | + try { | ||
200 | + context.hasRole(null); | ||
201 | + fail(); | ||
202 | + } catch (NotLoggedInException e) { | ||
203 | + assertTrue(e.getMessage().equals(bundle.getString("user-not-authenticated"))); | ||
204 | + } | ||
205 | + } | ||
206 | + | ||
207 | + @Test | ||
208 | + public void testHasRoleWithSecurityEnabledAndLoggedIn() { | ||
209 | + expect(config.isEnabled()).andReturn(true).anyTimes(); | ||
210 | + replay(config); | ||
211 | + | ||
212 | + loginSuccessfully(); | ||
213 | + | ||
214 | + Authorizer authorizer = createMock(Authorizer.class); | ||
215 | + expect(authorizer.hasRole(null)).andReturn(true); | ||
216 | + | ||
217 | + setInternalState(context, "authorizer", authorizer); | ||
218 | + | ||
219 | + replay(authorizer); | ||
220 | + | ||
221 | + try { | ||
222 | + assertTrue(context.hasRole(null)); | ||
223 | + } catch (NotLoggedInException e) { | ||
224 | + fail(); | ||
225 | + } | ||
226 | + } | ||
227 | + | ||
228 | + @Test | ||
229 | + public void testIsLoggedInWithSecurityEnabled() { | ||
230 | + Authenticator authenticator = createMock(Authenticator.class); | ||
231 | + expect(authenticator.getUser()).andReturn(null).anyTimes(); | ||
232 | + expect(config.isEnabled()).andReturn(true).anyTimes(); | ||
233 | + | ||
234 | + setInternalState(context, "authenticator", authenticator); | ||
235 | + | ||
236 | + replayAll(config, authenticator); | ||
237 | + | ||
238 | + assertFalse(context.isLoggedIn()); | ||
239 | + } | ||
240 | + | ||
241 | + @Test | ||
242 | + public void testIsLoggedInWithSecurityDisabled() { | ||
243 | + expect(config.isEnabled()).andReturn(false); | ||
244 | + replayAll(config,Beans.class); | ||
245 | + | ||
246 | + assertTrue(context.isLoggedIn()); | ||
247 | + } | ||
248 | + | ||
249 | + @Test | ||
250 | + public void testLoginWithSecurityDisabled() { | ||
251 | + expect(config.isEnabled()).andReturn(false).times(2); | ||
252 | + replayAll(config,Beans.class); | ||
253 | + context.login(); | ||
254 | + | ||
255 | + assertTrue(context.isLoggedIn()); | ||
256 | + } | ||
257 | + | ||
258 | + @Test | ||
259 | + public void testLoginWithAuthenticationFail() { | ||
260 | + Authenticator authenticator = createMock(Authenticator.class); | ||
261 | + | ||
262 | + expect(config.isEnabled()).andReturn(true).anyTimes(); | ||
263 | + expect(authenticator.authenticate()).andReturn(false); | ||
264 | + expect(authenticator.getUser()).andReturn(null).anyTimes(); | ||
265 | + | ||
266 | + setInternalState(context, "authenticator", authenticator); | ||
267 | + | ||
268 | + replayAll(authenticator, config); | ||
269 | + | ||
270 | + context.login(); | ||
271 | + assertFalse(context.isLoggedIn()); | ||
272 | + } | ||
273 | + | ||
274 | + @Test | ||
275 | + public void testLogOutWithSecurityDisabled() { | ||
276 | + expect(config.isEnabled()).andReturn(false).times(2); | ||
277 | + | ||
278 | + replayAll(config,Beans.class); | ||
279 | + | ||
280 | + try { | ||
281 | + context.logout(); | ||
282 | + assertTrue(context.isLoggedIn()); | ||
283 | + } catch (NotLoggedInException e) { | ||
284 | + fail(); | ||
285 | + } | ||
286 | + } | ||
287 | + | ||
288 | + @Test | ||
289 | + public void testLogOutWithoutPreviousLogin() { | ||
290 | + Authenticator authenticator = createMock(Authenticator.class); | ||
291 | + | ||
292 | + expect(authenticator.getUser()).andReturn(null).anyTimes(); | ||
293 | + expect(Beans.getReference(Locale.class)).andReturn(Locale.getDefault()).anyTimes(); | ||
294 | + expect(config.isEnabled()).andReturn(true).anyTimes(); | ||
295 | + | ||
296 | + setInternalState(context, "authenticator", authenticator); | ||
297 | + | ||
298 | + replayAll(config, authenticator, Beans.class); | ||
299 | + | ||
300 | + bundle = ResourceBundleProducer.create("demoiselle-core-bundle"); | ||
301 | + | ||
302 | + try { | ||
303 | + context.logout(); | ||
304 | + fail(); | ||
305 | + } catch (NotLoggedInException e) { | ||
306 | + assertTrue(e.getMessage().equals(bundle.getString("user-not-authenticated"))); | ||
307 | + } | ||
308 | + } | ||
309 | + | ||
310 | + @Test | ||
311 | + public void testLogOutAfterSuccessfulLogin() { | ||
312 | + expect(config.isEnabled()).andReturn(true).anyTimes(); | ||
313 | + | ||
314 | + Authenticator authenticator = createMock(Authenticator.class); | ||
315 | + expect(authenticator.authenticate()).andReturn(true); | ||
316 | + authenticator.unAuthenticate(); | ||
317 | + PowerMock.expectLastCall(); | ||
318 | + | ||
319 | + User user = createMock(User.class); | ||
320 | + expect(authenticator.getUser()).andReturn(user); | ||
321 | + expect(authenticator.getUser()).andReturn(null); | ||
322 | + | ||
323 | + BeanManager manager = createMock(BeanManager.class); | ||
324 | + expect(Beans.getBeanManager()).andReturn(manager).times(2); | ||
325 | + manager.fireEvent(EasyMock.anyObject(Class.class)); | ||
326 | + PowerMock.expectLastCall().times(2); | ||
327 | + | ||
328 | + setInternalState(context, "authenticator", authenticator); | ||
329 | + | ||
330 | + replayAll(Beans.class, authenticator, user, manager, config); | ||
331 | + | ||
332 | + context.login(); | ||
333 | + context.logout(); | ||
334 | + | ||
335 | + assertFalse(context.isLoggedIn()); | ||
336 | + } | ||
337 | + | ||
338 | + @Test | ||
339 | + public void testGetUserWhenSecurityIsDisabled() { | ||
340 | + Authenticator authenticator = createMock(Authenticator.class); | ||
341 | + expect(authenticator.getUser()).andReturn(null).anyTimes(); | ||
342 | + expect(config.isEnabled()).andReturn(false).anyTimes(); | ||
343 | + replay(config, authenticator, Beans.class); | ||
344 | + | ||
345 | + setInternalState(context, "authenticator", authenticator); | ||
346 | + | ||
347 | + assertNotNull(context.getUser()); | ||
348 | + assertNotNull(context.getUser().getId()); | ||
349 | + assertNull(context.getUser().getAttribute(null)); | ||
350 | + context.getUser().setAttribute(null, null); | ||
351 | + } | ||
352 | + | ||
353 | + @Test | ||
354 | + public void testGetUserWhenSecurityIsEnabled() { | ||
355 | + Authenticator authenticator = createMock(Authenticator.class); | ||
356 | + expect(authenticator.getUser()).andReturn(null).anyTimes(); | ||
357 | + expect(config.isEnabled()).andReturn(true); | ||
358 | + replay(config, authenticator, Beans.class); | ||
359 | + | ||
360 | + setInternalState(context, "authenticator", authenticator); | ||
361 | + | ||
362 | + assertNull(context.getUser()); | ||
363 | + } | ||
364 | + | ||
365 | + @Test | ||
366 | + public void testGetUserWhenSecurityIsEnabledAndUserIsNotNull() { | ||
367 | + User user = createMock(User.class); | ||
368 | + | ||
369 | + Authenticator authenticator = createMock(Authenticator.class); | ||
370 | + expect(authenticator.getUser()).andReturn(user).anyTimes(); | ||
371 | + expect(config.isEnabled()).andReturn(true).anyTimes(); | ||
372 | + replay(config, user, authenticator, Beans.class); | ||
373 | + | ||
374 | + setInternalState(context, "authenticator", authenticator); | ||
375 | + | ||
376 | + assertEquals(context.getUser(), user); | ||
377 | + } | ||
378 | + | ||
379 | + class AuthenticatorImpl implements Authenticator { | ||
380 | + | ||
381 | + private static final long serialVersionUID = 1L; | ||
382 | + | ||
383 | + @Override | ||
384 | + public boolean authenticate() { | ||
385 | + return false; | ||
386 | + } | ||
387 | + | ||
388 | + @Override | ||
389 | + public void unAuthenticate() { | ||
390 | + } | ||
391 | + | ||
392 | + @Override | ||
393 | + public User getUser() { | ||
394 | + return null; | ||
395 | + } | ||
396 | + } | ||
397 | +} |
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/TransactionContextImplTest.java
@@ -64,59 +64,60 @@ public class TransactionContextImplTest { | @@ -64,59 +64,60 @@ public class TransactionContextImplTest { | ||
64 | private TransactionContext context; | 64 | private TransactionContext context; |
65 | private Transaction transaction; | 65 | private Transaction transaction; |
66 | 66 | ||
67 | + @Test | ||
68 | + public void testGetTransactionNull() { | ||
69 | + context = new TransactionContextImpl(); | ||
70 | + | ||
71 | + Class<? extends Transaction> cache = TransactionImpl.class; | ||
72 | + | ||
73 | + List<Class<? extends Transaction>> cacheList = new ArrayList<Class<? extends Transaction>>(); | ||
74 | + cacheList.add(cache); | ||
75 | + | ||
76 | + TransactionBootstrap bootstrap = PowerMock.createMock(TransactionBootstrap.class); | ||
77 | + TransactionConfig config = PowerMock.createMock(TransactionConfig.class); | ||
78 | + | ||
79 | + mockStatic(Beans.class); | ||
80 | + expect(Beans.getReference(TransactionBootstrap.class)).andReturn(bootstrap).anyTimes(); | ||
81 | + expect(Beans.getReference(TransactionConfig.class)).andReturn(config); | ||
82 | + expect(config.getTransactionClass()).andReturn(null).anyTimes(); | ||
83 | + expect(bootstrap.getCache()).andReturn(cacheList); | ||
84 | + expect(Beans.getReference(TransactionImpl.class)).andReturn(new TransactionImpl()); | ||
85 | + | ||
86 | + replayAll(Beans.class); | ||
87 | + | ||
88 | + transaction = context.getCurrentTransaction(); | ||
89 | + Assert.assertEquals(transaction.getClass(),TransactionImpl.class); | ||
90 | + } | ||
91 | + | ||
67 | class TransactionImpl implements Transaction{ | 92 | class TransactionImpl implements Transaction{ |
68 | - | 93 | + |
69 | private static final long serialVersionUID = 1L; | 94 | private static final long serialVersionUID = 1L; |
70 | - | 95 | + |
71 | @Override | 96 | @Override |
72 | public boolean isActive() { | 97 | public boolean isActive() { |
73 | return false; | 98 | return false; |
74 | } | 99 | } |
75 | - | 100 | + |
76 | @Override | 101 | @Override |
77 | public boolean isMarkedRollback() { | 102 | public boolean isMarkedRollback() { |
78 | return false; | 103 | return false; |
79 | } | 104 | } |
80 | - | 105 | + |
81 | @Override | 106 | @Override |
82 | public void begin() { | 107 | public void begin() { |
83 | } | 108 | } |
84 | - | 109 | + |
85 | @Override | 110 | @Override |
86 | public void commit() { | 111 | public void commit() { |
87 | } | 112 | } |
88 | - | 113 | + |
89 | @Override | 114 | @Override |
90 | public void rollback() { | 115 | public void rollback() { |
91 | } | 116 | } |
92 | - | 117 | + |
93 | @Override | 118 | @Override |
94 | public void setRollbackOnly() { | 119 | public void setRollbackOnly() { |
95 | } | 120 | } |
96 | } | 121 | } |
97 | 122 | ||
98 | - @Test | ||
99 | - public void testGetTransactionNull() { | ||
100 | - context = new TransactionContextImpl(); | ||
101 | - | ||
102 | - Class<? extends Transaction> cache = TransactionImpl.class; | ||
103 | - | ||
104 | - List<Class<? extends Transaction>> cacheList = new ArrayList<Class<? extends Transaction>>(); | ||
105 | - cacheList.add(cache); | ||
106 | - | ||
107 | - TransactionBootstrap bootstrap = PowerMock.createMock(TransactionBootstrap.class); | ||
108 | - TransactionConfig config = PowerMock.createMock(TransactionConfig.class); | ||
109 | - | ||
110 | - mockStatic(Beans.class); | ||
111 | - expect(Beans.getReference(TransactionBootstrap.class)).andReturn(bootstrap).anyTimes(); | ||
112 | - expect(Beans.getReference(TransactionConfig.class)).andReturn(config); | ||
113 | - expect(config.getTransactionClass()).andReturn(null).anyTimes(); | ||
114 | - expect(bootstrap.getCache()).andReturn(cacheList); | ||
115 | - expect(Beans.getReference(TransactionImpl.class)).andReturn(new TransactionImpl()); | ||
116 | - | ||
117 | - replayAll(Beans.class); | ||
118 | - | ||
119 | - transaction = context.getCurrentTransaction(); | ||
120 | - Assert.assertNotNull(transaction); | ||
121 | - } | ||
122 | } | 123 | } |
impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/internal/proxy/QueryProxyTest.java
1 | +/* | ||
2 | + * Demoiselle Framework | ||
3 | + * Copyright (C) 2010 SERPRO | ||
4 | + * ---------------------------------------------------------------------------- | ||
5 | + * This file is part of Demoiselle Framework. | ||
6 | + * | ||
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + * as published by the Free Software Foundation. | ||
10 | + * | ||
11 | + * This program is distributed in the hope that it will be useful, | ||
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + * GNU General Public License for more details. | ||
15 | + * | ||
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + * ---------------------------------------------------------------------------- | ||
21 | + * Este arquivo é parte do Framework Demoiselle. | ||
22 | + * | ||
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + * do Software Livre (FSF). | ||
26 | + * | ||
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + * para maiores detalhes. | ||
31 | + * | ||
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | + */ | ||
1 | package br.gov.frameworkdemoiselle.internal.proxy; | 37 | package br.gov.frameworkdemoiselle.internal.proxy; |
2 | 38 | ||
39 | +import static junit.framework.Assert.assertTrue; | ||
40 | +import static org.easymock.EasyMock.expect; | ||
41 | +import static org.junit.Assert.assertEquals; | ||
42 | +import static org.powermock.api.easymock.PowerMock.replay; | ||
43 | +import static org.powermock.api.easymock.PowerMock.verifyAll; | ||
44 | + | ||
45 | +import java.util.ArrayList; | ||
46 | +import java.util.Calendar; | ||
3 | import java.util.Collections; | 47 | import java.util.Collections; |
4 | import java.util.Date; | 48 | import java.util.Date; |
5 | import java.util.HashMap; | 49 | import java.util.HashMap; |
@@ -10,15 +54,13 @@ import javax.persistence.EntityManager; | @@ -10,15 +54,13 @@ import javax.persistence.EntityManager; | ||
10 | import javax.persistence.EntityManagerFactory; | 54 | import javax.persistence.EntityManagerFactory; |
11 | import javax.persistence.FlushModeType; | 55 | import javax.persistence.FlushModeType; |
12 | import javax.persistence.LockModeType; | 56 | import javax.persistence.LockModeType; |
13 | -import javax.persistence.NoResultException; | 57 | +import javax.persistence.Parameter; |
14 | import javax.persistence.Persistence; | 58 | import javax.persistence.Persistence; |
15 | import javax.persistence.Query; | 59 | import javax.persistence.Query; |
16 | import javax.persistence.TemporalType; | 60 | import javax.persistence.TemporalType; |
17 | 61 | ||
18 | import org.easymock.EasyMock; | 62 | import org.easymock.EasyMock; |
19 | -import org.junit.Assert; | ||
20 | import org.junit.Before; | 63 | import org.junit.Before; |
21 | -import org.junit.Ignore; | ||
22 | import org.junit.Test; | 64 | import org.junit.Test; |
23 | import org.junit.runner.RunWith; | 65 | import org.junit.runner.RunWith; |
24 | import org.powermock.api.easymock.PowerMock; | 66 | import org.powermock.api.easymock.PowerMock; |
@@ -32,224 +74,221 @@ import br.gov.frameworkdemoiselle.util.Beans; | @@ -32,224 +74,221 @@ import br.gov.frameworkdemoiselle.util.Beans; | ||
32 | 74 | ||
33 | /** | 75 | /** |
34 | * Test the proxied {@link Query} class, {@link QueryProxy}. | 76 | * Test the proxied {@link Query} class, {@link QueryProxy}. |
77 | + * | ||
35 | * @author 81986912515 | 78 | * @author 81986912515 |
36 | - * | ||
37 | */ | 79 | */ |
38 | -@Ignore | ||
39 | @RunWith(PowerMockRunner.class) | 80 | @RunWith(PowerMockRunner.class) |
40 | -@PrepareForTest({Beans.class}) | 81 | +@PrepareForTest({ Beans.class }) |
41 | public class QueryProxyTest { | 82 | public class QueryProxyTest { |
42 | - | 83 | + |
43 | private EntityManager manager; | 84 | private EntityManager manager; |
85 | + | ||
44 | private EntityManagerProducer producer; | 86 | private EntityManagerProducer producer; |
45 | - | 87 | + |
88 | + private QueryProxy queryProxy; | ||
89 | + | ||
46 | @Before | 90 | @Before |
47 | - public void setUp(){ | ||
48 | - | 91 | + public void setUp() { |
92 | + | ||
49 | Map<String, Object> configOverrides = new HashMap<String, Object>(); | 93 | Map<String, Object> configOverrides = new HashMap<String, Object>(); |
50 | configOverrides.put("javax.persistence.provider", "org.hibernate.ejb.HibernatePersistence"); | 94 | configOverrides.put("javax.persistence.provider", "org.hibernate.ejb.HibernatePersistence"); |
51 | - configOverrides.put("javax.persistence.jdbc.url", "jdbc:hsqldb:hsql:."); | 95 | + |
96 | + configOverrides.put("javax.persistence.jdbc.url", "jdbc:hsqldb:mem:."); | ||
97 | + configOverrides.put("javax.persistence.jdbc.driver", "org.hsqldb.jdbcDriver"); | ||
98 | + configOverrides.put("javax.persistence.jdbc.user", "sa"); | ||
99 | + configOverrides.put("javax.persistence.jdbc.password", ""); | ||
100 | + | ||
52 | configOverrides.put("hibernate.show_sql", "true"); | 101 | configOverrides.put("hibernate.show_sql", "true"); |
53 | configOverrides.put("hibernate.hbm2ddl.auto", "create-drop"); | 102 | configOverrides.put("hibernate.hbm2ddl.auto", "create-drop"); |
54 | - | 103 | + |
55 | EntityManagerFactory factory = Persistence.createEntityManagerFactory("pu1", configOverrides); | 104 | EntityManagerFactory factory = Persistence.createEntityManagerFactory("pu1", configOverrides); |
56 | EntityManager delegate = factory.createEntityManager(); | 105 | EntityManager delegate = factory.createEntityManager(); |
57 | - | 106 | + |
58 | Map<String, EntityManager> cache = Collections.synchronizedMap(new HashMap<String, EntityManager>()); | 107 | Map<String, EntityManager> cache = Collections.synchronizedMap(new HashMap<String, EntityManager>()); |
59 | cache.put("pu1", delegate); | 108 | cache.put("pu1", delegate); |
60 | - | 109 | + |
61 | producer = new EntityManagerProducer(); | 110 | producer = new EntityManagerProducer(); |
62 | Whitebox.setInternalState(producer, "cache", cache); | 111 | Whitebox.setInternalState(producer, "cache", cache); |
63 | - | 112 | + |
64 | PowerMock.mockStatic(Beans.class); | 113 | PowerMock.mockStatic(Beans.class); |
65 | - EasyMock.expect(Beans.getReference(EntityManagerProducer.class)).andReturn(producer).times(12); | 114 | + EasyMock.expect(Beans.getReference(EntityManagerProducer.class)).andReturn(producer).anyTimes(); |
66 | PowerMock.replayAll(); | 115 | PowerMock.replayAll(); |
67 | 116 | ||
68 | manager = new EntityManagerProxy("pu1"); | 117 | manager = new EntityManagerProxy("pu1"); |
69 | - | ||
70 | - manager.getTransaction().begin(); | ||
71 | - manager.createQuery("delete from Client").executeUpdate(); | ||
72 | - | ||
73 | - Client client = new Client(); | ||
74 | - client.setName("Cliente 1"); | ||
75 | - client.setBirthDate(new Date()); | ||
76 | - manager.persist(client); | ||
77 | - | ||
78 | - client = new Client(); | ||
79 | - client.setName("Cliente 2"); | ||
80 | - client.setBirthDate(new Date()); | ||
81 | - manager.persist(client); | ||
82 | - | ||
83 | - client = new Client(); | ||
84 | - client.setName("Cliente 3"); | ||
85 | - client.setBirthDate(new Date()); | ||
86 | - manager.persist(client); | ||
87 | - | ||
88 | - manager.flush(); | ||
89 | - manager.getTransaction().commit(); | ||
90 | - manager.clear(); | ||
91 | - | ||
92 | - PowerMock.resetAll(); | ||
93 | } | 118 | } |
94 | - | ||
95 | - private QueryProxy getQueryProxy(String jpql,Object... params){ | ||
96 | - Query q = manager.createQuery(jpql); | ||
97 | - if (!(q instanceof QueryProxy)){ | ||
98 | - Assert.fail("Query não é instância de QueryProxy"); | ||
99 | - } | ||
100 | - | ||
101 | - if (params!=null){ | ||
102 | - int count = 1; | ||
103 | - for (Object param : params){ | ||
104 | - q.setParameter(count++, param); | ||
105 | - } | ||
106 | - } | ||
107 | - | ||
108 | - return (QueryProxy)q; | ||
109 | - } | ||
110 | - | 119 | + |
111 | @Test | 120 | @Test |
112 | - public void testResultList(){ | ||
113 | - EasyMock.expect(Beans.getReference(EntityManagerProducer.class)).andReturn(producer).times(2); | ||
114 | - PowerMock.replay(Beans.class); | ||
115 | - | ||
116 | - List<?> retorno = getQueryProxy("select c from Client c").getResultList(); | ||
117 | - Assert.assertNotNull(retorno); | ||
118 | - Assert.assertFalse(retorno.isEmpty()); | 121 | + public void testGetResultList() { |
122 | + Query queryDelegate = PowerMock.createMock(Query.class); | ||
123 | + List<String> result = new ArrayList<String>(); | ||
124 | + result.add("x"); | ||
125 | + EasyMock.expect(queryDelegate.getResultList()).andReturn(result).anyTimes(); | ||
126 | + | ||
127 | + replay(queryDelegate); | ||
128 | + | ||
129 | + queryProxy = new QueryProxy(queryDelegate, (EntityManagerProxy) manager); | ||
130 | + queryProxy.getResultList(); | ||
131 | + assertEquals(queryProxy.getResultList().size(), queryDelegate.getResultList().size()); | ||
132 | + | ||
133 | + verifyAll(); | ||
119 | } | 134 | } |
120 | - | 135 | + |
121 | @Test | 136 | @Test |
122 | - public void testSingleResult(){ | ||
123 | - EasyMock.expect(Beans.getReference(EntityManagerProducer.class)).andReturn(producer).times(2); | ||
124 | - PowerMock.replay(Beans.class); | ||
125 | - | ||
126 | - Client retorno = (Client)getQueryProxy("select c from Client c where c.name=?1","Cliente 1").getSingleResult(); | ||
127 | - Assert.assertNotNull(retorno); | 137 | + public void testSingleResult() { |
138 | + Query queryDelegate = PowerMock.createMock(Query.class); | ||
139 | + String result = "Resultado"; | ||
140 | + EasyMock.expect(queryDelegate.getSingleResult()).andReturn(result).anyTimes(); | ||
141 | + | ||
142 | + replay(queryDelegate); | ||
143 | + | ||
144 | + queryProxy = new QueryProxy(queryDelegate, (EntityManagerProxy) manager); | ||
145 | + assertEquals(queryProxy.getSingleResult(), queryDelegate.getSingleResult()); | ||
146 | + | ||
147 | + verifyAll(); | ||
128 | } | 148 | } |
129 | - | 149 | + |
130 | @Test | 150 | @Test |
131 | - public void testExecuteUpdate(){ | ||
132 | - EasyMock.expect(Beans.getReference(EntityManagerProducer.class)).andReturn(producer).times(4); | ||
133 | - PowerMock.replay(Beans.class); | ||
134 | - | ||
135 | - manager.getTransaction().begin(); | ||
136 | - int linesAffected = getQueryProxy("update Client set name=?1 where name=?2","Novo Cliente","Cliente 1").executeUpdate(); | ||
137 | - manager.getTransaction().commit(); | ||
138 | - Assert.assertEquals(1, linesAffected); | 151 | + public void testExecuteUpdate() { |
152 | + Query queryDelegate = PowerMock.createMock(Query.class); | ||
153 | + EasyMock.expect(queryDelegate.executeUpdate()).andReturn(1).anyTimes(); | ||
154 | + | ||
155 | + replay(queryDelegate); | ||
156 | + | ||
157 | + queryProxy = new QueryProxy(queryDelegate, (EntityManagerProxy) manager); | ||
158 | + assertEquals(queryProxy.executeUpdate(), 1); | ||
159 | + | ||
160 | + verifyAll(); | ||
139 | } | 161 | } |
140 | - | 162 | + |
141 | @Test | 163 | @Test |
142 | - public void testPagination(){ | ||
143 | - EasyMock.expect(Beans.getReference(EntityManagerProducer.class)).andReturn(producer).times(2); | ||
144 | - PowerMock.replay(Beans.class); | ||
145 | - | ||
146 | - QueryProxy proxy = getQueryProxy("select c from Client c"); | ||
147 | - | ||
148 | - proxy.setMaxResults(2); | ||
149 | - Assert.assertEquals(2, proxy.getMaxResults()); | ||
150 | - | ||
151 | - proxy.setFirstResult(1); | ||
152 | - Assert.assertEquals(1, proxy.getFirstResult()); | ||
153 | - | ||
154 | - List<?> result = proxy.getResultList(); | ||
155 | - Assert.assertEquals(2, result.size()); | 164 | + public void testPagination() { |
165 | + Query queryDelegate = PowerMock.createMock(Query.class); | ||
166 | + expect(queryDelegate.getMaxResults()).andReturn(4).times(2); | ||
167 | + expect(queryDelegate.getFirstResult()).andReturn(2).times(2); | ||
168 | + expect(queryDelegate.setMaxResults(EasyMock.anyInt())).andReturn(queryDelegate); | ||
169 | + expect(queryDelegate.setFirstResult(EasyMock.anyInt())).andReturn(queryDelegate); | ||
170 | + replay(queryDelegate); | ||
171 | + | ||
172 | + queryProxy = new QueryProxy(queryDelegate, (EntityManagerProxy) manager); | ||
173 | + queryProxy.setMaxResults(4); | ||
174 | + queryProxy.setFirstResult(2); | ||
175 | + assertEquals(queryProxy.getMaxResults(), queryDelegate.getMaxResults()); | ||
176 | + assertEquals(queryProxy.getFirstResult(), queryDelegate.getFirstResult()); | ||
177 | + | ||
178 | + verifyAll(); | ||
156 | } | 179 | } |
157 | - | 180 | + |
158 | @Test | 181 | @Test |
159 | - public void testHint(){ | ||
160 | - EasyMock.expect(Beans.getReference(EntityManagerProducer.class)).andReturn(producer).times(14); | ||
161 | - PowerMock.replay(Beans.class); | ||
162 | - | ||
163 | - //Consulta um cliente definindo a hint readOnly, que torna a entidade retornada não atualizável. | ||
164 | - manager.getTransaction().begin(); | ||
165 | - QueryProxy proxy = getQueryProxy("select c from Client c where c.name=?1","Cliente 1"); | ||
166 | - proxy.setHint("org.hibernate.readOnly", true); | ||
167 | - Assert.assertFalse( proxy.getHints().isEmpty() ); | ||
168 | - | ||
169 | - //Tenta atualizar a entidade e limpar o cache de primeiro nível | ||
170 | - Client c = (Client)proxy.getSingleResult(); | ||
171 | - c.setName("Cliente 1 Alterado"); | ||
172 | - manager.flush(); | ||
173 | - manager.getTransaction().commit(); | ||
174 | - manager.clear(); | ||
175 | - | ||
176 | - //Reconsultar a entidade tem que retornar 1 resultado, pois o nome "Cliente 1" não deve ter sido alterado. | ||
177 | - manager.getTransaction().begin(); | ||
178 | - proxy = getQueryProxy("select c from Client c where c.name=?1","Cliente 1"); | ||
179 | - c = (Client)proxy.getSingleResult(); | ||
180 | - Assert.assertNotNull(c); | ||
181 | - | ||
182 | - //Mudar a entidade agora tem que funcionar, pois não foi informado o hint | ||
183 | - c.setName("Cliente 1 Alterado"); | ||
184 | - manager.flush(); | ||
185 | - manager.getTransaction().commit(); | ||
186 | - manager.clear(); | ||
187 | - | ||
188 | - proxy = getQueryProxy("select c from Client c where c.name=?1","Cliente 1"); | ||
189 | - | ||
190 | - try{ | ||
191 | - proxy.getSingleResult(); | ||
192 | - Assert.fail(); | ||
193 | - } | ||
194 | - catch(NoResultException ne){ | ||
195 | - } | ||
196 | - | ||
197 | - PowerMock.verifyAll(); | 182 | + public void testHint() { |
183 | + Query queryDelegate = PowerMock.createMock(Query.class); | ||
184 | + Map<String, Object> map = new HashMap<String, Object>(); | ||
185 | + Client client = new Client(); | ||
186 | + map.put("1", client); | ||
187 | + expect(queryDelegate.getHints()).andReturn(map).times(2); | ||
188 | + expect(queryDelegate.setHint(EasyMock.anyObject(String.class), EasyMock.anyObject())).andReturn(queryDelegate); | ||
189 | + replay(queryDelegate); | ||
190 | + | ||
191 | + queryProxy = new QueryProxy(queryDelegate, (EntityManagerProxy) manager); | ||
192 | + queryProxy.setHint("1", client); | ||
193 | + assertEquals(queryProxy.getHints(), queryDelegate.getHints()); | ||
194 | + | ||
195 | + verifyAll(); | ||
198 | } | 196 | } |
199 | - | 197 | + |
198 | + @SuppressWarnings({ "unused", "rawtypes", "unchecked" }) | ||
200 | @Test | 199 | @Test |
201 | - public void testParameters(){ | ||
202 | - | ||
203 | - EasyMock.expect(Beans.getReference(EntityManagerProducer.class)).andReturn(producer).times(2); | ||
204 | - PowerMock.replay(Beans.class); | ||
205 | - | ||
206 | - QueryProxy proxy = getQueryProxy("select c.name from Client c where 'Named Parameter'=:name and c.birthDate=:dateName and c.name=?1 and c.birthDate=?2"); | ||
207 | - | 200 | + public void testParameters() { |
201 | + Query queryDelegate = PowerMock.createMock(Query.class); | ||
208 | Date dateValue = new Date(); | 202 | Date dateValue = new Date(); |
209 | - | ||
210 | - proxy.setParameter("name", "Named Parameter"); | ||
211 | - proxy.setParameter("dateName", dateValue, TemporalType.DATE); | ||
212 | - | ||
213 | - proxy.setParameter(1, "Cliente 1"); | ||
214 | - proxy.setParameter(2, dateValue,TemporalType.DATE); | ||
215 | - | ||
216 | - Assert.assertEquals(proxy.getParameterValue("name"),"Named Parameter"); | ||
217 | - Assert.assertEquals(proxy.getParameterValue(1), "Cliente 1"); | ||
218 | - | ||
219 | - @SuppressWarnings("unchecked") | ||
220 | - List<Map<String, Object>> result = proxy.getResultList(); | ||
221 | - | ||
222 | - Assert.assertNotNull(result); | ||
223 | - Assert.assertFalse(result.isEmpty()); | ||
224 | - | ||
225 | - PowerMock.verifyAll(); | 203 | + Calendar calendar = PowerMock.createMock(Calendar.class); |
204 | + Class<Date> type = Date.class; | ||
205 | + Parameter parameter = PowerMock.createMock(Parameter.class); | ||
206 | + | ||
207 | + expect(queryDelegate.setParameter(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))) | ||
208 | + .andReturn(queryDelegate); | ||
209 | + expect(queryDelegate.getParameterValue(EasyMock.anyObject(String.class))).andReturn("Named Parameter") | ||
210 | + .anyTimes(); | ||
211 | + expect(queryDelegate.setParameter(EasyMock.anyInt(), EasyMock.anyObject(String.class))) | ||
212 | + .andReturn(queryDelegate); | ||
213 | + expect(queryDelegate.getParameterValue(EasyMock.anyInt())).andReturn("Client").anyTimes(); | ||
214 | + expect( | ||
215 | + queryDelegate.setParameter(EasyMock.anyObject(String.class), EasyMock.anyObject(Date.class), | ||
216 | + EasyMock.anyObject(TemporalType.class))).andReturn(queryDelegate); | ||
217 | + expect( | ||
218 | + queryDelegate.setParameter(EasyMock.anyInt(), EasyMock.anyObject(Date.class), | ||
219 | + EasyMock.anyObject(TemporalType.class))).andReturn(queryDelegate); | ||
220 | + expect(queryDelegate.setParameter(EasyMock.anyObject(Parameter.class), EasyMock.anyObject())).andReturn( | ||
221 | + queryDelegate); | ||
222 | + expect(queryDelegate.getParameterValue(EasyMock.anyObject(Parameter.class))).andReturn(parameter).anyTimes(); | ||
223 | + expect( | ||
224 | + queryDelegate.setParameter(EasyMock.anyObject(String.class), EasyMock.anyObject(Calendar.class), | ||
225 | + EasyMock.anyObject(TemporalType.class))).andReturn(queryDelegate); | ||
226 | + expect( | ||
227 | + queryDelegate.setParameter(EasyMock.anyInt(), EasyMock.anyObject(Calendar.class), | ||
228 | + EasyMock.anyObject(TemporalType.class))).andReturn(queryDelegate); | ||
229 | + | ||
230 | + replay(queryDelegate, parameter, calendar); | ||
231 | + | ||
232 | + queryProxy = new QueryProxy(queryDelegate, (EntityManagerProxy) manager); | ||
233 | + queryProxy.setParameter("name", "Named Parameter"); | ||
234 | + assertEquals(queryProxy.getParameterValue("name"), queryDelegate.getParameterValue("name")); | ||
235 | + queryProxy.setParameter(1, "Client"); | ||
236 | + assertEquals(queryProxy.getParameterValue("1"), queryDelegate.getParameterValue("1")); | ||
237 | + queryProxy.setParameter("dateName", dateValue, TemporalType.DATE); | ||
238 | + queryProxy.setParameter(2, dateValue, TemporalType.DATE); | ||
239 | + queryProxy.setParameter(parameter, "X"); | ||
240 | + queryProxy.getParameterValue(parameter); | ||
241 | + assertEquals(queryProxy.getParameterValue(parameter), parameter); | ||
242 | + queryProxy.setParameter("dateName", calendar, TemporalType.DATE); | ||
243 | + queryProxy.setParameter(2, calendar, TemporalType.DATE); | ||
244 | + | ||
245 | + verifyAll(); | ||
246 | + } | ||
247 | + | ||
248 | + @SuppressWarnings("rawtypes") | ||
249 | + @Test | ||
250 | + public void testIsBound() { | ||
251 | + Query queryDelegate = PowerMock.createMock(Query.class); | ||
252 | + Parameter parameter = PowerMock.createMock(Parameter.class); | ||
253 | + expect(queryDelegate.isBound(EasyMock.anyObject(Parameter.class))).andReturn(true); | ||
254 | + | ||
255 | + replay(queryDelegate, parameter); | ||
256 | + | ||
257 | + queryProxy = new QueryProxy(queryDelegate, (EntityManagerProxy) manager); | ||
258 | + assertTrue(queryProxy.isBound(parameter)); | ||
259 | + | ||
260 | + verifyAll(); | ||
226 | } | 261 | } |
227 | - | 262 | + |
228 | @Test | 263 | @Test |
229 | - public void testFlushMode(){ | ||
230 | - EasyMock.expect(Beans.getReference(EntityManagerProducer.class)).andReturn(producer).times(3); | ||
231 | - PowerMock.replay(Beans.class); | ||
232 | - | ||
233 | - manager.getTransaction().begin(); | ||
234 | - QueryProxy proxy = getQueryProxy("update Client set name=?1 where name=?2","Cliente 1 Alterado","Cliente 1"); | ||
235 | - proxy.setFlushMode(FlushModeType.COMMIT); | ||
236 | - Assert.assertEquals(proxy.getFlushMode(), FlushModeType.COMMIT); | ||
237 | - manager.getTransaction().commit(); | ||
238 | - | ||
239 | - PowerMock.verifyAll(); | 264 | + public void testFlushMode() { |
265 | + Query queryDelegate = PowerMock.createMock(Query.class); | ||
266 | + FlushModeType flushModeType = FlushModeType.AUTO; | ||
267 | + | ||
268 | + expect(queryDelegate.setFlushMode(FlushModeType.AUTO)).andReturn(queryDelegate); | ||
269 | + expect(queryDelegate.getFlushMode()).andReturn(flushModeType).anyTimes(); | ||
270 | + | ||
271 | + replay(queryDelegate); | ||
272 | + | ||
273 | + queryProxy = new QueryProxy(queryDelegate, (EntityManagerProxy) manager); | ||
274 | + queryProxy.setFlushMode(FlushModeType.AUTO); | ||
275 | + assertEquals(queryProxy.getFlushMode(), queryDelegate.getFlushMode()); | ||
276 | + verifyAll(); | ||
240 | } | 277 | } |
241 | - | 278 | + |
242 | @Test | 279 | @Test |
243 | - public void testLockMode(){ | ||
244 | - EasyMock.expect(Beans.getReference(EntityManagerProducer.class)).andReturn(producer).times(4); | ||
245 | - PowerMock.replay(Beans.class); | ||
246 | - | ||
247 | - manager.getTransaction().begin(); | ||
248 | - QueryProxy proxy = getQueryProxy("update Client set name=?1 where name=?2","Cliente 1 Alterado","Cliente 1"); | ||
249 | - proxy.setLockMode(LockModeType.OPTIMISTIC); | ||
250 | - Assert.assertEquals(proxy.getLockMode(), LockModeType.OPTIMISTIC); | ||
251 | - manager.getTransaction().commit(); | ||
252 | - | ||
253 | - PowerMock.verifyAll(); | 280 | + public void testLockMode() { |
281 | + Query queryDelegate = PowerMock.createMock(Query.class); | ||
282 | + LockModeType lockModeType = LockModeType.OPTIMISTIC; | ||
283 | + | ||
284 | + expect(queryDelegate.setLockMode(lockModeType)).andReturn(queryDelegate); | ||
285 | + expect(queryDelegate.getLockMode()).andReturn(lockModeType).anyTimes(); | ||
286 | + | ||
287 | + replay(queryDelegate); | ||
288 | + | ||
289 | + queryProxy = new QueryProxy(queryDelegate, (EntityManagerProxy) manager); | ||
290 | + queryProxy.setLockMode(lockModeType); | ||
291 | + assertEquals(queryProxy.getLockMode(), queryDelegate.getLockMode()); | ||
292 | + verifyAll(); | ||
254 | } | 293 | } |
255 | } | 294 | } |
impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/internal/proxy/TypedQueryProxyTest.java
1 | package br.gov.frameworkdemoiselle.internal.proxy; | 1 | package br.gov.frameworkdemoiselle.internal.proxy; |
2 | 2 | ||
3 | +import static junit.framework.Assert.assertTrue; | ||
4 | +import static org.easymock.EasyMock.expect; | ||
5 | +import static org.junit.Assert.assertEquals; | ||
6 | +import static org.powermock.api.easymock.PowerMock.replay; | ||
7 | +import static org.powermock.api.easymock.PowerMock.verifyAll; | ||
8 | + | ||
9 | +import java.util.ArrayList; | ||
10 | +import java.util.Calendar; | ||
3 | import java.util.Collections; | 11 | import java.util.Collections; |
4 | import java.util.Date; | 12 | import java.util.Date; |
5 | import java.util.HashMap; | 13 | import java.util.HashMap; |
@@ -10,16 +18,14 @@ import javax.persistence.EntityManager; | @@ -10,16 +18,14 @@ import javax.persistence.EntityManager; | ||
10 | import javax.persistence.EntityManagerFactory; | 18 | import javax.persistence.EntityManagerFactory; |
11 | import javax.persistence.FlushModeType; | 19 | import javax.persistence.FlushModeType; |
12 | import javax.persistence.LockModeType; | 20 | import javax.persistence.LockModeType; |
13 | -import javax.persistence.NoResultException; | 21 | +import javax.persistence.Parameter; |
14 | import javax.persistence.Persistence; | 22 | import javax.persistence.Persistence; |
15 | import javax.persistence.Query; | 23 | import javax.persistence.Query; |
16 | import javax.persistence.TemporalType; | 24 | import javax.persistence.TemporalType; |
17 | import javax.persistence.TypedQuery; | 25 | import javax.persistence.TypedQuery; |
18 | 26 | ||
19 | import org.easymock.EasyMock; | 27 | import org.easymock.EasyMock; |
20 | -import org.junit.Assert; | ||
21 | import org.junit.Before; | 28 | import org.junit.Before; |
22 | -import org.junit.Ignore; | ||
23 | import org.junit.Test; | 29 | import org.junit.Test; |
24 | import org.junit.runner.RunWith; | 30 | import org.junit.runner.RunWith; |
25 | import org.powermock.api.easymock.PowerMock; | 31 | import org.powermock.api.easymock.PowerMock; |
@@ -33,212 +39,220 @@ import br.gov.frameworkdemoiselle.util.Beans; | @@ -33,212 +39,220 @@ import br.gov.frameworkdemoiselle.util.Beans; | ||
33 | 39 | ||
34 | /** | 40 | /** |
35 | * Test the proxied {@link Query} class, {@link TypedQueryProxy}. | 41 | * Test the proxied {@link Query} class, {@link TypedQueryProxy}. |
42 | + * | ||
36 | * @author 81986912515 | 43 | * @author 81986912515 |
37 | - * | 44 | + * @param <X> |
38 | */ | 45 | */ |
39 | -@Ignore | 46 | + |
47 | +@SuppressWarnings("rawtypes") | ||
40 | @RunWith(PowerMockRunner.class) | 48 | @RunWith(PowerMockRunner.class) |
41 | -@PrepareForTest({Beans.class}) | 49 | +@PrepareForTest({ Beans.class }) |
42 | public class TypedQueryProxyTest { | 50 | public class TypedQueryProxyTest { |
43 | - | 51 | + |
44 | private EntityManager manager; | 52 | private EntityManager manager; |
53 | + | ||
45 | private EntityManagerProducer producer; | 54 | private EntityManagerProducer producer; |
46 | - | 55 | + |
56 | + private TypedQueryProxy typedQueryProxy; | ||
57 | + | ||
47 | @Before | 58 | @Before |
48 | - public void setUp(){ | ||
49 | - | 59 | + public void setUp() { |
60 | + | ||
50 | Map<String, Object> configOverrides = new HashMap<String, Object>(); | 61 | Map<String, Object> configOverrides = new HashMap<String, Object>(); |
51 | configOverrides.put("javax.persistence.provider", "org.hibernate.ejb.HibernatePersistence"); | 62 | configOverrides.put("javax.persistence.provider", "org.hibernate.ejb.HibernatePersistence"); |
52 | - configOverrides.put("javax.persistence.jdbc.url", "jdbc:hsqldb:hsql:."); | 63 | + |
64 | + configOverrides.put("javax.persistence.jdbc.url", "jdbc:hsqldb:mem:."); | ||
65 | + configOverrides.put("javax.persistence.jdbc.driver", "org.hsqldb.jdbcDriver"); | ||
66 | + configOverrides.put("javax.persistence.jdbc.user", "sa"); | ||
67 | + configOverrides.put("javax.persistence.jdbc.password", ""); | ||
68 | + | ||
53 | configOverrides.put("hibernate.show_sql", "true"); | 69 | configOverrides.put("hibernate.show_sql", "true"); |
54 | configOverrides.put("hibernate.hbm2ddl.auto", "create-drop"); | 70 | configOverrides.put("hibernate.hbm2ddl.auto", "create-drop"); |
55 | - | 71 | + |
56 | EntityManagerFactory factory = Persistence.createEntityManagerFactory("pu1", configOverrides); | 72 | EntityManagerFactory factory = Persistence.createEntityManagerFactory("pu1", configOverrides); |
57 | EntityManager delegate = factory.createEntityManager(); | 73 | EntityManager delegate = factory.createEntityManager(); |
58 | - | 74 | + |
59 | Map<String, EntityManager> cache = Collections.synchronizedMap(new HashMap<String, EntityManager>()); | 75 | Map<String, EntityManager> cache = Collections.synchronizedMap(new HashMap<String, EntityManager>()); |
60 | cache.put("pu1", delegate); | 76 | cache.put("pu1", delegate); |
61 | - | 77 | + |
62 | producer = new EntityManagerProducer(); | 78 | producer = new EntityManagerProducer(); |
63 | Whitebox.setInternalState(producer, "cache", cache); | 79 | Whitebox.setInternalState(producer, "cache", cache); |
64 | - | 80 | + |
65 | PowerMock.mockStatic(Beans.class); | 81 | PowerMock.mockStatic(Beans.class); |
66 | - EasyMock.expect(Beans.getReference(EntityManagerProducer.class)).andReturn(producer).times(12); | 82 | + EasyMock.expect(Beans.getReference(EntityManagerProducer.class)).andReturn(producer).anyTimes(); |
67 | PowerMock.replayAll(); | 83 | PowerMock.replayAll(); |
68 | 84 | ||
69 | manager = new EntityManagerProxy("pu1"); | 85 | manager = new EntityManagerProxy("pu1"); |
70 | - | ||
71 | - manager.getTransaction().begin(); | ||
72 | - manager.createQuery("delete from Client").executeUpdate(); | ||
73 | - | ||
74 | - Client client = new Client(); | ||
75 | - client.setName("Cliente 1"); | ||
76 | - client.setBirthDate(new Date()); | ||
77 | - manager.persist(client); | ||
78 | - | ||
79 | - client = new Client(); | ||
80 | - client.setName("Cliente 2"); | ||
81 | - client.setBirthDate(new Date()); | ||
82 | - manager.persist(client); | ||
83 | - | ||
84 | - client = new Client(); | ||
85 | - client.setName("Cliente 3"); | ||
86 | - client.setBirthDate(new Date()); | ||
87 | - manager.persist(client); | ||
88 | - | ||
89 | - manager.flush(); | ||
90 | - manager.getTransaction().commit(); | ||
91 | - manager.clear(); | ||
92 | - | ||
93 | - PowerMock.resetAll(); | ||
94 | - } | ||
95 | - | ||
96 | - private <T> TypedQueryProxy<T> getQueryProxy(String jpql,Class<T> classType,Object... params){ | ||
97 | - TypedQuery<T> q = manager.createQuery(jpql,classType); | ||
98 | - if (!(q instanceof TypedQueryProxy)){ | ||
99 | - Assert.fail("Query não é instância de QueryProxy"); | ||
100 | - } | ||
101 | - | ||
102 | - if (params!=null){ | ||
103 | - int count = 1; | ||
104 | - for (Object param : params){ | ||
105 | - q.setParameter(count++, param); | ||
106 | - } | ||
107 | - } | ||
108 | - | ||
109 | - return (TypedQueryProxy<T>)q; | 86 | + |
87 | + // PowerMock.resetAll(); | ||
110 | } | 88 | } |
111 | - | 89 | + |
90 | + @SuppressWarnings("unchecked") | ||
112 | @Test | 91 | @Test |
113 | - public void testResultList(){ | ||
114 | - EasyMock.expect(Beans.getReference(EntityManagerProducer.class)).andReturn(producer).times(2); | ||
115 | - PowerMock.replay(Beans.class); | ||
116 | - | ||
117 | - List<?> retorno = getQueryProxy("select c from Client c",Client.class).getResultList(); | ||
118 | - Assert.assertNotNull(retorno); | ||
119 | - Assert.assertFalse(retorno.isEmpty()); | 92 | + public void testResultList() { |
93 | + | ||
94 | + TypedQuery queryDelegate = PowerMock.createMock(TypedQuery.class); | ||
95 | + List<String> result = new ArrayList<String>(); | ||
96 | + result.add("x"); | ||
97 | + EasyMock.expect(queryDelegate.getResultList()).andReturn(result).anyTimes(); | ||
98 | + | ||
99 | + replay(queryDelegate); | ||
100 | + | ||
101 | + typedQueryProxy = new TypedQueryProxy(queryDelegate, (EntityManagerProxy) manager); | ||
102 | + assertEquals(typedQueryProxy.getResultList().size(), queryDelegate.getResultList().size()); | ||
103 | + | ||
104 | + verifyAll(); | ||
120 | } | 105 | } |
121 | - | 106 | + |
107 | + @SuppressWarnings("unchecked") | ||
122 | @Test | 108 | @Test |
123 | - public void testSingleResult(){ | ||
124 | - EasyMock.expect(Beans.getReference(EntityManagerProducer.class)).andReturn(producer).times(2); | ||
125 | - PowerMock.replay(Beans.class); | ||
126 | - | ||
127 | - Client retorno = (Client)getQueryProxy("select c from Client c where c.name=?1",Client.class,"Cliente 1").getSingleResult(); | ||
128 | - Assert.assertNotNull(retorno); | 109 | + public void testSingleResult() { |
110 | + TypedQuery queryDelegate = PowerMock.createMock(TypedQuery.class); | ||
111 | + String result = "Resultado"; | ||
112 | + EasyMock.expect(queryDelegate.getSingleResult()).andReturn(result).anyTimes(); | ||
113 | + | ||
114 | + replay(queryDelegate); | ||
115 | + | ||
116 | + typedQueryProxy = new TypedQueryProxy(queryDelegate, (EntityManagerProxy) manager); | ||
117 | + assertEquals(typedQueryProxy.getSingleResult(), queryDelegate.getSingleResult()); | ||
118 | + | ||
119 | + verifyAll(); | ||
129 | } | 120 | } |
130 | - | 121 | + |
122 | + @SuppressWarnings("unchecked") | ||
131 | @Test | 123 | @Test |
132 | - public void testPagination(){ | ||
133 | - EasyMock.expect(Beans.getReference(EntityManagerProducer.class)).andReturn(producer).times(2); | ||
134 | - PowerMock.replay(Beans.class); | ||
135 | - | ||
136 | - TypedQueryProxy<Client> proxy = getQueryProxy("select c from Client c",Client.class); | ||
137 | - | ||
138 | - proxy.setMaxResults(2); | ||
139 | - Assert.assertEquals(2, proxy.getMaxResults()); | ||
140 | - | ||
141 | - proxy.setFirstResult(1); | ||
142 | - Assert.assertEquals(1, proxy.getFirstResult()); | ||
143 | - | ||
144 | - List<?> result = proxy.getResultList(); | ||
145 | - Assert.assertEquals(2, result.size()); | 124 | + public void testPagination() { |
125 | + TypedQuery queryDelegate = PowerMock.createMock(TypedQuery.class); | ||
126 | + expect(queryDelegate.getMaxResults()).andReturn(4).times(2); | ||
127 | + expect(queryDelegate.getFirstResult()).andReturn(2).times(2); | ||
128 | + expect(queryDelegate.setMaxResults(EasyMock.anyInt())).andReturn(queryDelegate); | ||
129 | + expect(queryDelegate.setFirstResult(EasyMock.anyInt())).andReturn(queryDelegate); | ||
130 | + replay(queryDelegate); | ||
131 | + | ||
132 | + typedQueryProxy = new TypedQueryProxy(queryDelegate, (EntityManagerProxy) manager); | ||
133 | + typedQueryProxy.setMaxResults(4); | ||
134 | + typedQueryProxy.setFirstResult(2); | ||
135 | + assertEquals(typedQueryProxy.getMaxResults(), queryDelegate.getMaxResults()); | ||
136 | + assertEquals(typedQueryProxy.getFirstResult(), queryDelegate.getFirstResult()); | ||
137 | + | ||
138 | + verifyAll(); | ||
146 | } | 139 | } |
147 | - | 140 | + |
141 | + @SuppressWarnings("unchecked") | ||
148 | @Test | 142 | @Test |
149 | - public void testHint(){ | ||
150 | - EasyMock.expect(Beans.getReference(EntityManagerProducer.class)).andReturn(producer).times(14); | ||
151 | - PowerMock.replay(Beans.class); | ||
152 | - | ||
153 | - //Consulta um cliente definindo a hint readOnly, que torna a entidade retornada não atualizável. | ||
154 | - manager.getTransaction().begin(); | ||
155 | - TypedQueryProxy<Client> proxy = getQueryProxy("select c from Client c where c.name=?1",Client.class,"Cliente 1"); | ||
156 | - proxy.setHint("org.hibernate.readOnly", true); | ||
157 | - Assert.assertFalse( proxy.getHints().isEmpty() ); | ||
158 | - | ||
159 | - //Tenta atualizar a entidade e limpar o cache de primeiro nível | ||
160 | - Client c = (Client)proxy.getSingleResult(); | ||
161 | - c.setName("Cliente 1 Alterado"); | ||
162 | - manager.flush(); | ||
163 | - manager.getTransaction().commit(); | ||
164 | - manager.clear(); | ||
165 | - | ||
166 | - //Reconsultar a entidade tem que retornar 1 resultado, pois o nome "Cliente 1" não deve ter sido alterado. | ||
167 | - manager.getTransaction().begin(); | ||
168 | - proxy = getQueryProxy("select c from Client c where c.name=?1",Client.class,"Cliente 1"); | ||
169 | - c = (Client)proxy.getSingleResult(); | ||
170 | - Assert.assertNotNull(c); | ||
171 | - | ||
172 | - //Mudar a entidade agora tem que funcionar, pois não foi informado o hint | ||
173 | - c.setName("Cliente 1 Alterado"); | ||
174 | - manager.flush(); | ||
175 | - manager.getTransaction().commit(); | ||
176 | - manager.clear(); | ||
177 | - | ||
178 | - proxy = getQueryProxy("select c from Client c where c.name=?1",Client.class,"Cliente 1"); | ||
179 | - | ||
180 | - try{ | ||
181 | - proxy.getSingleResult(); | ||
182 | - Assert.fail(); | ||
183 | - } | ||
184 | - catch(NoResultException ne){ | ||
185 | - } | ||
186 | - | ||
187 | - PowerMock.verifyAll(); | 143 | + public void testHint() { |
144 | + TypedQuery queryDelegate = PowerMock.createMock(TypedQuery.class); | ||
145 | + Map<String, Object> map = new HashMap<String, Object>(); | ||
146 | + Client client = new Client(); | ||
147 | + map.put("1", client); | ||
148 | + expect(queryDelegate.getHints()).andReturn(map).times(2); | ||
149 | + expect(queryDelegate.setHint(EasyMock.anyObject(String.class), EasyMock.anyObject())).andReturn(queryDelegate); | ||
150 | + replay(queryDelegate); | ||
151 | + | ||
152 | + typedQueryProxy = new TypedQueryProxy(queryDelegate, (EntityManagerProxy) manager); | ||
153 | + typedQueryProxy.setHint("1", client); | ||
154 | + assertEquals(typedQueryProxy.getHints(), queryDelegate.getHints()); | ||
155 | + | ||
156 | + verifyAll(); | ||
188 | } | 157 | } |
189 | - | 158 | + |
159 | + @SuppressWarnings({ "unchecked", "unused" }) | ||
190 | @Test | 160 | @Test |
191 | - public void testParameters(){ | ||
192 | - | ||
193 | - EasyMock.expect(Beans.getReference(EntityManagerProducer.class)).andReturn(producer).times(2); | ||
194 | - PowerMock.replay(Beans.class); | ||
195 | - | ||
196 | - TypedQueryProxy<Client> proxy = getQueryProxy("select c from Client c where 'Named Parameter'=:name and c.birthDate=:dateName and c.name=?1 and c.birthDate=?2",Client.class); | ||
197 | - | 161 | + public void testParameters() { |
162 | + TypedQuery queryDelegate = PowerMock.createMock(TypedQuery.class); | ||
198 | Date dateValue = new Date(); | 163 | Date dateValue = new Date(); |
199 | - | ||
200 | - proxy.setParameter("name", "Named Parameter"); | ||
201 | - proxy.setParameter("dateName", dateValue, TemporalType.DATE); | ||
202 | - | ||
203 | - proxy.setParameter(1, "Cliente 1"); | ||
204 | - proxy.setParameter(2, dateValue,TemporalType.DATE); | ||
205 | - | ||
206 | - Assert.assertEquals(proxy.getParameterValue("name"),"Named Parameter"); | ||
207 | - Assert.assertEquals(proxy.getParameterValue(1), "Cliente 1"); | ||
208 | - | ||
209 | - List<Client> result = proxy.getResultList(); | ||
210 | - | ||
211 | - Assert.assertNotNull(result); | ||
212 | - Assert.assertFalse(result.isEmpty()); | ||
213 | - | ||
214 | - PowerMock.verifyAll(); | 164 | + Calendar calendar = PowerMock.createMock(Calendar.class); |
165 | + Class<Date> type = Date.class; | ||
166 | + Parameter parameter = PowerMock.createMock(Parameter.class); | ||
167 | + | ||
168 | + expect(queryDelegate.setParameter(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))) | ||
169 | + .andReturn(queryDelegate); | ||
170 | + expect(queryDelegate.getParameterValue(EasyMock.anyObject(String.class))).andReturn("Named Parameter") | ||
171 | + .anyTimes(); | ||
172 | + expect(queryDelegate.setParameter(EasyMock.anyInt(), EasyMock.anyObject(String.class))) | ||
173 | + .andReturn(queryDelegate); | ||
174 | + expect(queryDelegate.getParameterValue(EasyMock.anyInt())).andReturn("Client").anyTimes(); | ||
175 | + expect( | ||
176 | + queryDelegate.setParameter(EasyMock.anyObject(String.class), EasyMock.anyObject(Date.class), | ||
177 | + EasyMock.anyObject(TemporalType.class))).andReturn(queryDelegate); | ||
178 | + expect( | ||
179 | + queryDelegate.setParameter(EasyMock.anyInt(), EasyMock.anyObject(Date.class), | ||
180 | + EasyMock.anyObject(TemporalType.class))).andReturn(queryDelegate); | ||
181 | + expect(queryDelegate.setParameter(EasyMock.anyObject(Parameter.class), EasyMock.anyObject())).andReturn( | ||
182 | + queryDelegate); | ||
183 | + expect(queryDelegate.getParameterValue(EasyMock.anyObject(Parameter.class))).andReturn(parameter).anyTimes(); | ||
184 | + expect( | ||
185 | + queryDelegate.setParameter(EasyMock.anyObject(String.class), EasyMock.anyObject(Calendar.class), | ||
186 | + EasyMock.anyObject(TemporalType.class))).andReturn(queryDelegate); | ||
187 | + expect( | ||
188 | + queryDelegate.setParameter(EasyMock.anyInt(), EasyMock.anyObject(Calendar.class), | ||
189 | + EasyMock.anyObject(TemporalType.class))).andReturn(queryDelegate); | ||
190 | + | ||
191 | + replay(queryDelegate, parameter, calendar); | ||
192 | + | ||
193 | + typedQueryProxy = new TypedQueryProxy(queryDelegate, (EntityManagerProxy) manager); | ||
194 | + typedQueryProxy.setParameter("name", "Named Parameter"); | ||
195 | + assertEquals(typedQueryProxy.getParameterValue("name"), queryDelegate.getParameterValue("name")); | ||
196 | + typedQueryProxy.setParameter(1, "Client"); | ||
197 | + assertEquals(typedQueryProxy.getParameterValue("1"), queryDelegate.getParameterValue("1")); | ||
198 | + typedQueryProxy.setParameter("dateName", dateValue, TemporalType.DATE); | ||
199 | + typedQueryProxy.setParameter(2, dateValue, TemporalType.DATE); | ||
200 | + typedQueryProxy.setParameter(parameter, "X"); | ||
201 | + typedQueryProxy.getParameterValue(parameter); | ||
202 | + assertEquals(typedQueryProxy.getParameterValue(parameter), parameter); | ||
203 | + typedQueryProxy.setParameter("dateName", calendar, TemporalType.DATE); | ||
204 | + typedQueryProxy.setParameter(2, calendar, TemporalType.DATE); | ||
205 | + | ||
206 | + verifyAll(); | ||
207 | + } | ||
208 | + | ||
209 | + @SuppressWarnings("unchecked") | ||
210 | + @Test | ||
211 | + public void testIsBound() { | ||
212 | + TypedQuery queryDelegate = PowerMock.createMock(TypedQuery.class); | ||
213 | + Parameter parameter = PowerMock.createMock(Parameter.class); | ||
214 | + expect(queryDelegate.isBound(EasyMock.anyObject(Parameter.class))).andReturn(true); | ||
215 | + | ||
216 | + replay(queryDelegate, parameter); | ||
217 | + | ||
218 | + typedQueryProxy = new TypedQueryProxy(queryDelegate, (EntityManagerProxy) manager); | ||
219 | + assertTrue(typedQueryProxy.isBound(parameter)); | ||
220 | + | ||
221 | + verifyAll(); | ||
215 | } | 222 | } |
216 | - | 223 | + |
224 | + @SuppressWarnings("unchecked") | ||
217 | @Test | 225 | @Test |
218 | - public void testFlushMode(){ | ||
219 | - EasyMock.expect(Beans.getReference(EntityManagerProducer.class)).andReturn(producer).times(3); | ||
220 | - PowerMock.replay(Beans.class); | ||
221 | - | ||
222 | - manager.getTransaction().begin(); | ||
223 | - TypedQueryProxy<Client> proxy = getQueryProxy("select c from Client c where c.name=?1",Client.class,"Cliente 1"); | ||
224 | - proxy.setFlushMode(FlushModeType.COMMIT); | ||
225 | - Assert.assertEquals(proxy.getFlushMode(), FlushModeType.COMMIT); | ||
226 | - manager.getTransaction().commit(); | ||
227 | - | ||
228 | - PowerMock.verifyAll(); | 226 | + public void testFlushMode() { |
227 | + TypedQuery queryDelegate = PowerMock.createMock(TypedQuery.class); | ||
228 | + FlushModeType flushModeType = FlushModeType.AUTO; | ||
229 | + | ||
230 | + expect(queryDelegate.setFlushMode(FlushModeType.AUTO)).andReturn(queryDelegate); | ||
231 | + expect(queryDelegate.getFlushMode()).andReturn(flushModeType).anyTimes(); | ||
232 | + | ||
233 | + replay(queryDelegate); | ||
234 | + | ||
235 | + typedQueryProxy = new TypedQueryProxy(queryDelegate, (EntityManagerProxy) manager); | ||
236 | + typedQueryProxy.setFlushMode(FlushModeType.AUTO); | ||
237 | + assertEquals(typedQueryProxy.getFlushMode(), queryDelegate.getFlushMode()); | ||
238 | + verifyAll(); | ||
229 | } | 239 | } |
230 | - | 240 | + |
241 | + @SuppressWarnings("unchecked") | ||
231 | @Test | 242 | @Test |
232 | - public void testLockMode(){ | ||
233 | - EasyMock.expect(Beans.getReference(EntityManagerProducer.class)).andReturn(producer).times(3); | ||
234 | - PowerMock.replay(Beans.class); | ||
235 | - | ||
236 | - manager.getTransaction().begin(); | ||
237 | - TypedQueryProxy<Client> proxy = getQueryProxy("select c from Client c where c.name=?1",Client.class,"Cliente 1"); | ||
238 | - proxy.setLockMode(LockModeType.OPTIMISTIC); | ||
239 | - Assert.assertEquals(proxy.getLockMode(), LockModeType.OPTIMISTIC); | ||
240 | - manager.getTransaction().commit(); | ||
241 | - | ||
242 | - PowerMock.verifyAll(); | 243 | + public void testLockMode() { |
244 | + TypedQuery queryDelegate = PowerMock.createMock(TypedQuery.class); | ||
245 | + LockModeType lockModeType = LockModeType.OPTIMISTIC; | ||
246 | + | ||
247 | + expect(queryDelegate.setLockMode(lockModeType)).andReturn(queryDelegate); | ||
248 | + expect(queryDelegate.getLockMode()).andReturn(lockModeType).anyTimes(); | ||
249 | + | ||
250 | + replay(queryDelegate); | ||
251 | + | ||
252 | + typedQueryProxy = new TypedQueryProxy(queryDelegate, (EntityManagerProxy) manager); | ||
253 | + typedQueryProxy.setLockMode(lockModeType); | ||
254 | + assertEquals(typedQueryProxy.getLockMode(), queryDelegate.getLockMode()); | ||
255 | + verifyAll(); | ||
243 | } | 256 | } |
257 | + | ||
244 | } | 258 | } |
impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/internal/bootstrap/JsfBootstrapTest.java
@@ -39,27 +39,20 @@ package br.gov.frameworkdemoiselle.internal.bootstrap; | @@ -39,27 +39,20 @@ package br.gov.frameworkdemoiselle.internal.bootstrap; | ||
39 | import static org.easymock.EasyMock.expect; | 39 | import static org.easymock.EasyMock.expect; |
40 | import static org.powermock.api.easymock.PowerMock.createMock; | 40 | import static org.powermock.api.easymock.PowerMock.createMock; |
41 | import static org.powermock.api.easymock.PowerMock.mockStatic; | 41 | import static org.powermock.api.easymock.PowerMock.mockStatic; |
42 | -import static org.powermock.api.easymock.PowerMock.replayAll; | ||
43 | import static org.powermock.api.easymock.PowerMock.replay; | 42 | import static org.powermock.api.easymock.PowerMock.replay; |
44 | import static org.powermock.api.easymock.PowerMock.verifyAll; | 43 | import static org.powermock.api.easymock.PowerMock.verifyAll; |
45 | -import static org.powermock.api.easymock.PowerMock.verify; | ||
46 | 44 | ||
47 | -import java.lang.annotation.Annotation; | ||
48 | import java.util.ArrayList; | 45 | import java.util.ArrayList; |
49 | import java.util.List; | 46 | import java.util.List; |
50 | import java.util.Locale; | 47 | import java.util.Locale; |
51 | 48 | ||
52 | -import javax.enterprise.context.spi.Contextual; | ||
53 | -import javax.enterprise.context.spi.CreationalContext; | ||
54 | import javax.enterprise.inject.spi.AfterBeanDiscovery; | 49 | import javax.enterprise.inject.spi.AfterBeanDiscovery; |
55 | import javax.enterprise.inject.spi.AfterDeploymentValidation; | 50 | import javax.enterprise.inject.spi.AfterDeploymentValidation; |
56 | 51 | ||
57 | import junit.framework.Assert; | 52 | import junit.framework.Assert; |
58 | 53 | ||
59 | -import org.easymock.EasyMock; | ||
60 | import org.junit.Before; | 54 | import org.junit.Before; |
61 | import org.junit.Test; | 55 | import org.junit.Test; |
62 | -import org.junit.rules.TemporaryFolder; | ||
63 | import org.junit.runner.RunWith; | 56 | import org.junit.runner.RunWith; |
64 | import org.powermock.core.classloader.annotations.PrepareForTest; | 57 | import org.powermock.core.classloader.annotations.PrepareForTest; |
65 | import org.powermock.modules.junit4.PowerMockRunner; | 58 | import org.powermock.modules.junit4.PowerMockRunner; |
impl/extension/se/src/main/java/br/gov/frameworkdemoiselle/internal/producer/SeLocaleProducer.java
1 | +/* | ||
2 | + * Demoiselle Framework | ||
3 | + * Copyright (C) 2010 SERPRO | ||
4 | + * ---------------------------------------------------------------------------- | ||
5 | + * This file is part of Demoiselle Framework. | ||
6 | + * | ||
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + * as published by the Free Software Foundation. | ||
10 | + * | ||
11 | + * This program is distributed in the hope that it will be useful, | ||
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + * GNU General Public License for more details. | ||
15 | + * | ||
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + * ---------------------------------------------------------------------------- | ||
21 | + * Este arquivo é parte do Framework Demoiselle. | ||
22 | + * | ||
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + * do Software Livre (FSF). | ||
26 | + * | ||
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + * para maiores detalhes. | ||
31 | + * | ||
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | + */ | ||
1 | package br.gov.frameworkdemoiselle.internal.producer; | 37 | package br.gov.frameworkdemoiselle.internal.producer; |
2 | 38 | ||
3 | import java.util.Locale; | 39 | import java.util.Locale; |
impl/extension/se/src/test/java/br/gov/frameworkdemoiselle/internal/bootstrap/SeBootstrapTest.java
0 → 100644
@@ -0,0 +1,102 @@ | @@ -0,0 +1,102 @@ | ||
1 | +/* | ||
2 | + * Demoiselle Framework | ||
3 | + * Copyright (C) 2010 SERPRO | ||
4 | + * ---------------------------------------------------------------------------- | ||
5 | + * This file is part of Demoiselle Framework. | ||
6 | + * | ||
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + * as published by the Free Software Foundation. | ||
10 | + * | ||
11 | + * This program is distributed in the hope that it will be useful, | ||
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + * GNU General Public License for more details. | ||
15 | + * | ||
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + * ---------------------------------------------------------------------------- | ||
21 | + * Este arquivo é parte do Framework Demoiselle. | ||
22 | + * | ||
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + * do Software Livre (FSF). | ||
26 | + * | ||
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + * para maiores detalhes. | ||
31 | + * | ||
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | + */ | ||
37 | +package br.gov.frameworkdemoiselle.internal.bootstrap; | ||
38 | + | ||
39 | +import static org.easymock.EasyMock.expect; | ||
40 | +import static org.powermock.api.easymock.PowerMock.createMock; | ||
41 | +import static org.powermock.api.easymock.PowerMock.mockStatic; | ||
42 | +import static org.powermock.api.easymock.PowerMock.replay; | ||
43 | +import static org.powermock.api.easymock.PowerMock.verifyAll; | ||
44 | + | ||
45 | +import java.util.List; | ||
46 | +import java.util.Locale; | ||
47 | + | ||
48 | +import javax.enterprise.inject.spi.AfterBeanDiscovery; | ||
49 | + | ||
50 | +import junit.framework.Assert; | ||
51 | + | ||
52 | +import org.junit.Before; | ||
53 | +import org.junit.Test; | ||
54 | +import org.junit.runner.RunWith; | ||
55 | +import org.powermock.core.classloader.annotations.PrepareForTest; | ||
56 | +import org.powermock.modules.junit4.PowerMockRunner; | ||
57 | +import org.powermock.reflect.Whitebox; | ||
58 | + | ||
59 | +import br.gov.frameworkdemoiselle.internal.context.Contexts; | ||
60 | +import br.gov.frameworkdemoiselle.internal.context.CustomContext; | ||
61 | +import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; | ||
62 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
63 | + | ||
64 | +@RunWith(PowerMockRunner.class) | ||
65 | +@PrepareForTest({ Beans.class, Contexts.class }) | ||
66 | +public class SeBootstrapTest { | ||
67 | + | ||
68 | + private SeBootstrap seBootstrap; | ||
69 | + | ||
70 | + private AfterBeanDiscovery event; | ||
71 | + | ||
72 | + @Before | ||
73 | + public void before() { | ||
74 | + event = createMock(AfterBeanDiscovery.class); | ||
75 | + mockStatic(Beans.class); | ||
76 | + expect(Beans.getReference(Locale.class)).andReturn(Locale.getDefault()).anyTimes(); | ||
77 | + replay(Beans.class); | ||
78 | + seBootstrap = new SeBootstrap(); | ||
79 | + } | ||
80 | + | ||
81 | + @Test | ||
82 | + public void testStoreContext() { | ||
83 | + seBootstrap.storeContexts(event); | ||
84 | + replay(event); | ||
85 | + | ||
86 | + Assert.assertEquals(event, Whitebox.getInternalState(seBootstrap, "afterBeanDiscoveryEvent")); | ||
87 | + List<CustomContext> context = Whitebox.getInternalState(seBootstrap, "tempContexts"); | ||
88 | + Assert.assertEquals(4, context.size()); | ||
89 | + verifyAll(); | ||
90 | + } | ||
91 | + | ||
92 | + @Test | ||
93 | + public void testRemoveContexts() { | ||
94 | + seBootstrap.storeContexts(event); | ||
95 | + | ||
96 | + AfterShutdownProccess afterShutdownProccess = createMock(AfterShutdownProccess.class); | ||
97 | + replay(event, afterShutdownProccess); | ||
98 | + seBootstrap.removeContexts(afterShutdownProccess); | ||
99 | + | ||
100 | + verifyAll(); | ||
101 | + } | ||
102 | +} |
impl/extension/se/src/test/java/br/gov/frameworkdemoiselle/internal/producer/SeLocaleProducerTest.java
1 | +/* | ||
2 | + * Demoiselle Framework | ||
3 | + * Copyright (C) 2010 SERPRO | ||
4 | + * ---------------------------------------------------------------------------- | ||
5 | + * This file is part of Demoiselle Framework. | ||
6 | + * | ||
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + * as published by the Free Software Foundation. | ||
10 | + * | ||
11 | + * This program is distributed in the hope that it will be useful, | ||
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + * GNU General Public License for more details. | ||
15 | + * | ||
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + * ---------------------------------------------------------------------------- | ||
21 | + * Este arquivo é parte do Framework Demoiselle. | ||
22 | + * | ||
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + * do Software Livre (FSF). | ||
26 | + * | ||
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + * para maiores detalhes. | ||
31 | + * | ||
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | + */ | ||
1 | package br.gov.frameworkdemoiselle.internal.producer; | 37 | package br.gov.frameworkdemoiselle.internal.producer; |
2 | -import org.junit.Ignore; | 38 | + |
3 | import java.util.Locale; | 39 | import java.util.Locale; |
4 | 40 | ||
5 | import junit.framework.Assert; | 41 | import junit.framework.Assert; |
@@ -10,11 +46,7 @@ public class SeLocaleProducerTest { | @@ -10,11 +46,7 @@ public class SeLocaleProducerTest { | ||
10 | 46 | ||
11 | @Test | 47 | @Test |
12 | public void testCreate() { | 48 | public void testCreate() { |
13 | - | ||
14 | Locale locale = (new SeLocaleProducer()).create(); | 49 | Locale locale = (new SeLocaleProducer()).create(); |
15 | - | ||
16 | Assert.assertNotNull(locale); | 50 | Assert.assertNotNull(locale); |
17 | - | ||
18 | } | 51 | } |
19 | - | ||
20 | } | 52 | } |
impl/extension/servlet/pom.xml
@@ -71,6 +71,11 @@ | @@ -71,6 +71,11 @@ | ||
71 | <groupId>javax.servlet</groupId> | 71 | <groupId>javax.servlet</groupId> |
72 | <artifactId>servlet-api</artifactId> | 72 | <artifactId>servlet-api</artifactId> |
73 | </dependency> | 73 | </dependency> |
74 | + <dependency> | ||
75 | + <groupId>javax.el</groupId> | ||
76 | + <artifactId>el-api</artifactId> | ||
77 | + <scope>test</scope> | ||
78 | + </dependency> | ||
74 | </dependencies> | 79 | </dependencies> |
75 | 80 | ||
76 | <repositories> | 81 | <repositories> |
impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/HttpServletRequestProxy.java
@@ -1,307 +0,0 @@ | @@ -1,307 +0,0 @@ | ||
1 | -//package br.gov.frameworkdemoiselle.internal.proxy; | ||
2 | -// | ||
3 | -//import java.io.BufferedReader; | ||
4 | -//import java.io.IOException; | ||
5 | -//import java.io.Serializable; | ||
6 | -//import java.io.UnsupportedEncodingException; | ||
7 | -//import java.security.Principal; | ||
8 | -//import java.util.Enumeration; | ||
9 | -//import java.util.Locale; | ||
10 | -//import java.util.Map; | ||
11 | -// | ||
12 | -//import javax.enterprise.context.RequestScoped; | ||
13 | -//import javax.enterprise.inject.Default; | ||
14 | -//import javax.servlet.RequestDispatcher; | ||
15 | -//import javax.servlet.ServletInputStream; | ||
16 | -//import javax.servlet.http.Cookie; | ||
17 | -//import javax.servlet.http.HttpServletRequest; | ||
18 | -//import javax.servlet.http.HttpSession; | ||
19 | -// | ||
20 | -//@Default | ||
21 | -//@RequestScoped | ||
22 | -//public class HttpServletRequestProxy implements HttpServletRequest, Serializable { | ||
23 | -// | ||
24 | -// private static final long serialVersionUID = 1L; | ||
25 | -// | ||
26 | -// private transient HttpServletRequest delegate; | ||
27 | -// | ||
28 | -// public HttpServletRequestProxy(HttpServletRequest delegate) { | ||
29 | -// this.delegate = delegate; | ||
30 | -// } | ||
31 | -// | ||
32 | -// private HttpServletRequest getDelegate() { | ||
33 | -// return delegate; | ||
34 | -// } | ||
35 | -// | ||
36 | -// @Override | ||
37 | -// public Object getAttribute(String name) { | ||
38 | -// return getDelegate().getAttribute(name); | ||
39 | -// } | ||
40 | -// | ||
41 | -// @Override | ||
42 | -// public Enumeration<?> getAttributeNames() { | ||
43 | -// return getDelegate().getAttributeNames(); | ||
44 | -// } | ||
45 | -// | ||
46 | -// @Override | ||
47 | -// public String getCharacterEncoding() { | ||
48 | -// return getDelegate().getCharacterEncoding(); | ||
49 | -// } | ||
50 | -// | ||
51 | -// @Override | ||
52 | -// public void setCharacterEncoding(String env) throws UnsupportedEncodingException { | ||
53 | -// getDelegate().setCharacterEncoding(env); | ||
54 | -// } | ||
55 | -// | ||
56 | -// @Override | ||
57 | -// public int getContentLength() { | ||
58 | -// return getDelegate().getContentLength(); | ||
59 | -// } | ||
60 | -// | ||
61 | -// @Override | ||
62 | -// public String getContentType() { | ||
63 | -// return getDelegate().getContentType(); | ||
64 | -// } | ||
65 | -// | ||
66 | -// @Override | ||
67 | -// public ServletInputStream getInputStream() throws IOException { | ||
68 | -// return getDelegate().getInputStream(); | ||
69 | -// } | ||
70 | -// | ||
71 | -// @Override | ||
72 | -// public String getParameter(String name) { | ||
73 | -// return getDelegate().getParameter(name); | ||
74 | -// } | ||
75 | -// | ||
76 | -// @Override | ||
77 | -// public Enumeration<?> getParameterNames() { | ||
78 | -// return getDelegate().getParameterNames(); | ||
79 | -// } | ||
80 | -// | ||
81 | -// @Override | ||
82 | -// public String[] getParameterValues(String name) { | ||
83 | -// return getDelegate().getParameterValues(name); | ||
84 | -// } | ||
85 | -// | ||
86 | -// @Override | ||
87 | -// public Map<?, ?> getParameterMap() { | ||
88 | -// return getDelegate().getParameterMap(); | ||
89 | -// } | ||
90 | -// | ||
91 | -// @Override | ||
92 | -// public String getProtocol() { | ||
93 | -// return getDelegate().getProtocol(); | ||
94 | -// } | ||
95 | -// | ||
96 | -// @Override | ||
97 | -// public String getScheme() { | ||
98 | -// return getDelegate().getScheme(); | ||
99 | -// } | ||
100 | -// | ||
101 | -// @Override | ||
102 | -// public String getServerName() { | ||
103 | -// return getDelegate().getServerName(); | ||
104 | -// } | ||
105 | -// | ||
106 | -// @Override | ||
107 | -// public int getServerPort() { | ||
108 | -// return getDelegate().getServerPort(); | ||
109 | -// } | ||
110 | -// | ||
111 | -// @Override | ||
112 | -// public BufferedReader getReader() throws IOException { | ||
113 | -// return getDelegate().getReader(); | ||
114 | -// } | ||
115 | -// | ||
116 | -// @Override | ||
117 | -// public String getRemoteAddr() { | ||
118 | -// return getDelegate().getRemoteAddr(); | ||
119 | -// } | ||
120 | -// | ||
121 | -// @Override | ||
122 | -// public String getRemoteHost() { | ||
123 | -// return getDelegate().getRemoteHost(); | ||
124 | -// } | ||
125 | -// | ||
126 | -// @Override | ||
127 | -// public void setAttribute(String name, Object o) { | ||
128 | -// getDelegate().setAttribute(name, o); | ||
129 | -// } | ||
130 | -// | ||
131 | -// @Override | ||
132 | -// public void removeAttribute(String name) { | ||
133 | -// getDelegate().removeAttribute(name); | ||
134 | -// } | ||
135 | -// | ||
136 | -// @Override | ||
137 | -// public Locale getLocale() { | ||
138 | -// return getDelegate().getLocale(); | ||
139 | -// } | ||
140 | -// | ||
141 | -// @Override | ||
142 | -// public Enumeration<?> getLocales() { | ||
143 | -// return getDelegate().getLocales(); | ||
144 | -// } | ||
145 | -// | ||
146 | -// @Override | ||
147 | -// public boolean isSecure() { | ||
148 | -// return getDelegate().isSecure(); | ||
149 | -// } | ||
150 | -// | ||
151 | -// @Override | ||
152 | -// public RequestDispatcher getRequestDispatcher(String path) { | ||
153 | -// return getDelegate().getRequestDispatcher(path); | ||
154 | -// } | ||
155 | -// | ||
156 | -// @Override | ||
157 | -// @Deprecated | ||
158 | -// public String getRealPath(String path) { | ||
159 | -// return getDelegate().getRealPath(path); | ||
160 | -// } | ||
161 | -// | ||
162 | -// @Override | ||
163 | -// public int getRemotePort() { | ||
164 | -// return getDelegate().getRemotePort(); | ||
165 | -// } | ||
166 | -// | ||
167 | -// @Override | ||
168 | -// public String getLocalName() { | ||
169 | -// return getDelegate().getLocalName(); | ||
170 | -// } | ||
171 | -// | ||
172 | -// @Override | ||
173 | -// public String getLocalAddr() { | ||
174 | -// return getDelegate().getLocalAddr(); | ||
175 | -// } | ||
176 | -// | ||
177 | -// @Override | ||
178 | -// public int getLocalPort() { | ||
179 | -// return getDelegate().getLocalPort(); | ||
180 | -// } | ||
181 | -// | ||
182 | -// @Override | ||
183 | -// public String getAuthType() { | ||
184 | -// return getDelegate().getAuthType(); | ||
185 | -// } | ||
186 | -// | ||
187 | -// @Override | ||
188 | -// public Cookie[] getCookies() { | ||
189 | -// return getDelegate().getCookies(); | ||
190 | -// } | ||
191 | -// | ||
192 | -// @Override | ||
193 | -// public long getDateHeader(String name) { | ||
194 | -// return getDelegate().getDateHeader(name); | ||
195 | -// } | ||
196 | -// | ||
197 | -// @Override | ||
198 | -// public String getHeader(String name) { | ||
199 | -// return getDelegate().getHeader(name); | ||
200 | -// } | ||
201 | -// | ||
202 | -// @Override | ||
203 | -// public Enumeration<?> getHeaders(String name) { | ||
204 | -// return getDelegate().getHeaders(name); | ||
205 | -// } | ||
206 | -// | ||
207 | -// @Override | ||
208 | -// public Enumeration<?> getHeaderNames() { | ||
209 | -// return getDelegate().getHeaderNames(); | ||
210 | -// } | ||
211 | -// | ||
212 | -// @Override | ||
213 | -// public int getIntHeader(String name) { | ||
214 | -// return getDelegate().getIntHeader(name); | ||
215 | -// } | ||
216 | -// | ||
217 | -// @Override | ||
218 | -// public String getMethod() { | ||
219 | -// return getDelegate().getMethod(); | ||
220 | -// } | ||
221 | -// | ||
222 | -// @Override | ||
223 | -// public String getPathInfo() { | ||
224 | -// return getDelegate().getPathInfo(); | ||
225 | -// } | ||
226 | -// | ||
227 | -// @Override | ||
228 | -// public String getPathTranslated() { | ||
229 | -// return getDelegate().getPathTranslated(); | ||
230 | -// } | ||
231 | -// | ||
232 | -// @Override | ||
233 | -// public String getContextPath() { | ||
234 | -// return getDelegate().getContextPath(); | ||
235 | -// } | ||
236 | -// | ||
237 | -// @Override | ||
238 | -// public String getQueryString() { | ||
239 | -// return getDelegate().getQueryString(); | ||
240 | -// } | ||
241 | -// | ||
242 | -// @Override | ||
243 | -// public String getRemoteUser() { | ||
244 | -// return getDelegate().getRemoteUser(); | ||
245 | -// } | ||
246 | -// | ||
247 | -// @Override | ||
248 | -// public boolean isUserInRole(String role) { | ||
249 | -// return getDelegate().isUserInRole(role); | ||
250 | -// } | ||
251 | -// | ||
252 | -// @Override | ||
253 | -// public Principal getUserPrincipal() { | ||
254 | -// return getDelegate().getUserPrincipal(); | ||
255 | -// } | ||
256 | -// | ||
257 | -// @Override | ||
258 | -// public String getRequestedSessionId() { | ||
259 | -// return getDelegate().getRequestedSessionId(); | ||
260 | -// } | ||
261 | -// | ||
262 | -// @Override | ||
263 | -// public String getRequestURI() { | ||
264 | -// return getDelegate().getRequestURI(); | ||
265 | -// } | ||
266 | -// | ||
267 | -// @Override | ||
268 | -// public StringBuffer getRequestURL() { | ||
269 | -// return getDelegate().getRequestURL(); | ||
270 | -// } | ||
271 | -// | ||
272 | -// @Override | ||
273 | -// public String getServletPath() { | ||
274 | -// return getDelegate().getServletPath(); | ||
275 | -// } | ||
276 | -// | ||
277 | -// @Override | ||
278 | -// public HttpSession getSession(boolean create) { | ||
279 | -// return getDelegate().getSession(create); | ||
280 | -// } | ||
281 | -// | ||
282 | -// @Override | ||
283 | -// public HttpSession getSession() { | ||
284 | -// return getDelegate().getSession(); | ||
285 | -// } | ||
286 | -// | ||
287 | -// @Override | ||
288 | -// public boolean isRequestedSessionIdValid() { | ||
289 | -// return getDelegate().isRequestedSessionIdValid(); | ||
290 | -// } | ||
291 | -// | ||
292 | -// @Override | ||
293 | -// public boolean isRequestedSessionIdFromCookie() { | ||
294 | -// return getDelegate().isRequestedSessionIdFromCookie(); | ||
295 | -// } | ||
296 | -// | ||
297 | -// @Override | ||
298 | -// public boolean isRequestedSessionIdFromURL() { | ||
299 | -// return getDelegate().isRequestedSessionIdFromURL(); | ||
300 | -// } | ||
301 | -// | ||
302 | -// @Override | ||
303 | -// @Deprecated | ||
304 | -// public boolean isRequestedSessionIdFromUrl() { | ||
305 | -// return getDelegate().isRequestedSessionIdFromUrl(); | ||
306 | -// } | ||
307 | -//} |
impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/HttpServletResponseProxy.java
@@ -1,192 +0,0 @@ | @@ -1,192 +0,0 @@ | ||
1 | -//package br.gov.frameworkdemoiselle.internal.proxy; | ||
2 | -// | ||
3 | -//import java.io.IOException; | ||
4 | -//import java.io.PrintWriter; | ||
5 | -//import java.io.Serializable; | ||
6 | -//import java.util.Locale; | ||
7 | -// | ||
8 | -//import javax.enterprise.context.RequestScoped; | ||
9 | -//import javax.enterprise.inject.Default; | ||
10 | -//import javax.servlet.ServletOutputStream; | ||
11 | -//import javax.servlet.http.Cookie; | ||
12 | -//import javax.servlet.http.HttpServletResponse; | ||
13 | -// | ||
14 | -//@Default | ||
15 | -//@RequestScoped | ||
16 | -//public class HttpServletResponseProxy implements HttpServletResponse, Serializable { | ||
17 | -// | ||
18 | -// private static final long serialVersionUID = 1L; | ||
19 | -// | ||
20 | -// private transient HttpServletResponse delegate; | ||
21 | -// | ||
22 | -// public HttpServletResponseProxy(HttpServletResponse delegate) { | ||
23 | -// this.delegate = delegate; | ||
24 | -// } | ||
25 | -// | ||
26 | -// private HttpServletResponse getDelegate() { | ||
27 | -// return delegate; | ||
28 | -// } | ||
29 | -// | ||
30 | -// @Override | ||
31 | -// public String getCharacterEncoding() { | ||
32 | -// return getDelegate().getCharacterEncoding(); | ||
33 | -// } | ||
34 | -// | ||
35 | -// @Override | ||
36 | -// public String getContentType() { | ||
37 | -// return getDelegate().getContentType(); | ||
38 | -// } | ||
39 | -// | ||
40 | -// @Override | ||
41 | -// public ServletOutputStream getOutputStream() throws IOException { | ||
42 | -// return getDelegate().getOutputStream(); | ||
43 | -// } | ||
44 | -// | ||
45 | -// @Override | ||
46 | -// public PrintWriter getWriter() throws IOException { | ||
47 | -// return getDelegate().getWriter(); | ||
48 | -// } | ||
49 | -// | ||
50 | -// @Override | ||
51 | -// public void setCharacterEncoding(String charset) { | ||
52 | -// getDelegate().setCharacterEncoding(charset); | ||
53 | -// } | ||
54 | -// | ||
55 | -// @Override | ||
56 | -// public void setContentLength(int len) { | ||
57 | -// getDelegate().setContentLength(len); | ||
58 | -// } | ||
59 | -// | ||
60 | -// @Override | ||
61 | -// public void setContentType(String type) { | ||
62 | -// getDelegate().setContentType(type); | ||
63 | -// } | ||
64 | -// | ||
65 | -// @Override | ||
66 | -// public void setBufferSize(int size) { | ||
67 | -// getDelegate().setBufferSize(size); | ||
68 | -// } | ||
69 | -// | ||
70 | -// @Override | ||
71 | -// public int getBufferSize() { | ||
72 | -// return getDelegate().getBufferSize(); | ||
73 | -// } | ||
74 | -// | ||
75 | -// @Override | ||
76 | -// public void flushBuffer() throws IOException { | ||
77 | -// getDelegate().flushBuffer(); | ||
78 | -// } | ||
79 | -// | ||
80 | -// @Override | ||
81 | -// public void resetBuffer() { | ||
82 | -// getDelegate().resetBuffer(); | ||
83 | -// } | ||
84 | -// | ||
85 | -// @Override | ||
86 | -// public boolean isCommitted() { | ||
87 | -// return getDelegate().isCommitted(); | ||
88 | -// } | ||
89 | -// | ||
90 | -// @Override | ||
91 | -// public void reset() { | ||
92 | -// getDelegate().reset(); | ||
93 | -// } | ||
94 | -// | ||
95 | -// @Override | ||
96 | -// public void setLocale(Locale loc) { | ||
97 | -// getDelegate().setLocale(loc); | ||
98 | -// } | ||
99 | -// | ||
100 | -// @Override | ||
101 | -// public Locale getLocale() { | ||
102 | -// return getDelegate().getLocale(); | ||
103 | -// } | ||
104 | -// | ||
105 | -// @Override | ||
106 | -// public void addCookie(Cookie cookie) { | ||
107 | -// getDelegate().addCookie(cookie); | ||
108 | -// } | ||
109 | -// | ||
110 | -// @Override | ||
111 | -// public boolean containsHeader(String name) { | ||
112 | -// return getDelegate().containsHeader(name); | ||
113 | -// } | ||
114 | -// | ||
115 | -// @Override | ||
116 | -// public String encodeURL(String url) { | ||
117 | -// return getDelegate().encodeURL(url); | ||
118 | -// } | ||
119 | -// | ||
120 | -// @Override | ||
121 | -// public String encodeRedirectURL(String url) { | ||
122 | -// return getDelegate().encodeRedirectURL(url); | ||
123 | -// } | ||
124 | -// | ||
125 | -// @Override | ||
126 | -// @Deprecated | ||
127 | -// public String encodeUrl(String url) { | ||
128 | -// return getDelegate().encodeUrl(url); | ||
129 | -// } | ||
130 | -// | ||
131 | -// @Override | ||
132 | -// @Deprecated | ||
133 | -// public String encodeRedirectUrl(String url) { | ||
134 | -// return getDelegate().encodeRedirectUrl(url); | ||
135 | -// } | ||
136 | -// | ||
137 | -// @Override | ||
138 | -// public void sendError(int sc, String msg) throws IOException { | ||
139 | -// getDelegate().sendError(sc, msg); | ||
140 | -// } | ||
141 | -// | ||
142 | -// @Override | ||
143 | -// public void sendError(int sc) throws IOException { | ||
144 | -// getDelegate().sendError(sc); | ||
145 | -// } | ||
146 | -// | ||
147 | -// @Override | ||
148 | -// public void sendRedirect(String location) throws IOException { | ||
149 | -// getDelegate().sendRedirect(location); | ||
150 | -// } | ||
151 | -// | ||
152 | -// @Override | ||
153 | -// public void setDateHeader(String name, long date) { | ||
154 | -// getDelegate().setDateHeader(name, date); | ||
155 | -// } | ||
156 | -// | ||
157 | -// @Override | ||
158 | -// public void addDateHeader(String name, long date) { | ||
159 | -// getDelegate().addDateHeader(name, date); | ||
160 | -// } | ||
161 | -// | ||
162 | -// @Override | ||
163 | -// public void setHeader(String name, String value) { | ||
164 | -// getDelegate().setHeader(name, value); | ||
165 | -// } | ||
166 | -// | ||
167 | -// @Override | ||
168 | -// public void addHeader(String name, String value) { | ||
169 | -// getDelegate().addHeader(name, value); | ||
170 | -// } | ||
171 | -// | ||
172 | -// @Override | ||
173 | -// public void setIntHeader(String name, int value) { | ||
174 | -// getDelegate().setIntHeader(name, value); | ||
175 | -// } | ||
176 | -// | ||
177 | -// @Override | ||
178 | -// public void addIntHeader(String name, int value) { | ||
179 | -// getDelegate().addIntHeader(name, value); | ||
180 | -// } | ||
181 | -// | ||
182 | -// @Override | ||
183 | -// public void setStatus(int sc) { | ||
184 | -// getDelegate().setStatus(sc); | ||
185 | -// } | ||
186 | -// | ||
187 | -// @Override | ||
188 | -// @Deprecated | ||
189 | -// public void setStatus(int sc, String sm) { | ||
190 | -// getDelegate().setStatus(sc, sm); | ||
191 | -// } | ||
192 | -//} |
impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/HttpSessionProxy.java
@@ -1,118 +0,0 @@ | @@ -1,118 +0,0 @@ | ||
1 | -//package br.gov.frameworkdemoiselle.internal.proxy; | ||
2 | -// | ||
3 | -//import java.io.Serializable; | ||
4 | -//import java.util.Enumeration; | ||
5 | -// | ||
6 | -//import javax.enterprise.context.SessionScoped; | ||
7 | -//import javax.enterprise.inject.Default; | ||
8 | -//import javax.servlet.ServletContext; | ||
9 | -//import javax.servlet.http.HttpSession; | ||
10 | -//import javax.servlet.http.HttpSessionContext; | ||
11 | -// | ||
12 | -//@Default | ||
13 | -//@SessionScoped | ||
14 | -//@SuppressWarnings("deprecation") | ||
15 | -//public class HttpSessionProxy implements HttpSession, Serializable { | ||
16 | -// | ||
17 | -// private static final long serialVersionUID = 1L; | ||
18 | -// | ||
19 | -// private transient HttpSession delegate; | ||
20 | -// | ||
21 | -// public HttpSessionProxy(HttpSession delegate) { | ||
22 | -// this.delegate = delegate; | ||
23 | -// } | ||
24 | -// | ||
25 | -// private HttpSession getDelegate() { | ||
26 | -// return delegate; | ||
27 | -// } | ||
28 | -// | ||
29 | -// @Override | ||
30 | -// public long getCreationTime() { | ||
31 | -// return getDelegate().getCreationTime(); | ||
32 | -// } | ||
33 | -// | ||
34 | -// @Override | ||
35 | -// public String getId() { | ||
36 | -// return getDelegate().getId(); | ||
37 | -// } | ||
38 | -// | ||
39 | -// @Override | ||
40 | -// public long getLastAccessedTime() { | ||
41 | -// return getDelegate().getLastAccessedTime(); | ||
42 | -// } | ||
43 | -// | ||
44 | -// @Override | ||
45 | -// public ServletContext getServletContext() { | ||
46 | -// return getDelegate().getServletContext(); | ||
47 | -// } | ||
48 | -// | ||
49 | -// @Override | ||
50 | -// public void setMaxInactiveInterval(int interval) { | ||
51 | -// getDelegate().setMaxInactiveInterval(interval); | ||
52 | -// } | ||
53 | -// | ||
54 | -// @Override | ||
55 | -// public int getMaxInactiveInterval() { | ||
56 | -// return getDelegate().getMaxInactiveInterval(); | ||
57 | -// } | ||
58 | -// | ||
59 | -// @Override | ||
60 | -// @Deprecated | ||
61 | -// public HttpSessionContext getSessionContext() { | ||
62 | -// return getDelegate().getSessionContext(); | ||
63 | -// } | ||
64 | -// | ||
65 | -// @Override | ||
66 | -// public Object getAttribute(String name) { | ||
67 | -// return getDelegate().getAttribute(name); | ||
68 | -// } | ||
69 | -// | ||
70 | -// @Override | ||
71 | -// @Deprecated | ||
72 | -// public Object getValue(String name) { | ||
73 | -// return getDelegate().getValue(name); | ||
74 | -// } | ||
75 | -// | ||
76 | -// @Override | ||
77 | -// public Enumeration<?> getAttributeNames() { | ||
78 | -// return getDelegate().getAttributeNames(); | ||
79 | -// } | ||
80 | -// | ||
81 | -// @Override | ||
82 | -// @Deprecated | ||
83 | -// public String[] getValueNames() { | ||
84 | -// return getDelegate().getValueNames(); | ||
85 | -// } | ||
86 | -// | ||
87 | -// @Override | ||
88 | -// public void setAttribute(String name, Object value) { | ||
89 | -// getDelegate().setAttribute(name, value); | ||
90 | -// } | ||
91 | -// | ||
92 | -// @Override | ||
93 | -// @Deprecated | ||
94 | -// public void putValue(String name, Object value) { | ||
95 | -// getDelegate().putValue(name, value); | ||
96 | -// } | ||
97 | -// | ||
98 | -// @Override | ||
99 | -// public void removeAttribute(String name) { | ||
100 | -// getDelegate().removeAttribute(name); | ||
101 | -// } | ||
102 | -// | ||
103 | -// @Override | ||
104 | -// @Deprecated | ||
105 | -// public void removeValue(String name) { | ||
106 | -// getDelegate().removeValue(name); | ||
107 | -// } | ||
108 | -// | ||
109 | -// @Override | ||
110 | -// public void invalidate() { | ||
111 | -// getDelegate().invalidate(); | ||
112 | -// } | ||
113 | -// | ||
114 | -// @Override | ||
115 | -// public boolean isNew() { | ||
116 | -// return getDelegate().isNew(); | ||
117 | -// } | ||
118 | -//} |
impl/extension/servlet/src/main/java/br/gov/frameworkdemoiselle/util/ServletContextListener.java
@@ -1,44 +0,0 @@ | @@ -1,44 +0,0 @@ | ||
1 | -/* | ||
2 | - * Demoiselle Framework | ||
3 | - * Copyright (C) 2010 SERPRO | ||
4 | - * ---------------------------------------------------------------------------- | ||
5 | - * This file is part of Demoiselle Framework. | ||
6 | - * | ||
7 | - * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | - * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | - * as published by the Free Software Foundation. | ||
10 | - * | ||
11 | - * This program is distributed in the hope that it will be useful, | ||
12 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | - * GNU General Public License for more details. | ||
15 | - * | ||
16 | - * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | - * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | - * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | - * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | - * ---------------------------------------------------------------------------- | ||
21 | - * Este arquivo é parte do Framework Demoiselle. | ||
22 | - * | ||
23 | - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | - * do Software Livre (FSF). | ||
26 | - * | ||
27 | - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | - * para maiores detalhes. | ||
31 | - * | ||
32 | - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | - * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | - */ | ||
37 | -package br.gov.frameworkdemoiselle.util; | ||
38 | - | ||
39 | -/** | ||
40 | - * @deprecated Use br.gov.frameworkdemoiselle.util.ServletListener instead. | ||
41 | - */ | ||
42 | -@Deprecated | ||
43 | -public class ServletContextListener extends ServletListener { | ||
44 | -} |
impl/extension/servlet/src/test/java/br/gov/frameworkdemoiselle/internal/producer/HttpServletRequestProducerTest.java
0 → 100644
@@ -0,0 +1,48 @@ | @@ -0,0 +1,48 @@ | ||
1 | +package br.gov.frameworkdemoiselle.internal.producer; | ||
2 | + | ||
3 | +import static org.easymock.EasyMock.replay; | ||
4 | +import static org.powermock.api.easymock.PowerMock.createMock; | ||
5 | +import static org.powermock.api.easymock.PowerMock.verifyAll; | ||
6 | + | ||
7 | +import javax.servlet.http.HttpServletRequest; | ||
8 | +import javax.servlet.http.HttpServletResponse; | ||
9 | + | ||
10 | +import junit.framework.Assert; | ||
11 | + | ||
12 | +import org.junit.Test; | ||
13 | +import org.powermock.reflect.Whitebox; | ||
14 | + | ||
15 | + | ||
16 | +public class HttpServletRequestProducerTest { | ||
17 | + | ||
18 | + private HttpServletRequestProducer httpServletRequestProducer; | ||
19 | + | ||
20 | + private HttpServletRequest request; | ||
21 | + | ||
22 | + @Test | ||
23 | + public void testCreate() { | ||
24 | + request = createMock(HttpServletRequest.class); | ||
25 | + replay(request); | ||
26 | + | ||
27 | + httpServletRequestProducer = new HttpServletRequestProducer(); | ||
28 | + Whitebox.setInternalState(httpServletRequestProducer, "request", request); | ||
29 | + | ||
30 | + Assert.assertEquals(httpServletRequestProducer.create(), request); | ||
31 | + | ||
32 | + verifyAll(); | ||
33 | + } | ||
34 | + | ||
35 | + @Test | ||
36 | + public void testSetDelegate() { | ||
37 | + request = createMock(HttpServletRequest.class); | ||
38 | + replay(request); | ||
39 | + | ||
40 | + httpServletRequestProducer = new HttpServletRequestProducer(); | ||
41 | + | ||
42 | + httpServletRequestProducer.setDelegate(request); | ||
43 | + Assert.assertEquals(Whitebox.getInternalState(httpServletRequestProducer, "request"),request); | ||
44 | + | ||
45 | + verifyAll(); | ||
46 | + } | ||
47 | + | ||
48 | +} |
impl/extension/servlet/src/test/java/br/gov/frameworkdemoiselle/internal/producer/HttpServletResponseProducerTest.java
0 → 100644
@@ -0,0 +1,48 @@ | @@ -0,0 +1,48 @@ | ||
1 | +package br.gov.frameworkdemoiselle.internal.producer; | ||
2 | + | ||
3 | +import static org.easymock.EasyMock.replay; | ||
4 | +import static org.powermock.api.easymock.PowerMock.createMock; | ||
5 | +import static org.powermock.api.easymock.PowerMock.verifyAll; | ||
6 | + | ||
7 | +import javax.servlet.http.HttpServletRequest; | ||
8 | +import javax.servlet.http.HttpServletResponse; | ||
9 | + | ||
10 | +import junit.framework.Assert; | ||
11 | + | ||
12 | +import org.junit.Test; | ||
13 | +import org.powermock.reflect.Whitebox; | ||
14 | + | ||
15 | + | ||
16 | +public class HttpServletResponseProducerTest { | ||
17 | + | ||
18 | + private HttpServletResponseProducer httpServletResponseProducer; | ||
19 | + | ||
20 | + private HttpServletResponse response; | ||
21 | + | ||
22 | + @Test | ||
23 | + public void testCreate() { | ||
24 | + response = createMock(HttpServletResponse.class); | ||
25 | + replay(response); | ||
26 | + | ||
27 | + httpServletResponseProducer = new HttpServletResponseProducer(); | ||
28 | + Whitebox.setInternalState(httpServletResponseProducer, "response", response); | ||
29 | + | ||
30 | + Assert.assertEquals(httpServletResponseProducer.create(), response); | ||
31 | + | ||
32 | + verifyAll(); | ||
33 | + } | ||
34 | + | ||
35 | + @Test | ||
36 | + public void testSetDelegate() { | ||
37 | + response = createMock(HttpServletResponse.class); | ||
38 | + replay(response); | ||
39 | + | ||
40 | + httpServletResponseProducer = new HttpServletResponseProducer(); | ||
41 | + | ||
42 | + httpServletResponseProducer.setDelegate(response); | ||
43 | + Assert.assertEquals(Whitebox.getInternalState(httpServletResponseProducer, "response"), response); | ||
44 | + | ||
45 | + verifyAll(); | ||
46 | + } | ||
47 | + | ||
48 | +} |
impl/extension/servlet/src/test/java/br/gov/frameworkdemoiselle/internal/producer/HttpSessionProducerTest.java
0 → 100644
@@ -0,0 +1,43 @@ | @@ -0,0 +1,43 @@ | ||
1 | +package br.gov.frameworkdemoiselle.internal.producer; | ||
2 | + | ||
3 | +import static org.easymock.EasyMock.createMock; | ||
4 | +import static org.easymock.EasyMock.replay; | ||
5 | +import static org.powermock.api.easymock.PowerMock.verifyAll; | ||
6 | + | ||
7 | +import javax.servlet.http.HttpServletRequest; | ||
8 | +import javax.servlet.http.HttpSession; | ||
9 | + | ||
10 | +import junit.framework.Assert; | ||
11 | + | ||
12 | +import org.easymock.EasyMock; | ||
13 | +import org.junit.Test; | ||
14 | + | ||
15 | +public class HttpSessionProducerTest { | ||
16 | + | ||
17 | + private HttpSessionProducer httpSessionProducer; | ||
18 | + | ||
19 | + private HttpServletRequest request; | ||
20 | + | ||
21 | + @Test | ||
22 | + public void testCreateWithRequestNull() { | ||
23 | + httpSessionProducer = new HttpSessionProducer(); | ||
24 | + Assert.assertNull(httpSessionProducer.create(null)); | ||
25 | + | ||
26 | + verifyAll(); | ||
27 | + } | ||
28 | + | ||
29 | + @Test | ||
30 | + public void testCreateWithRequest() { | ||
31 | + request = createMock(HttpServletRequest.class); | ||
32 | + HttpSession session = createMock(HttpSession.class); | ||
33 | + EasyMock.expect(request.getSession()).andReturn(session); | ||
34 | + replay(request, session); | ||
35 | + | ||
36 | + httpSessionProducer = new HttpSessionProducer(); | ||
37 | + Assert.assertNotNull(httpSessionProducer.create(request)); | ||
38 | + | ||
39 | + verifyAll(); | ||
40 | + | ||
41 | + } | ||
42 | + | ||
43 | +} |
impl/extension/servlet/src/test/java/br/gov/frameworkdemoiselle/internal/producer/ServletLocaleProducerTest.java
0 → 100644
@@ -0,0 +1,48 @@ | @@ -0,0 +1,48 @@ | ||
1 | +package br.gov.frameworkdemoiselle.internal.producer; | ||
2 | + | ||
3 | +import static org.easymock.EasyMock.createMock; | ||
4 | +import static org.easymock.EasyMock.expect; | ||
5 | +import static org.powermock.api.easymock.PowerMock.mockStatic; | ||
6 | +import static org.powermock.api.easymock.PowerMock.replay; | ||
7 | +import static org.powermock.api.easymock.PowerMock.verifyAll; | ||
8 | + | ||
9 | +import javax.servlet.http.HttpServletRequest; | ||
10 | + | ||
11 | +import org.junit.Test; | ||
12 | +import org.junit.runner.RunWith; | ||
13 | +import org.powermock.core.classloader.annotations.PrepareForTest; | ||
14 | +import org.powermock.modules.junit4.PowerMockRunner; | ||
15 | + | ||
16 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
17 | + | ||
18 | +@RunWith(PowerMockRunner.class) | ||
19 | +@PrepareForTest(Beans.class) | ||
20 | +public class ServletLocaleProducerTest { | ||
21 | + | ||
22 | + private ServletLocaleProducer servletLocaleProducer; | ||
23 | + | ||
24 | + private HttpServletRequest request; | ||
25 | + | ||
26 | + @Test | ||
27 | + public void testCreate() { | ||
28 | + request = createMock(HttpServletRequest.class); | ||
29 | + | ||
30 | + mockStatic(Beans.class); | ||
31 | + expect(Beans.getReference(HttpServletRequest.class)).andReturn(request); | ||
32 | + replay(Beans.class); | ||
33 | + | ||
34 | + servletLocaleProducer = new ServletLocaleProducer(); | ||
35 | + servletLocaleProducer.create(); | ||
36 | + | ||
37 | + verifyAll(); | ||
38 | + } | ||
39 | + | ||
40 | + @Test | ||
41 | + public void testCreate2() { | ||
42 | + servletLocaleProducer = new ServletLocaleProducer(); | ||
43 | + servletLocaleProducer.create(); | ||
44 | + | ||
45 | + verifyAll(); | ||
46 | + } | ||
47 | + | ||
48 | +} |
impl/extension/servlet/src/test/java/br/gov/frameworkdemoiselle/util/ServletListenerTest.java
0 → 100644
@@ -0,0 +1,64 @@ | @@ -0,0 +1,64 @@ | ||
1 | +package br.gov.frameworkdemoiselle.util; | ||
2 | + | ||
3 | +import static org.easymock.EasyMock.createMock; | ||
4 | +import static org.easymock.EasyMock.expect; | ||
5 | +import static org.powermock.api.easymock.PowerMock.mockStatic; | ||
6 | +import static org.powermock.api.easymock.PowerMock.replayAll; | ||
7 | +import static org.powermock.api.easymock.PowerMock.verifyAll; | ||
8 | + | ||
9 | +import javax.enterprise.inject.spi.BeanManager; | ||
10 | +import javax.servlet.ServletContextEvent; | ||
11 | + | ||
12 | +import org.easymock.EasyMock; | ||
13 | +import org.junit.Test; | ||
14 | +import org.junit.runner.RunWith; | ||
15 | +import org.powermock.api.easymock.PowerMock; | ||
16 | +import org.powermock.core.classloader.annotations.PrepareForTest; | ||
17 | +import org.powermock.modules.junit4.PowerMockRunner; | ||
18 | + | ||
19 | +import br.gov.frameworkdemoiselle.internal.bootstrap.ShutdownBootstrap; | ||
20 | +import br.gov.frameworkdemoiselle.lifecycle.AfterStartupProccess; | ||
21 | + | ||
22 | +@RunWith(PowerMockRunner.class) | ||
23 | +@PrepareForTest(Beans.class) | ||
24 | +public class ServletListenerTest { | ||
25 | + | ||
26 | + private ServletListener listener; | ||
27 | + | ||
28 | + @Test | ||
29 | + public void testContextInitialized() { | ||
30 | + ServletContextEvent event = createMock(ServletContextEvent.class); | ||
31 | + BeanManager beanManager = PowerMock.createMock(BeanManager.class); | ||
32 | + | ||
33 | + mockStatic(Beans.class); | ||
34 | + expect(Beans.getBeanManager()).andReturn(beanManager); | ||
35 | + beanManager.fireEvent(EasyMock.anyObject(AfterStartupProccess.class)); | ||
36 | + PowerMock.expectLastCall().times(1); | ||
37 | + | ||
38 | + replayAll(); | ||
39 | + | ||
40 | + listener = new ServletListener(); | ||
41 | + listener.contextInitialized(event); | ||
42 | + | ||
43 | + verifyAll(); | ||
44 | + } | ||
45 | + | ||
46 | + @Test | ||
47 | + public void testContextDestroyed() { | ||
48 | + ServletContextEvent event = createMock(ServletContextEvent.class); | ||
49 | + BeanManager beanManager = PowerMock.createMock(BeanManager.class); | ||
50 | + | ||
51 | + mockStatic(Beans.class); | ||
52 | + expect(Beans.getBeanManager()).andReturn(beanManager); | ||
53 | + beanManager.fireEvent(EasyMock.anyObject(ShutdownBootstrap.class)); | ||
54 | + PowerMock.expectLastCall().times(1); | ||
55 | + | ||
56 | + replayAll(); | ||
57 | + | ||
58 | + listener = new ServletListener(); | ||
59 | + listener.contextDestroyed(event); | ||
60 | + | ||
61 | + verifyAll(); | ||
62 | + } | ||
63 | + | ||
64 | +} |
parent/bom/pom.xml
@@ -338,7 +338,7 @@ | @@ -338,7 +338,7 @@ | ||
338 | <arquillian.junit.version>1.0.0.Alpha4.SP2</arquillian.junit.version> | 338 | <arquillian.junit.version>1.0.0.Alpha4.SP2</arquillian.junit.version> |
339 | <arquillian.weld.embdedded.version>1.0.0.Alpha2</arquillian.weld.embdedded.version> | 339 | <arquillian.weld.embdedded.version>1.0.0.Alpha2</arquillian.weld.embdedded.version> |
340 | <powermock.version>1.4.6</powermock.version> | 340 | <powermock.version>1.4.6</powermock.version> |
341 | - <primefaces.version>3.2</primefaces.version> | 341 | + <primefaces.version>3.4</primefaces.version> |
342 | <slf4j.version>1.6.1</slf4j.version> | 342 | <slf4j.version>1.6.1</slf4j.version> |
343 | <weld.version>1.1.8.Final</weld.version> | 343 | <weld.version>1.1.8.Final</weld.version> |
344 | <commons.configuration.version>1.5</commons.configuration.version> | 344 | <commons.configuration.version>1.5</commons.configuration.version> |