diff --git a/impl/extension/jsf/src/test/java/exception/handler/authentication/AuthenticationBean.java b/impl/extension/jsf/src/test/java/exception/handler/authentication/AuthenticationBean.java new file mode 100644 index 0000000..03c00da --- /dev/null +++ b/impl/extension/jsf/src/test/java/exception/handler/authentication/AuthenticationBean.java @@ -0,0 +1,50 @@ +/* + * 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 exception.handler.authentication; + +import br.gov.frameworkdemoiselle.security.NotLoggedInException; +import br.gov.frameworkdemoiselle.stereotype.ViewController; + +@ViewController +public class AuthenticationBean { + + private String msg = "Authentication Exception"; + + public String getMsg() { + throw new NotLoggedInException(msg); + } +} diff --git a/impl/extension/jsf/src/test/java/exception/handler/authentication/AuthenticationExceptionTest.java b/impl/extension/jsf/src/test/java/exception/handler/authentication/AuthenticationExceptionTest.java new file mode 100644 index 0000000..5246313 --- /dev/null +++ b/impl/extension/jsf/src/test/java/exception/handler/authentication/AuthenticationExceptionTest.java @@ -0,0 +1,90 @@ +/* + * 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 exception.handler.authentication; + +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.net.URL; + +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpException; +import org.apache.commons.httpclient.methods.GetMethod; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Test; +import org.junit.runner.RunWith; + +import test.Tests; + +@RunWith(Arquillian.class) +public class AuthenticationExceptionTest { + + @ArquillianResource + private URL deploymentUrl; + + private static final String PATH = "src/test/resources/security-authentication"; + + @Deployment(testable = false) + public static WebArchive createDeployment() { + return Tests.createDeployment().addClass(AuthenticationExceptionTest.class) + .addClass(AuthenticationBean.class) + .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") + .addAsWebResource(Tests.createFileAsset(PATH + "/login.xhtml"), "login.xhtml") + .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml"); + } + + @Test + public void authenticationException() { + HttpClient client = new HttpClient(); + GetMethod method = new GetMethod(deploymentUrl + "/index.jsf"); + + try { + client.executeMethod(method); + String message = method.getResponseBodyAsString(); + System.out.println("MESAGE: " + message); + assertTrue(message.contains("Called the page /login")); + + } catch (HttpException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/impl/extension/jsf/src/test/resources/security-authentication/index.xhtml b/impl/extension/jsf/src/test/resources/security-authentication/index.xhtml new file mode 100644 index 0000000..5853f88 --- /dev/null +++ b/impl/extension/jsf/src/test/resources/security-authentication/index.xhtml @@ -0,0 +1,8 @@ + + + + #{authenticationBean.msg} + + + diff --git a/impl/extension/jsf/src/test/resources/security-authentication/login.xhtml b/impl/extension/jsf/src/test/resources/security-authentication/login.xhtml new file mode 100644 index 0000000..37bc783 --- /dev/null +++ b/impl/extension/jsf/src/test/resources/security-authentication/login.xhtml @@ -0,0 +1,9 @@ + + + + + Called the page /login + + + \ No newline at end of file diff --git a/impl/extension/jsf/src/test/resources/security-authentication/web.xml b/impl/extension/jsf/src/test/resources/security-authentication/web.xml new file mode 100644 index 0000000..c2a321e --- /dev/null +++ b/impl/extension/jsf/src/test/resources/security-authentication/web.xml @@ -0,0 +1,61 @@ + + + + + br.gov.frameworkdemoiselle.util.ServletListener + + + Demoiselle Servlet Filter + br.gov.frameworkdemoiselle.util.ServletFilter + + + Demoiselle Servlet Filter + /* + + + + Faces Servlet + javax.faces.webapp.FacesServlet + 1 + + + Faces Servlet + *.jsf + + \ No newline at end of file -- libgit2 0.21.2