From 0633ded6d6aa3d75f604845b6656b823fd269ea4 Mon Sep 17 00:00:00 2001 From: Cleverson Sacramento Date: Thu, 3 Oct 2013 09:09:15 -0300 Subject: [PATCH] IN PROGRESS - issue FWK-92: Redirecionamento ao usar securityContext.hasRole/hasPermissions com propriedade desativada --- impl/core/src/main/java/br/gov/frameworkdemoiselle/security/NotLoggedInException.java | 2 +- impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/AuthenticationExceptionHandler.java | 25 +++++++++++++++++++++++-- impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/AuthorizationExceptionHandler.java | 13 +++++++++++-- impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/template/AbstractEditPageBean.java | 2 +- impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/template/AbstractListPageBean.java | 2 +- impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/template/AbstractPageBean.java | 2 +- impl/extension/jsf/src/test/java/exception/handler/authentication/AuthenticationBean.java | 4 +--- impl/extension/jsf/src/test/java/exception/handler/authentication/AuthenticationExceptionTest.java | 89 ----------------------------------------------------------------------------------------- impl/extension/jsf/src/test/java/exception/handler/authentication/HandledAuthenticationExceptionTest.java | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/extension/jsf/src/test/java/exception/handler/authentication/UnhandledAuthenticationExceptionTest.java | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/extension/jsf/src/test/java/exception/handler/authorization/AuthorizationBean.java | 17 ++--------------- impl/extension/jsf/src/test/java/exception/handler/authorization/AuthorizationHandledExceptionTest.java | 94 ---------------------------------------------------------------------------------------------- impl/extension/jsf/src/test/java/exception/handler/authorization/AuthorizationNotHandledExceptionTest.java | 93 --------------------------------------------------------------------------------------------- impl/extension/jsf/src/test/java/exception/handler/authorization/HandledAuthorizationExceptionTest.java | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/extension/jsf/src/test/java/exception/handler/authorization/UnhandledAuthorizationExceptionTest.java | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/extension/jsf/src/test/java/exception/handler/configuration/ExceptionHandlerDefaultConfigTest.java | 35 ++++++++++------------------------- impl/extension/jsf/src/test/java/exception/handler/configuration/ExceptionHandlerRedirectConfigTest.java | 3 +-- impl/extension/jsf/src/test/java/exception/handler/configuration/ExceptionNotHandlerConfigTest.java | 14 +++----------- impl/extension/jsf/src/test/java/exception/handler/configuration/compatibility/ExceptionHandlerRedirectConfigTest.java | 18 +++++------------- impl/extension/jsf/src/test/java/exception/handler/configuration/compatibility/ExceptionNotHandlerConfigTest.java | 16 ++++------------ impl/extension/jsf/src/test/java/exception/handler/redirect/RedirectExceptionTest.java | 13 +++++-------- impl/extension/jsf/src/test/java/message/MessageTest.java | 18 +++++------------- impl/extension/jsf/src/test/java/proxy/FacesContextProxyTest.java | 12 +++--------- impl/extension/jsf/src/test/java/test/Tests.java | 6 +----- impl/extension/jsf/src/test/resources/exception-handler-authentication/demoiselle.properties | 36 ++++++++++++++++++++++++++++++++++++ impl/extension/jsf/src/test/resources/exception-handler-authorization/error.xhtml | 43 +++++++++++++++++++++++++++++++++++++++++++ impl/extension/jsf/src/test/resources/exception-handler-authorization/index.xhtml | 42 ++++++++++++++++++++++++++++++++++++++---- impl/extension/jsf/src/test/resources/exception-handler-authorization/page.xhtml | 10 ---------- impl/extension/jsf/src/test/resources/exception-handler-authorization/pretty-config.xml | 2 +- impl/extension/jsf/src/test/resources/exception-handler-authorization/web.xml | 5 +++++ 30 files changed, 529 insertions(+), 415 deletions(-) delete mode 100644 impl/extension/jsf/src/test/java/exception/handler/authentication/AuthenticationExceptionTest.java create mode 100644 impl/extension/jsf/src/test/java/exception/handler/authentication/HandledAuthenticationExceptionTest.java create mode 100644 impl/extension/jsf/src/test/java/exception/handler/authentication/UnhandledAuthenticationExceptionTest.java delete mode 100644 impl/extension/jsf/src/test/java/exception/handler/authorization/AuthorizationHandledExceptionTest.java delete mode 100644 impl/extension/jsf/src/test/java/exception/handler/authorization/AuthorizationNotHandledExceptionTest.java create mode 100644 impl/extension/jsf/src/test/java/exception/handler/authorization/HandledAuthorizationExceptionTest.java create mode 100644 impl/extension/jsf/src/test/java/exception/handler/authorization/UnhandledAuthorizationExceptionTest.java create mode 100644 impl/extension/jsf/src/test/resources/exception-handler-authentication/demoiselle.properties create mode 100644 impl/extension/jsf/src/test/resources/exception-handler-authorization/error.xhtml delete mode 100644 impl/extension/jsf/src/test/resources/exception-handler-authorization/page.xhtml diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/security/NotLoggedInException.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/security/NotLoggedInException.java index 570466f..629ce2b 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/security/NotLoggedInException.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/security/NotLoggedInException.java @@ -44,7 +44,7 @@ package br.gov.frameworkdemoiselle.security; public class NotLoggedInException extends AuthenticationException { private static final long serialVersionUID = 1L; - + /** * Constructs an NotLoggedInException with a message. */ diff --git a/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/AuthenticationExceptionHandler.java b/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/AuthenticationExceptionHandler.java index 4a6791e..d9a98fc 100644 --- a/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/AuthenticationExceptionHandler.java +++ b/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/AuthenticationExceptionHandler.java @@ -36,14 +36,20 @@ */ package br.gov.frameworkdemoiselle.internal.implementation; +import static org.apache.http.HttpStatus.SC_FORBIDDEN; + import javax.faces.context.ExceptionHandler; import javax.faces.context.FacesContext; +import javax.servlet.http.HttpServletResponse; +import br.gov.frameworkdemoiselle.internal.configuration.JsfSecurityConfig; import br.gov.frameworkdemoiselle.security.NotLoggedInException; import br.gov.frameworkdemoiselle.util.Beans; public class AuthenticationExceptionHandler extends AbstractExceptionHandler { + private transient JsfSecurityConfig config; + public AuthenticationExceptionHandler(final ExceptionHandler wrapped) { super(wrapped); } @@ -53,10 +59,25 @@ public class AuthenticationExceptionHandler extends AbstractExceptionHandler { if (cause instanceof NotLoggedInException) { handled = true; - //TODO Inter [NQ]: remover referência a SecurityObserver criando uma classe comum que faz o redirecionamento e que é compartilhada entre elas. - Beans.getReference(SecurityObserver.class).redirectToLoginPage(); + // TODO Inter [NQ]: remover referência a SecurityObserver criando uma classe comum que faz o + // redirecionamento e que é compartilhada entre elas. + + if (getConfig().isRedirectEnabled()) { + Beans.getReference(SecurityObserver.class).redirectToLoginPage(); + } else { + HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse(); + response.setStatus(SC_FORBIDDEN); + } } return handled; } + + public JsfSecurityConfig getConfig() { + if (this.config == null) { + this.config = Beans.getReference(JsfSecurityConfig.class); + } + + return this.config; + } } diff --git a/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/AuthorizationExceptionHandler.java b/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/AuthorizationExceptionHandler.java index d142f70..e9e0717 100644 --- a/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/AuthorizationExceptionHandler.java +++ b/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/AuthorizationExceptionHandler.java @@ -36,9 +36,12 @@ */ package br.gov.frameworkdemoiselle.internal.implementation; +import static org.apache.http.HttpStatus.SC_UNAUTHORIZED; + import javax.faces.context.ExceptionHandler; import javax.faces.context.FacesContext; import javax.faces.event.PhaseId; +import javax.servlet.http.HttpServletResponse; import br.gov.frameworkdemoiselle.security.AuthorizationException; import br.gov.frameworkdemoiselle.util.Faces; @@ -53,9 +56,15 @@ public class AuthorizationExceptionHandler extends AbstractExceptionHandler { boolean handled = false; boolean rendering = PhaseId.RENDER_RESPONSE.equals(facesContext.getCurrentPhaseId()); - if (!rendering && cause instanceof AuthorizationException) { - Faces.addMessage(cause); + if (cause instanceof AuthorizationException) { handled = true; + + if (rendering) { + HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse(); + response.setStatus(SC_UNAUTHORIZED); + } else { + Faces.addMessage(cause); + } } return handled; diff --git a/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/template/AbstractEditPageBean.java b/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/template/AbstractEditPageBean.java index eae4892..f5b2f8e 100644 --- a/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/template/AbstractEditPageBean.java +++ b/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/template/AbstractEditPageBean.java @@ -49,7 +49,7 @@ import br.gov.frameworkdemoiselle.util.Reflections; import br.gov.frameworkdemoiselle.util.ResourceBundle; /** - * Template Managed Bean class that implements the methods defined by the interface EditPageBean. + * Template Managed AuthenticationBean class that implements the methods defined by the interface EditPageBean. * * @param * bean object type diff --git a/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/template/AbstractListPageBean.java b/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/template/AbstractListPageBean.java index d97b2fe..c035303 100644 --- a/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/template/AbstractListPageBean.java +++ b/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/template/AbstractListPageBean.java @@ -50,7 +50,7 @@ import br.gov.frameworkdemoiselle.pagination.Pagination; import br.gov.frameworkdemoiselle.pagination.PaginationContext; import br.gov.frameworkdemoiselle.util.Reflections; /** - * Template Managed Bean class that implements the methods defined by the interface ListPageBean. + * Template Managed AuthenticationBean class that implements the methods defined by the interface ListPageBean. * * @param * bean object type diff --git a/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/template/AbstractPageBean.java b/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/template/AbstractPageBean.java index 8683111..17e875c 100644 --- a/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/template/AbstractPageBean.java +++ b/impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/template/AbstractPageBean.java @@ -43,7 +43,7 @@ import br.gov.frameworkdemoiselle.annotation.NextView; import br.gov.frameworkdemoiselle.annotation.PreviousView; /** - * Template Managed Bean class that implements the methods defined by the interface PageBean. + * Template Managed AuthenticationBean class that implements the methods defined by the interface PageBean. * * @author SERPRO * @see PageBean 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 index dfc8c6f..0f2fbe6 100644 --- a/impl/extension/jsf/src/test/java/exception/handler/authentication/AuthenticationBean.java +++ b/impl/extension/jsf/src/test/java/exception/handler/authentication/AuthenticationBean.java @@ -46,9 +46,7 @@ public class AuthenticationBean implements Serializable { private static final long serialVersionUID = 1L; - private String msg = "Authentication Exception"; - public String getMsg() { - throw new NotLoggedInException(msg); + throw new NotLoggedInException(""); } } 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 deleted file mode 100644 index 7c23b70..0000000 --- a/impl/extension/jsf/src/test/java/exception/handler/authentication/AuthenticationExceptionTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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/exception-handler-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/java/exception/handler/authentication/HandledAuthenticationExceptionTest.java b/impl/extension/jsf/src/test/java/exception/handler/authentication/HandledAuthenticationExceptionTest.java new file mode 100644 index 0000000..fd2c29a --- /dev/null +++ b/impl/extension/jsf/src/test/java/exception/handler/authentication/HandledAuthenticationExceptionTest.java @@ -0,0 +1,81 @@ +/* + * 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 HandledAuthenticationExceptionTest { + + @ArquillianResource + private URL deploymentUrl; + + private static final String PATH = "src/test/resources/exception-handler-authentication"; + + @Deployment(testable = false) + public static WebArchive createDeployment() { + return Tests.createDeployment().addClasses(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() throws HttpException, IOException { + HttpClient client = new HttpClient(); + GetMethod method = new GetMethod(deploymentUrl + "/index.jsf"); + + client.executeMethod(method); + String message = method.getResponseBodyAsString(); + assertTrue(message.contains("Called the page /login")); + } +} diff --git a/impl/extension/jsf/src/test/java/exception/handler/authentication/UnhandledAuthenticationExceptionTest.java b/impl/extension/jsf/src/test/java/exception/handler/authentication/UnhandledAuthenticationExceptionTest.java new file mode 100644 index 0000000..af75248 --- /dev/null +++ b/impl/extension/jsf/src/test/java/exception/handler/authentication/UnhandledAuthenticationExceptionTest.java @@ -0,0 +1,81 @@ +/* + * 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.apache.http.HttpStatus.SC_FORBIDDEN; +import static org.junit.Assert.assertEquals; + +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 UnhandledAuthenticationExceptionTest { + + @ArquillianResource + private URL deploymentUrl; + + private static final String PATH = "src/test/resources/exception-handler-authentication"; + + @Deployment(testable = false) + public static WebArchive createDeployment() { + return Tests.createDeployment().addClasses(AuthenticationBean.class) + .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") + .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml") + .addAsResource(Tests.createFileAsset(PATH + "/demoiselle.properties"), "demoiselle.properties"); + } + + @Test + public void authenticationException() throws HttpException, IOException { + HttpClient client = new HttpClient(); + GetMethod method = new GetMethod(deploymentUrl + "/index.jsf"); + + int status = client.executeMethod(method); + assertEquals(SC_FORBIDDEN, status); + } +} diff --git a/impl/extension/jsf/src/test/java/exception/handler/authorization/AuthorizationBean.java b/impl/extension/jsf/src/test/java/exception/handler/authorization/AuthorizationBean.java index b09d53f..a04e121 100644 --- a/impl/extension/jsf/src/test/java/exception/handler/authorization/AuthorizationBean.java +++ b/impl/extension/jsf/src/test/java/exception/handler/authorization/AuthorizationBean.java @@ -46,20 +46,7 @@ public class AuthorizationBean implements Serializable { private static final long serialVersionUID = 1L; - private String correctMessage = "Authorization Message."; - - private String exceptionMessage = "Authorization Exception!"; - - public String getCorrectMessage() { - return correctMessage; - } - - public String getExceptionMessage() { - throw new AuthorizationException(exceptionMessage); + public String getThrowExceptionMessage() { + throw new AuthorizationException("Authorization Exception!"); } - - public void loadExceptionMessage() { - throw new AuthorizationException(exceptionMessage); - } - } diff --git a/impl/extension/jsf/src/test/java/exception/handler/authorization/AuthorizationHandledExceptionTest.java b/impl/extension/jsf/src/test/java/exception/handler/authorization/AuthorizationHandledExceptionTest.java deleted file mode 100644 index 3f9be47..0000000 --- a/impl/extension/jsf/src/test/java/exception/handler/authorization/AuthorizationHandledExceptionTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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.authorization; - -import static org.junit.Assert.assertNotSame; -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.HttpStatus; -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 AuthorizationHandledExceptionTest { - - @ArquillianResource - private URL deploymentUrl; - - private static final String PATH = "src/test/resources/exception-handler-authorization"; - - @Deployment(testable = false) - public static WebArchive createDeployment() { - return Tests.createDeployment().addClass(AuthorizationHandledExceptionTest.class).addClass(AuthorizationBean.class) - .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") - .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml") - .addAsWebInfResource(Tests.createFileAsset(PATH + "/pretty-config.xml"), "pretty-config.xml"); - - } - - @Test - public void authorizationHandledException() { - HttpClient client = new HttpClient(); - GetMethod method = new GetMethod(deploymentUrl + "/index"); - - try { - int status = client.executeMethod(method); - String message = method.getResponseBodyAsString(); - - assertNotSame(HttpStatus.SC_INTERNAL_SERVER_ERROR, status); - assertTrue(message.contains("Authorization Message.")); - assertTrue(message.contains("Authorization Exception!")); - - } catch (HttpException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - } -} diff --git a/impl/extension/jsf/src/test/java/exception/handler/authorization/AuthorizationNotHandledExceptionTest.java b/impl/extension/jsf/src/test/java/exception/handler/authorization/AuthorizationNotHandledExceptionTest.java deleted file mode 100644 index 0442fb5..0000000 --- a/impl/extension/jsf/src/test/java/exception/handler/authorization/AuthorizationNotHandledExceptionTest.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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.authorization; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -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.HttpStatus; -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 AuthorizationNotHandledExceptionTest { - - @ArquillianResource - private URL deploymentUrl; - - private static final String PATH = "src/test/resources/exception-handler-authorization"; - - @Deployment(testable = false) - public static WebArchive createDeployment() { - return Tests.createDeployment().addClass(AuthorizationNotHandledExceptionTest.class).addClass(AuthorizationBean.class) - .addAsWebResource(Tests.createFileAsset(PATH + "/page.xhtml"), "page.xhtml") - .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml"); - } - - @Test - public void authorizationNotHandledException() { - HttpClient client = new HttpClient(); - GetMethod method = new GetMethod(deploymentUrl + "/page.jsf"); - - try { - int status = client.executeMethod(method); - String message = method.getResponseBodyAsString(); - - assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, status); - assertTrue(message.contains("Authorization Exception!")); - assertFalse(message.contains("Authorization Message.")); - - } catch (HttpException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - } -} diff --git a/impl/extension/jsf/src/test/java/exception/handler/authorization/HandledAuthorizationExceptionTest.java b/impl/extension/jsf/src/test/java/exception/handler/authorization/HandledAuthorizationExceptionTest.java new file mode 100644 index 0000000..46a2850 --- /dev/null +++ b/impl/extension/jsf/src/test/java/exception/handler/authorization/HandledAuthorizationExceptionTest.java @@ -0,0 +1,86 @@ +/* + * 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.authorization; + +import static org.apache.commons.httpclient.HttpStatus.SC_OK; +import static org.junit.Assert.assertEquals; +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 HandledAuthorizationExceptionTest { + + @ArquillianResource + private URL deploymentUrl; + + private static final String PATH = "src/test/resources/exception-handler-authorization"; + + @Deployment(testable = false) + public static WebArchive createDeployment() { + return Tests.createDeployment().addClasses(AuthorizationBean.class) + .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") + .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml") + .addAsWebInfResource(Tests.createFileAsset(PATH + "/pretty-config.xml"), "pretty-config.xml"); + + } + + @Test + public void authorizationException() throws HttpException, IOException { + HttpClient client = new HttpClient(); + GetMethod method = new GetMethod(deploymentUrl + "/index"); + + int status = client.executeMethod(method); + String message = method.getResponseBodyAsString(); + + assertEquals(SC_OK, status); + assertTrue(message.contains("Authorization Exception!")); + } +} diff --git a/impl/extension/jsf/src/test/java/exception/handler/authorization/UnhandledAuthorizationExceptionTest.java b/impl/extension/jsf/src/test/java/exception/handler/authorization/UnhandledAuthorizationExceptionTest.java new file mode 100644 index 0000000..b42e5d0 --- /dev/null +++ b/impl/extension/jsf/src/test/java/exception/handler/authorization/UnhandledAuthorizationExceptionTest.java @@ -0,0 +1,80 @@ +/* + * 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.authorization; + +import static org.apache.commons.httpclient.HttpStatus.SC_UNAUTHORIZED; +import static org.junit.Assert.assertEquals; + +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 UnhandledAuthorizationExceptionTest { + + @ArquillianResource + private URL deploymentUrl; + + private static final String PATH = "src/test/resources/exception-handler-authorization"; + + @Deployment(testable = false) + public static WebArchive createDeployment() { + return Tests.createDeployment().addClasses(AuthorizationBean.class) + .addAsWebResource(Tests.createFileAsset(PATH + "/error.xhtml"), "error.xhtml") + .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml"); + } + + @Test + public void authorizationException() throws HttpException, IOException { + HttpClient client = new HttpClient(); + GetMethod method = new GetMethod(deploymentUrl + "/error.jsf"); + + int status = client.executeMethod(method); + assertEquals(SC_UNAUTHORIZED, status); + } +} diff --git a/impl/extension/jsf/src/test/java/exception/handler/configuration/ExceptionHandlerDefaultConfigTest.java b/impl/extension/jsf/src/test/java/exception/handler/configuration/ExceptionHandlerDefaultConfigTest.java index d31653a..e3e3fa7 100644 --- a/impl/extension/jsf/src/test/java/exception/handler/configuration/ExceptionHandlerDefaultConfigTest.java +++ b/impl/extension/jsf/src/test/java/exception/handler/configuration/ExceptionHandlerDefaultConfigTest.java @@ -51,48 +51,33 @@ import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; +import test.Tests; import exception.handler.common.DummyException; import exception.handler.common.ExceptionHandlerConfigBean; -import test.Tests; @RunWith(Arquillian.class) -public class ExceptionHandlerDefaultConfigTest{ +public class ExceptionHandlerDefaultConfigTest { @ArquillianResource private URL deploymentUrl; - + private static final String PATH = "src/test/resources/exception-handler-config"; @Deployment(testable = false) public static WebArchive createDeployment() { - return Tests.createDeployment().addClass(ExceptionHandlerDefaultConfigTest.class) - .addClass(DummyException.class) - .addClass(ExceptionHandlerConfigBean.class) + return Tests.createDeployment().addClasses(DummyException.class, ExceptionHandlerConfigBean.class) .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") .addAsWebResource(Tests.createFileAsset(PATH + "/application_error.xhtml"), "application_error.xhtml") .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml"); } - + @Test - public void defaultConfiguration() { + public void defaultConfiguration() throws HttpException, IOException { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(deploymentUrl + "/index.jsf"); - - try { - client.executeMethod(method); - String message = method.getResponseBodyAsString(); - assertTrue(message.contains("Called the page /application_error")); - - } catch (HttpException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } + + client.executeMethod(method); + String message = method.getResponseBodyAsString(); + assertTrue(message.contains("Called the page /application_error")); } } - - - - - - diff --git a/impl/extension/jsf/src/test/java/exception/handler/configuration/ExceptionHandlerRedirectConfigTest.java b/impl/extension/jsf/src/test/java/exception/handler/configuration/ExceptionHandlerRedirectConfigTest.java index 0fa0943..63b1350 100644 --- a/impl/extension/jsf/src/test/java/exception/handler/configuration/ExceptionHandlerRedirectConfigTest.java +++ b/impl/extension/jsf/src/test/java/exception/handler/configuration/ExceptionHandlerRedirectConfigTest.java @@ -65,8 +65,7 @@ public class ExceptionHandlerRedirectConfigTest { @Deployment(testable = false) public static WebArchive createDeployment() { - return Tests.createDeployment().addClass(ExceptionHandlerRedirectConfigTest.class) - .addClass(DummyException.class).addClass(ExceptionHandlerConfigBean.class) + return Tests.createDeployment().addClasses(DummyException.class, ExceptionHandlerConfigBean.class) .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") .addAsWebResource(Tests.createFileAsset(PATH + "/error_page.xhtml"), "error_page.xhtml") .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml") diff --git a/impl/extension/jsf/src/test/java/exception/handler/configuration/ExceptionNotHandlerConfigTest.java b/impl/extension/jsf/src/test/java/exception/handler/configuration/ExceptionNotHandlerConfigTest.java index dc7c4c8..9352b33 100644 --- a/impl/extension/jsf/src/test/java/exception/handler/configuration/ExceptionNotHandlerConfigTest.java +++ b/impl/extension/jsf/src/test/java/exception/handler/configuration/ExceptionNotHandlerConfigTest.java @@ -66,8 +66,7 @@ public class ExceptionNotHandlerConfigTest { @Deployment(testable = false) public static WebArchive createDeployment() { - return Tests.createDeployment().addClass(ExceptionNotHandlerConfigTest.class).addClass(DummyException.class) - .addClass(ExceptionHandlerConfigBean.class) + return Tests.createDeployment().addClasses(DummyException.class, ExceptionHandlerConfigBean.class) .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") .addAsWebResource(Tests.createFileAsset(PATH + "/application_error.xhtml"), "application_error.xhtml") .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml") @@ -75,17 +74,10 @@ public class ExceptionNotHandlerConfigTest { } @Test - public void notHandlerConfiguration() { + public void notHandlerConfiguration() throws HttpException, IOException { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(deploymentUrl + "/index.jsf"); - try { - assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, client.executeMethod(method)); - - } catch (HttpException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } + assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, client.executeMethod(method)); } } diff --git a/impl/extension/jsf/src/test/java/exception/handler/configuration/compatibility/ExceptionHandlerRedirectConfigTest.java b/impl/extension/jsf/src/test/java/exception/handler/configuration/compatibility/ExceptionHandlerRedirectConfigTest.java index a86dae8..063292c 100644 --- a/impl/extension/jsf/src/test/java/exception/handler/configuration/compatibility/ExceptionHandlerRedirectConfigTest.java +++ b/impl/extension/jsf/src/test/java/exception/handler/configuration/compatibility/ExceptionHandlerRedirectConfigTest.java @@ -65,8 +65,7 @@ public class ExceptionHandlerRedirectConfigTest { @Deployment(testable = false) public static WebArchive createDeployment() { - return Tests.createDeployment().addClass(ExceptionHandlerRedirectConfigTest.class) - .addClass(DummyException.class).addClass(ExceptionHandlerConfigBean.class) + return Tests.createDeployment().addClasses(DummyException.class, ExceptionHandlerConfigBean.class) .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") .addAsWebResource(Tests.createFileAsset(PATH + "/error_page.xhtml"), "error_page.xhtml") .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml") @@ -74,19 +73,12 @@ public class ExceptionHandlerRedirectConfigTest { } @Test - public void notHandlerConfiguration() { + public void notHandlerConfiguration() throws HttpException, IOException { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(deploymentUrl + "/index.jsf"); - try { - client.executeMethod(method); - String message = method.getResponseBodyAsString(); - assertTrue(message.contains("Called the page /error_page")); - - } catch (HttpException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } + client.executeMethod(method); + String message = method.getResponseBodyAsString(); + assertTrue(message.contains("Called the page /error_page")); } } diff --git a/impl/extension/jsf/src/test/java/exception/handler/configuration/compatibility/ExceptionNotHandlerConfigTest.java b/impl/extension/jsf/src/test/java/exception/handler/configuration/compatibility/ExceptionNotHandlerConfigTest.java index 9796e6a..816fc1a 100644 --- a/impl/extension/jsf/src/test/java/exception/handler/configuration/compatibility/ExceptionNotHandlerConfigTest.java +++ b/impl/extension/jsf/src/test/java/exception/handler/configuration/compatibility/ExceptionNotHandlerConfigTest.java @@ -66,8 +66,7 @@ public class ExceptionNotHandlerConfigTest { @Deployment(testable = false) public static WebArchive createDeployment() { - return Tests.createDeployment().addClass(ExceptionNotHandlerConfigTest.class).addClass(DummyException.class) - .addClass(ExceptionHandlerConfigBean.class) + return Tests.createDeployment().addClasses(DummyException.class, ExceptionHandlerConfigBean.class) .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") .addAsWebResource(Tests.createFileAsset(PATH + "/application_error.xhtml"), "application_error.xhtml") .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml") @@ -75,18 +74,11 @@ public class ExceptionNotHandlerConfigTest { } @Test - public void notHandlerConfiguration() { + public void notHandlerConfiguration() throws HttpException, IOException { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(deploymentUrl + "/index.jsf"); - try { - int status = client.executeMethod(method); - assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, status); - - } catch (HttpException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } + int status = client.executeMethod(method); + assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, status); } } diff --git a/impl/extension/jsf/src/test/java/exception/handler/redirect/RedirectExceptionTest.java b/impl/extension/jsf/src/test/java/exception/handler/redirect/RedirectExceptionTest.java index 08a6eeb..e4e409a 100644 --- a/impl/extension/jsf/src/test/java/exception/handler/redirect/RedirectExceptionTest.java +++ b/impl/extension/jsf/src/test/java/exception/handler/redirect/RedirectExceptionTest.java @@ -25,20 +25,18 @@ public class RedirectExceptionTest { @ArquillianResource private URL deploymentUrl; - + private static final String PATH = "src/test/resources/exception-handler-redirect"; @Deployment(testable = false) public static WebArchive createDeployment() { - return Tests.createDeployment().addClass(RedirectExceptionTest.class) - .addClass(RedirectBean.class) - .addClass(ExceptionWithCorrectRedirect.class) + return Tests.createDeployment().addClasses(RedirectBean.class, ExceptionWithCorrectRedirect.class) .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") .addAsWebResource(Tests.createFileAsset(PATH + "/page.xhtml"), "page.xhtml") .addAsWebResource(Tests.createFileAsset(PATH + "/redirect.xhtml"), "redirect.xhtml") .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml"); } - + @Test public void handleExceptionWithCorrectRedirect() { HttpClient client = new HttpClient(); @@ -47,7 +45,7 @@ public class RedirectExceptionTest { try { int status = client.executeMethod(method); String message = method.getResponseBodyAsString(); - + assertEquals(HttpStatus.SC_OK, status); assertFalse(message.contains("Correct Redirect Exception!")); assertTrue(message.contains("Page redirected!")); @@ -58,7 +56,7 @@ public class RedirectExceptionTest { e.printStackTrace(); } } - + @Test public void handleExceptionWithWrongRedirect() { HttpClient client = new HttpClient(); @@ -75,4 +73,3 @@ public class RedirectExceptionTest { } } } - diff --git a/impl/extension/jsf/src/test/java/message/MessageTest.java b/impl/extension/jsf/src/test/java/message/MessageTest.java index 73f091a..fdf1150 100644 --- a/impl/extension/jsf/src/test/java/message/MessageTest.java +++ b/impl/extension/jsf/src/test/java/message/MessageTest.java @@ -63,26 +63,18 @@ public class MessageTest { @Deployment(testable = false) public static WebArchive createDeployment() { - return Tests.createDeployment().addClass(MessageTest.class) - .addClass(MessageBean.class) + return Tests.createDeployment().addClasses(MessageBean.class) .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml"); } @Test - public void showMessage() { + public void showMessage() throws HttpException, IOException { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(deploymentUrl + "/index.jsf"); - try { - client.executeMethod(method); - String message = method.getResponseBodyAsString(); - assertTrue(message.contains("Message shown.")); - - } catch (HttpException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } + client.executeMethod(method); + String message = method.getResponseBodyAsString(); + assertTrue(message.contains("Message shown.")); } } diff --git a/impl/extension/jsf/src/test/java/proxy/FacesContextProxyTest.java b/impl/extension/jsf/src/test/java/proxy/FacesContextProxyTest.java index 14f6ff0..95161d0 100644 --- a/impl/extension/jsf/src/test/java/proxy/FacesContextProxyTest.java +++ b/impl/extension/jsf/src/test/java/proxy/FacesContextProxyTest.java @@ -69,17 +69,11 @@ public class FacesContextProxyTest { } @Test - public void facesContextProxy() { + public void facesContextProxy() throws HttpException, IOException { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(deploymentUrl + "/index"); - try { - int status = client.executeMethod(method); - assertEquals( HttpStatus.SC_OK, status); - } catch (HttpException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } + int status = client.executeMethod(method); + assertEquals(HttpStatus.SC_OK, status); } } diff --git a/impl/extension/jsf/src/test/java/test/Tests.java b/impl/extension/jsf/src/test/java/test/Tests.java index 970bb51..23e9dd3 100644 --- a/impl/extension/jsf/src/test/java/test/Tests.java +++ b/impl/extension/jsf/src/test/java/test/Tests.java @@ -80,17 +80,13 @@ import br.gov.frameworkdemoiselle.util.PageNotFoundException; import br.gov.frameworkdemoiselle.util.Parameter; import br.gov.frameworkdemoiselle.util.Redirector; -@SuppressWarnings("deprecation") @Ignore +@SuppressWarnings("deprecation") public final class Tests { private Tests() { } - public static WebArchive createDeployment(final Class baseClass) { - return createDeployment().addPackages(true, baseClass.getPackage()).addClass(Tests.class); - } - public static WebArchive createDeployment() { File[] libs = Maven.resolver().offline().loadPomFromFile("pom.xml", "arquillian-test") .importCompileAndRuntimeDependencies().resolve().withTransitivity().asFile(); diff --git a/impl/extension/jsf/src/test/resources/exception-handler-authentication/demoiselle.properties b/impl/extension/jsf/src/test/resources/exception-handler-authentication/demoiselle.properties new file mode 100644 index 0000000..f182598 --- /dev/null +++ b/impl/extension/jsf/src/test/resources/exception-handler-authentication/demoiselle.properties @@ -0,0 +1,36 @@ +# 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. + +frameworkdemoiselle.security.redirect.enabled=false \ No newline at end of file diff --git a/impl/extension/jsf/src/test/resources/exception-handler-authorization/error.xhtml b/impl/extension/jsf/src/test/resources/exception-handler-authorization/error.xhtml new file mode 100644 index 0000000..3fbb912 --- /dev/null +++ b/impl/extension/jsf/src/test/resources/exception-handler-authorization/error.xhtml @@ -0,0 +1,43 @@ + + + + + #{authorizationBean.throwExceptionMessage} + + + diff --git a/impl/extension/jsf/src/test/resources/exception-handler-authorization/index.xhtml b/impl/extension/jsf/src/test/resources/exception-handler-authorization/index.xhtml index 71b029a..dc5ff3a 100644 --- a/impl/extension/jsf/src/test/resources/exception-handler-authorization/index.xhtml +++ b/impl/extension/jsf/src/test/resources/exception-handler-authorization/index.xhtml @@ -1,9 +1,43 @@ - + + - #{authorizationBean.correctMessage} - + diff --git a/impl/extension/jsf/src/test/resources/exception-handler-authorization/page.xhtml b/impl/extension/jsf/src/test/resources/exception-handler-authorization/page.xhtml deleted file mode 100644 index 821aa31..0000000 --- a/impl/extension/jsf/src/test/resources/exception-handler-authorization/page.xhtml +++ /dev/null @@ -1,10 +0,0 @@ - - - - #{authorizationBean.correctMessage} - #{authorizationBean.exceptionMessage} - - - - \ No newline at end of file diff --git a/impl/extension/jsf/src/test/resources/exception-handler-authorization/pretty-config.xml b/impl/extension/jsf/src/test/resources/exception-handler-authorization/pretty-config.xml index 0e17aec..384dda4 100644 --- a/impl/extension/jsf/src/test/resources/exception-handler-authorization/pretty-config.xml +++ b/impl/extension/jsf/src/test/resources/exception-handler-authorization/pretty-config.xml @@ -43,7 +43,7 @@ - #{authorizationBean.loadExceptionMessage} + #{authorizationBean.getThrowExceptionMessage} \ No newline at end of file diff --git a/impl/extension/jsf/src/test/resources/exception-handler-authorization/web.xml b/impl/extension/jsf/src/test/resources/exception-handler-authorization/web.xml index b8a230d..4ba6625 100644 --- a/impl/extension/jsf/src/test/resources/exception-handler-authorization/web.xml +++ b/impl/extension/jsf/src/test/resources/exception-handler-authorization/web.xml @@ -71,4 +71,9 @@ Faces Servlet *.jsf + + + facelets.SKIP_COMMENTS + true + \ No newline at end of file -- libgit2 0.21.2