Skip to content

Commit 0f456b8

Browse files
committed
Add profile 'wildfly-docker-maven'
This profile demonstrates the usage of a docker-maven-plugin for starting a Docker container for integration tests (without Arquillian). It has been tested with the example 'simple-servlet'. The image created contains the deployment artifact already which is copied to `/opt/wildfly/standalone/deployments` so no extra deployment step is required. To test it simply call: mvn -f servlet/simple-servlet/pom.xml -Pwildfly-docker-maven clean install (assuming your DOCKER_HOST variable is set properly). One can also build the image, start and stop it separately: mvn -f servlet/simple-servlet/pom.xml -Pwildfly-docker-maven package docker:build mvn -f servlet/simple-servlet/pom.xml -Pwildfly-docker-maven docker:start mvn -f servlet/simple-servlet/pom.xml -Pwildfly-docker-maven docker:stop It use dynamically assigned ports, so multiples test can be run in parallel.
1 parent 4c1ea37 commit 0f456b8

File tree

3 files changed

+146
-61
lines changed

3 files changed

+146
-61
lines changed

pom.xml

Lines changed: 93 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<java.min.version>1.7</java.min.version>
1313
<maven.min.version>3.0.0</maven.min.version>
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15-
<org.jboss.arquillian.version>1.1.1.Final</org.jboss.arquillian.version>
15+
<org.jboss.arquillian.version>1.1.7.Final</org.jboss.arquillian.version>
1616
<org.jboss.arquillian.drone.version>1.3.0.Final</org.jboss.arquillian.drone.version>
1717
<org.jboss.arquillian.selenium.bom.version>2.40.0</org.jboss.arquillian.selenium.bom.version>
1818
<org.jboss.arquillian.graphene.version>2.0.2.Final</org.jboss.arquillian.graphene.version>
@@ -729,7 +729,7 @@
729729
<arq.container.wildfly-docker.configuration.password>Admin#70365</arq.container.wildfly-docker.configuration.password>
730730
<arq.extension.docker.serverVersion>1.15</arq.extension.docker.serverVersion>
731731
<!--<arq.extension.docker.serverUri>http://192.168.59.103:2376</arq.extension.docker.serverUri>-->
732-
<arq.extension.docker.serverUri>http://127.0.0.1:2375</arq.extension.docker.serverUri>
732+
<arq.extension.docker.serverUri>http://boot2docker:2376</arq.extension.docker.serverUri>
733733
<arq.extension.docker.dockerContainers>
734734
wildfly-docker:
735735
image: arungupta/javaee7-samples-wildfly
@@ -747,70 +747,111 @@
747747
</build>
748748
</profile>
749749
<profile>
750-
<id>wildfly-docker-arquillian-maven</id>
750+
<id>wildfly-docker-maven</id>
751751
<properties>
752-
<browser>chromium-browser</browser>
753-
<serverProfile>standalone-full.xml</serverProfile>
754-
<serverRoot>${project.build.directory}/wildfly-${org.wildfly}</serverRoot>
752+
<docker.api.host>localhost</docker.api.host>
755753
</properties>
756-
<dependencies>
757-
<dependency>
758-
<groupId>org.arquillian.cube</groupId>
759-
<artifactId>arquillian-cube-docker</artifactId>
760-
<version>${org.jboss.arquillian.cube.version}</version>
761-
<scope>test</scope>
762-
</dependency>
763-
<dependency>
764-
<groupId>io.undertow</groupId>
765-
<artifactId>undertow-websockets-jsr</artifactId>
766-
<version>1.0.0.Beta25</version>
767-
<scope>test</scope>
768-
</dependency>
769-
<!-- <dependency>
770-
<groupId>org.jboss.resteasy</groupId>
771-
<artifactId>resteasy-client</artifactId>
772-
<version>3.0.5.Final</version>
773-
<scope>test</scope>
774-
</dependency>
775-
<dependency>
776-
<groupId>org.jboss.resteasy</groupId>
777-
<artifactId>resteasy-jaxb-provider</artifactId>
778-
<version>3.0.5.Final</version>
779-
<scope>test</scope>
780-
</dependency>
781-
<dependency>
782-
<groupId>org.jboss.resteasy</groupId>
783-
<artifactId>resteasy-json-p-provider</artifactId>
784-
<version>3.0.5.Final</version>
785-
<scope>test</scope>
786-
</dependency>-->
787-
<dependency>
788-
<groupId>org.wildfly</groupId>
789-
<artifactId>wildfly-arquillian-container-remote</artifactId>
790-
<version>${org.wildfly}</version>
791-
<scope>test</scope>
792-
</dependency>
793-
</dependencies>
794754
<build>
795-
<testResources>
796-
<testResource>
797-
<directory>src/test/resources</directory>
798-
<filtering>true</filtering>
799-
</testResource>
800-
</testResources>
801755
<plugins>
802756
<plugin>
803757
<groupId>org.jolokia</groupId>
804758
<artifactId>docker-maven-plugin</artifactId>
805-
<version>0.10.4</version>
759+
<version>0.11.3-SNAPSHOT</version>
806760
<configuration>
807761
<images>
808762
<image>
809-
<name>arungupta/wildfly-centos</name>
763+
<name>${project.groupId}/${project.artifactId}</name>
764+
<alias>wildfly</alias>
765+
<!-- How to build image with servlet included -->
766+
<build>
767+
<!-- Base image (aka "USE") -->
768+
<from>arungupta/javaee7-samples-wildfly</from>
769+
<!-- Exposed ports -->
770+
<ports>
771+
<port>8080</port>
772+
<port>9990</port>
773+
</ports>
774+
<!-- Describe what to put into the image with an assembly -->
775+
<assembly>
776+
<!-- The artefact will be copied there into the image -->
777+
<basedir>/opt/wildfly/standalone/deployments</basedir>
778+
<!-- Use the artifact (predefined descriptor) -->
779+
<descriptorRef>artifact</descriptorRef>
780+
</assembly>
781+
</build>
782+
<!-- How to run it for integration tests or "docker:start" and "docker:stop" -->
783+
<run>
784+
<ports>
785+
<!-- Dynamically let Docker choose ports, store them in ${wildfly.http.port}
786+
and ${wildfly.admin.port} -->
787+
<port>wildfly.http.port:8080</port>
788+
<port>wildfly.admin.port:9990</port>
789+
</ports>
790+
<wait>
791+
<!-- The plugin waits until this URL is reachable via HTTP ... -->
792+
<url>http://${docker.api.host}:${wildfly.http.port}</url>
793+
<!-- ... but at most 10 seconds -->
794+
<time>10000</time>
795+
</wait>
796+
</run>
810797
</image>
811798
</images>
812799
</configuration>
800+
<executions>
801+
<!-- Hook this plugin into pre- and post-integration tests -->
802+
<execution>
803+
<id>start</id>
804+
<phase>pre-integration-test</phase>
805+
<goals>
806+
<goal>build</goal>
807+
<goal>start</goal>
808+
</goals>
809+
</execution>
810+
<execution>
811+
<id>stop</id>
812+
<phase>post-integration-test</phase>
813+
<goals>
814+
<goal>stop</goal>
815+
</goals>
816+
</execution>
817+
</executions>
818+
</plugin>
819+
820+
<!-- Skip Arquillian Tests -->
821+
<plugin>
822+
<artifactId>maven-surefire-plugin</artifactId>
823+
<configuration>
824+
<skip>true</skip>
825+
</configuration>
813826
</plugin>
827+
828+
<plugin>
829+
<artifactId>maven-failsafe-plugin</artifactId>
830+
<version>2.18.1</version>
831+
<configuration>
832+
<systemPropertyVariables>
833+
<!-- In our example, since we use the "artifact" assembly descriptor ref, the WAR is
834+
called like the artifacto ("simple-servlet.war") and hence the webapp context is
835+
also the same -->
836+
<test.url>http://${docker.api.host}:${wildfly.http.port}/${project.artifactId}</test.url>
837+
</systemPropertyVariables>
838+
</configuration>
839+
<!-- Boilerplate for enablign the failsafe tests (test classes need to end with "IT") -->
840+
<executions>
841+
<execution>
842+
<id>integration-test</id>
843+
<goals>
844+
<goal>integration-test</goal>
845+
</goals>
846+
</execution>
847+
<execution>
848+
<id>verify</id>
849+
<goals>
850+
<goal>verify</goal>
851+
</goals>
852+
</execution>
853+
</executions>
854+
</plugin>
814855
</plugins>
815856
</build>
816857
</profile>

servlet/simple-servlet/src/test/java/org/javaee7/servlet/metadata/complete/SimpleServletTest.java renamed to servlet/simple-servlet/src/test/java/org/javaee7/servlet/metadata/complete/SimpleServletArquillianTest.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
package org.javaee7.servlet.metadata.complete;
22

3-
import org.javaee7.servlet.simple.SimpleServlet;
4-
import com.gargoylesoftware.htmlunit.HttpMethod;
5-
import com.gargoylesoftware.htmlunit.TextPage;
6-
import com.gargoylesoftware.htmlunit.WebClient;
7-
import com.gargoylesoftware.htmlunit.WebRequest;
8-
import java.io.File;
93
import java.io.IOException;
4+
import java.net.MalformedURLException;
105
import java.net.URL;
6+
7+
import com.gargoylesoftware.htmlunit.*;
8+
import org.javaee7.servlet.simple.SimpleServlet;
119
import org.jboss.arquillian.container.test.api.Deployment;
1210
import org.jboss.arquillian.junit.Arquillian;
1311
import org.jboss.arquillian.test.api.ArquillianResource;
1412
import org.jboss.shrinkwrap.api.ShrinkWrap;
1513
import org.jboss.shrinkwrap.api.spec.WebArchive;
16-
import static org.junit.Assert.*;
1714
import org.junit.Before;
1815
import org.junit.Test;
1916
import org.junit.runner.RunWith;
2017
import org.xml.sax.SAXException;
2118

19+
import static org.junit.Assert.assertEquals;
20+
2221
/**
2322
* @author Arun Gupta
2423
*/
2524
@RunWith(Arquillian.class)
26-
public class SimpleServletTest {
25+
public class SimpleServletArquillianTest {
2726

2827
@ArquillianResource
2928
private URL base;
@@ -38,8 +37,11 @@ public static WebArchive createDeployment() {
3837
}
3938

4039
@Before
41-
public void setup() {
40+
public void setup() throws MalformedURLException {
4241
webClient = new WebClient();
42+
if (base == null) {
43+
base = new URL(System.getProperty("test.url"));
44+
}
4345
}
4446

4547
@Test
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.javaee7.servlet.metadata.complete;
2+
3+
import java.io.IOException;
4+
import java.net.MalformedURLException;
5+
import java.net.URL;
6+
7+
import com.gargoylesoftware.htmlunit.*;
8+
import org.junit.Before;
9+
import org.junit.Test;
10+
import org.xml.sax.SAXException;
11+
12+
import static org.junit.Assert.assertEquals;
13+
14+
/**
15+
* @author Roland Huss
16+
*
17+
* Plain Test without any framework dependency accessing the test servlet directly.
18+
*/
19+
public class SimpleServletPlainIT {
20+
21+
private WebClient webClient;
22+
private URL base;
23+
24+
@Before
25+
public void setup() throws MalformedURLException {
26+
webClient = new WebClient();
27+
base = new URL(System.getProperty("test.url"));
28+
}
29+
30+
@Test
31+
public void testGet() throws IOException, SAXException {
32+
TextPage page = webClient.getPage(base + "/SimpleServlet");
33+
assertEquals("my GET", page.getContent());
34+
}
35+
36+
@Test
37+
public void testPost() throws IOException, SAXException {
38+
WebRequest request = new WebRequest(new URL(base + "/SimpleServlet"), HttpMethod.POST);
39+
TextPage page = webClient.getPage(request);
40+
assertEquals("my POST", page.getContent());
41+
}
42+
}

0 commit comments

Comments
 (0)