[jboss-svn-commits] JBoss Common SVN: r4541 - in arquillian/trunk/containers: tomcat-embedded-6 and 31 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Jun 23 17:09:08 EDT 2010


Author: dan.j.allen
Date: 2010-06-23 17:09:07 -0400 (Wed, 23 Jun 2010)
New Revision: 4541

Added:
   arquillian/trunk/containers/tomcat-embedded-6/
   arquillian/trunk/containers/tomcat-embedded-6/src/
   arquillian/trunk/containers/tomcat-embedded-6/src/main/
   arquillian/trunk/containers/tomcat-embedded-6/src/main/java/
   arquillian/trunk/containers/tomcat-embedded-6/src/main/java/org/
   arquillian/trunk/containers/tomcat-embedded-6/src/main/java/org/jboss/
   arquillian/trunk/containers/tomcat-embedded-6/src/main/java/org/jboss/arquillian/
   arquillian/trunk/containers/tomcat-embedded-6/src/main/java/org/jboss/arquillian/container/
   arquillian/trunk/containers/tomcat-embedded-6/src/main/java/org/jboss/arquillian/container/tomcat/
   arquillian/trunk/containers/tomcat-embedded-6/src/main/java/org/jboss/arquillian/container/tomcat/embedded/
   arquillian/trunk/containers/tomcat-embedded-6/src/main/java/org/jboss/arquillian/container/tomcat/embedded/TomcatConfiguration.java
   arquillian/trunk/containers/tomcat-embedded-6/src/main/java/org/jboss/arquillian/container/tomcat/embedded/TomcatContainer.java
   arquillian/trunk/containers/tomcat-embedded-6/src/main/resources/
   arquillian/trunk/containers/tomcat-embedded-6/src/main/resources/META-INF/
   arquillian/trunk/containers/tomcat-embedded-6/src/main/resources/META-INF/services/
   arquillian/trunk/containers/tomcat-embedded-6/src/main/resources/META-INF/services/org.jboss.arquillian.spi.ContainerConfiguration
   arquillian/trunk/containers/tomcat-embedded-6/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer
   arquillian/trunk/containers/tomcat-embedded-6/src/test/
   arquillian/trunk/containers/tomcat-embedded-6/src/test/java/
   arquillian/trunk/containers/tomcat-embedded-6/src/test/java/org/
   arquillian/trunk/containers/tomcat-embedded-6/src/test/java/org/jboss/
   arquillian/trunk/containers/tomcat-embedded-6/src/test/java/org/jboss/arquillian/
   arquillian/trunk/containers/tomcat-embedded-6/src/test/java/org/jboss/arquillian/container/
   arquillian/trunk/containers/tomcat-embedded-6/src/test/java/org/jboss/arquillian/container/tomcat/
   arquillian/trunk/containers/tomcat-embedded-6/src/test/java/org/jboss/arquillian/container/tomcat/embedded/
   arquillian/trunk/containers/tomcat-embedded-6/src/test/java/org/jboss/arquillian/container/tomcat/embedded/TomcatIntegrationTestCase.java
   arquillian/trunk/containers/tomcat-embedded-6/src/test/java/org/jboss/arquillian/container/tomcat/embedded/test/
   arquillian/trunk/containers/tomcat-embedded-6/src/test/java/org/jboss/arquillian/container/tomcat/embedded/test/war/
   arquillian/trunk/containers/tomcat-embedded-6/src/test/java/org/jboss/arquillian/container/tomcat/embedded/test/war/HelloWorldServlet.java
   arquillian/trunk/containers/tomcat-embedded-6/src/test/resources/
   arquillian/trunk/containers/tomcat-embedded-6/src/test/resources/arquillian.xml
   arquillian/trunk/containers/tomcat-embedded-6/src/test/resources/org/
   arquillian/trunk/containers/tomcat-embedded-6/src/test/resources/org/jboss/
   arquillian/trunk/containers/tomcat-embedded-6/src/test/resources/org/jboss/arquillian/
   arquillian/trunk/containers/tomcat-embedded-6/src/test/resources/org/jboss/arquillian/container/
   arquillian/trunk/containers/tomcat-embedded-6/src/test/resources/org/jboss/arquillian/container/tomcat/
   arquillian/trunk/containers/tomcat-embedded-6/src/test/resources/org/jboss/arquillian/container/tomcat/embedded/
   arquillian/trunk/containers/tomcat-embedded-6/src/test/resources/org/jboss/arquillian/container/tomcat/embedded/test/
   arquillian/trunk/containers/tomcat-embedded-6/src/test/resources/org/jboss/arquillian/container/tomcat/embedded/test/war/
   arquillian/trunk/containers/tomcat-embedded-6/src/test/resources/org/jboss/arquillian/container/tomcat/embedded/test/war/web.xml
Log:
ARQ-189 contributed by Jean Deruelle



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


Added: arquillian/trunk/containers/tomcat-embedded-6/src/main/java/org/jboss/arquillian/container/tomcat/embedded/TomcatConfiguration.java
===================================================================
--- arquillian/trunk/containers/tomcat-embedded-6/src/main/java/org/jboss/arquillian/container/tomcat/embedded/TomcatConfiguration.java	                        (rev 0)
+++ arquillian/trunk/containers/tomcat-embedded-6/src/main/java/org/jboss/arquillian/container/tomcat/embedded/TomcatConfiguration.java	2010-06-23 21:09:07 UTC (rev 4541)
@@ -0,0 +1,114 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.tomcat.embedded;
+
+import org.jboss.arquillian.spi.ContainerConfiguration;
+import org.jboss.arquillian.spi.ContainerProfile;
+
+/**
+ * Arquillian Tomcat Container Configuration
+ * 
+ * @author <a href="mailto:jean.deruelle at gmail.com">Jean Deruelle</a>
+ * @version $Revision: $
+ */
+public class TomcatConfiguration implements ContainerConfiguration {
+
+	private String bindAddress = "localhost";
+
+	private int httpPort = 8080;
+
+	private String tomcatHome = null;
+	
+	private String appBase = null;
+
+	private String workDir = null;
+	
+	private String serverName = null;
+
+	public ContainerProfile getContainerProfile() {
+		return ContainerProfile.CLIENT;
+	}
+
+	public String getBindAddress() {
+		return bindAddress;
+	}
+
+	public void setBindAddress(String bindAddress) {
+		this.bindAddress = bindAddress;
+	}
+
+	public int getHttpPort() {
+		return httpPort;
+	}
+
+	/**
+	 * Set the HTTP Connect port. <br/>
+	 * This is not the JBoss AS HTTP Bind port, bind port must be set in the
+	 * JBoss XML configuration.<br/>
+	 * <b>Only set this if default http port is changed in JBoss AS!</b>
+	 * 
+	 * @param httpPort
+	 *            HTTP Connect port
+	 */
+	public void setHttpPort(int httpPort) {
+		this.httpPort = httpPort;
+	}
+
+	public void setTomcatHome(String jbossHome) {
+		this.tomcatHome = jbossHome;
+	}
+
+	public String getTomcatHome() {
+		return tomcatHome;
+	}
+
+	/**
+	 * @param appBase the directory where the deployed webapps are stored within the Tomcat installation
+	 */
+	public void setAppBase(String tomcatAppBase) {
+		this.appBase = tomcatAppBase;
+	}
+
+	public String getAppBase() {
+		return appBase;
+	}
+
+	/**
+	 * @param workDir the directory where the compiled JSP files and session serialization data is stored
+	 */
+	public void setWorkDir(String tomcatWorkDir) {
+		this.workDir = tomcatWorkDir;
+	}
+
+	public String getTomcatWorkDir() {
+		return workDir;
+	}
+
+	/**
+	 * @param serverName the serverName to set
+	 */
+	public void setServerName(String serverName) {
+		this.serverName = serverName;
+	}
+
+	/**
+	 * @return the serverName
+	 */
+	public String getServerName() {
+		return serverName;
+	}
+}


Property changes on: arquillian/trunk/containers/tomcat-embedded-6/src/main/java/org/jboss/arquillian/container/tomcat/embedded/TomcatConfiguration.java
___________________________________________________________________
Name: svn:executable
   + *

Added: arquillian/trunk/containers/tomcat-embedded-6/src/main/java/org/jboss/arquillian/container/tomcat/embedded/TomcatContainer.java
===================================================================
--- arquillian/trunk/containers/tomcat-embedded-6/src/main/java/org/jboss/arquillian/container/tomcat/embedded/TomcatContainer.java	                        (rev 0)
+++ arquillian/trunk/containers/tomcat-embedded-6/src/main/java/org/jboss/arquillian/container/tomcat/embedded/TomcatContainer.java	2010-06-23 21:09:07 UTC (rev 4541)
@@ -0,0 +1,298 @@
+/*
+ * 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.tomcat.embedded;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Logger;
+
+import org.apache.catalina.Container;
+import org.apache.catalina.Engine;
+import org.apache.catalina.Host;
+import org.apache.catalina.connector.Connector;
+import org.apache.catalina.core.StandardContext;
+import org.apache.catalina.session.StandardManager;
+import org.apache.catalina.startup.Embedded;
+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.arquillian.spi.TestMethodExecutor;
+import org.jboss.arquillian.spi.TestResult;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.exporter.ZipExporter;
+
+/**
+ * Arquillian {@link DeployableContainer} adaptor for a target Tomcat
+ * environment; responible for lifecycle and deployment operations
+ * 
+ * @author <a href="mailto:jean.deruelle at gmail.com">Jean Deruelle</a>
+ * @version $Revision: $
+ */
+public class TomcatContainer implements DeployableContainer {
+
+	private static final String ENV_VAR = "${env.";
+
+	// -------------------------------------------------------------------------------------||
+	// Class Members
+	// ----------------------------------------------------------------------||
+	// -------------------------------------------------------------------------------------||	
+
+	private static final String SEPARATOR = "/";
+
+	/**
+	 * Logger
+	 */
+	private static final Logger log = Logger.getLogger(TomcatContainer.class
+			.getName());
+
+	// -------------------------------------------------------------------------------------||
+	// Instance Members
+	// -------------------------------------------------------------------||
+	// -------------------------------------------------------------------------------------||
+
+	/**
+	 * Tomcat embedded
+	 */
+	private Embedded tomcatEmbedded;
+	/**
+	 * Engine contained within Tomcat embedded
+	 */
+	private Engine engine;
+	
+	/**
+	 * Host contained in the tomcat engine
+	 */
+	private Host standardHost;	
+
+	/**
+	 * Tomcat configuration
+	 */
+	private TomcatConfiguration configuration;
+
+	private String serverName = "tomcat";
+	
+	private String host = "localhost";
+
+	private int port = 8080;
+
+	private boolean wasStarted;
+
+	private final List<String> failedUndeployments = new ArrayList<String>();
+
+	// -------------------------------------------------------------------------------------||
+	// Required Implementations
+	// -----------------------------------------------------------||
+	// -------------------------------------------------------------------------------------||
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.jboss.arquillian.spi.DeployableContainer#setup(org.jboss.arquillian
+	 * .spi.Context, org.jboss.arquillian.spi.Configuration)
+	 */
+	public void setup(Context context, Configuration configuration) {
+		this.configuration = configuration
+				.getContainerConfig(TomcatConfiguration.class);
+		host = this.configuration.getBindAddress();
+		port = this.configuration.getHttpPort();
+		if (this.configuration.getServerName() != null) {
+			serverName = this.configuration.getServerName();
+		}
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.jboss.arquillian.spi.DeployableContainer#start(org.jboss.arquillian
+	 * .spi.Context)
+	 */
+	public void start(Context context) throws LifecycleException {
+		try {
+			startTomcatEmbedded();
+		} catch (Exception e) {
+			throw new LifecycleException("Bad shit happened", e);
+		}
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.jboss.arquillian.spi.DeployableContainer#stop(org.jboss.arquillian
+	 * .spi.Context)
+	 */
+	public void stop(Context context) throws LifecycleException {
+		try {
+			removeFailedUnDeployments();
+		} catch (Exception e) {
+			throw new LifecycleException("Could not clean up", e);
+		}
+		if (wasStarted) {
+			try {
+				stopTomcatEmbedded();
+			} catch (org.apache.catalina.LifecycleException e) {
+				throw new LifecycleException("An unexpected error occurred", e);
+			}
+		}
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.jboss.arquillian.spi.DeployableContainer#deploy(org.jboss.arquillian
+	 * .spi.Context, org.jboss.shrinkwrap.api.Archive)
+	 */
+	public ContainerMethodExecutor deploy(Context context,
+			final Archive<?> archive) throws DeploymentException {
+		if (archive == null) {
+			throw new IllegalArgumentException("Archive must be specified");
+		}
+		if (tomcatEmbedded == null) {
+			throw new IllegalStateException("start has not been called!");
+		}
+		final String deploymentName = archive.getName();
+
+		File file = new File(deploymentName);
+		archive.as(ZipExporter.class).exportZip(file, true);
+
+		try {
+			StandardContext standardContext = (StandardContext) tomcatEmbedded
+					.createContext(deploymentName, file.getAbsolutePath());
+			StandardManager manager = new StandardManager();		
+			standardContext.setManager(manager);
+			standardContext.setParent(standardHost);
+         if (configuration.getTomcatWorkDir() != null)
+         {
+            standardContext.setWorkDir(configuration.getTomcatWorkDir());
+         }
+			standardHost.addChild(standardContext);
+		} catch (Exception e) {
+			throw new DeploymentException("Failed to deploy " + deploymentName,
+					e);
+		}
+		return new ContainerMethodExecutor() {
+			
+			public TestResult invoke(TestMethodExecutor testMethodExecutor) {
+				// nothing to do here, done by the test
+				return null;
+			}
+		};		
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.jboss.arquillian.spi.DeployableContainer#undeploy(org.jboss.arquillian
+	 * .spi.Context, org.jboss.shrinkwrap.api.Archive)
+	 */
+	public void undeploy(Context context, Archive<?> archive)
+			throws DeploymentException {
+		if (archive == null) {
+			throw new IllegalArgumentException("Archive must be specified");
+		}		
+		undeploy(archive.getName());
+	}
+
+	private void undeploy(String name) throws DeploymentException {
+		Container child = standardHost.findChild(name);
+		if(child != null) {
+			standardHost.removeChild(child);
+		}
+		File file = new File(name);
+		file.delete();
+	}
+
+	private void removeFailedUnDeployments() throws IOException {
+		List<String> remainingDeployments = new ArrayList<String>();
+		for (String name : failedUndeployments) {
+
+			try {
+				undeploy(name);
+
+			} catch (Exception e) {
+				IOException ioe = new IOException();
+				ioe.initCause(e);
+				throw ioe;
+			}
+		}
+		if (remainingDeployments.size() > 0) {
+			log.severe("Failed to undeploy these artifacts: "
+					+ remainingDeployments);
+		}
+		failedUndeployments.clear();
+	}
+
+	protected void startTomcatEmbedded() throws UnknownHostException, org.apache.catalina.LifecycleException {
+		// creating the tomcat embedded == service tag in server.xml
+		tomcatEmbedded = new Embedded();
+		tomcatEmbedded.setName(serverName);
+		String tomcatHome = configuration.getTomcatHome();
+		if(tomcatHome != null) {
+			if(tomcatHome.startsWith(ENV_VAR)) {
+				String sysVar = tomcatHome.substring(ENV_VAR.length(), tomcatHome.length() -1);
+				tomcatHome = System.getProperty(sysVar);
+				System.out.println("Sys var for tomcat : " + tomcatHome);
+			} 
+			if(tomcatHome != null) {
+				tomcatHome = new File(tomcatHome).getAbsolutePath();
+				tomcatEmbedded.setCatalinaBase(tomcatHome);
+				tomcatEmbedded.setCatalinaHome(tomcatHome);
+			}						
+		}
+		// creates the engine == engine tag in server.xml
+		engine = tomcatEmbedded.createEngine();
+		engine.setName(serverName);
+		engine.setDefaultHost(host + SEPARATOR);
+		engine.setService(tomcatEmbedded);
+		tomcatEmbedded.setContainer(engine);
+		tomcatEmbedded.addEngine(engine);
+		// creates the host == host tag in server.xml
+		if(tomcatHome != null) {
+			standardHost = tomcatEmbedded.createHost(host + SEPARATOR, tomcatEmbedded.getCatalinaHome() + configuration
+				.getAppBase());
+		} else {
+			standardHost = tomcatEmbedded.createHost(host + SEPARATOR, System.getProperty("java.io.tmpdir"));
+		}
+		standardHost.setParent(engine);
+		engine.addChild(standardHost);
+		// creates an http connector == connector in server.xml
+		// TODO externalize this stuff in the configuration
+		Connector connector = tomcatEmbedded.createConnector(InetAddress
+				.getByName(host), port, false);
+		tomcatEmbedded.addConnector(connector);
+		connector.setContainer(engine);
+		//starts tomcat embedded
+		tomcatEmbedded.init();
+		tomcatEmbedded.start();
+		wasStarted = true;
+	}
+
+	protected void stopTomcatEmbedded() throws LifecycleException, org.apache.catalina.LifecycleException {
+		tomcatEmbedded.stop();
+	}
+}


Property changes on: arquillian/trunk/containers/tomcat-embedded-6/src/main/java/org/jboss/arquillian/container/tomcat/embedded/TomcatContainer.java
___________________________________________________________________
Name: svn:executable
   + *

Added: arquillian/trunk/containers/tomcat-embedded-6/src/main/resources/META-INF/services/org.jboss.arquillian.spi.ContainerConfiguration
===================================================================
--- arquillian/trunk/containers/tomcat-embedded-6/src/main/resources/META-INF/services/org.jboss.arquillian.spi.ContainerConfiguration	                        (rev 0)
+++ arquillian/trunk/containers/tomcat-embedded-6/src/main/resources/META-INF/services/org.jboss.arquillian.spi.ContainerConfiguration	2010-06-23 21:09:07 UTC (rev 4541)
@@ -0,0 +1 @@
+org.jboss.arquillian.container.tomcat.embedded.TomcatConfiguration
\ No newline at end of file


Property changes on: arquillian/trunk/containers/tomcat-embedded-6/src/main/resources/META-INF/services/org.jboss.arquillian.spi.ContainerConfiguration
___________________________________________________________________
Name: svn:executable
   + *

Added: arquillian/trunk/containers/tomcat-embedded-6/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer
===================================================================
--- arquillian/trunk/containers/tomcat-embedded-6/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer	                        (rev 0)
+++ arquillian/trunk/containers/tomcat-embedded-6/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer	2010-06-23 21:09:07 UTC (rev 4541)
@@ -0,0 +1 @@
+org.jboss.arquillian.container.tomcat.embedded.TomcatContainer
\ No newline at end of file


Property changes on: arquillian/trunk/containers/tomcat-embedded-6/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer
___________________________________________________________________
Name: svn:executable
   + *

Added: arquillian/trunk/containers/tomcat-embedded-6/src/test/java/org/jboss/arquillian/container/tomcat/embedded/TomcatIntegrationTestCase.java
===================================================================
--- arquillian/trunk/containers/tomcat-embedded-6/src/test/java/org/jboss/arquillian/container/tomcat/embedded/TomcatIntegrationTestCase.java	                        (rev 0)
+++ arquillian/trunk/containers/tomcat-embedded-6/src/test/java/org/jboss/arquillian/container/tomcat/embedded/TomcatIntegrationTestCase.java	2010-06-23 21:09:07 UTC (rev 4541)
@@ -0,0 +1,101 @@
+/*
+ * 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.tomcat.embedded;
+
+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.api.RunModeType;
+import org.jboss.arquillian.container.tomcat.embedded.test.war.HelloWorldServlet;
+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;
+
+/**
+ * Tests that Tomcat deployments into the Tomcat server work through the
+ * Arquillian lifecycle
+ * 
+ * @author <a href="mailto:jean.deruelle at gmail.com">Jean Deruelle</a>
+ * @version $Revision: $
+ */
+ at RunWith(Arquillian.class)
+ at Run(RunModeType.AS_CLIENT)
+public class TomcatIntegrationTestCase {
+
+	private static final String HELLO_WORLD_URL = "http://127.0.0.1:8080/test.war/hello";
+
+	// -------------------------------------------------------------------------------------||
+	// Class Members
+	// ----------------------------------------------------------------------||
+	// -------------------------------------------------------------------------------------||
+
+	/**
+	 * Logger
+	 */
+	private static final Logger log = Logger
+			.getLogger(TomcatIntegrationTestCase.class.getName());
+
+	// -------------------------------------------------------------------------------------||
+	// Instance Members
+	// -------------------------------------------------------------------||
+	// -------------------------------------------------------------------------------------||
+
+	/**
+	 * Define the deployment
+	 */
+	@Deployment
+	public static WebArchive createDeployment() {
+		return ShrinkWrap.create("test.war", WebArchive.class).addClasses(
+				HelloWorldServlet.class).addWebResource(
+				HelloWorldServlet.class.getPackage(), "web.xml", "web.xml");
+	}
+
+	// -------------------------------------------------------------------------------------||
+	// Tests
+	// ------------------------------------------------------------------------------||
+	// -------------------------------------------------------------------------------------||
+
+	/**
+	 * Ensures the {@link HelloWorldServlet} returns the expected response
+	 */
+	@Test
+	public void testHelloWorldServlet() throws Exception {
+		// Define the input and expected outcome
+		final String expected = "Hello, world!";
+
+		URL url = new URL(HELLO_WORLD_URL);
+		InputStream in = url.openConnection().getInputStream();
+
+		byte[] buffer = new byte[10000];
+		int len = in.read(buffer);
+		String httpResponse = "";
+		for (int q = 0; q < len; q++)
+			httpResponse += (char) buffer[q];
+		System.out.println("Received the follwing HTTP response: " + httpResponse);
+
+		// Test
+		Assert.assertEquals("Expected output was not equal by value", expected,
+				httpResponse);
+		log.info("Got expected result from Http Servlet: " + httpResponse);
+	}
+}


Property changes on: arquillian/trunk/containers/tomcat-embedded-6/src/test/java/org/jboss/arquillian/container/tomcat/embedded/TomcatIntegrationTestCase.java
___________________________________________________________________
Name: svn:executable
   + *

Added: arquillian/trunk/containers/tomcat-embedded-6/src/test/java/org/jboss/arquillian/container/tomcat/embedded/test/war/HelloWorldServlet.java
===================================================================
--- arquillian/trunk/containers/tomcat-embedded-6/src/test/java/org/jboss/arquillian/container/tomcat/embedded/test/war/HelloWorldServlet.java	                        (rev 0)
+++ arquillian/trunk/containers/tomcat-embedded-6/src/test/java/org/jboss/arquillian/container/tomcat/embedded/test/war/HelloWorldServlet.java	2010-06-23 21:09:07 UTC (rev 4541)
@@ -0,0 +1,42 @@
+/*
+ * 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.tomcat.embedded.test.war;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Sample Servlet to test Tomcat based Arquillian deployment
+ * 
+ * @author jean.deruelle at gmail.com
+ * 
+ */
+public class HelloWorldServlet extends HttpServlet {
+
+	public void doGet(HttpServletRequest req, HttpServletResponse res)
+			throws ServletException, IOException {
+		PrintWriter out = res.getWriter();
+
+		out.print("Hello, world!");
+		out.close();
+	}
+}


Property changes on: arquillian/trunk/containers/tomcat-embedded-6/src/test/java/org/jboss/arquillian/container/tomcat/embedded/test/war/HelloWorldServlet.java
___________________________________________________________________
Name: svn:executable
   + *

Added: arquillian/trunk/containers/tomcat-embedded-6/src/test/resources/arquillian.xml
===================================================================
--- arquillian/trunk/containers/tomcat-embedded-6/src/test/resources/arquillian.xml	                        (rev 0)
+++ arquillian/trunk/containers/tomcat-embedded-6/src/test/resources/arquillian.xml	2010-06-23 21:09:07 UTC (rev 4541)
@@ -0,0 +1,16 @@
+<?xml version="1.0"?>
+
+<arquillian xmlns="http://jboss.com/arquillian"
+		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+		xmlns:tomcat="urn:arq:org.jboss.arquillian.container.tomcat.embedded">
+
+	<tomcat:container>
+		<!--tomcat:tomcatHome>/home/deruelle/servers/apache-tomcat-6.0.20</tomcat:tomcatHome-->
+		<!--tomcat:tomcatHome>${env.CATALINA_HOME}</tomcat:tomcatHome-->
+		<tomcat:workDir>target/work</tomcat:workDir> 
+		<tomcat:appBase>target/webapps</tomcat:appBase> 
+		<tomcat:bindAddress>127.0.0.1</tomcat:bindAddress>
+		<tomcat:httpPort>8080</tomcat:httpPort>
+	</tomcat:container>	
+
+</arquillian>


Property changes on: arquillian/trunk/containers/tomcat-embedded-6/src/test/resources/arquillian.xml
___________________________________________________________________
Name: svn:executable
   + *

Added: arquillian/trunk/containers/tomcat-embedded-6/src/test/resources/org/jboss/arquillian/container/tomcat/embedded/test/war/web.xml
===================================================================
--- arquillian/trunk/containers/tomcat-embedded-6/src/test/resources/org/jboss/arquillian/container/tomcat/embedded/test/war/web.xml	                        (rev 0)
+++ arquillian/trunk/containers/tomcat-embedded-6/src/test/resources/org/jboss/arquillian/container/tomcat/embedded/test/war/web.xml	2010-06-23 21:09:07 UTC (rev 4541)
@@ -0,0 +1,13 @@
+<web-app xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http:/java.sun.com/dtd/web-app_2_3.dtd">
+  <servlet>
+    <servlet-name>hello</servlet-name>
+    <servlet-class>org.jboss.arquillian.container.tomcat.embedded.test.war.HelloWorldServlet</servlet-class>
+  </servlet>
+
+  <servlet-mapping>
+    <servlet-name>hello</servlet-name>
+    <url-pattern>/hello</url-pattern>
+  </servlet-mapping>
+</web-app>
\ No newline at end of file


Property changes on: arquillian/trunk/containers/tomcat-embedded-6/src/test/resources/org/jboss/arquillian/container/tomcat/embedded/test/war/web.xml
___________________________________________________________________
Name: svn:executable
   + *



More information about the jboss-svn-commits mailing list