Commit f3fe0f573940a2ad0b2a00e497fb4baa020cc4ba

Authored by Cleverson Sacramento
1 parent 5557a7f5
Exists in master

Configuração dos testes da extensão JSF e Servlet usando Arquillian

(client/server)
impl/extension/jsf/src/test/java/test/Tests.java 0 → 100644
... ... @@ -0,0 +1,84 @@
  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 test;
  38 +
  39 +import java.io.File;
  40 +
  41 +import org.jboss.shrinkwrap.api.ShrinkWrap;
  42 +import org.jboss.shrinkwrap.api.asset.FileAsset;
  43 +import org.jboss.shrinkwrap.api.spec.WebArchive;
  44 +import org.jboss.shrinkwrap.resolver.api.maven.Maven;
  45 +import org.junit.Ignore;
  46 +
  47 +@Ignore
  48 +public final class Tests {
  49 +
  50 + private Tests() {
  51 + }
  52 +
  53 + public static WebArchive createDeployment(final Class<?> baseClass) {
  54 + return createDeployment().addPackages(true, baseClass.getPackage()).addClass(Tests.class);
  55 + }
  56 +
  57 + public static WebArchive createDeployment() {
  58 + File[] libs = Maven.resolver().offline().loadPomFromFile("pom.xml", "arquillian-test")
  59 + .importCompileAndRuntimeDependencies().resolve().withTransitivity().asFile();
  60 +
  61 + return ShrinkWrap
  62 + .create(WebArchive.class)
  63 + // .addClass(ServletAuthenticator.class)
  64 + // .addClass(ServletAuthorizer.class)
  65 + // .addClass(ServletFilter.class)
  66 + // .addClass(ServletListener.class)
  67 + // .addClass(HttpServletRequestProducer.class)
  68 + // .addClass(HttpServletResponseProducer.class)
  69 + // .addClass(HttpSessionProducer.class)
  70 + // .addClass(ServletLocaleProducer.class)
  71 + // .addClass(BasicAuthenticationFilter.class)
  72 + // .addClass(HttpServletRequestProducerFilter.class)
  73 + // .addClass(HttpServletResponseProducerFilter.class)
  74 + // .addClass(InternalProcessorFilterImpl.class)
  75 + .addAsResource(createFileAsset("src/main/resources/demoiselle-jsf-bundle.properties"),
  76 + "demoiselle-jsf-bundle.properties")
  77 + .addAsWebInfResource(createFileAsset("src/test/resources/test/beans.xml"), "beans.xml")
  78 + .addAsLibraries(libs);
  79 + }
  80 +
  81 + public static FileAsset createFileAsset(final String pathname) {
  82 + return new FileAsset(new File(pathname));
  83 + }
  84 +}
... ...
impl/extension/jsf/src/test/java/xxxx/XServlet.java 0 → 100644
... ... @@ -0,0 +1,35 @@
  1 +package xxxx;
  2 +
  3 +import java.io.IOException;
  4 +
  5 +import javax.inject.Inject;
  6 +import javax.servlet.ServletException;
  7 +import javax.servlet.annotation.WebServlet;
  8 +import javax.servlet.http.HttpServlet;
  9 +import javax.servlet.http.HttpServletRequest;
  10 +import javax.servlet.http.HttpServletResponse;
  11 +
  12 +import br.gov.frameworkdemoiselle.security.Credentials;
  13 +import br.gov.frameworkdemoiselle.security.SecurityContext;
  14 +
  15 +@WebServlet("/login")
  16 +public class XServlet extends HttpServlet {
  17 +
  18 + private static final long serialVersionUID = 1L;
  19 +
  20 + @Inject
  21 + private SecurityContext securityContext;
  22 +
  23 + @Inject
  24 + private Credentials credentials;
  25 +
  26 + @Override
  27 + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  28 + super.doGet(request, response);
  29 +
  30 + credentials.setUsername("admin");
  31 + credentials.setPassword("changeit");
  32 +
  33 + securityContext.login();
  34 + }
  35 +}
... ...
impl/extension/jsf/src/test/java/xxxx/XTest.java 0 → 100644
... ... @@ -0,0 +1,46 @@
  1 +package xxxx;
  2 +
  3 +import java.net.URL;
  4 +
  5 +import org.jboss.arquillian.container.test.api.Deployment;
  6 +import org.jboss.arquillian.drone.api.annotation.Drone;
  7 +import org.jboss.arquillian.junit.Arquillian;
  8 +import org.jboss.arquillian.test.api.ArquillianResource;
  9 +import org.jboss.shrinkwrap.api.spec.WebArchive;
  10 +import org.junit.Test;
  11 +import org.junit.runner.RunWith;
  12 +
  13 +import test.Tests;
  14 +
  15 +import com.thoughtworks.selenium.DefaultSelenium;
  16 +
  17 +@RunWith(Arquillian.class)
  18 +public class XTest {
  19 +
  20 + private static final String PATH = "src/test/resources/xxx";
  21 +
  22 + @Drone
  23 + private DefaultSelenium browser;
  24 +
  25 + @ArquillianResource
  26 + private URL deploymentUrl;
  27 +
  28 + @Deployment(testable = false)
  29 + public static WebArchive createDeployment() {
  30 + return Tests.createDeployment().addClass(XServlet.class)
  31 + .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml");
  32 + }
  33 +
  34 + @Test
  35 + public void xxxx() {
  36 + browser.open(deploymentUrl + "login");
  37 +
  38 + // browser.type("id=xxx-input", "demo");
  39 + // browser.waitForPageToLoad("15000");
  40 +
  41 + // assertTrue("User should be logged in!",
  42 + // browser.isElementPresent("xpath=//li[contains(text(), 'Welcome')]"));
  43 + // assertTrue("Username should be shown!",
  44 + // browser.isElementPresent("xpath=//p[contains(text(), 'You are signed in as demo.')]"));
  45 + }
  46 +}
... ...
impl/extension/jsf/src/test/resources/arquillian.xml 0 → 100644
... ... @@ -0,0 +1,68 @@
  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 +<arquillian xmlns="http://jboss.org/schema/arquillian" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  38 + xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
  39 +
  40 + <!--
  41 + -->
  42 + <engine>
  43 + <property name="deploymentExportPath">target/deployments</property>
  44 + </engine>
  45 +
  46 + <!--
  47 + <extension qualifier="selenium">
  48 + <property name="browser">*googlechrome</property>
  49 + </extension>
  50 + -->
  51 +
  52 + <!--
  53 + <container qualifier="glassfish" default="true">
  54 + <configuration>
  55 + <property name="autoDelete">true</property>
  56 + </configuration>
  57 + </container>
  58 + -->
  59 +
  60 + <!--
  61 + <container qualifier="jbossas-managed" default="true">
  62 + <protocol type="Servlet 3.0" />
  63 + <configuration>
  64 + <property name="jbossHome">target/jboss-as-${jboss.as.version}</property>
  65 + </configuration>
  66 + </container>
  67 + -->
  68 +</arquillian>
... ...
impl/extension/jsf/src/test/resources/test/beans.xml 0 → 100644
... ... @@ -0,0 +1,47 @@
  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 +<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  38 + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
  39 +
  40 + <interceptors>
  41 + <class>br.gov.frameworkdemoiselle.transaction.TransactionalInterceptor</class>
  42 + <class>br.gov.frameworkdemoiselle.security.RequiredPermissionInterceptor</class>
  43 + <class>br.gov.frameworkdemoiselle.security.RequiredRoleInterceptor</class>
  44 + <class>br.gov.frameworkdemoiselle.exception.ExceptionHandlerInterceptor</class>
  45 + </interceptors>
  46 +
  47 +</beans>
... ...
impl/extension/jsf/src/test/resources/xxx/web.xml 0 → 100644
... ... @@ -0,0 +1,52 @@
  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 +</web-app>
0 53 \ No newline at end of file
... ...
impl/extension/servlet/pom.xml
... ... @@ -84,6 +84,12 @@
84 84 <scope>test</scope>
85 85 </dependency>
86 86 -->
  87 + <dependency>
  88 + <groupId>commons-httpclient</groupId>
  89 + <artifactId>commons-httpclient</artifactId>
  90 + <version>3.1</version>
  91 + <scope>test</scope>
  92 + </dependency>
87 93 </dependencies>
88 94  
89 95 <repositories>
... ...
impl/extension/servlet/src/test/java/xxxx/XServlet.java
... ... @@ -26,6 +26,8 @@ public class XServlet extends HttpServlet {
26 26 @Override
27 27 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
28 28 super.doGet(request, response);
  29 +
  30 + System.out.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
29 31  
30 32 credentials.setUsername("admin");
31 33 credentials.setPassword("changeit");
... ...
impl/extension/servlet/src/test/java/xxxx/XTest.java
1 1 package xxxx;
2 2  
  3 +import java.io.IOException;
3 4 import java.net.URL;
4 5  
  6 +import org.apache.commons.httpclient.HttpClient;
  7 +import org.apache.commons.httpclient.HttpException;
  8 +import org.apache.commons.httpclient.methods.GetMethod;
5 9 import org.jboss.arquillian.container.test.api.Deployment;
6   -import org.jboss.arquillian.drone.api.annotation.Drone;
7 10 import org.jboss.arquillian.junit.Arquillian;
8 11 import org.jboss.arquillian.test.api.ArquillianResource;
9 12 import org.jboss.shrinkwrap.api.spec.WebArchive;
... ... @@ -12,27 +15,37 @@ import org.junit.runner.RunWith;
12 15  
13 16 import test.Tests;
14 17  
15   -import com.thoughtworks.selenium.DefaultSelenium;
16   -
17 18 @RunWith(Arquillian.class)
18 19 public class XTest {
19 20  
20 21 private static final String PATH = "src/test/resources/xxx";
21 22  
22   - @Drone
23   - private DefaultSelenium browser;
24   -
25 23 @ArquillianResource
26 24 private URL deploymentUrl;
27 25  
28 26 @Deployment(testable = false)
29 27 public static WebArchive createDeployment() {
30   - return Tests.createDeployment().addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml");
  28 + return Tests.createDeployment().addClass(XServlet.class)
  29 + .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml");
31 30 }
32 31  
33 32 @Test
34 33 public void xxxx() {
35   - browser.open(deploymentUrl + "login");
  34 + HttpClient client = new HttpClient();
  35 + GetMethod method = new GetMethod(deploymentUrl + "login");
  36 +
  37 + try {
  38 + int status = client.executeMethod(method);
  39 + System.out.println(status);
  40 +
  41 + } catch (HttpException e) {
  42 + e.printStackTrace();
  43 +
  44 + } catch (IOException e) {
  45 + e.printStackTrace();
  46 + }
  47 +
  48 + // browser.open(deploymentUrl + "login");
36 49  
37 50 // browser.type("id=xxx-input", "demo");
38 51 // browser.waitForPageToLoad("15000");
... ...
impl/extension/servlet/src/test/resources/.drone.profile