[jboss-svn-commits] JBoss Common SVN: r4406 - in arquillian/trunk/containers: jbossas-local-60 and 19 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sat May 22 11:12:45 EDT 2010
Author: aslak
Date: 2010-05-22 11:12:44 -0400 (Sat, 22 May 2010)
New Revision: 4406
Added:
arquillian/trunk/containers/jbossas-local-60/
arquillian/trunk/containers/jbossas-local-60/pom.xml
arquillian/trunk/containers/jbossas-local-60/src/
arquillian/trunk/containers/jbossas-local-60/src/main/
arquillian/trunk/containers/jbossas-local-60/src/main/java/
arquillian/trunk/containers/jbossas-local-60/src/main/java/org/
arquillian/trunk/containers/jbossas-local-60/src/main/java/org/jboss/
arquillian/trunk/containers/jbossas-local-60/src/main/java/org/jboss/arquillian/
arquillian/trunk/containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/
arquillian/trunk/containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/JBossASConfiguration.java
arquillian/trunk/containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/JBossASDeploymentAppender.java
arquillian/trunk/containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/JBossASLocalContainer.java
arquillian/trunk/containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/utils/
arquillian/trunk/containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/utils/AsLifecycleDelegate.java
arquillian/trunk/containers/jbossas-local-60/src/main/resources/
arquillian/trunk/containers/jbossas-local-60/src/main/resources/META-INF/
arquillian/trunk/containers/jbossas-local-60/src/main/resources/META-INF/services/
arquillian/trunk/containers/jbossas-local-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.AuxiliaryArchiveAppender
arquillian/trunk/containers/jbossas-local-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.ContainerConfiguration
arquillian/trunk/containers/jbossas-local-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer
arquillian/trunk/containers/jbossas-local-60/src/test/
arquillian/trunk/containers/jbossas-local-60/src/test/java/
arquillian/trunk/containers/jbossas-local-60/src/test/java/org/
arquillian/trunk/containers/jbossas-local-60/src/test/java/org/jboss/
arquillian/trunk/containers/jbossas-local-60/src/test/java/org/jboss/arquillian/
arquillian/trunk/containers/jbossas-local-60/src/test/java/org/jboss/arquillian/jboss/
arquillian/trunk/containers/jbossas-local-60/src/test/java/org/jboss/arquillian/jboss/JBossASIntegrationTestCase.java
arquillian/trunk/containers/jbossas-local-60/src/test/java/org/jboss/arquillian/jboss/ejb/
arquillian/trunk/containers/jbossas-local-60/src/test/java/org/jboss/arquillian/jboss/ejb/MyEjb.java
arquillian/trunk/containers/jbossas-local-60/src/test/resources/
arquillian/trunk/containers/jbossas-local-60/src/test/resources/arquillian.xml
Log:
ARQ-48 Added JBoss AS 6.0 Local container, supports starting and stopping the server. Use arquillian.xml or JBOSS_HOME to specify the location.
Property changes on: arquillian/trunk/containers/jbossas-local-60
___________________________________________________________________
Name: svn:ignore
+ .classpath
.project
.settings
target
Added: arquillian/trunk/containers/jbossas-local-60/pom.xml
===================================================================
--- arquillian/trunk/containers/jbossas-local-60/pom.xml (rev 0)
+++ arquillian/trunk/containers/jbossas-local-60/pom.xml 2010-05-22 15:12:44 UTC (rev 4406)
@@ -0,0 +1,150 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <!-- Parent -->
+ <parent>
+ <groupId>org.jboss.arquillian</groupId>
+ <artifactId>arquillian-build</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../../build/pom.xml</relativePath>
+ </parent>
+
+ <!-- Model Version -->
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- Artifact Configuration -->
+ <groupId>org.jboss.arquillian.container</groupId>
+ <artifactId>arquillian-jbossas-local-60</artifactId>
+ <name>Arquillian Container Jboss AS Local 6.0</name>
+ <description>Jboss AS 6.0 Local Container integration for the Arquillian Project</description>
+
+
+ <!-- Properties -->
+ <properties>
+
+ <!-- Versioning -->
+
+ </properties>
+
+ <!-- Dependencies -->
+ <dependencies>
+
+ <!--
+ org.jboss.arquillian
+ -->
+ <dependency>
+ <groupId>org.jboss.arquillian</groupId>
+ <artifactId>arquillian-spi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.arquillian.protocol</groupId>
+ <artifactId>arquillian-protocol-servlet-ee6</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.arquillian.packager</groupId>
+ <artifactId>arquillian-packager-javaee</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.arquillian.testenricher</groupId>
+ <artifactId>arquillian-testenricher-cdi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.arquillian.testenricher</groupId>
+ <artifactId>arquillian-testenricher-ejb</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.arquillian.testenricher</groupId>
+ <artifactId>arquillian-testenricher-resource</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <!--
+ org.jboss
+ -->
+
+ <dependency>
+ <groupId>org.jboss.jbossas</groupId>
+ <artifactId>jboss-server-manager</artifactId>
+ <version>1.0.3.GA</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.jbossas</groupId>
+ <artifactId>jboss-as-client</artifactId>
+ <type>pom</type>
+ <version>6.0.0.20100429-M3</version>
+ </dependency>
+
+
+ <!-- Testing -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-api</artifactId>
+ <version>3.1.0</version>
+ <scope>test</scope>
+ </dependency>
+ <!-- TODO: needed by the CDIInjectionEnricher, ShrinkWrap fail to package the AuxiliaryArchive without it -->
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <version>1.0-SP1</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.arquillian</groupId>
+ <artifactId>arquillian-junit</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+<!--
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>unpack</id>
+ <phase>process-test-classes</phase>
+ <goals>
+ <goal>unpack</goal>
+ </goals>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.jboss.jbossas</groupId>
+ <artifactId>jboss-as-distribution</artifactId>
+ <version>6.0.0.20100429-M3</version>
+ <type>zip</type>
+ <overWrite>false</overWrite>
+ <outputDirectory>${project.build.directory}</outputDirectory>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+-->
+
+</project>
+
Added: arquillian/trunk/containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/JBossASConfiguration.java
===================================================================
--- arquillian/trunk/containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/JBossASConfiguration.java (rev 0)
+++ arquillian/trunk/containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/JBossASConfiguration.java 2010-05-22 15:12:44 UTC (rev 4406)
@@ -0,0 +1,108 @@
+/*
+ * 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.jboss;
+
+import java.io.File;
+
+import org.jboss.arquillian.spi.ContainerConfiguration;
+import org.jboss.arquillian.spi.ContainerProfile;
+
+/**
+ * A {@link org.jboss.arquillian.spi.ContainerConfiguration} implementation for
+ * the JBoss AS container.
+ *
+ * @author <a href="mailto:german.escobarc at gmail.com">German Escobar</a>
+ * @version $Revision: $
+ */
+public class JBossASConfiguration implements ContainerConfiguration
+{
+ private String bindAddress = "localhost";
+
+ private int httpPort = 8080;
+
+ private String profileName = "default";
+
+ private String jbossHome = null;
+
+ private String javaHome = 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 String getProfileName()
+ {
+ return profileName;
+ }
+
+ public void setProfileName(String profileName)
+ {
+ this.profileName = profileName;
+ }
+
+ public void setJbossHome(String jbossHome)
+ {
+ this.jbossHome = jbossHome;
+ }
+
+ public String getJbossHome()
+ {
+ if(jbossHome != null)
+ {
+ return new File(jbossHome).getAbsolutePath();
+ }
+ return jbossHome;
+ }
+
+ public void setJavaHome(String javaHome)
+ {
+ this.javaHome = javaHome;
+ }
+
+ public String getJavaHome()
+ {
+ return javaHome;
+ }
+}
Added: arquillian/trunk/containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/JBossASDeploymentAppender.java
===================================================================
--- arquillian/trunk/containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/JBossASDeploymentAppender.java (rev 0)
+++ arquillian/trunk/containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/JBossASDeploymentAppender.java 2010-05-22 15:12:44 UTC (rev 4406)
@@ -0,0 +1,56 @@
+/*
+ * 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.jboss;
+
+import org.jboss.arquillian.spi.AuxiliaryArchiveAppender;
+import org.jboss.arquillian.spi.TestEnricher;
+import org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher;
+import org.jboss.arquillian.testenricher.ejb.EJBInjectionEnricher;
+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;
+
+/**
+ * EmbeddedDeploymentAppender
+ *
+ * Package the required dependencies needed by the Jboss Embedded Container plugin
+ * to run in container.
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class JBossASDeploymentAppender implements AuxiliaryArchiveAppender
+{
+
+ public Archive<?> createAuxiliaryArchive()
+ {
+ JavaArchive archive = ShrinkWrap.create("arquillian-jboss-testenrichers.jar", JavaArchive.class)
+ .addPackages(
+ true,
+ EJBInjectionEnricher.class.getPackage(),
+ ResourceInjectionEnricher.class.getPackage(),
+ CDIInjectionEnricher.class.getPackage())
+ .addServiceProvider(
+ TestEnricher.class,
+ EJBInjectionEnricher.class,
+ ResourceInjectionEnricher.class,
+ CDIInjectionEnricher.class);
+ return archive;
+ }
+
+}
Added: arquillian/trunk/containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/JBossASLocalContainer.java
===================================================================
--- arquillian/trunk/containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/JBossASLocalContainer.java (rev 0)
+++ arquillian/trunk/containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/JBossASLocalContainer.java 2010-05-22 15:12:44 UTC (rev 4406)
@@ -0,0 +1,357 @@
+/*
+ * 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.jboss;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.arquillian.jboss.utils.AsLifecycleDelegate;
+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.jbossas.servermanager.Server;
+import org.jboss.jbossas.servermanager.ServerController;
+import org.jboss.jbossas.servermanager.ServerManager;
+import org.jboss.logging.Logger;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.exporter.ZipExporter;
+
+/**
+ * JbossLocalContainer
+ *
+ * @author <a href="mailto:aamonten at gmail.com">Alejandro Montenegro</a>
+ * @version $Revision: $
+ */
+public class JBossASLocalContainer implements DeployableContainer
+{
+ private static Logger log = Logger.getLogger(JBossASLocalContainer.class);
+
+ private static AsLifecycleDelegate delegate;
+
+ protected Server server;
+
+ protected ServerManager manager;
+
+ private boolean wasStarted;
+
+ private final List<String> failedUndeployments = new ArrayList<String>();
+
+ private Boolean forceRestart = false;
+
+ private Integer shutdownDelay = 15000;
+
+ private Long bootTimeout = 240000L;
+
+ private String host = "localhost";
+
+ private int port = 8181;
+
+ private String profile = "default";
+
+ private JBossASConfiguration configuration;
+
+ public JBossASLocalContainer()
+ {
+
+ }
+
+ /* (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(JBossASConfiguration.class);
+ host = this.configuration.getBindAddress();
+ profile = this.configuration.getProfileName();
+ port = this.configuration.getHttpPort();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.spi.DeployableContainer#start(org.jboss.arquillian.spi.Context)
+ */
+ public void start(Context context) throws LifecycleException
+ {
+ try
+ {
+ startServerManager();
+ restartServer();
+ }
+ catch (IOException e)
+ {
+ throw new LifecycleException("Could not start remote container", 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)
+ {
+ stopServer();
+ }
+ }
+
+ /* (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 (manager == null || server == 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);
+
+ Exception failure = null;
+ try
+ {
+ server.deploy(file);
+ }
+ catch (Exception e)
+ {
+ throw new DeploymentException("Could not deploy " + deploymentName, e);
+ }
+ if (failure != null)
+ {
+ throw new DeploymentException("Failed to deploy " + deploymentName, failure);
+ }
+ try
+ {
+ return new ServletMethodExecutor(new URL(server.getHttpUrl().toExternalForm() + "/"));
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Could not create ContainerMethodExecutor", e);
+ }
+ }
+
+ /* (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");
+ }
+ File file = new File(archive.getName());
+ archive.as(ZipExporter.class).exportZip(file, true);
+ undeploy(file);
+ }
+
+ private void undeploy(File file) throws DeploymentException
+ {
+ try
+ {
+ server.undeploy(file);
+ }
+ catch (Exception e)
+ {
+ failedUndeployments.add(file.getName());
+ throw new DeploymentException("Could not undeploy " + file.getName(), e);
+ }
+ finally
+ {
+ file.delete();
+ }
+ }
+
+ private void removeFailedUnDeployments() throws IOException
+ {
+ List<String> remainingDeployments = new ArrayList<String>();
+ for (String name : failedUndeployments)
+ {
+
+ try
+ {
+ server.undeploy(new File(name));
+
+ }
+ catch (Exception e)
+ {
+ IOException ioe = new IOException();
+ ioe.initCause(e);
+ throw ioe;
+ }
+ }
+ if (remainingDeployments.size() > 0)
+ {
+ log.error("Failed to undeploy these artifacts: " + remainingDeployments);
+ }
+ failedUndeployments.clear();
+ }
+
+ protected void startServerManager()
+ {
+ manager = getDelegate().getServerManager();
+ server = new Server();
+ server.setName(profile);
+ server.setHttpPort(port);
+ server.setHost(host);
+
+ if(configuration.getJbossHome() != null)
+ {
+ manager.setJbossHome(configuration.getJbossHome());
+ }
+ if(configuration.getJavaHome() != null)
+ {
+ manager.setJavaHome(configuration.getJavaHome());
+ }
+
+ AsLifecycleDelegate.applyServerDefaults(server, manager);
+ }
+
+ protected void restartServer() throws IOException, LifecycleException
+ {
+ if (getForceRestart())
+ {
+ if (isServerUp())
+ {
+ log.info("Shutting down server as in force-restart mode");
+ stopServer();
+ try
+ {
+ Thread.sleep(getShutdownDelay());
+ }
+ catch (InterruptedException e)
+ {
+ Thread.currentThread().interrupt();
+ }
+ }
+ }
+ if (!isServerUp())
+ {
+ wasStarted = true;
+ startServer();
+ log.info("Starting server");
+ // Wait for server to come up
+ long timeoutTime = System.currentTimeMillis() + getServerBootTimeout();
+ boolean interrupted = false;
+ while (timeoutTime > System.currentTimeMillis())
+ {
+ if (isServerUp())
+ {
+ log.info("Started server");
+ return;
+ }
+ try
+ {
+ Thread.sleep(200);
+ }
+ catch (InterruptedException e)
+ {
+ interrupted = true;
+ }
+ }
+ if (interrupted)
+ {
+ Thread.currentThread().interrupt();
+ }
+ // If we got this far something went wrong
+ log.info("Unable to connect to server after " + getServerBootTimeout() + "ms, giving up!");
+ stopServer();
+ throw new IllegalStateException("Error connecting to server");
+ }
+ }
+
+ protected void stopServer() throws LifecycleException
+ {
+ try
+ {
+ getDelegate().stopJbossAs(profile);
+ }
+ catch (Throwable t)
+ {
+ throw new LifecycleException("could not stop local container", t);
+ }
+ }
+
+ private void startServer() throws LifecycleException
+ {
+ try
+ {
+ getDelegate().startJbossAs(profile);
+ }
+ catch (Throwable t)
+ {
+ throw new LifecycleException("could not start local container", t);
+ }
+ }
+
+ protected boolean isServerUp() throws IOException
+ {
+ return ServerController.isServerStarted(server);
+ }
+
+ protected synchronized static AsLifecycleDelegate getDelegate()
+ {
+ if (delegate == null)
+ {
+ delegate = new AsLifecycleDelegate();
+ }
+ return delegate;
+ }
+
+ protected String getHost()
+ {
+ return host;
+ }
+
+ protected Boolean getForceRestart()
+ {
+ return forceRestart;
+ }
+
+ protected Integer getShutdownDelay()
+ {
+ return shutdownDelay;
+ }
+
+ protected Long getServerBootTimeout()
+ {
+ return bootTimeout;
+ }
+
+ public int getPort()
+ {
+ return port;
+ }
+}
Added: arquillian/trunk/containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/utils/AsLifecycleDelegate.java
===================================================================
--- arquillian/trunk/containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/utils/AsLifecycleDelegate.java (rev 0)
+++ arquillian/trunk/containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/utils/AsLifecycleDelegate.java 2010-05-22 15:12:44 UTC (rev 4406)
@@ -0,0 +1,192 @@
+/*
+ * 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.jboss.utils;
+
+import org.jboss.jbossas.servermanager.Server;
+import org.jboss.jbossas.servermanager.ServerController;
+import org.jboss.jbossas.servermanager.ServerManager;
+import org.jboss.jbossas.servermanager.Argument;
+import org.jboss.jbossas.servermanager.Property;
+
+import java.io.File;
+
+/**
+ * @author <a href="mailto:amontenegro at ifitec.com">Alejandro Montenegro</a>
+ */
+public class AsLifecycleDelegate
+{
+
+ /*
+ * Environment Variables
+ */
+
+ private static final String ENV_VAR_JAVA_HOME = "JAVA_HOME";
+
+ private static final String ENV_VAR_JBOSS_HOME = "JBOSS_HOME";
+
+ /**
+ * The Configuration Name to use
+ *
+ * For this, "default" will suffice as we're only testing the
+ * start/stop of AS, not its full complement
+ */
+ public static final String SERVER_NAME_DEFAULT = "default";
+
+ private ServerManager serverManager;
+
+ /**
+ * Constructor
+ */
+ public AsLifecycleDelegate()
+ {
+ // Create and set a new ServerManager
+ ServerManager sm = new ServerManager();
+ applyServerManagerDefaults(sm);
+ this.setServerManager(sm);
+ }
+
+ /**
+ * Lifecycle Start
+ *
+ * Starts JBossASs
+ *
+ * @throws Throwable
+ */
+ public void startJbossAs(String serverName) throws Throwable
+ {
+ Server server = null;
+
+ // Get ServerManager
+ ServerManager manager = this.getServerManager();
+
+ try
+ {
+ server = manager.getServer(serverName);
+ }
+ catch (IllegalArgumentException e)
+ {
+ // Create the Server
+ server = new Server();
+ server.setName(serverName);
+
+ // Add a Server to the Manager with defaults
+ applyServerDefaults(server, manager);
+ }
+
+ // Start the Server
+ ServerController.startServer(server, manager);
+ }
+
+ /**
+ * Lifecycle Stop
+ *
+ * Stops JBossAS
+ *
+ * @throws Throwable
+ */
+ public void stopJbossAs(String serverName) throws Throwable
+ {
+ // Obtain the server
+ ServerManager manager = this.getServerManager();
+ Server server = manager.getServer(serverName);
+
+ // If started/running
+ if (ServerController.isServerStarted(server))
+ {
+ // Stop
+ ServerController.stopServer(server, manager);
+ }
+ }
+
+ /**
+ * Apply defaults to ServerManager
+ *
+ * @param manager the server manager to apply defaults to
+ * @return the server manager with applied defaults
+ */
+ public static ServerManager applyServerManagerDefaults(final ServerManager manager)
+ {
+ // Set JVM / JBOSS_HOME
+ manager.setJavaHome(getJavaHome());
+ manager.setJbossHome(getJbossHome());
+
+ // Set UDP group to use
+ // manager.setUdpGroup("241.34.53.227");
+
+ return manager;
+ }
+
+ /**
+ * Apply defaults to Server
+ *
+ * @param server the server to apply defaults to
+ * @return the Server with applied defaults
+ */
+ public static Server applyServerDefaults(final Server server, final ServerManager manager)
+ {
+ // add Server to manager
+ manager.addServer(server);
+
+ server.setUsername("admin");
+ server.setPassword("admin");
+ server.setPartition(Long.toHexString(System.currentTimeMillis()));
+
+ // Set server's JVM arguments
+ Argument arg = new Argument();
+ arg.setValue("-Xmx512m");
+ server.addJvmArg(arg);
+ arg = new Argument();
+ arg.setValue("-XX:MaxPermSize=128m");
+ server.addJvmArg(arg);
+
+ // Set server's system properties
+ Property prop = new Property();
+ prop.setKey("jbosstest.udp.ip_ttl");
+ prop.setValue("0");
+ server.addSysProperty(prop);
+ prop = new Property();
+ prop.setKey("java.endorsed.dirs");
+ prop.setValue(new File(manager.getJBossHome(), "lib/endorsed").getAbsolutePath());
+ server.addSysProperty(prop);
+
+ return server;
+ }
+
+ //----------------------------------------------------------------------------------||
+ // Internal Helper Methods ---------------------------------------------------------||
+ //----------------------------------------------------------------------------------||
+
+ public static String getJavaHome()
+ {
+ return System.getenv(ENV_VAR_JAVA_HOME);
+ }
+
+ public static String getJbossHome()
+ {
+ return System.getenv(ENV_VAR_JBOSS_HOME);
+ }
+
+ public ServerManager getServerManager()
+ {
+ return serverManager;
+ }
+
+ private void setServerManager(ServerManager manager)
+ {
+ this.serverManager = manager;
+ }
+}
Added: arquillian/trunk/containers/jbossas-local-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.AuxiliaryArchiveAppender
===================================================================
--- arquillian/trunk/containers/jbossas-local-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.AuxiliaryArchiveAppender (rev 0)
+++ arquillian/trunk/containers/jbossas-local-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.AuxiliaryArchiveAppender 2010-05-22 15:12:44 UTC (rev 4406)
@@ -0,0 +1 @@
+org.jboss.arquillian.jboss.JBossASDeploymentAppender
\ No newline at end of file
Added: arquillian/trunk/containers/jbossas-local-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.ContainerConfiguration
===================================================================
--- arquillian/trunk/containers/jbossas-local-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.ContainerConfiguration (rev 0)
+++ arquillian/trunk/containers/jbossas-local-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.ContainerConfiguration 2010-05-22 15:12:44 UTC (rev 4406)
@@ -0,0 +1 @@
+org.jboss.arquillian.jboss.JBossASConfiguration
\ No newline at end of file
Added: arquillian/trunk/containers/jbossas-local-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer
===================================================================
--- arquillian/trunk/containers/jbossas-local-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer (rev 0)
+++ arquillian/trunk/containers/jbossas-local-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer 2010-05-22 15:12:44 UTC (rev 4406)
@@ -0,0 +1 @@
+org.jboss.arquillian.jboss.JBossASLocalContainer
\ No newline at end of file
Added: arquillian/trunk/containers/jbossas-local-60/src/test/java/org/jboss/arquillian/jboss/JBossASIntegrationTestCase.java
===================================================================
--- arquillian/trunk/containers/jbossas-local-60/src/test/java/org/jboss/arquillian/jboss/JBossASIntegrationTestCase.java (rev 0)
+++ arquillian/trunk/containers/jbossas-local-60/src/test/java/org/jboss/arquillian/jboss/JBossASIntegrationTestCase.java 2010-05-22 15:12:44 UTC (rev 4406)
@@ -0,0 +1,61 @@
+/*
+ * 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.jboss;
+
+import javax.ejb.EJB;
+
+import junit.framework.Assert;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.jboss.ejb.MyEjb;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * JBossEmbeddedIntegrationTestCase
+ *
+ * @author <a href="mailto:aslak at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ at RunWith(Arquillian.class)
+public class JBossASIntegrationTestCase
+{
+ @Deployment
+ public static JavaArchive createDeployment() throws Exception
+ {
+ return ShrinkWrap.create("test.jar", JavaArchive.class)
+ .addClasses(
+ JBossASIntegrationTestCase.class,
+ MyEjb.class);
+ }
+
+ @EJB
+ private MyEjb instanceVariable;
+
+ @Test
+ public void shouldBeAbleToInjectEJBAsInstanceVariable() throws Exception
+ {
+ Assert.assertNotNull(
+ "Verify that the Bean has been injected",
+ instanceVariable);
+
+ Assert.assertEquals("aslak", instanceVariable.getName());
+ }
+}
Added: arquillian/trunk/containers/jbossas-local-60/src/test/java/org/jboss/arquillian/jboss/ejb/MyEjb.java
===================================================================
--- arquillian/trunk/containers/jbossas-local-60/src/test/java/org/jboss/arquillian/jboss/ejb/MyEjb.java (rev 0)
+++ arquillian/trunk/containers/jbossas-local-60/src/test/java/org/jboss/arquillian/jboss/ejb/MyEjb.java 2010-05-22 15:12:44 UTC (rev 4406)
@@ -0,0 +1,34 @@
+/*
+ * 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.jboss.ejb;
+
+import javax.ejb.Stateless;
+
+/**
+ * MyEjb
+ *
+ * @author <a href="mailto:aslak at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ at Stateless
+public class MyEjb
+{
+ public String getName()
+ {
+ return "aslak";
+ }
+}
Added: arquillian/trunk/containers/jbossas-local-60/src/test/resources/arquillian.xml
===================================================================
--- arquillian/trunk/containers/jbossas-local-60/src/test/resources/arquillian.xml (rev 0)
+++ arquillian/trunk/containers/jbossas-local-60/src/test/resources/arquillian.xml 2010-05-22 15:12:44 UTC (rev 4406)
@@ -0,0 +1,14 @@
+<?xml version="1.0"?>
+
+<arquillian xmlns="http://jboss.com/arquillian"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:jboss="urn:arq:org.jboss.arquillian.jboss">
+
+ <jboss:container>
+ <jbossHome>target/jboss-6.0.0.20100429-M3</jbossHome>
+ <!-- <javaHome>/usr/lib/jvm/java-6-openjdk</javaHome> Will default o JAVA_HOME-->
+ <bindAddress>127.0.0.1</bindAddress>
+ <httpPort>8080</httpPort> <!-- WARN: this is not the bind port, but connect port. Bind port must be set in jboss xml config -->
+ </jboss:container>
+
+</arquillian>
\ No newline at end of file
More information about the jboss-svn-commits
mailing list