Commit 08439823f6b03131d271a6180b2d1bbe938e7921
1 parent
d1c1de02
Exists in
master
Teste unitário: HttpSessionProxyTest
Showing
1 changed file
with
125 additions
and
0 deletions
Show diff stats
impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/internal/proxy/HttpSessionProxyTest.java
0 → 100644
... | ... | @@ -0,0 +1,125 @@ |
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 | + | |
38 | +package br.gov.frameworkdemoiselle.internal.proxy; | |
39 | + | |
40 | +import static org.easymock.EasyMock.expect; | |
41 | +import static org.easymock.EasyMock.replay; | |
42 | +import static org.easymock.EasyMock.verify; | |
43 | +import static org.junit.Assert.assertEquals; | |
44 | + | |
45 | +import java.util.Enumeration; | |
46 | + | |
47 | +import javax.servlet.ServletContext; | |
48 | +import javax.servlet.http.HttpSession; | |
49 | +import javax.servlet.http.HttpSessionContext; | |
50 | + | |
51 | +import org.junit.Before; | |
52 | +import org.junit.Test; | |
53 | +import org.junit.runner.RunWith; | |
54 | +import org.powermock.api.easymock.PowerMock; | |
55 | +import org.powermock.modules.junit4.PowerMockRunner; | |
56 | + | |
57 | +@SuppressWarnings("deprecation") | |
58 | +@RunWith(PowerMockRunner.class) | |
59 | +public class HttpSessionProxyTest { | |
60 | + | |
61 | + private HttpSessionProxy proxy; | |
62 | + | |
63 | + private ServletContext servletContext; | |
64 | + | |
65 | + private Enumeration<?> enumeration; | |
66 | + | |
67 | + private HttpSession session; | |
68 | + | |
69 | + private HttpSessionContext sessionContext; | |
70 | + | |
71 | + @Before | |
72 | + public void before() { | |
73 | + session = PowerMock.createMock(HttpSession.class); | |
74 | + servletContext = PowerMock.createMock(ServletContext.class); | |
75 | + enumeration = PowerMock.createMock(Enumeration.class); | |
76 | + sessionContext = PowerMock.createMock(HttpSessionContext.class); | |
77 | + | |
78 | + expect(session.getValueNames()).andReturn(new String[] { "abcdef" }); | |
79 | + expect(session.getValue("value")).andReturn("value"); | |
80 | + expect(session.getSessionContext()).andReturn(sessionContext); | |
81 | + expect(session.getCreationTime()).andReturn(10L); | |
82 | + expect(session.getId()).andReturn("ID"); | |
83 | + expect(session.getLastAccessedTime()).andReturn(1L); | |
84 | + expect(session.getServletContext()).andReturn(servletContext); | |
85 | + expect(session.getMaxInactiveInterval()).andReturn(2); | |
86 | + expect(session.getAttribute("attribute")).andReturn("attribute-1"); | |
87 | + expect(session.getAttributeNames()).andReturn(enumeration); | |
88 | + expect(session.isNew()).andReturn(true); | |
89 | + | |
90 | + session.removeValue("removeValue"); | |
91 | + session.putValue("put", "it"); | |
92 | + session.invalidate(); | |
93 | + session.removeAttribute("remove"); | |
94 | + session.setAttribute("name", "object"); | |
95 | + session.setMaxInactiveInterval(1); | |
96 | + | |
97 | + replay(session); | |
98 | + | |
99 | + proxy = new HttpSessionProxy(session); | |
100 | + } | |
101 | + | |
102 | + @Test | |
103 | + public void testDelegation() { | |
104 | + assertEquals(sessionContext, proxy.getSessionContext()); | |
105 | + assertEquals("value", proxy.getValue("value")); | |
106 | + assertEquals("abcdef", proxy.getValueNames()[0]); | |
107 | + assertEquals(10L, proxy.getCreationTime()); | |
108 | + assertEquals("ID", proxy.getId()); | |
109 | + assertEquals(1L, proxy.getLastAccessedTime()); | |
110 | + assertEquals(servletContext, proxy.getServletContext()); | |
111 | + assertEquals(2, proxy.getMaxInactiveInterval()); | |
112 | + assertEquals("attribute-1", proxy.getAttribute("attribute")); | |
113 | + assertEquals(enumeration, proxy.getAttributeNames()); | |
114 | + assertEquals(true, proxy.isNew()); | |
115 | + | |
116 | + proxy.removeValue("removeValue"); | |
117 | + proxy.putValue("put", "it"); | |
118 | + proxy.invalidate(); | |
119 | + proxy.removeAttribute("remove"); | |
120 | + proxy.setAttribute("name", "object"); | |
121 | + proxy.setMaxInactiveInterval(1); | |
122 | + | |
123 | + verify(session); | |
124 | + } | |
125 | +} | ... | ... |