Commit f9cce5c8065695ab468c8042c0723aa3389e8c38
1 parent
0ad84710
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 teste de mensagem
Showing
4 changed files
with
216 additions
and
0 deletions
Show diff stats
impl/extension/jsf/src/test/java/message/MessageBean.java
0 → 100644
... | ... | @@ -0,0 +1,56 @@ |
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 message; | |
38 | + | |
39 | +import javax.inject.Inject; | |
40 | + | |
41 | +import br.gov.frameworkdemoiselle.message.MessageContext; | |
42 | +import br.gov.frameworkdemoiselle.stereotype.ViewController; | |
43 | + | |
44 | +@ViewController | |
45 | +public class MessageBean { | |
46 | + | |
47 | + private String msg = "Message shown."; | |
48 | + | |
49 | + @Inject | |
50 | + private MessageContext messageContext; | |
51 | + | |
52 | + public String getMsg() { | |
53 | + messageContext.add(msg); | |
54 | + return ""; | |
55 | + } | |
56 | +} | ... | ... |
impl/extension/jsf/src/test/java/message/MessageTest.java
0 → 100644
... | ... | @@ -0,0 +1,88 @@ |
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 message; | |
38 | + | |
39 | +import static org.junit.Assert.assertTrue; | |
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.methods.GetMethod; | |
47 | +import org.jboss.arquillian.container.test.api.Deployment; | |
48 | +import org.jboss.arquillian.junit.Arquillian; | |
49 | +import org.jboss.arquillian.test.api.ArquillianResource; | |
50 | +import org.jboss.shrinkwrap.api.spec.WebArchive; | |
51 | +import org.junit.Test; | |
52 | +import org.junit.runner.RunWith; | |
53 | + | |
54 | +import test.Tests; | |
55 | + | |
56 | +@RunWith(Arquillian.class) | |
57 | +public class MessageTest { | |
58 | + | |
59 | + @ArquillianResource | |
60 | + private URL deploymentUrl; | |
61 | + | |
62 | + private static final String PATH = "src/test/resources/message"; | |
63 | + | |
64 | + @Deployment(testable = false) | |
65 | + public static WebArchive createDeployment() { | |
66 | + return Tests.createDeployment().addClass(MessageTest.class) | |
67 | + .addClass(MessageBean.class) | |
68 | + .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") | |
69 | + .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml"); | |
70 | + } | |
71 | + | |
72 | + @Test | |
73 | + public void showMessage() { | |
74 | + HttpClient client = new HttpClient(); | |
75 | + GetMethod method = new GetMethod(deploymentUrl + "/index.jsf"); | |
76 | + | |
77 | + try { | |
78 | + client.executeMethod(method); | |
79 | + String message = method.getResponseBodyAsString(); | |
80 | + assertTrue(message.contains("Message shown.")); | |
81 | + | |
82 | + } catch (HttpException e) { | |
83 | + e.printStackTrace(); | |
84 | + } catch (IOException e) { | |
85 | + e.printStackTrace(); | |
86 | + } | |
87 | + } | |
88 | +} | ... | ... |
impl/extension/jsf/src/test/resources/message/index.xhtml
0 → 100644
... | ... | @@ -0,0 +1,61 @@ |
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>Faces Servlet</servlet-name> | |
54 | + <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> | |
55 | + <load-on-startup>1</load-on-startup> | |
56 | + </servlet> | |
57 | + <servlet-mapping> | |
58 | + <servlet-name>Faces Servlet</servlet-name> | |
59 | + <url-pattern>*.jsf</url-pattern> | |
60 | + </servlet-mapping> | |
61 | +</web-app> | |
0 | 62 | \ No newline at end of file | ... | ... |