Commit d651fcf9e299010b3165148ec9b258e67bb091f5
1 parent
d291d454
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 exceções com redirecionamento de páginas
Showing
8 changed files
with
229 additions
and
0 deletions
Show diff stats
impl/extension/jsf/src/test/java/exception/handler/redirect/ExceptionWithCorrectRedirect.java
0 → 100644
... | ... | @@ -0,0 +1,15 @@ |
1 | +package exception.handler.redirect; | |
2 | + | |
3 | +import br.gov.frameworkdemoiselle.annotation.Redirect; | |
4 | +import br.gov.frameworkdemoiselle.exception.ApplicationException; | |
5 | + | |
6 | +@Redirect(viewId="/redirect.jsf") | |
7 | +@ApplicationException | |
8 | +public class ExceptionWithCorrectRedirect extends RuntimeException{ | |
9 | + | |
10 | + private static final long serialVersionUID = 1L; | |
11 | + | |
12 | + public ExceptionWithCorrectRedirect(String msg) { | |
13 | + super(msg); | |
14 | + } | |
15 | +} | ... | ... |
impl/extension/jsf/src/test/java/exception/handler/redirect/ExceptionWithWrongRedirect.java
0 → 100644
... | ... | @@ -0,0 +1,15 @@ |
1 | +package exception.handler.redirect; | |
2 | + | |
3 | +import br.gov.frameworkdemoiselle.annotation.Redirect; | |
4 | +import br.gov.frameworkdemoiselle.exception.ApplicationException; | |
5 | + | |
6 | +@Redirect(viewId="/inexist.jsf") | |
7 | +@ApplicationException | |
8 | +public class ExceptionWithWrongRedirect extends RuntimeException{ | |
9 | + | |
10 | + private static final long serialVersionUID = 1L; | |
11 | + | |
12 | + public ExceptionWithWrongRedirect(String msg) { | |
13 | + super(msg); | |
14 | + } | |
15 | +} | ... | ... |
impl/extension/jsf/src/test/java/exception/handler/redirect/RedirectBean.java
0 → 100644
... | ... | @@ -0,0 +1,20 @@ |
1 | +package exception.handler.redirect; | |
2 | + | |
3 | +import br.gov.frameworkdemoiselle.stereotype.ViewController; | |
4 | + | |
5 | +@ViewController | |
6 | +public class RedirectBean { | |
7 | + | |
8 | + private String redirectCorrectPage = "Correct Redirect Exception!"; | |
9 | + | |
10 | + private String redirectWrongPage = "Wrong Redirect Exception!"; | |
11 | + | |
12 | + public String getRedirectCorrectPage() { | |
13 | + throw new ExceptionWithCorrectRedirect(redirectCorrectPage); | |
14 | + } | |
15 | + | |
16 | + public String getRedirectWrongPage() { | |
17 | + throw new ExceptionWithWrongRedirect(redirectWrongPage); | |
18 | + } | |
19 | + | |
20 | +} | ... | ... |
impl/extension/jsf/src/test/java/exception/handler/redirect/RedirectExceptionTest.java
0 → 100644
... | ... | @@ -0,0 +1,78 @@ |
1 | +package exception.handler.redirect; | |
2 | + | |
3 | +import static org.junit.Assert.assertEquals; | |
4 | +import static org.junit.Assert.assertFalse; | |
5 | +import static org.junit.Assert.assertTrue; | |
6 | + | |
7 | +import java.io.IOException; | |
8 | +import java.net.URL; | |
9 | + | |
10 | +import org.apache.commons.httpclient.HttpClient; | |
11 | +import org.apache.commons.httpclient.HttpException; | |
12 | +import org.apache.commons.httpclient.HttpStatus; | |
13 | +import org.apache.commons.httpclient.methods.GetMethod; | |
14 | +import org.jboss.arquillian.container.test.api.Deployment; | |
15 | +import org.jboss.arquillian.junit.Arquillian; | |
16 | +import org.jboss.arquillian.test.api.ArquillianResource; | |
17 | +import org.jboss.shrinkwrap.api.spec.WebArchive; | |
18 | +import org.junit.Test; | |
19 | +import org.junit.runner.RunWith; | |
20 | + | |
21 | +import test.Tests; | |
22 | + | |
23 | +@RunWith(Arquillian.class) | |
24 | +public class RedirectExceptionTest { | |
25 | + | |
26 | + @ArquillianResource | |
27 | + private URL deploymentUrl; | |
28 | + | |
29 | + private static final String PATH = "src/test/resources/exception-handler-redirect"; | |
30 | + | |
31 | + @Deployment(testable = false) | |
32 | + public static WebArchive createDeployment() { | |
33 | + return Tests.createDeployment().addClass(RedirectExceptionTest.class) | |
34 | + .addClass(RedirectBean.class) | |
35 | + .addClass(ExceptionWithCorrectRedirect.class) | |
36 | + .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") | |
37 | + .addAsWebResource(Tests.createFileAsset(PATH + "/page.xhtml"), "page.xhtml") | |
38 | + .addAsWebResource(Tests.createFileAsset(PATH + "/redirect.xhtml"), "redirect.xhtml") | |
39 | + .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml"); | |
40 | + } | |
41 | + | |
42 | + @Test | |
43 | + public void handleExceptionWithCorrectRedirect() { | |
44 | + HttpClient client = new HttpClient(); | |
45 | + GetMethod method = new GetMethod(deploymentUrl + "/index.jsf"); | |
46 | + | |
47 | + try { | |
48 | + int status = client.executeMethod(method); | |
49 | + String message = method.getResponseBodyAsString(); | |
50 | + | |
51 | + assertEquals(HttpStatus.SC_OK, status); | |
52 | + assertFalse(message.contains("Correct Redirect Exception!")); | |
53 | + assertTrue(message.contains("Page redirected!")); | |
54 | + | |
55 | + } catch (HttpException e) { | |
56 | + e.printStackTrace(); | |
57 | + } catch (IOException e) { | |
58 | + e.printStackTrace(); | |
59 | + } | |
60 | + } | |
61 | + | |
62 | + @Test | |
63 | + public void handleExceptionWithWrongRedirect() { | |
64 | + HttpClient client = new HttpClient(); | |
65 | + GetMethod method = new GetMethod(deploymentUrl + "/page.jsf"); | |
66 | + | |
67 | + try { | |
68 | + int status = client.executeMethod(method); | |
69 | + assertEquals(HttpStatus.SC_NOT_FOUND, status); | |
70 | + | |
71 | + } catch (HttpException e) { | |
72 | + e.printStackTrace(); | |
73 | + } catch (IOException e) { | |
74 | + e.printStackTrace(); | |
75 | + } | |
76 | + } | |
77 | +} | |
78 | + | ... | ... |
impl/extension/jsf/src/test/resources/exception-handler-redirect/index.xhtml
0 → 100644
impl/extension/jsf/src/test/resources/exception-handler-redirect/page.xhtml
0 → 100644
impl/extension/jsf/src/test/resources/exception-handler-redirect/redirect.xhtml
0 → 100644
impl/extension/jsf/src/test/resources/exception-handler-redirect/web.xml
0 → 100644
... | ... | @@ -0,0 +1,74 @@ |
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 | + <filter> | |
53 | + <filter-name>Pretty Filter</filter-name> | |
54 | + <filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class> | |
55 | + </filter> | |
56 | + | |
57 | + <filter-mapping> | |
58 | + <filter-name>Pretty Filter</filter-name> | |
59 | + <url-pattern>/*</url-pattern> | |
60 | + <dispatcher>FORWARD</dispatcher> | |
61 | + <dispatcher>REQUEST</dispatcher> | |
62 | + <dispatcher>ERROR</dispatcher> | |
63 | + </filter-mapping> | |
64 | + | |
65 | + <servlet> | |
66 | + <servlet-name>Faces Servlet</servlet-name> | |
67 | + <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> | |
68 | + <load-on-startup>1</load-on-startup> | |
69 | + </servlet> | |
70 | + <servlet-mapping> | |
71 | + <servlet-name>Faces Servlet</servlet-name> | |
72 | + <url-pattern>*.jsf</url-pattern> | |
73 | + </servlet-mapping> | |
74 | +</web-app> | |
0 | 75 | \ No newline at end of file | ... | ... |