Commit 4bdaff89bfc63b8f58651e4f470e5d95db0b42c8
1 parent
68eb5604
Exists in
master
Adicionados testes com método anotado com @LoggedIn
Showing
2 changed files
with
84 additions
and
4 deletions
Show diff stats
impl/core/src/test/java/security/interceptor/loggedin/DummyProtectedMethods.java
0 → 100644
... | ... | @@ -0,0 +1,54 @@ |
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 security.interceptor.loggedin; | |
38 | + | |
39 | +import br.gov.frameworkdemoiselle.security.LoggedIn; | |
40 | + | |
41 | +public class DummyProtectedMethods { | |
42 | + | |
43 | + private String dummyAttrib = "Default"; | |
44 | + | |
45 | + public String getDummyAttrib() { | |
46 | + return dummyAttrib; | |
47 | + } | |
48 | + | |
49 | + @LoggedIn | |
50 | + public void setDummyAttrib(String dummyAttrib) { | |
51 | + this.dummyAttrib = dummyAttrib; | |
52 | + } | |
53 | + | |
54 | +} | ... | ... |
impl/core/src/test/java/security/interceptor/loggedin/LoggedInInterceptorTest.java
... | ... | @@ -63,22 +63,26 @@ public class LoggedInInterceptorTest { |
63 | 63 | private DummyProtectedClass protectedClass; |
64 | 64 | |
65 | 65 | @Inject |
66 | + private DummyProtectedMethods protectedMethods; | |
67 | + | |
68 | + @Inject | |
66 | 69 | private SecurityContext context; |
67 | 70 | |
68 | 71 | @Deployment |
69 | 72 | public static JavaArchive createDeployment() { |
70 | 73 | JavaArchive deployment = Tests.createDeployment(); |
71 | 74 | deployment.addClass(DummyProtectedClass.class); |
75 | + deployment.addClass(DummyProtectedMethods.class); | |
72 | 76 | deployment.addClass(CustomAuthenticator.class); |
73 | 77 | return deployment; |
74 | 78 | } |
75 | 79 | |
76 | 80 | @Before |
77 | - public void activeContext(){ | |
81 | + public void activeContext() { | |
78 | 82 | SessionContext ctx = Beans.getReference(SessionContext.class); |
79 | 83 | ctx.activate(); |
80 | 84 | } |
81 | - | |
85 | + | |
82 | 86 | @Test |
83 | 87 | public void callProtectedClassAttribNotLogged() { |
84 | 88 | try { |
... | ... | @@ -95,9 +99,31 @@ public class LoggedInInterceptorTest { |
95 | 99 | protectedClass.setDummyAttrib("Test"); |
96 | 100 | assertEquals("Test", protectedClass.getDummyAttrib()); |
97 | 101 | } |
98 | - | |
102 | + | |
103 | + @Test | |
104 | + public void callUnprotectedMethod() { | |
105 | + assertEquals("Default", protectedMethods.getDummyAttrib()); | |
106 | + } | |
107 | + | |
108 | + @Test | |
109 | + public void callProtectedMethodUnLogged() { | |
110 | + try { | |
111 | + protectedMethods.setDummyAttrib("Value Changed"); | |
112 | + } catch (NotLoggedInException cause) { | |
113 | + assertEquals(Beans.getReference(ResourceBundle.class, new NameQualifier("demoiselle-core-bundle")) | |
114 | + .getString("user-not-authenticated"), cause.getMessage()); | |
115 | + } | |
116 | + } | |
117 | + | |
118 | + @Test | |
119 | + public void callProtectedMethodLogged() { | |
120 | + context.login(); | |
121 | + protectedMethods.setDummyAttrib("Value Changed"); | |
122 | + assertEquals("Value Changed", protectedMethods.getDummyAttrib()); | |
123 | + } | |
124 | + | |
99 | 125 | @After |
100 | - public void deactiveContext(){ | |
126 | + public void deactiveContext() { | |
101 | 127 | SessionContext ctx = Beans.getReference(SessionContext.class); |
102 | 128 | ctx.deactivate(); |
103 | 129 | } | ... | ... |