[jboss-svn-commits] JBoss Common SVN: r4563 - in arquillian/trunk/containers: jetty-embedded-6_1 and 21 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sun Jun 27 22:05:20 EDT 2010


Author: dan.j.allen
Date: 2010-06-27 22:05:19 -0400 (Sun, 27 Jun 2010)
New Revision: 4563

Added:
   arquillian/trunk/containers/jetty-embedded-6_1/
   arquillian/trunk/containers/jetty-embedded-6_1/pom.xml
   arquillian/trunk/containers/jetty-embedded-6_1/src/
   arquillian/trunk/containers/jetty-embedded-6_1/src/main/
   arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/
   arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/
   arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/
   arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/
   arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/
   arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/
   arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded6_1/
   arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded6_1/CompositeConfiguration.java
   arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded6_1/JettyEmbeddedConfiguration.java
   arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded6_1/JettyEmbeddedContainer.java
   arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded6_1/JettyEmbeddedDeploymentAppender.java
   arquillian/trunk/containers/jetty-embedded-6_1/src/main/resources/
   arquillian/trunk/containers/jetty-embedded-6_1/src/main/resources/META-INF/
   arquillian/trunk/containers/jetty-embedded-6_1/src/main/resources/META-INF/services/
   arquillian/trunk/containers/jetty-embedded-6_1/src/main/resources/META-INF/services/org.jboss.arquillian.spi.AuxiliaryArchiveAppender
   arquillian/trunk/containers/jetty-embedded-6_1/src/main/resources/META-INF/services/org.jboss.arquillian.spi.ContainerConfiguration
   arquillian/trunk/containers/jetty-embedded-6_1/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer
   arquillian/trunk/containers/jetty-embedded-6_1/src/test/
   arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/
   arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/
   arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/
   arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/
   arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/
   arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/
   arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded6_1/
   arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded6_1/JettyEmbeddedContainerClientTestCase.java
   arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded6_1/JettyEmbeddedInContainerTestCase.java
   arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded6_1/TestBean.java
   arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded6_1/TestServlet.java
   arquillian/trunk/containers/jetty-embedded-6_1/src/test/resources/
   arquillian/trunk/containers/jetty-embedded-6_1/src/test/resources/arquillian.xml
   arquillian/trunk/containers/jetty-embedded-6_1/src/test/resources/client-web.xml
   arquillian/trunk/containers/jetty-embedded-6_1/src/test/resources/in-container-web.xml
   arquillian/trunk/containers/jetty-embedded-6_1/src/test/resources/jetty-env.xml
Log:
ARQ-145 initial implementation



Property changes on: arquillian/trunk/containers/jetty-embedded-6_1
___________________________________________________________________
Name: svn:ignore
   + target
.project
.classpath
.settings


Added: arquillian/trunk/containers/jetty-embedded-6_1/pom.xml
===================================================================
--- arquillian/trunk/containers/jetty-embedded-6_1/pom.xml	                        (rev 0)
+++ arquillian/trunk/containers/jetty-embedded-6_1/pom.xml	2010-06-28 02:05:19 UTC (rev 4563)
@@ -0,0 +1,149 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+   <parent>
+      <groupId>org.jboss.arquillian</groupId>
+      <artifactId>arquillian-build</artifactId>
+      <version>1.0.0-SNAPSHOT</version>
+      <relativePath>../../build/pom.xml</relativePath>
+   </parent>
+
+   <modelVersion>4.0.0</modelVersion>
+
+   <groupId>org.jboss.arquillian.container</groupId>
+   <artifactId>arquillian-jetty-embedded-6_1</artifactId>
+   <name>Arquillian Container Jetty Embedded 6.1.x</name>
+   <description>Jetty Embedded 6.1.x Container integration for the Arquillian project</description>
+
+   <properties>
+      <!-- minimum version known to work with tests (minimum recommended version) -->
+      <version.jetty>6.1.12</version.jetty>
+   </properties>
+
+   <dependencies>
+
+      <dependency>
+         <groupId>org.jboss.arquillian</groupId>
+         <artifactId>arquillian-spi</artifactId>
+         <version>${project.version}</version>
+      </dependency>
+
+      <dependency>
+         <groupId>org.mortbay.jetty</groupId>
+         <artifactId>jetty</artifactId>
+         <version>${version.jetty}</version>
+         <scope>provided</scope>
+      </dependency>
+
+      <dependency>
+         <groupId>org.jboss.shrinkwrap</groupId>
+         <artifactId>shrinkwrap-extension-jetty</artifactId>
+         <version>${version.shrinkwrap_shrinkwrap}</version>
+         <scope>provided</scope>
+      </dependency>
+
+      <dependency>
+         <groupId>org.jboss.arquillian.protocol</groupId>
+         <artifactId>arquillian-protocol-servlet-ee6</artifactId>
+         <version>${project.version}</version>
+      </dependency>
+
+      <!-- TODO We likely need a servlet packager to restrict use of EAR -->
+      <dependency>
+         <groupId>org.jboss.arquillian.packager</groupId>
+         <artifactId>arquillian-packager-javaee</artifactId>
+         <version>${project.version}</version>
+      </dependency>
+
+      <dependency>
+         <groupId>org.jboss.arquillian.testenricher</groupId>
+         <artifactId>arquillian-testenricher-cdi</artifactId>
+         <version>${project.version}</version>
+      </dependency>
+
+      <dependency>
+         <groupId>org.jboss.arquillian.testenricher</groupId>
+         <artifactId>arquillian-testenricher-resource</artifactId>
+         <version>${project.version}</version>
+      </dependency>
+
+      <dependency>
+         <groupId>org.jboss.shrinkwrap</groupId>
+         <artifactId>shrinkwrap-impl-base</artifactId>
+      </dependency>
+
+      <dependency>
+         <groupId>org.jboss.arquillian</groupId>
+         <artifactId>arquillian-impl-base</artifactId>
+         <version>${project.version}</version>
+         <scope>test</scope>
+      </dependency>
+      
+      <dependency>
+        <groupId>org.jboss.arquillian</groupId>
+        <artifactId>arquillian-junit</artifactId>
+        <version>${project.version}</version>
+        <scope>test</scope>
+      </dependency>
+
+      <dependency>
+         <groupId>junit</groupId>
+         <artifactId>junit</artifactId>
+         <scope>test</scope>
+      </dependency>
+
+      <dependency>
+         <groupId>javax.enterprise</groupId>
+         <artifactId>cdi-api</artifactId>
+         <version>1.0</version>
+         <scope>test</scope>
+      </dependency>
+
+      <!-- Jetty plus and naming required for testing resource injections -->
+      <dependency>
+         <groupId>org.mortbay.jetty</groupId>
+         <artifactId>jetty-plus</artifactId>
+         <version>${version.jetty}</version>
+         <scope>provided</scope>
+      </dependency>
+
+      <dependency>
+         <groupId>org.mortbay.jetty</groupId>
+         <artifactId>jetty-naming</artifactId>
+         <version>${version.jetty}</version>
+         <scope>test</scope>
+      </dependency>
+
+      <!-- Weld servlet required for testing CDI injections -->
+      <dependency>
+         <groupId>org.jboss.weld.servlet</groupId>
+         <artifactId>weld-servlet</artifactId>
+         <version>1.0.1-Final</version>
+         <scope>test</scope>
+      </dependency>
+
+      <dependency>
+         <groupId>org.glassfish.web</groupId>
+         <artifactId>el-impl</artifactId>
+         <version>2.2</version>
+         <scope>test</scope>
+      </dependency>
+
+      <dependency>
+         <groupId>javax.servlet.jsp</groupId>
+         <artifactId>jsp-api</artifactId>
+         <version>2.2</version>
+         <scope>test</scope>
+      </dependency>
+
+      <dependency>
+         <groupId>com.h2database</groupId>
+         <artifactId>h2</artifactId>
+         <version>1.2.138</version>
+         <scope>test</scope>
+      </dependency>
+
+   </dependencies>
+</project>
+

Added: arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded6_1/CompositeConfiguration.java
===================================================================
--- arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded6_1/CompositeConfiguration.java	                        (rev 0)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded6_1/CompositeConfiguration.java	2010-06-28 02:05:19 UTC (rev 4563)
@@ -0,0 +1,65 @@
+package org.jboss.arquillian.container.jetty.embedded6_1;
+
+import java.net.URL;
+import org.mortbay.jetty.plus.webapp.Configuration;
+import org.mortbay.log.Log;
+import org.mortbay.resource.Resource;
+
+/**
+ * A Jetty {@link Configuration} object that gathers configuration from
+ * WEB-INF/web.xml, annotations, an override descriptor, an exactly one
+ * META-INF/web-fragment.xml.
+ *
+ * @author Dan Allen
+ */
+public class CompositeConfiguration extends Configuration
+{
+   @Override
+   public void configureWebApp() throws Exception
+   {
+      // logic from WebXmlConfiguration
+      if (_context.isStarted())
+      {
+         if (Log.isDebugEnabled())
+         {
+            Log.debug("Cannot configure webapp after it is started");
+         }
+         return;
+      }
+
+      URL webxml = findWebXml();
+      if (webxml != null)
+      {
+         configure(webxml.toString());
+      }
+
+      String overrideDescriptor = getWebAppContext().getOverrideDescriptor();
+      if (overrideDescriptor != null && overrideDescriptor.length() > 0)
+      {
+         Resource orideResource = Resource.newSystemResource(overrideDescriptor);
+         if (orideResource == null)
+         {
+            orideResource = Resource.newResource(overrideDescriptor);
+         }
+         _xmlParser.setValidating(false);
+         configure(orideResource.getURL().toString());
+      }
+
+      Resource webFragment = Resource.newSystemResource("META-INF/web-fragment.xml");
+      if (webFragment != null)
+      {
+         _xmlParser.setValidating(false);
+         configure(webFragment.getURL().toString());
+      }
+
+      // logic from AbstractConfiguration
+      bindUserTransaction();
+
+      // logic from Configuration
+      //lock this webapp's java:comp namespace as per J2EE spec
+      ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
+      Thread.currentThread().setContextClassLoader(getWebAppContext().getClassLoader());
+      lockCompEnv();
+      Thread.currentThread().setContextClassLoader(oldLoader);
+   }
+}

Added: arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded6_1/JettyEmbeddedConfiguration.java
===================================================================
--- arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded6_1/JettyEmbeddedConfiguration.java	                        (rev 0)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded6_1/JettyEmbeddedConfiguration.java	2010-06-28 02:05:19 UTC (rev 4563)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. 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.arquillian.container.jetty.embedded6_1;
+
+import org.jboss.arquillian.spi.ContainerConfiguration;
+import org.jboss.arquillian.spi.ContainerProfile;
+
+/**
+ * A {@link org.jboss.arquillian.spi.ContainerConfiguration} implementation for
+ * the Jetty Embedded 6.1.x container.
+ *
+ * @author Dan Allen
+ * @version $Revision: $
+ */
+public class JettyEmbeddedConfiguration implements ContainerConfiguration
+{
+   private String bindHost = "localhost";
+
+   private int bindHttpPort = 9090;
+
+   private boolean jettyPlus = true;
+
+   public ContainerProfile getContainerProfile()
+   {
+      return ContainerProfile.CLIENT;
+   }
+
+   public int getBindHttpPort()
+   {
+      return bindHttpPort;
+   }
+
+   public void setBindHttpPort(int bindHttpPort)
+   {
+      this.bindHttpPort = bindHttpPort;
+   }
+
+   public String getBindHost()
+   {
+      return bindHost;
+   }
+
+   public void setBindHost(String bindHost)
+   {
+      this.bindHost = bindHost;
+   }
+
+   public boolean isJettyPlus()
+   {
+      return jettyPlus;
+   }
+
+   public void setJettyPlus(boolean jettyPlus)
+   {
+      this.jettyPlus = jettyPlus;
+   }
+}

Added: arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded6_1/JettyEmbeddedContainer.java
===================================================================
--- arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded6_1/JettyEmbeddedContainer.java	                        (rev 0)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded6_1/JettyEmbeddedContainer.java	2010-06-28 02:05:19 UTC (rev 4563)
@@ -0,0 +1,190 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. 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.arquillian.container.jetty.embedded6_1;
+
+import java.net.URL;
+import java.util.logging.Logger;
+
+import org.jboss.arquillian.protocol.servlet.ServletMethodExecutor;
+import org.jboss.arquillian.spi.Configuration;
+import org.jboss.arquillian.spi.ContainerMethodExecutor;
+import org.jboss.arquillian.spi.Context;
+import org.jboss.arquillian.spi.DeployableContainer;
+import org.jboss.arquillian.spi.DeploymentException;
+import org.jboss.arquillian.spi.LifecycleException;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.jetty.api.ShrinkWrapWebAppContext;
+import org.mortbay.jetty.Connector;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.nio.SelectChannelConnector;
+import org.mortbay.jetty.webapp.WebAppContext;
+
+/**
+ * <p>Jetty Embedded 6.1.x container for the Arquillian project.</p>
+ *
+ * <p>This container only supports a WebArchive deployment. The context path of the
+ * deployed application is always set to "/test", which is expected by the servlet protocol.</p>
+ *
+ * <p>A known issue is that you cannot deploy two archives with the same name (i.e., test.war).
+ * The ShrinkWrap Jetty extension always uses the same temporary file and doesn't delete
+ * it until the JVM exists. Therefore, two successive Arquillian tests will collide trying
+ * to write to the same file. The workaround is to give your archive a unique name in the
+ * <code>@Deployment</code> method.</p>
+ *
+ * <p>Another known issue is that the container configuration process logs an exception when
+ * running in-container. However, the container is still configured properly during setup.</p>
+ *
+ * <p>Minimum recommended Jetty version is 6.1.12, due to compatibility changes
+ * with JNDI bindings (prior to 6.1.12, scoping was implemented differently).
+ * Not compatible with Jetty 7 due to changes in package names.</p>
+ *
+ * @author Dan Allen
+ * @version $Revision: $
+ */
+public class JettyEmbeddedContainer implements DeployableContainer
+{
+   public static final String HTTP_PROTOCOL = "http";
+
+   public static final String WEB_APP_CONTEXT_PATH = "/test";
+
+   public static final String[] JETTY_PLUS_CONFIGURATION_CLASSES =
+   {
+       "org.mortbay.jetty.webapp.WebInfConfiguration",
+       "org.mortbay.jetty.plus.webapp.EnvConfiguration",
+       //"org.mortbay.jetty.plus.webapp.Configuration",
+       "org.jboss.arquillian.container.jetty.embedded6_1.CompositeConfiguration",
+       "org.mortbay.jetty.webapp.JettyWebXmlConfiguration"
+   };
+
+   private static final Logger log = Logger.getLogger(JettyEmbeddedContainer.class.getName());
+
+   private Server server;
+
+   private JettyEmbeddedConfiguration containerConfig;
+   
+   public JettyEmbeddedContainer()
+   {
+   }
+   
+   public void setup(Context context, Configuration arquillianConfig)
+   {
+      containerConfig = arquillianConfig.getContainerConfig(JettyEmbeddedConfiguration.class);
+   }
+   
+   public void start(Context context) throws LifecycleException
+   {
+      try 
+      {
+         server = new Server();
+         Connector connector = new SelectChannelConnector();
+         connector.setHost(containerConfig.getBindHost());
+         connector.setPort(containerConfig.getBindHttpPort());
+         server.setConnectors(new Connector[] { connector });
+         server.start();
+      } 
+      catch (Exception e) 
+      {
+         throw new LifecycleException("Could not start container", e);
+      }
+   }
+
+   public void stop(Context context) throws LifecycleException
+   {
+      try 
+      {
+         server.stop();
+      } 
+      catch (Exception e) 
+      {
+         throw new LifecycleException("Could not stop container", e);
+      }
+   }
+
+   public ContainerMethodExecutor deploy(Context context, Archive<?> archive) throws DeploymentException
+   {
+      try 
+      {
+         WebAppContext wctx = archive.as(ShrinkWrapWebAppContext.class);
+         // Jetty plus is required to support in-container invocation and enrichment
+         if (containerConfig.isJettyPlus())
+         {
+            wctx.setConfigurationClasses(JETTY_PLUS_CONFIGURATION_CLASSES);
+         }
+         // FIXME shrinkwrap jetty adapter does not remove file extension from name when setting context path
+         wctx.setContextPath(WEB_APP_CONTEXT_PATH);
+         // HACK this needs to be rethought, perhaps another auxiliary archive appender to guarantee uniqueness and a static check for run mode?
+//         if (archive.contains(ArchivePaths.create("/WEB-INF/lib/arquillian-protocol.jar")))
+//         {
+//            // wctx.setOverrideDescriptor("jar:file:" + wctx.getTempDirectory() + "/webapp/WEB-INF/lib/arquillian-protocol.jar!/META-INF/web-fragment.xml");
+//            // NOTE go on faith there is only one META-INF/web-fragment.xml
+//            wctx.setOverrideDescriptor("META-INF/web-fragment.xml");
+//         }
+         // possible configuration parameters
+         wctx.setExtractWAR(true);
+         wctx.setLogUrlOnStart(true);
+         server.addHandler(wctx);
+         wctx.start();
+         context.add(WebAppContext.class, wctx);
+      } 
+      catch (Exception e) 
+      {
+         throw new DeploymentException("Could not deploy " + archive.getName(), e);
+      }
+
+      try 
+      {
+         return new ServletMethodExecutor(
+               new URL(
+                     HTTP_PROTOCOL,
+                     containerConfig.getBindHost(),
+                     containerConfig.getBindHttpPort(),
+                     "/")
+               );
+      } 
+      catch (Exception e) 
+      {
+         throw new RuntimeException("Could not create ContainerMethodExecutor", e);
+      }
+   }
+
+   public void undeploy(Context context, Archive<?> archive) throws DeploymentException
+   {
+      WebAppContext wctx = context.get(WebAppContext.class);
+      if (wctx != null)
+      {
+         try
+         {
+            wctx.stop();
+         }
+         catch (Exception e)
+         {
+            e.printStackTrace();
+            log.severe("Could not stop context " + wctx.getContextPath() + ": " + e.getMessage());
+         }
+         // NOTE work around a bug in Jetty where removeHandler is ignored if only one handler is set
+         if (server.getHandlers() == null)
+         {
+            server.setHandler(null);
+         }
+         else
+         {
+            server.removeHandler(wctx);
+         }
+      }
+   }
+   
+}

Added: arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded6_1/JettyEmbeddedDeploymentAppender.java
===================================================================
--- arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded6_1/JettyEmbeddedDeploymentAppender.java	                        (rev 0)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded6_1/JettyEmbeddedDeploymentAppender.java	2010-06-28 02:05:19 UTC (rev 4563)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. 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.arquillian.container.jetty.embedded6_1;
+
+import org.jboss.arquillian.spi.AuxiliaryArchiveAppender;
+import org.jboss.arquillian.spi.TestEnricher;
+import org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher;
+import org.jboss.arquillian.testenricher.resource.ResourceInjectionEnricher;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+
+/**
+ * Package the test enrichers supported by the Jetty Embedded 6.1.x Container plugin.
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @author Dan Allen
+ * @version $Revision: $
+ */
+public class JettyEmbeddedDeploymentAppender implements AuxiliaryArchiveAppender
+{
+
+   public Archive<?> createAuxiliaryArchive()
+   {
+      JavaArchive archive = ShrinkWrap.create("arquillian-jetty-testenrichers.jar", JavaArchive.class)
+                        .addPackages(
+                              false,
+                              CDIInjectionEnricher.class.getPackage(),
+                              ResourceInjectionEnricher.class.getPackage())
+                        .addServiceProvider(
+                              TestEnricher.class,
+                              CDIInjectionEnricher.class,
+                              ResourceInjectionEnricher.class);
+      return archive;
+   }
+
+}

Added: arquillian/trunk/containers/jetty-embedded-6_1/src/main/resources/META-INF/services/org.jboss.arquillian.spi.AuxiliaryArchiveAppender
===================================================================
--- arquillian/trunk/containers/jetty-embedded-6_1/src/main/resources/META-INF/services/org.jboss.arquillian.spi.AuxiliaryArchiveAppender	                        (rev 0)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/main/resources/META-INF/services/org.jboss.arquillian.spi.AuxiliaryArchiveAppender	2010-06-28 02:05:19 UTC (rev 4563)
@@ -0,0 +1 @@
+org.jboss.arquillian.container.jetty.embedded6_1.JettyEmbeddedDeploymentAppender
\ No newline at end of file

Added: arquillian/trunk/containers/jetty-embedded-6_1/src/main/resources/META-INF/services/org.jboss.arquillian.spi.ContainerConfiguration
===================================================================
--- arquillian/trunk/containers/jetty-embedded-6_1/src/main/resources/META-INF/services/org.jboss.arquillian.spi.ContainerConfiguration	                        (rev 0)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/main/resources/META-INF/services/org.jboss.arquillian.spi.ContainerConfiguration	2010-06-28 02:05:19 UTC (rev 4563)
@@ -0,0 +1 @@
+org.jboss.arquillian.container.jetty.embedded6_1.JettyEmbeddedConfiguration

Added: arquillian/trunk/containers/jetty-embedded-6_1/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer
===================================================================
--- arquillian/trunk/containers/jetty-embedded-6_1/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer	                        (rev 0)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer	2010-06-28 02:05:19 UTC (rev 4563)
@@ -0,0 +1 @@
+org.jboss.arquillian.container.jetty.embedded6_1.JettyEmbeddedContainer

Added: arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded6_1/JettyEmbeddedContainerClientTestCase.java
===================================================================
--- arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded6_1/JettyEmbeddedContainerClientTestCase.java	                        (rev 0)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded6_1/JettyEmbeddedContainerClientTestCase.java	2010-06-28 02:05:19 UTC (rev 4563)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. 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.arquillian.container.jetty.embedded6_1;
+
+import static org.jboss.arquillian.api.RunModeType.AS_CLIENT;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.logging.Logger;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.api.Run;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Client test case for the Jetty Embedded 6.1.x container
+ *
+ * @author <a href="mailto:aslak at redhat.com">Aslak Knutsen</a>
+ * @author Dan Allen
+ * @version $Revision: $
+ */
+ at RunWith(Arquillian.class)
+ at Run(AS_CLIENT)
+public class JettyEmbeddedContainerClientTestCase
+{
+   private static final Logger log = Logger.getLogger(JettyEmbeddedContainerClientTestCase.class.getName());
+   
+   /**
+    * Deployment for the test
+    */
+   @Deployment
+   public static WebArchive getTestArchive()
+   {
+      final WebArchive war = ShrinkWrap.create("client-test.war", WebArchive.class)
+         .addClass(TestServlet.class)
+         .setWebXML("client-web.xml");
+      log.info(war.toString(true));
+      return war;
+   }
+
+   @Test
+   public void shouldBeAbleToInvokeServletInDeployedWebApp() throws Exception
+   {
+      String body = readAllAndClose(
+            new URL("http://localhost:9595/test" + TestServlet.URL_PATTERN).openStream());
+      
+      Assert.assertEquals(
+            "Verify that the servlet was deployed and returns expected result",
+            TestServlet.MESSAGE,
+            body);
+   }
+   
+   private String readAllAndClose(InputStream is) throws Exception 
+   {
+      ByteArrayOutputStream out = new ByteArrayOutputStream();
+      try
+      {
+         int read;
+         while( (read = is.read()) != -1)
+         {
+            out.write(read);
+         }
+      }
+      finally 
+      {
+         try { is.close(); } catch (Exception e) { }
+      }
+      return out.toString();
+   }
+}

Added: arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded6_1/JettyEmbeddedInContainerTestCase.java
===================================================================
--- arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded6_1/JettyEmbeddedInContainerTestCase.java	                        (rev 0)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded6_1/JettyEmbeddedInContainerTestCase.java	2010-06-28 02:05:19 UTC (rev 4563)
@@ -0,0 +1,108 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. 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.arquillian.container.jetty.embedded6_1;
+
+import java.io.File;
+import java.sql.Connection;
+import java.util.logging.Logger;
+import javax.annotation.Resource;
+import javax.inject.Inject;
+import javax.sql.DataSource;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * In-container test case for the Jetty Embedded 6.1.x container
+ *
+ * @author Dan Allen
+ * @version $Revision: $
+ */
+ at RunWith(Arquillian.class)
+public class JettyEmbeddedInContainerTestCase
+{
+   private static final Logger log = Logger.getLogger(JettyEmbeddedInContainerTestCase.class.getName());
+   
+   /**
+    * Deployment for the test
+    */
+   @Deployment
+   public static WebArchive getTestArchive()
+   {
+      final WebArchive war = ShrinkWrap.create("in-container-test.war", WebArchive.class)
+         .addClass(TestBean.class)
+         // adding the configuration class silences the logged exception when building the configuration on the server-side, but shouldn't be necessary
+         //.addClass(JettyEmbeddedConfiguration.class)
+         .addLibrary(new File(System.getProperty("user.home") + "/.m2/repository/org/jboss/weld/servlet/weld-servlet/1.0.1-Final/weld-servlet-1.0.1-Final.jar"))
+         .addWebResource("jetty-env.xml")
+         .addWebResource(new ByteArrayAsset(new byte[0]), "beans.xml")
+         .setWebXML("in-container-web.xml");
+      log.info(war.toString(true));
+      return war;
+   }
+
+   // defined in jetty-env.xml, scoped to global
+   @Resource(mappedName = "version") Integer version;
+
+   // defined in web.xml, scoped to webapp (relative to java:comp/env)
+   @Resource(name = "name") String name;
+
+   // defined in jetty-env.xml, scoped to webapp (relative to java:comp/env)
+   @Resource(name = "type") String containerType;
+
+   @Resource(name = "jdbc/test") DataSource ds;
+
+   @Inject TestBean testBean;
+
+   @Test
+   public void shouldBeAbleToInjectMembersIntoTestClass() throws Exception
+   {
+      Assert.assertNotNull(version);
+      Assert.assertEquals(new Integer(6), version);
+      Assert.assertNotNull(name);
+      Assert.assertEquals("Jetty", name);
+      Assert.assertNotNull(containerType);
+      Assert.assertEquals("Embedded", containerType);
+      Assert.assertNotNull(ds);
+      Connection c = null;
+      try
+      {
+         c = ds.getConnection();
+         Assert.assertEquals("H2", c.getMetaData().getDatabaseProductName());
+         c.close();
+      }
+      catch (Exception e)
+      {
+         Assert.fail(e.getMessage());
+      }
+      finally
+      {
+         if (c != null && !c.isClosed())
+         {
+            c.close();
+         }
+      }
+      Assert.assertNotNull(testBean);
+      Assert.assertEquals("value", testBean.getValue());
+   }
+}

Added: arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded6_1/TestBean.java
===================================================================
--- arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded6_1/TestBean.java	                        (rev 0)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded6_1/TestBean.java	2010-06-28 02:05:19 UTC (rev 4563)
@@ -0,0 +1,27 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. 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.arquillian.container.jetty.embedded6_1;
+
+public class TestBean
+{
+   private String value = "value";
+
+   public String getValue()
+   {
+      return value;
+   }
+}

Added: arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded6_1/TestServlet.java
===================================================================
--- arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded6_1/TestServlet.java	                        (rev 0)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded6_1/TestServlet.java	2010-06-28 02:05:19 UTC (rev 4563)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. 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.arquillian.container.jetty.embedded6_1;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * TestServlet
+ *
+ * @author <a href="mailto:aslak at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class TestServlet extends HttpServlet
+{
+   private static final long serialVersionUID = 1L;
+
+   public static final String URL_PATTERN = "/Test";
+
+   public static final String MESSAGE = "hello";
+
+   @Override
+   protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+   {
+      response.getWriter().append(MESSAGE);
+   }
+}

Added: arquillian/trunk/containers/jetty-embedded-6_1/src/test/resources/arquillian.xml
===================================================================
--- arquillian/trunk/containers/jetty-embedded-6_1/src/test/resources/arquillian.xml	                        (rev 0)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/test/resources/arquillian.xml	2010-06-28 02:05:19 UTC (rev 4563)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<arquillian xmlns="http://jboss.com/arquillian"
+   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+   xmlns:jetty6="urn:arq:org.jboss.arquillian.container.jetty.embedded6_1">
+
+   <jetty6:container>
+      <jetty6:bindHttpPort>9595</jetty6:bindHttpPort>
+   </jetty6:container>
+
+</arquillian>

Added: arquillian/trunk/containers/jetty-embedded-6_1/src/test/resources/client-web.xml
===================================================================
--- arquillian/trunk/containers/jetty-embedded-6_1/src/test/resources/client-web.xml	                        (rev 0)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/test/resources/client-web.xml	2010-06-28 02:05:19 UTC (rev 4563)
@@ -0,0 +1,17 @@
+<?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">
+
+   <servlet>
+      <servlet-name>Test</servlet-name>
+      <servlet-class>org.jboss.arquillian.container.jetty.embedded6_1.TestServlet</servlet-class>
+   </servlet>
+
+   <servlet-mapping>
+      <servlet-name>Test</servlet-name>
+      <url-pattern>/Test</url-pattern>
+   </servlet-mapping>
+   
+</web-app>

Added: arquillian/trunk/containers/jetty-embedded-6_1/src/test/resources/in-container-web.xml
===================================================================
--- arquillian/trunk/containers/jetty-embedded-6_1/src/test/resources/in-container-web.xml	                        (rev 0)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/test/resources/in-container-web.xml	2010-06-28 02:05:19 UTC (rev 4563)
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app version="2.5"
+   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">
+   
+   <env-entry>
+      <env-entry-name>name</env-entry-name>
+      <env-entry-type>java.lang.String</env-entry-type>
+      <env-entry-value>Jetty</env-entry-value>
+   </env-entry>
+
+   <!-- Should be overridden by jetty-env.xml -->
+   <env-entry>
+      <env-entry-name>type</env-entry-name>
+      <env-entry-type>java.lang.String</env-entry-type>
+      <env-entry-value>Remote</env-entry-value>
+   </env-entry>
+
+   <listener>
+      <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
+   </listener>
+
+</web-app>

Added: arquillian/trunk/containers/jetty-embedded-6_1/src/test/resources/jetty-env.xml
===================================================================
--- arquillian/trunk/containers/jetty-embedded-6_1/src/test/resources/jetty-env.xml	                        (rev 0)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/test/resources/jetty-env.xml	2010-06-28 02:05:19 UTC (rev 4563)
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"
+   "http://jetty.mortbay.org/configure.dtd">
+<Configure id="webAppCtx" class="org.mortbay.jetty.webapp.WebAppContext">
+   <!-- Third argument to EnvEntry constructor (overrideWebXml) required for Jetty <= 6.1.14 -->
+   <!-- EnvEntry scope not implemented until Jetty 6.1.12 -->
+   <New class="org.mortbay.jetty.plus.naming.EnvEntry">
+      <Arg><Ref id="webAppCtx"/></Arg>
+      <Arg>type</Arg>
+      <Arg type="java.lang.String">Embedded</Arg>
+      <Arg type="boolean">true</Arg>
+   </New>
+   <New class="org.mortbay.jetty.plus.naming.EnvEntry">
+      <Arg>version</Arg>
+      <Arg type="java.lang.Integer">6</Arg>
+      <Arg type="boolean">true</Arg>
+   </New>
+   <New class="org.mortbay.jetty.plus.naming.EnvEntry">
+      <Arg><Ref id="webAppCtx"/></Arg>
+      <Arg>BeanManager</Arg>
+      <Arg>
+         <New class="javax.naming.Reference">
+            <Arg>javax.enterprise.inject.spi.BeanManager</Arg>
+            <Arg>org.jboss.weld.resources.ManagerObjectFactory</Arg>
+            <Arg/>
+         </New>
+      </Arg>
+      <Arg type="boolean">true</Arg>
+   </New>
+   <New class="org.mortbay.jetty.plus.naming.EnvEntry">
+      <Arg><Ref id="webAppCtx"/></Arg>
+      <Arg>jdbc/test</Arg>
+      <Arg>
+         <New class="org.h2.jdbcx.JdbcDataSource">
+            <Set name="URL">jdbc:h2:mem:test</Set>
+            <Set name="user">sa</Set>
+            <Set name="password">sa</Set>
+         </New>  
+      </Arg>
+      <Arg type="boolean">true</Arg>
+   </New>
+</Configure>



More information about the jboss-svn-commits mailing list