Property changes on: containers/jbossas-local-60 ___________________________________________________________________ Added: svn:ignore + .classpath .project target Index: containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/JBossConfiguration.java =================================================================== --- containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/JBossConfiguration.java (revision 0) +++ containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/JBossConfiguration.java (revision 0) @@ -0,0 +1,72 @@ +/* + * 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.ContainerConfiguration; +import org.jboss.arquillian.spi.ContainerProfile; + +/** + * A {@link org.jboss.arquillian.spi.ContainerConfiguration} implementation for + * the JBoss AS container. + * + * @author German Escobar + * @version $Revision: $ + */ +public class JBossConfiguration implements ContainerConfiguration +{ + private String bindAddress = "localhost"; + + private int bindPort = 8181; + + private String profileName = "default"; + + public ContainerProfile getContainerProfile() + { + return ContainerProfile.CLIENT; + } + + public String getBindAddress() + { + return bindAddress; + } + + public void setBindAddress(String bindAddress) + { + this.bindAddress = bindAddress; + } + + public int getBindPort() + { + return bindPort; + } + + public void setBindPort(int bindPort) + { + this.bindPort = bindPort; + } + + public String getProfileName() + { + return profileName; + } + + public void setProfileName(String profileName) + { + this.profileName = profileName; + } + +} Property changes on: containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/JBossConfiguration.java ___________________________________________________________________ Added: svn:eol-style + native Index: containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/utils/AsLifecycleDelegate.java =================================================================== --- containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/utils/AsLifecycleDelegate.java (revision 0) +++ containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/utils/AsLifecycleDelegate.java (revision 0) @@ -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 Alejandro Montenegro + */ +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; + } +} Property changes on: containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/utils/AsLifecycleDelegate.java ___________________________________________________________________ Added: svn:eol-style + native Index: containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/JbossLocalContainer.java =================================================================== --- containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/JbossLocalContainer.java (revision 0) +++ containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/JbossLocalContainer.java (revision 0) @@ -0,0 +1,274 @@ +/* + * 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 javax.naming.InitialContext; +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 Alejandro Montenegro + * @version $Revision: $ + */ +public class JbossLocalContainer implements DeployableContainer { + + private static Logger log = Logger.getLogger(JbossLocalContainer.class); + + private static AsLifecycleDelegate delegate; + protected Server server; + protected ServerManager manager; + private boolean wasStarted; + + private final List failedUndeployments = new ArrayList(); + + private Boolean forceRestart = false; + private Integer shutdownDelay = 15000; + private Long bootTimeout = 240000L; + private String host = "localhost"; + private String profile = "default"; + + private JBossConfiguration configuration; + + public JbossLocalContainer() { + + } + + @Override + public void setup(Context context, Configuration configuration) { + this.configuration = configuration.getContainerConfig(JBossConfiguration.class); + host = this.configuration.getBindAddress(); + profile = this.configuration.getProfileName(); + } + + @Override + public void start(Context context) throws LifecycleException { + + try { + startServerManager(); + restartServer(); + } catch (IOException e) { + throw new LifecycleException("Could not start remote container", e); + } + } + + @Override + public void stop(Context context) throws LifecycleException { + try { + removeFailedUnDeployments(); + } catch (Exception e) { + throw new LifecycleException("Could not clean up", e); + } + if (wasStarted) { + stopServer(); + } + } + + @Override + 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( + "http", + findRemoteServerHostAddress(), + 8080, + "/")); + } catch (Exception e) { + throw new RuntimeException("Could not create ContainerMethodExecutor", e); + } + } + + @Override + 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); + } + } + + private void removeFailedUnDeployments() throws IOException { + List remainingDeployments = new ArrayList(); + 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(); + } + + private String findRemoteServerHostAddress() { + try { + String providerURL = (String) new InitialContext().getEnvironment().get( + InitialContext.PROVIDER_URL); + + return providerURL.substring(0, providerURL.indexOf(":")); + } catch (Exception e) { + throw new RuntimeException("Could not determine host address", e); + } + } + + protected void startServerManager() { + manager = getDelegate().getServerManager(); + server = new Server(); + server.setName(profile); + 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"); + } + } + + private void startServer() throws LifecycleException { + try { + + getDelegate().startJbossAs(profile); + } catch (Throwable t) { + throw new LifecycleException("could not start local container"); + } + } + + 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; + } +} Property changes on: containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/JbossLocalContainer.java ___________________________________________________________________ Added: svn:eol-style + native Index: containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/JbossDeploymentAppender.java =================================================================== --- containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/JbossDeploymentAppender.java (revision 0) +++ containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/JbossDeploymentAppender.java (revision 0) @@ -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 Aslak Knutsen + * @version $Revision: $ + */ +public class JbossDeploymentAppender 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; + } + +} Property changes on: containers/jbossas-local-60/src/main/java/org/jboss/arquillian/jboss/JbossDeploymentAppender.java ___________________________________________________________________ Added: svn:eol-style + native Index: containers/jbossas-local-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.AuxiliaryArchiveAppender =================================================================== --- containers/jbossas-local-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.AuxiliaryArchiveAppender (revision 0) +++ containers/jbossas-local-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.AuxiliaryArchiveAppender (revision 0) @@ -0,0 +1 @@ +org.jboss.arquillian.jboss.JbossDeploymentAppender \ No newline at end of file Property changes on: containers/jbossas-local-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.AuxiliaryArchiveAppender ___________________________________________________________________ Added: svn:eol-style + native Index: containers/jbossas-local-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.ContainerConfiguration =================================================================== --- containers/jbossas-local-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.ContainerConfiguration (revision 0) +++ containers/jbossas-local-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.ContainerConfiguration (revision 0) @@ -0,0 +1 @@ +org.jboss.arquillian.jboss.JBossConfiguration \ No newline at end of file Property changes on: containers/jbossas-local-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.ContainerConfiguration ___________________________________________________________________ Added: svn:eol-style + native Index: containers/jbossas-local-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer =================================================================== --- containers/jbossas-local-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer (revision 0) +++ containers/jbossas-local-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer (revision 0) @@ -0,0 +1 @@ +org.jboss.arquillian.jboss.JbossLocalContainer \ No newline at end of file Property changes on: containers/jbossas-local-60/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer ___________________________________________________________________ Added: svn:eol-style + native Index: containers/jbossas-local-60/pom.xml =================================================================== --- containers/jbossas-local-60/pom.xml (revision 0) +++ containers/jbossas-local-60/pom.xml (revision 0) @@ -0,0 +1,86 @@ + + + + + + org.jboss.arquillian + arquillian-build + 1.0.0-SNAPSHOT + ../../build/pom.xml + + + + 4.0.0 + + + org.jboss.arquillian.container + arquillian-jbossas-local-60 + Arquillian Container Jboss AS Local 6.0 + Jboss AS 6.0 Local Container integration for the Arquillian Project + + + + + + + + + + + + + + + org.jboss.arquillian + arquillian-spi + ${project.version} + + + org.jboss.arquillian.protocol + arquillian-protocol-servlet + ${project.version} + + + + org.jboss.arquillian.packager + arquillian-packager-javaee + ${project.version} + + + + org.jboss.arquillian.testenricher + arquillian-testenricher-cdi + ${project.version} + + + org.jboss.arquillian.testenricher + arquillian-testenricher-ejb + ${project.version} + + + org.jboss.arquillian.testenricher + arquillian-testenricher-resource + ${project.version} + + + + + + org.jboss.jbossas + jboss-as-client + pom + 6.0.0.20100429-M3 + + + org.jboss.jbossas + jboss-server-manager + 1.0.3.GA + + + + Property changes on: containers/jbossas-local-60/pom.xml ___________________________________________________________________ Added: svn:eol-style + native Property changes on: containers/jbossas-local-51 ___________________________________________________________________ Added: svn:ignore + .classpath .project target Index: containers/jbossas-local-51/src/main/java/org/jboss/arquillian/jboss/JBossConfiguration.java =================================================================== --- containers/jbossas-local-51/src/main/java/org/jboss/arquillian/jboss/JBossConfiguration.java (revision 0) +++ containers/jbossas-local-51/src/main/java/org/jboss/arquillian/jboss/JBossConfiguration.java (revision 0) @@ -0,0 +1,72 @@ +/* + * 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.ContainerConfiguration; +import org.jboss.arquillian.spi.ContainerProfile; + +/** + * A {@link org.jboss.arquillian.spi.ContainerConfiguration} implementation for + * the JBoss AS container. + * + * @author German Escobar + * @version $Revision: $ + */ +public class JBossConfiguration implements ContainerConfiguration +{ + private String bindAddress = "localhost"; + + private int bindPort = 8181; + + private String profileName = "default"; + + public ContainerProfile getContainerProfile() + { + return ContainerProfile.CLIENT; + } + + public String getBindAddress() + { + return bindAddress; + } + + public void setBindAddress(String bindAddress) + { + this.bindAddress = bindAddress; + } + + public int getBindPort() + { + return bindPort; + } + + public void setBindPort(int bindPort) + { + this.bindPort = bindPort; + } + + public String getProfileName() + { + return profileName; + } + + public void setProfileName(String profileName) + { + this.profileName = profileName; + } + +} Property changes on: containers/jbossas-local-51/src/main/java/org/jboss/arquillian/jboss/JBossConfiguration.java ___________________________________________________________________ Added: svn:eol-style + native Index: containers/jbossas-local-51/src/main/java/org/jboss/arquillian/jboss/utils/AsLifecycleDelegate.java =================================================================== --- containers/jbossas-local-51/src/main/java/org/jboss/arquillian/jboss/utils/AsLifecycleDelegate.java (revision 0) +++ containers/jbossas-local-51/src/main/java/org/jboss/arquillian/jboss/utils/AsLifecycleDelegate.java (revision 0) @@ -0,0 +1,184 @@ +/* + * 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 Alejandro Montenegro + */ +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"; + + 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; + } +} Property changes on: containers/jbossas-local-51/src/main/java/org/jboss/arquillian/jboss/utils/AsLifecycleDelegate.java ___________________________________________________________________ Added: svn:eol-style + native Index: containers/jbossas-local-51/src/main/java/org/jboss/arquillian/jboss/JbossLocalContainer.java =================================================================== --- containers/jbossas-local-51/src/main/java/org/jboss/arquillian/jboss/JbossLocalContainer.java (revision 0) +++ containers/jbossas-local-51/src/main/java/org/jboss/arquillian/jboss/JbossLocalContainer.java (revision 0) @@ -0,0 +1,280 @@ +/* + * 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 javax.naming.InitialContext; +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 Alejandro Montenegro + * @version $Revision: $ + */ +public class JbossLocalContainer implements DeployableContainer { + + private static Logger log = Logger.getLogger(JbossLocalContainer.class); + + private static AsLifecycleDelegate delegate; + protected Server server; + protected ServerManager manager; + private boolean wasStarted; + + private final List failedUndeployments = new ArrayList(); + + private boolean forceRestart = false; + private int shutdownDelay = 15000; + private int bootTimeout = 240000; + private String host = "localhost"; + private String profile = "default"; + private int port = 8080; + + private JBossConfiguration configuration; + + public JbossLocalContainer() { + + } + + @Override + public void setup(Context context, Configuration configuration) { + this.configuration = configuration.getContainerConfig(JBossConfiguration.class); + host = this.configuration.getBindAddress(); + profile = this.configuration.getProfileName(); + port = this.configuration.getBindPort(); + } + + @Override + public void start(Context context) throws LifecycleException { + + try { + startServerManager(); + restartServer(); + } catch (IOException e) { + throw new LifecycleException("Could not start local container", e); + } + } + + @Override + public void stop(Context context) throws LifecycleException { + try { + removeFailedUnDeployments(); + } catch (Exception e) { + throw new LifecycleException("Could not clean up", e); + } + if (wasStarted) { + stopServer(); + } + } + + @Override + 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( + "http", + findRemoteServerHostAddress(), + 8080, + "/")); + } catch (Exception e) { + throw new RuntimeException("Could not create ContainerMethodExecutor", e); + } + } + + @Override + 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); + } + } + + private void removeFailedUnDeployments() throws IOException { + List remainingDeployments = new ArrayList(); + 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(); + } + + private String findRemoteServerHostAddress() { + try { + String providerURL = (String) new InitialContext().getEnvironment().get( + InitialContext.PROVIDER_URL); + + return providerURL.substring(0, providerURL.indexOf(":")); + } catch (Exception e) { + throw new RuntimeException("Could not determine host address", e); + } + } + + protected void startServerManager() { + manager = getDelegate().getServerManager(); + server = new Server(); + server.setName(profile); + 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"); + } + } + + private void startServer() throws LifecycleException { + try { + + getDelegate().startJbossAs(profile); + } catch (Throwable t) { + throw new LifecycleException("could not start local container"); + } + } + + 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 int getShutdownDelay() { + return shutdownDelay; + } + + protected int getServerBootTimeout() { + return bootTimeout; + } + + protected int getPort(){ + return port; + } +} Property changes on: containers/jbossas-local-51/src/main/java/org/jboss/arquillian/jboss/JbossLocalContainer.java ___________________________________________________________________ Added: svn:eol-style + native Index: containers/jbossas-local-51/src/main/java/org/jboss/arquillian/jboss/JbossDeploymentAppender.java =================================================================== --- containers/jbossas-local-51/src/main/java/org/jboss/arquillian/jboss/JbossDeploymentAppender.java (revision 0) +++ containers/jbossas-local-51/src/main/java/org/jboss/arquillian/jboss/JbossDeploymentAppender.java (revision 0) @@ -0,0 +1,53 @@ +/* + * 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.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 Aslak Knutsen + * @version $Revision: $ + */ +public class JbossDeploymentAppender implements AuxiliaryArchiveAppender +{ + + public Archive createAuxiliaryArchive() + { + JavaArchive archive = ShrinkWrap.create("arquillian-jboss-testenrichers.jar", JavaArchive.class) + .addPackages( + true, + EJBInjectionEnricher.class.getPackage(), + ResourceInjectionEnricher.class.getPackage()) + .addServiceProvider( + TestEnricher.class, + EJBInjectionEnricher.class, + ResourceInjectionEnricher.class); + return archive; + } + +} Property changes on: containers/jbossas-local-51/src/main/java/org/jboss/arquillian/jboss/JbossDeploymentAppender.java ___________________________________________________________________ Added: svn:eol-style + native Index: containers/jbossas-local-51/src/main/resources/META-INF/services/org.jboss.arquillian.spi.AuxiliaryArchiveAppender =================================================================== --- containers/jbossas-local-51/src/main/resources/META-INF/services/org.jboss.arquillian.spi.AuxiliaryArchiveAppender (revision 0) +++ containers/jbossas-local-51/src/main/resources/META-INF/services/org.jboss.arquillian.spi.AuxiliaryArchiveAppender (revision 0) @@ -0,0 +1 @@ +org.jboss.arquillian.jboss.JbossDeploymentAppender \ No newline at end of file Property changes on: containers/jbossas-local-51/src/main/resources/META-INF/services/org.jboss.arquillian.spi.AuxiliaryArchiveAppender ___________________________________________________________________ Added: svn:eol-style + native Index: containers/jbossas-local-51/src/main/resources/META-INF/services/org.jboss.arquillian.spi.ContainerConfiguration =================================================================== --- containers/jbossas-local-51/src/main/resources/META-INF/services/org.jboss.arquillian.spi.ContainerConfiguration (revision 0) +++ containers/jbossas-local-51/src/main/resources/META-INF/services/org.jboss.arquillian.spi.ContainerConfiguration (revision 0) @@ -0,0 +1 @@ +org.jboss.arquillian.jboss.JBossConfiguration \ No newline at end of file Property changes on: containers/jbossas-local-51/src/main/resources/META-INF/services/org.jboss.arquillian.spi.ContainerConfiguration ___________________________________________________________________ Added: svn:eol-style + native Index: containers/jbossas-local-51/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer =================================================================== --- containers/jbossas-local-51/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer (revision 0) +++ containers/jbossas-local-51/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer (revision 0) @@ -0,0 +1 @@ +org.jboss.arquillian.jboss.JbossLocalContainer \ No newline at end of file Property changes on: containers/jbossas-local-51/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer ___________________________________________________________________ Added: svn:eol-style + native Index: containers/jbossas-local-51/pom.xml =================================================================== --- containers/jbossas-local-51/pom.xml (revision 0) +++ containers/jbossas-local-51/pom.xml (revision 0) @@ -0,0 +1,94 @@ + + + + + + org.jboss.arquillian + arquillian-build + 1.0.0-SNAPSHOT + ../../build/pom.xml + + + + 4.0.0 + + + org.jboss.arquillian.container + arquillian-jbossas-local-51 + Arquillian Container Jboss AS Local 5.1 + Jboss AS 5.1 Local Container integration for the Arquillian Project + + + + + + + + + + + + + + + org.jboss.arquillian + arquillian-spi + ${project.version} + + + org.jboss.arquillian.protocol + arquillian-protocol-servlet + ${project.version} + + + + org.jboss.arquillian.packager + arquillian-packager-javaee + ${project.version} + + + + org.jboss.arquillian.testenricher + arquillian-testenricher-ejb + ${project.version} + + + org.jboss.arquillian.testenricher + arquillian-testenricher-resource + ${project.version} + + + + + + org.jboss.jbossas + jboss-as-client + pom + 5.1.0.GA + + + org.jboss.jbossas + jboss-server-manager + 1.0.3.GA + + + + + + Property changes on: containers/jbossas-local-51/pom.xml ___________________________________________________________________ Added: svn:eol-style + native Index: containers/pom.xml =================================================================== --- containers/pom.xml (revision 4401) +++ containers/pom.xml (working copy) @@ -1,9 +1,7 @@ - +--> @@ -29,8 +27,9 @@ jbossas-remote-51 jbossas-remote-60 + jbossas-local-51 + jbossas-local-60 jbossas-embedded-60 - glassfish-embedded-30 weld-embedded openejb @@ -38,4 +37,4 @@ openwebbeans-embedded - + \ No newline at end of file