diff --git a/impl/core/src/test/java/security/interceptor/loggedin/DummyProtectedMethods.java b/impl/core/src/test/java/security/interceptor/loggedin/DummyProtectedMethods.java
new file mode 100644
index 0000000..8f6ed12
--- /dev/null
+++ b/impl/core/src/test/java/security/interceptor/loggedin/DummyProtectedMethods.java
@@ -0,0 +1,54 @@
+/*
+ * Demoiselle Framework
+ * Copyright (C) 2010 SERPRO
+ * ----------------------------------------------------------------------------
+ * This file is part of Demoiselle Framework.
+ *
+ * Demoiselle Framework is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License version 3
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License version 3
+ * along with this program; if not, see
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package security.interceptor.loggedin;
+
+import br.gov.frameworkdemoiselle.security.LoggedIn;
+
+public class DummyProtectedMethods {
+
+ private String dummyAttrib = "Default";
+
+ public String getDummyAttrib() {
+ return dummyAttrib;
+ }
+
+ @LoggedIn
+ public void setDummyAttrib(String dummyAttrib) {
+ this.dummyAttrib = dummyAttrib;
+ }
+
+}
diff --git a/impl/core/src/test/java/security/interceptor/loggedin/LoggedInInterceptorTest.java b/impl/core/src/test/java/security/interceptor/loggedin/LoggedInInterceptorTest.java
index 970c628..60ebb7b 100644
--- a/impl/core/src/test/java/security/interceptor/loggedin/LoggedInInterceptorTest.java
+++ b/impl/core/src/test/java/security/interceptor/loggedin/LoggedInInterceptorTest.java
@@ -63,22 +63,26 @@ public class LoggedInInterceptorTest {
private DummyProtectedClass protectedClass;
@Inject
+ private DummyProtectedMethods protectedMethods;
+
+ @Inject
private SecurityContext context;
@Deployment
public static JavaArchive createDeployment() {
JavaArchive deployment = Tests.createDeployment();
deployment.addClass(DummyProtectedClass.class);
+ deployment.addClass(DummyProtectedMethods.class);
deployment.addClass(CustomAuthenticator.class);
return deployment;
}
@Before
- public void activeContext(){
+ public void activeContext() {
SessionContext ctx = Beans.getReference(SessionContext.class);
ctx.activate();
}
-
+
@Test
public void callProtectedClassAttribNotLogged() {
try {
@@ -95,9 +99,31 @@ public class LoggedInInterceptorTest {
protectedClass.setDummyAttrib("Test");
assertEquals("Test", protectedClass.getDummyAttrib());
}
-
+
+ @Test
+ public void callUnprotectedMethod() {
+ assertEquals("Default", protectedMethods.getDummyAttrib());
+ }
+
+ @Test
+ public void callProtectedMethodUnLogged() {
+ try {
+ protectedMethods.setDummyAttrib("Value Changed");
+ } catch (NotLoggedInException cause) {
+ assertEquals(Beans.getReference(ResourceBundle.class, new NameQualifier("demoiselle-core-bundle"))
+ .getString("user-not-authenticated"), cause.getMessage());
+ }
+ }
+
+ @Test
+ public void callProtectedMethodLogged() {
+ context.login();
+ protectedMethods.setDummyAttrib("Value Changed");
+ assertEquals("Value Changed", protectedMethods.getDummyAttrib());
+ }
+
@After
- public void deactiveContext(){
+ public void deactiveContext() {
SessionContext ctx = Beans.getReference(SessionContext.class);
ctx.deactivate();
}
--
libgit2 0.21.2