Permalink
Browse files

[ARQ-1193] Add a showcase example for the Arquillian Server Daemon

  • Loading branch information...
1 parent 02eaafa commit d40bd45bd0aff8610040cb84e81f21b31f01c540 @ALRubinger ALRubinger committed Nov 13, 2012
View
@@ -0,0 +1,104 @@
+<?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">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.jboss.arquillian.showcase</groupId>
+ <artifactId>arquillian-showcase-parent</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../parent/pom.xml</relativePath>
+ </parent>
+
+ <artifactId>arquillian-showcase-daemon</artifactId>
+ <packaging>jar</packaging>
+ <name>Arquillian Showcase: Daemon</name>
+ <description>Examples that demonstrate how to test arbitrary code on a remote JVM using Arquillian Daemon</description>
+
+ <properties>
+ <version.org.jboss.arquillian.daemon>1.0.0.Alpha1</version.org.jboss.arquillian.daemon>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.arquillian.junit</groupId>
+ <artifactId>arquillian-junit-container</artifactId>
+ </dependency>
+ <!--
+ To run in remote mode and handle server lifecycle yourself,
+ use "arquillian-daemon-container-remote" and launch:
+
+ java -jar arquillian-daemon-main.jar [hostname] [port]
+
+ -->
+ <dependency>
+ <groupId>org.jboss.arquillian.daemon</groupId>
+ <artifactId>arquillian-daemon-container-managed</artifactId>
+ <version>${version.org.jboss.arquillian.daemon}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.arquillian.daemon</groupId>
+ <artifactId>arquillian-daemon-main</artifactId>
+ <version>${version.org.jboss.arquillian.daemon}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copyMain</id>
+ <phase>pre-integration-test</phase>
+ <goals>
+ <goal>copy</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${project.build.directory}</outputDirectory>
+ <overWriteReleases>false</overWriteReleases>
+ <overWriteSnapshots>false</overWriteSnapshots>
+ <overWriteIfNewer>true</overWriteIfNewer>
+ <stripVersion>true</stripVersion>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.jboss.arquillian.daemon</groupId>
+ <artifactId>arquillian-daemon-main</artifactId>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ <executions>
+ <execution>
+ <id>it</id>
+ <phase>integration-test</phase>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+<!--
+vi:ts=4:sw=4:expandtab:
+-->
+</project>
@@ -0,0 +1,30 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2012, 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 com.acme.daemon;
+
+/**
+ * Bean to discover the {@link ClassLoader} which loaded this class.
+ *
+ * @author <a href="mailto:alr@jboss.org">Andrew Lee Rubinger</a>
+ */
+public class ClassLoaderDiscoveryBean {
+
+ public String getClassLoader() {
+ return ClassLoaderDiscoveryBean.class.getClassLoader().getClass().getName();
+ }
+
+}
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2012, 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 com.acme.daemon;
+
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Ensures that this test was lanuched in a VM from the Arquillian Main Daemon
+ *
+ * @author <a href="mailto:alr@jboss.org">Andrew Lee Rubinger</a>
+ */
+@RunWith(Arquillian.class)
+public class DaemonTest {
+
+ private static final String NAME_SW_CLASSLOADER = "org.jboss.shrinkwrap.api.classloader.ShrinkWrapClassLoader";
+
+ @Deployment
+ public static JavaArchive createDeployment() {
+ final JavaArchive archive = ShrinkWrap.create(JavaArchive.class).addClass(ClassLoaderDiscoveryBean.class);
+ return archive;
+ }
+
+ /**
+ * Ensures we're tested in the context of the Arquillian Server Daemon by checking the loading CL of our test bean
+ * is a ShrinkWrap CL (relies on implementation internals, really, but proves that we were not launched by this
+ * current VM on the client side).
+ */
+ @Test
+ public void isExecutedInArquillianServerDaemon() {
+ final String classLoaderName = new ClassLoaderDiscoveryBean().getClassLoader();
+ System.out.println("Loading CL Name: " + classLoaderName);
+ Assert.assertEquals("Test was not executed via Arquillian Server Daemon Main Launcher", NAME_SW_CLASSLOADER,
+ classLoaderName);
+ }
+
+}
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<arquillian xmlns="http://jboss.org/schema/arquillian"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
+
+ <container qualifier="daemon" default="true">
+ <configuration>
+ <property name="host">localhost</property>
+ <property name="port">12345</property>
+ <property name="serverJarFile">target/arquillian-daemon-main.jar</property>
+ </configuration>
+ </container>
+</arquillian>
View
@@ -24,6 +24,7 @@
<module>ejb</module>
<module>ejb-testng</module>
<module>cdi-ejb</module>
+ <module>daemon</module>
<!-- jms only works on JBoss AS 6, add queue/test to server/default/deploy/hornetq/hornetq-jms.xml -->
<!--
<module>jms</module>

0 comments on commit d40bd45

Please sign in to comment.