Permalink
Browse files

JSFUNIT-273 Add support for Servlet 2.5 type WebArchive deployments b…

…y manipulating the web.xml in the background

- Split FacadeAPITest in two versions, one using CDI and one without.
- Add tomcat-embedded: Tomcat 6 Embedded Profile for Servlet 2.5 tests.
- Add jbossas-remote-5.1: JBoss AS 5.1 Remote Profile for Servlet 2.5 tests.

(Update JSFUnitArchiveAppender with missing HTMLUnit deps that are not default present)

git-svn-id: https://svn.jboss.org/repos/jsfunit/trunk@573 992343fe-802f-0410-85da-d31fbad5f0a6
  • Loading branch information...
1 parent fc5ef0f commit dc06ac254bd6f50f6158096f18a9e4e0526f5eba @aslakknutsen aslakknutsen committed Apr 5, 2011
Showing with 718 additions and 170 deletions.
  1. +46 −0 examples-arquillian/hellojsf/pom.xml
  2. 0 examples-arquillian/hellojsf/src/main/jetty/{jetty-env.xml → cdi-jetty-env.xml}
  3. +7 −0 examples-arquillian/hellojsf/src/main/tomcat/cdi-context.xml
  4. +47 −0 examples-arquillian/hellojsf/src/main/tomcat/web.xml
  5. +0 −1 examples-arquillian/hellojsf/src/main/webapp/WEB-INF/web.xml
  6. +1 −1 ...arquillian/hellojsf/src/test/java/org/jboss/jsfunit/example/hellojsf/BasicAuthenticationTest.java
  7. +190 −0 examples-arquillian/hellojsf/src/test/java/org/jboss/jsfunit/example/hellojsf/Deployments.java
  8. +58 −104 ...llojsf/src/test/java/org/jboss/jsfunit/example/hellojsf/{FacadeAPITest.java → FacadeAPIBase.java}
  9. +106 −0 examples-arquillian/hellojsf/src/test/java/org/jboss/jsfunit/example/hellojsf/FasadeAPICDITest.java
  10. +57 −0 ...les-arquillian/hellojsf/src/test/java/org/jboss/jsfunit/example/hellojsf/FasadeAPINonCDITest.java
  11. +1 −1 ...-arquillian/hellojsf/src/test/java/org/jboss/jsfunit/example/hellojsf/FormAuthenticationTest.java
  12. +0 −62 examples-arquillian/hellojsf/src/test/java/org/jboss/jsfunit/example/hellojsf/NoCDITest.java
  13. +15 −0 examples-arquillian/hellojsf/src/test/resources-tomcat/arquillian.xml
  14. 0 examples-arquillian/hellojsf/src/test/resources/jndi.properties
  15. +80 −0 examples-arquillian/pom.xml
  16. +2 −0 jboss-jsfunit-arquillian/src/main/java/org/jboss/jsfunit/api/BasicAuthentication.java
  17. +2 −0 jboss-jsfunit-arquillian/src/main/java/org/jboss/jsfunit/api/BrowserVersion.java
  18. +2 −0 jboss-jsfunit-arquillian/src/main/java/org/jboss/jsfunit/api/Cookies.java
  19. +2 −0 jboss-jsfunit-arquillian/src/main/java/org/jboss/jsfunit/api/FormAuthentication.java
  20. +2 −0 jboss-jsfunit-arquillian/src/main/java/org/jboss/jsfunit/api/InitialPage.java
  21. +2 −0 jboss-jsfunit-arquillian/src/main/java/org/jboss/jsfunit/api/InitialRequest.java
  22. +1 −1 jboss-jsfunit-arquillian/src/main/java/org/jboss/jsfunit/api/JSFUnitResource.java
  23. +2 −0 jboss-jsfunit-arquillian/src/main/java/org/jboss/jsfunit/api/Proxy.java
  24. +1 −0 ...-jsfunit-arquillian/src/main/java/org/jboss/jsfunit/arquillian/client/JSFUnitArchiveAppender.java
  25. +93 −0 ...arquillian/src/main/java/org/jboss/jsfunit/arquillian/client/JSFUnitProtocolArchiveProcessor.java
  26. +1 −0 ...n/resources/META-INF/services/org.jboss.arquillian.spi.client.deployment.ProtocolArchiveProcessor
@@ -77,6 +77,29 @@
</profile>
<profile>
+ <id>jbossas-remote-5.1</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <systemProperties>
+ <property>
+ <name>jbossas-remote-51-</name>
+ <value>active</value>
+ </property>
+ </systemProperties>
+ <includes>
+ <include>**/FasadeAPINonCDITest.java</include>
+ </includes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+
+ <profile>
<id>jetty-embedded</id>
<build>
<plugins>
@@ -98,5 +121,28 @@
</plugins>
</build>
</profile>
+
+ <profile>
+ <id>tomcat-embedded</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <systemProperties>
+ <property>
+ <name>tomcat-embedded</name>
+ <value>active</value>
+ </property>
+ </systemProperties>
+ <excludes>
+ <exclude>**/FormAuthenticationTest.java</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
</profiles>
</project>
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Context>
+ <Resource name="BeanManager"
+ auth="Container"
+ type="javax.enterprise.inject.spi.BeanManager"
+ factory="org.jboss.weld.resources.ManagerObjectFactory"/>
+</Context>
@@ -0,0 +1,47 @@
+<?xml version="1.0"?>
+<web-app xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+ version="2.5">
+
+ <context-param>
+ <param-name>javax.faces.CONFIG_FILES</param-name>
+ <param-value>/WEB-INF/local-module-faces-config.xml</param-value>
+ </context-param>
+
+ <servlet>
+ <servlet-name>Faces Servlet</servlet-name>
+ <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>Faces Servlet</servlet-name>
+ <url-pattern>*.faces</url-pattern>
+ </servlet-mapping>
+
+ <welcome-file-list>
+ <welcome-file>index.html</welcome-file>
+ </welcome-file-list>
+
+ <security-constraint>
+ <display-name>Basic Authentication for the Admin</display-name>
+ <web-resource-collection>
+ <web-resource-name>Authenticated</web-resource-name>
+ <url-pattern>/secured-page.faces</url-pattern>
+ </web-resource-collection>
+ <auth-constraint>
+ <role-name>hellotestadmin</role-name>
+ </auth-constraint>
+ </security-constraint>
+
+ <login-config>
+ <auth-method>BASIC</auth-method>
+ <realm-name>Authenticated</realm-name>
+ </login-config>
+
+ <security-role>
+ <role-name>hellotestadmin</role-name>
+ </security-role>
+
+</web-app>
@@ -6,7 +6,6 @@
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
- <!-- <param-value>/WEB-INF/validator-config.xml,/WEB-INF/timer-config.xml,/WEB-INF/local-module-faces-config.xml</param-value> -->
<param-value>/WEB-INF/local-module-faces-config.xml</param-value>
</context-param>
@@ -45,7 +45,7 @@
@Deployment
public static WebArchive createDeployment() {
- return FacadeAPITest.createDeployment();
+ return Deployments.createDeployment();
}
@Test
@@ -0,0 +1,190 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
+ * as indicated by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.jsfunit.example.hellojsf;
+
+import java.io.File;
+
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.asset.StringAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.shrinkwrap.descriptor.api.Descriptors;
+import org.jboss.shrinkwrap.descriptor.api.Node;
+import org.jboss.shrinkwrap.descriptor.api.spec.servlet.web.AuthMethodType;
+import org.jboss.shrinkwrap.descriptor.api.spec.servlet.web.WebAppDescriptor;
+import org.jboss.shrinkwrap.descriptor.spi.NodeProvider;
+import org.jboss.shrinkwrap.resolver.api.DependencyResolvers;
+import org.jboss.shrinkwrap.resolver.api.maven.MavenDependencyResolver;
+
+/**
+ * Deployments
+ *
+ * @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class Deployments
+{
+ // property surefire sys prop setting
+ public static final boolean IS_JETTY = (System.getProperty("jetty-embedded") != null);
+ public static final boolean IS_TOMCAT = (System.getProperty("tomcat-embedded") != null);
+ public static final boolean IS_JBOSS_51 = (System.getProperty("jbossas-remote-51") != null);
+
+ public static final boolean IS_JSF_1_2 = IS_JBOSS_51;
+
+
+ public static WebArchive createCDIDeployment()
+ {
+ WebArchive war = createBaseDeployment();
+ war.setWebXML(new StringAsset(createCDIWebXML().exportAsString()));
+ war.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
+
+ if(IS_TOMCAT)
+ {
+ war.addAsLibraries(
+ DependencyResolvers.use(MavenDependencyResolver.class).artifacts(
+ "org.jboss.weld.servlet:weld-servlet:1.1.0.Final").resolveAsFiles());
+ war.addAsManifestResource(new File("src/main/tomcat/cdi-context.xml"), "context.xml");
+ }
+ if(IS_JETTY)
+ {
+ war.addAsWebInfResource(new File("src/main/jetty/cdi-jetty-env.xml"), "jetty-env.xml");
+ }
+ return war;
+ }
+
+ public static WebArchive createDeployment()
+ {
+ WebArchive war = createBaseDeployment();
+ war.setWebXML(new StringAsset(createWebXML().exportAsString()));
+ return war;
+ }
+
+ private static WebArchive createBaseDeployment()
+ {
+ WebArchive war =
+ ShrinkWrap.create(WebArchive.class)
+ .addPackage(Package.getPackage("org.jboss.jsfunit.example.hellojsf"))
+ .addAsWebInfResource(new File("src/main/webapp/WEB-INF/faces-config.xml"), "faces-config.xml")
+ .addAsWebInfResource(new File("src/main/webapp/WEB-INF/local-module-faces-config.xml"), "local-module-faces-config.xml")
+ .addAsWebInfResource(new File("src/main/webapp/WEB-INF/jboss-web.xml"), "jboss-web.xml")
+ .addAsWebInfResource(new File("src/main/webapp/WEB-INF/classes/users.properties"), "classes/users.properties")
+ .addAsWebInfResource(new File("src/main/webapp/WEB-INF/classes/roles.properties"), "classes/roles.properties");
+
+ if(IS_JSF_1_2)
+ {
+ war.addAsWebResource(new File("src/main/webapp", "index.jsp"))
+ .addAsWebResource(new File("src/main/webapp", "finalgreeting.jsp"))
+ .addAsWebResource(new File("src/main/webapp", "secured-page.jsp"))
+ .addAsWebResource(new File("src/main/webapp", "NestedNamingContainers.jsp"))
+ .addAsWebResource(new File("src/main/webapp", "indexWithExtraComponents.jsp"))
+ .addAsWebResource(new File("src/main/webapp", "marathons.jsp"))
+ .addAsWebResource(new File("src/main/webapp", "marathons_datatable.jsp"));
+ }
+ else
+ {
+ war.addAsWebResource(new File("src/main/webapp", "index.xhtml"))
+ .addAsWebResource(new File("src/main/webapp", "finalgreeting.xhtml"))
+ .addAsWebResource(new File("src/main/webapp", "secured-page.xhtml"))
+ .addAsWebResource(new File("src/main/webapp", "NestedNamingContainers.xhtml"))
+ .addAsWebResource(new File("src/main/webapp", "indexWithExtraComponents.xhtml"))
+ .addAsWebResource(new File("src/main/webapp", "marathons.xhtml"))
+ .addAsWebResource(new File("src/main/webapp", "marathons_datatable.xhtml"));
+ }
+ appendForEmbedded(war);
+ return war;
+ }
+
+ private static void appendForEmbedded(WebArchive war)
+ {
+ if(IS_JETTY || IS_TOMCAT)
+ {
+ war.addAsLibraries(
+ DependencyResolvers.use(MavenDependencyResolver.class).artifacts(
+ "com.sun.faces:jsf-api:2.0.4-b03",
+ "com.sun.faces:jsf-impl:2.0.4-b03",
+ "javax.annotation:jsr250-api:1.0",
+ "javax.servlet:jstl:1.2").resolveAsFiles());
+ }
+ if(IS_JETTY)
+ {
+ war.addAsLibraries(
+ DependencyResolvers.use(MavenDependencyResolver.class).artifacts(
+ "org.glassfish.web:el-impl:2.2").resolveAsFiles());
+ }
+ }
+
+ public static WebAppDescriptor createCDIWebXML()
+ {
+ WebAppDescriptor desc = Descriptors.create(WebAppDescriptor.class);
+
+ if(IS_JETTY || IS_TOMCAT)
+ {
+ if(IS_TOMCAT) // jetty is added by default. It finds weld-servlet on appCl and insists on loading it.
+ {
+ desc.listener("org.jboss.weld.environment.servlet.Listener");
+ }
+
+ Node rootNode = ((NodeProvider)desc).getRootNode();
+ rootNode.getOrCreate("/web-app/resource-env-ref")
+ .create("resource-env-ref-name").text("BeanManager")
+ .parent()
+ .create("resource-env-ref-type").text("javax.enterprise.inject.spi.BeanManager");
+ }
+ appendBaseWebXML(desc);
+ return desc;
+ }
+
+ public static WebAppDescriptor createWebXML()
+ {
+ WebAppDescriptor desc = Descriptors.create(WebAppDescriptor.class);
+
+ appendBaseWebXML(desc);
+
+ return desc;
+ }
+
+ private static void appendBaseWebXML(WebAppDescriptor desc)
+ {
+ desc.displayName("JSFUnit Arquillian TestCase")
+ .contextParam("javax.faces.CONFIG_FILES", "/WEB-INF/local-module-faces-config.xml")
+ .welcomeFile("index.html")
+ .servlet("javax.faces.webapp.FacesServlet", "*.faces")
+ .loadOnStartup(1);
+
+
+ if(! (IS_JETTY || IS_TOMCAT))
+ {
+ // SHRINKDESC-48 desc.securityConstraint("Basic Authentication for the Admin")
+ desc.securityConstraint()
+ .webResourceCollection("Authenticated")
+ .urlPatterns("/secured-page.faces")
+ .authConstraint("hellotestadmin")
+ .loginConfig(AuthMethodType.BASIC, "Authenticated")
+ .securityRole("hellotestadmin");
+ }
+ if(IS_JETTY)
+ {
+ desc.listener("org.jboss.weld.environment.servlet.Listener");
+ desc.listener("com.sun.faces.config.ConfigureListener");
+ }
+ if(IS_TOMCAT || IS_JBOSS_51)
+ {
+ desc.version("2.5");
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit dc06ac2

Please sign in to comment.