[jboss-svn-commits] JBoss Common SVN: r4577 - in arquillian/trunk/containers/jetty-embedded-6_1/src: main/java/org/jboss/arquillian/container/jetty/embedded6_1 and 6 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Jun 28 15:27:55 EDT 2010


Author: dan.j.allen
Date: 2010-06-28 15:27:54 -0400 (Mon, 28 Jun 2010)
New Revision: 4577

Added:
   arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded_6_1/
   arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded_6_1/CompositeConfiguration.java
   arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded_6_1/JettyEmbeddedConfiguration.java
   arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded_6_1/JettyEmbeddedContainer.java
   arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded_6_1/JettyEmbeddedDeploymentAppender.java
   arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded_6_1/
   arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded_6_1/JettyEmbeddedContainerClientTestCase.java
   arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded_6_1/JettyEmbeddedInContainerTestCase.java
   arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded_6_1/MavenArtifactResolver.java
   arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded_6_1/TestBean.java
   arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded_6_1/TestServlet.java
Removed:
   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/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/MavenArtifactResolver.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
Modified:
   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/resources/arquillian.xml
   arquillian/trunk/containers/jetty-embedded-6_1/src/test/resources/client-web.xml
Log:
ARQ-200


Deleted: 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	2010-06-28 16:22:09 UTC (rev 4576)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded6_1/CompositeConfiguration.java	2010-06-28 19:27:54 UTC (rev 4577)
@@ -1,69 +0,0 @@
-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. Most of the code is copied from
- * the standard and plus configurations, augmented to search for
- * a META-INF/web-fragment.xml resource (though multiple entries
- * should be supported in the future).
- *
- * @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());
-      }
-
-      // FIXME support multiple web-fragment.xml files
-      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);
-   }
-}

Deleted: 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	2010-06-28 16:22:09 UTC (rev 4576)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded6_1/JettyEmbeddedConfiguration.java	2010-06-28 19:27:54 UTC (rev 4577)
@@ -1,71 +0,0 @@
-/*
- * 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;
-   }
-}

Deleted: 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	2010-06-28 16:22:09 UTC (rev 4576)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded6_1/JettyEmbeddedContainer.java	2010-06-28 19:27:54 UTC (rev 4577)
@@ -1,190 +0,0 @@
-/*
- * 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 (SHRINKWRAP-196).</p>
- *
- * <p>A known issue (SHRINKWRAP-197) 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);
-         }
-      }
-   }
-   
-}

Deleted: 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	2010-06-28 16:22:09 UTC (rev 4576)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded6_1/JettyEmbeddedDeploymentAppender.java	2010-06-28 19:27:54 UTC (rev 4577)
@@ -1,51 +0,0 @@
-/*
- * 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;
-   }
-
-}

Copied: arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded_6_1/CompositeConfiguration.java (from rev 4573, 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/embedded_6_1/CompositeConfiguration.java	                        (rev 0)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded_6_1/CompositeConfiguration.java	2010-06-28 19:27:54 UTC (rev 4577)
@@ -0,0 +1,69 @@
+package org.jboss.arquillian.container.jetty.embedded_6_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. Most of the code is copied from
+ * the standard and plus configurations, augmented to search for
+ * a META-INF/web-fragment.xml resource (though multiple entries
+ * should be supported in the future).
+ *
+ * @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());
+      }
+
+      // FIXME support multiple web-fragment.xml files
+      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);
+   }
+}

Copied: arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded_6_1/JettyEmbeddedConfiguration.java (from rev 4564, 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/embedded_6_1/JettyEmbeddedConfiguration.java	                        (rev 0)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded_6_1/JettyEmbeddedConfiguration.java	2010-06-28 19:27:54 UTC (rev 4577)
@@ -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.embedded_6_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;
+   }
+}

Copied: arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded_6_1/JettyEmbeddedContainer.java (from rev 4565, 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/embedded_6_1/JettyEmbeddedContainer.java	                        (rev 0)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded_6_1/JettyEmbeddedContainer.java	2010-06-28 19:27:54 UTC (rev 4577)
@@ -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.embedded_6_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 (SHRINKWRAP-196).</p>
+ *
+ * <p>A known issue (SHRINKWRAP-197) 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",
+       CompositeConfiguration.class.getName(),
+       "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);
+         }
+      }
+   }
+   
+}

Copied: arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded_6_1/JettyEmbeddedDeploymentAppender.java (from rev 4564, 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/embedded_6_1/JettyEmbeddedDeploymentAppender.java	                        (rev 0)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/main/java/org/jboss/arquillian/container/jetty/embedded_6_1/JettyEmbeddedDeploymentAppender.java	2010-06-28 19:27:54 UTC (rev 4577)
@@ -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.embedded_6_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;
+   }
+
+}

Modified: 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	2010-06-28 16:22:09 UTC (rev 4576)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/main/resources/META-INF/services/org.jboss.arquillian.spi.AuxiliaryArchiveAppender	2010-06-28 19:27:54 UTC (rev 4577)
@@ -1 +1 @@
-org.jboss.arquillian.container.jetty.embedded6_1.JettyEmbeddedDeploymentAppender
\ No newline at end of file
+org.jboss.arquillian.container.jetty.embedded_6_1.JettyEmbeddedDeploymentAppender
\ No newline at end of file

Modified: 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	2010-06-28 16:22:09 UTC (rev 4576)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/main/resources/META-INF/services/org.jboss.arquillian.spi.ContainerConfiguration	2010-06-28 19:27:54 UTC (rev 4577)
@@ -1 +1 @@
-org.jboss.arquillian.container.jetty.embedded6_1.JettyEmbeddedConfiguration
+org.jboss.arquillian.container.jetty.embedded_6_1.JettyEmbeddedConfiguration

Modified: 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	2010-06-28 16:22:09 UTC (rev 4576)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer	2010-06-28 19:27:54 UTC (rev 4577)
@@ -1 +1 @@
-org.jboss.arquillian.container.jetty.embedded6_1.JettyEmbeddedContainer
+org.jboss.arquillian.container.jetty.embedded_6_1.JettyEmbeddedContainer

Deleted: 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	2010-06-28 16:22:09 UTC (rev 4576)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded6_1/JettyEmbeddedContainerClientTestCase.java	2010-06-28 19:27:54 UTC (rev 4577)
@@ -1,90 +0,0 @@
-/*
- * 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();
-   }
-}

Deleted: 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	2010-06-28 16:22:09 UTC (rev 4576)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded6_1/JettyEmbeddedInContainerTestCase.java	2010-06-28 19:27:54 UTC (rev 4577)
@@ -1,107 +0,0 @@
-/*
- * 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.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(MavenArtifactResolver.resolve("org.jboss.weld.servlet:weld-servlet:1.0.1-Final"))
-         .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("Jetty", testBean.getName());
-   }
-}

Deleted: arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded6_1/MavenArtifactResolver.java
===================================================================
--- arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded6_1/MavenArtifactResolver.java	2010-06-28 16:22:09 UTC (rev 4576)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded6_1/MavenArtifactResolver.java	2010-06-28 19:27:54 UTC (rev 4577)
@@ -1,63 +0,0 @@
-/*
- * 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;
-
-/**
- * A crude resolver that converts a Maven artifact reference
- * into a {@link java.io.File} object.
- * 
- * <p>This approach is an interim solution for Maven projects
- * until the open feature request to add formally add artifacts
- * to a test (ARQ-66) is implementated.</p>
- *
- * <p>The testCompile goal will resolve any test dependencies and
- * put them in your local Maven repository. By the time the test
- * executes, you can be sure that the JAR files you need will be
- * in your local repository.</p>
- *
- * <p>Example usage:</p>
- * 
- * <pre>
- * WebArchive war = ShrinkWrap.create("test.war", WebArchive.class)
- *     .addLibrary(MavenArtifactResolver.resolve("commons-lang:commons-lang:2.5"));
- * </pre>
- *
- * @author Dan Allen
- */
-public class MavenArtifactResolver
-{
-   private static final String LOCAL_MAVEN_REPO =
-         System.getProperty("user.home") + File.separatorChar +
-         ".m2" + File.separatorChar + "repository";
-
-   public static File resolve(String groupId, String artifactId, String version)
-   {
-      return new File(LOCAL_MAVEN_REPO + File.separatorChar +
-            groupId.replace(".", File.separator) + File.separatorChar +
-            artifactId + File.separatorChar +
-            version + File.separatorChar +
-            artifactId + "-" + version + ".jar");
-   }
-
-   public static File resolve(String qualifiedArtifactId)
-   {
-      String[] segments = qualifiedArtifactId.split(":");
-      return resolve(segments[0], segments[1], segments[2]);
-   }
-}

Deleted: 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	2010-06-28 16:22:09 UTC (rev 4576)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded6_1/TestBean.java	2010-06-28 19:27:54 UTC (rev 4577)
@@ -1,30 +0,0 @@
-/*
- * 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 javax.annotation.Resource;
-
-public class TestBean
-{
-   @Resource(name = "name")
-   private String name;
-
-   public String getName()
-   {
-      return name;
-   }
-}

Deleted: 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	2010-06-28 16:22:09 UTC (rev 4576)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded6_1/TestServlet.java	2010-06-28 19:27:54 UTC (rev 4577)
@@ -1,45 +0,0 @@
-/*
- * 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);
-   }
-}

Copied: arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded_6_1/JettyEmbeddedContainerClientTestCase.java (from rev 4564, 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/embedded_6_1/JettyEmbeddedContainerClientTestCase.java	                        (rev 0)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded_6_1/JettyEmbeddedContainerClientTestCase.java	2010-06-28 19:27:54 UTC (rev 4577)
@@ -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.embedded_6_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();
+   }
+}

Copied: arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded_6_1/JettyEmbeddedInContainerTestCase.java (from rev 4572, 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/embedded_6_1/JettyEmbeddedInContainerTestCase.java	                        (rev 0)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded_6_1/JettyEmbeddedInContainerTestCase.java	2010-06-28 19:27:54 UTC (rev 4577)
@@ -0,0 +1,107 @@
+/*
+ * 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.embedded_6_1;
+
+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(MavenArtifactResolver.resolve("org.jboss.weld.servlet:weld-servlet:1.0.1-Final"))
+         .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("Jetty", testBean.getName());
+   }
+}

Copied: arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded_6_1/MavenArtifactResolver.java (from rev 4571, arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded6_1/MavenArtifactResolver.java)
===================================================================
--- arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded_6_1/MavenArtifactResolver.java	                        (rev 0)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded_6_1/MavenArtifactResolver.java	2010-06-28 19:27:54 UTC (rev 4577)
@@ -0,0 +1,63 @@
+/*
+ * 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.embedded_6_1;
+
+import java.io.File;
+
+/**
+ * A crude resolver that converts a Maven artifact reference
+ * into a {@link java.io.File} object.
+ * 
+ * <p>This approach is an interim solution for Maven projects
+ * until the open feature request to add formally add artifacts
+ * to a test (ARQ-66) is implementated.</p>
+ *
+ * <p>The testCompile goal will resolve any test dependencies and
+ * put them in your local Maven repository. By the time the test
+ * executes, you can be sure that the JAR files you need will be
+ * in your local repository.</p>
+ *
+ * <p>Example usage:</p>
+ * 
+ * <pre>
+ * WebArchive war = ShrinkWrap.create("test.war", WebArchive.class)
+ *     .addLibrary(MavenArtifactResolver.resolve("commons-lang:commons-lang:2.5"));
+ * </pre>
+ *
+ * @author Dan Allen
+ */
+public class MavenArtifactResolver
+{
+   private static final String LOCAL_MAVEN_REPO =
+         System.getProperty("user.home") + File.separatorChar +
+         ".m2" + File.separatorChar + "repository";
+
+   public static File resolve(String groupId, String artifactId, String version)
+   {
+      return new File(LOCAL_MAVEN_REPO + File.separatorChar +
+            groupId.replace(".", File.separator) + File.separatorChar +
+            artifactId + File.separatorChar +
+            version + File.separatorChar +
+            artifactId + "-" + version + ".jar");
+   }
+
+   public static File resolve(String qualifiedArtifactId)
+   {
+      String[] segments = qualifiedArtifactId.split(":");
+      return resolve(segments[0], segments[1], segments[2]);
+   }
+}

Copied: arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded_6_1/TestBean.java (from rev 4566, 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/embedded_6_1/TestBean.java	                        (rev 0)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded_6_1/TestBean.java	2010-06-28 19:27:54 UTC (rev 4577)
@@ -0,0 +1,30 @@
+/*
+ * 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.embedded_6_1;
+
+import javax.annotation.Resource;
+
+public class TestBean
+{
+   @Resource(name = "name")
+   private String name;
+
+   public String getName()
+   {
+      return name;
+   }
+}

Copied: arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded_6_1/TestServlet.java (from rev 4564, 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/embedded_6_1/TestServlet.java	                        (rev 0)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/test/java/org/jboss/arquillian/container/jetty/embedded_6_1/TestServlet.java	2010-06-28 19:27:54 UTC (rev 4577)
@@ -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.embedded_6_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);
+   }
+}

Modified: arquillian/trunk/containers/jetty-embedded-6_1/src/test/resources/arquillian.xml
===================================================================
--- arquillian/trunk/containers/jetty-embedded-6_1/src/test/resources/arquillian.xml	2010-06-28 16:22:09 UTC (rev 4576)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/test/resources/arquillian.xml	2010-06-28 19:27:54 UTC (rev 4577)
@@ -1,7 +1,7 @@
 <?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">
+   xmlns:jetty6="urn:arq:org.jboss.arquillian.container.jetty.embedded_6_1">
 
    <jetty6:container>
       <jetty6:bindHttpPort>9595</jetty6:bindHttpPort>

Modified: 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	2010-06-28 16:22:09 UTC (rev 4576)
+++ arquillian/trunk/containers/jetty-embedded-6_1/src/test/resources/client-web.xml	2010-06-28 19:27:54 UTC (rev 4577)
@@ -6,7 +6,7 @@
 
    <servlet>
       <servlet-name>Test</servlet-name>
-      <servlet-class>org.jboss.arquillian.container.jetty.embedded6_1.TestServlet</servlet-class>
+      <servlet-class>org.jboss.arquillian.container.jetty.embedded_6_1.TestServlet</servlet-class>
    </servlet>
 
    <servlet-mapping>



More information about the jboss-svn-commits mailing list