Commit ce21163dcde51ce07657809404bf5cbab14d09aa
1 parent
fd8a89d6
Exists in
master
IN PROGRESS - issue FWK-120: Testes da extensão JSF (segurança +
mensagem + exceção) https://demoiselle.atlassian.net/browse/FWK-120 Adição de testes para injeção do FacesContextProxy.
Showing
5 changed files
with
219 additions
and
0 deletions
Show diff stats
impl/extension/jsf/src/test/java/proxy/FacesContextProxyServlet.java
0 → 100644
| ... | ... | @@ -0,0 +1,69 @@ |
| 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 proxy; | |
| 38 | + | |
| 39 | +import java.io.IOException; | |
| 40 | + | |
| 41 | +import javax.faces.context.FacesContext; | |
| 42 | +import javax.servlet.ServletException; | |
| 43 | +import javax.servlet.annotation.WebServlet; | |
| 44 | +import javax.servlet.http.HttpServlet; | |
| 45 | +import javax.servlet.http.HttpServletRequest; | |
| 46 | +import javax.servlet.http.HttpServletResponse; | |
| 47 | + | |
| 48 | +import org.apache.commons.httpclient.HttpStatus; | |
| 49 | + | |
| 50 | +import br.gov.frameworkdemoiselle.internal.proxy.FacesContextProxy; | |
| 51 | +import br.gov.frameworkdemoiselle.util.Beans; | |
| 52 | + | |
| 53 | +@WebServlet("/index") | |
| 54 | +public class FacesContextProxyServlet extends HttpServlet { | |
| 55 | + | |
| 56 | + private static final long serialVersionUID = 1L; | |
| 57 | + | |
| 58 | + private FacesContext facesContext; | |
| 59 | + | |
| 60 | + @Override | |
| 61 | + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |
| 62 | + facesContext = Beans.getReference(FacesContext.class); | |
| 63 | + if (facesContext.getClass() == FacesContextProxy.class) { | |
| 64 | + response.setStatus(HttpStatus.SC_OK); | |
| 65 | + } else { | |
| 66 | + response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); | |
| 67 | + } | |
| 68 | + } | |
| 69 | +} | ... | ... |
impl/extension/jsf/src/test/java/proxy/FacesContextProxyTest.java
0 → 100644
| ... | ... | @@ -0,0 +1,85 @@ |
| 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 proxy; | |
| 38 | + | |
| 39 | +import static org.junit.Assert.assertEquals; | |
| 40 | + | |
| 41 | +import java.io.IOException; | |
| 42 | +import java.net.URL; | |
| 43 | + | |
| 44 | +import org.apache.commons.httpclient.HttpClient; | |
| 45 | +import org.apache.commons.httpclient.HttpException; | |
| 46 | +import org.apache.commons.httpclient.HttpStatus; | |
| 47 | +import org.apache.commons.httpclient.methods.GetMethod; | |
| 48 | +import org.jboss.arquillian.container.test.api.Deployment; | |
| 49 | +import org.jboss.arquillian.junit.Arquillian; | |
| 50 | +import org.jboss.arquillian.test.api.ArquillianResource; | |
| 51 | +import org.jboss.shrinkwrap.api.spec.WebArchive; | |
| 52 | +import org.junit.Test; | |
| 53 | +import org.junit.runner.RunWith; | |
| 54 | + | |
| 55 | +import test.Tests; | |
| 56 | + | |
| 57 | +@RunWith(Arquillian.class) | |
| 58 | +public class FacesContextProxyTest { | |
| 59 | + | |
| 60 | + @ArquillianResource | |
| 61 | + private URL deploymentUrl; | |
| 62 | + | |
| 63 | + private static final String PATH = "src/test/resources/proxy"; | |
| 64 | + | |
| 65 | + @Deployment(testable = false) | |
| 66 | + public static WebArchive createDeployment() { | |
| 67 | + return Tests.createDeployment().addClass(FacesContextProxyServlet.class) | |
| 68 | + .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml"); | |
| 69 | + } | |
| 70 | + | |
| 71 | + @Test | |
| 72 | + public void facesContextProxy() { | |
| 73 | + HttpClient client = new HttpClient(); | |
| 74 | + GetMethod method = new GetMethod(deploymentUrl + "/index"); | |
| 75 | + | |
| 76 | + try { | |
| 77 | + int status = client.executeMethod(method); | |
| 78 | + assertEquals( HttpStatus.SC_OK, status); | |
| 79 | + } catch (HttpException e) { | |
| 80 | + e.printStackTrace(); | |
| 81 | + } catch (IOException e) { | |
| 82 | + e.printStackTrace(); | |
| 83 | + } | |
| 84 | + } | |
| 85 | +} | ... | ... |
impl/extension/jsf/src/test/java/test/Tests.java
| ... | ... | @@ -48,6 +48,7 @@ import br.gov.frameworkdemoiselle.annotation.NextView; |
| 48 | 48 | import br.gov.frameworkdemoiselle.annotation.PreviousView; |
| 49 | 49 | import br.gov.frameworkdemoiselle.annotation.Redirect; |
| 50 | 50 | import br.gov.frameworkdemoiselle.internal.bootstrap.JsfBootstrap; |
| 51 | +import br.gov.frameworkdemoiselle.internal.configuration.ExceptionHandlerConfigCompatible; | |
| 51 | 52 | import br.gov.frameworkdemoiselle.internal.configuration.ExceptionHandlerConfig; |
| 52 | 53 | import br.gov.frameworkdemoiselle.internal.configuration.JsfSecurityConfig; |
| 53 | 54 | import br.gov.frameworkdemoiselle.internal.context.FacesViewContextImpl; |
| ... | ... | @@ -102,6 +103,7 @@ public final class Tests { |
| 102 | 103 | .addClass(Redirector.class) |
| 103 | 104 | .addClass(FileRenderer.class) |
| 104 | 105 | .addClass(JsfSecurityConfig.class) |
| 106 | + .addClass(ExceptionHandlerConfigCompatible.class) | |
| 105 | 107 | .addClass(ExceptionHandlerConfig.class) |
| 106 | 108 | .addClass(FacesViewContextImpl.class) |
| 107 | 109 | .addClass(AuthorizationExceptionHandlerFactory.class) | ... | ... |
impl/extension/jsf/src/test/resources/.arquillian-drone.profile
| ... | ... | @@ -0,0 +1,63 @@ |
| 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 | +<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" | |
| 38 | + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> | |
| 39 | + | |
| 40 | + <listener> | |
| 41 | + <listener-class>br.gov.frameworkdemoiselle.util.ServletListener</listener-class> | |
| 42 | + </listener> | |
| 43 | + <filter> | |
| 44 | + <filter-name>Demoiselle Servlet Filter</filter-name> | |
| 45 | + <filter-class>br.gov.frameworkdemoiselle.util.ServletFilter</filter-class> | |
| 46 | + </filter> | |
| 47 | + <filter-mapping> | |
| 48 | + <filter-name>Demoiselle Servlet Filter</filter-name> | |
| 49 | + <url-pattern>/*</url-pattern> | |
| 50 | + </filter-mapping> | |
| 51 | + | |
| 52 | + <servlet> | |
| 53 | + <servlet-name>Servlet Class</servlet-name> | |
| 54 | + <servlet-class>proxy.FacesContextProxyServlet</servlet-class> | |
| 55 | + <!-- <load-on-startup>1</load-on-startup> --> | |
| 56 | + </servlet> | |
| 57 | + | |
| 58 | + <servlet-mapping> | |
| 59 | + <servlet-name>Servlet Class</servlet-name> | |
| 60 | + <url-pattern>/index</url-pattern> | |
| 61 | + </servlet-mapping> | |
| 62 | + | |
| 63 | +</web-app> | |
| 0 | 64 | \ No newline at end of file | ... | ... |