I had a similar problem when I had several small servlets that started their integration phase at the same time, which became a problem because they were configured to use the same port. But thanks to build-helper-maven-plugin: reserve-network-port , you can get arbitrary port numbers that are available. Then I can create a URL containing http: // localhost: [port] / [servletname] , which feed into the Java test class.
Getting a random port :
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>1.7</version> <executions> <execution> <id>reserve-network-port</id> <goals> <goal>reserve-network-port</goal> </goals> <phase>pre-integration-test</phase> <configuration> <portNames> <portName>tomcat.http.port</portName> </portNames> </configuration> </execution> </executions>
Running tomcat with port
<plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat6-maven-plugin</artifactId> <configuration> <port>${tomcat.http.port}</port> <useTestClasspath>true</useTestClasspath> </configuration> .... </plugin>
Passing a URL into a Java Integration Test, which is run by a fail-safe plugin
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>2.12.3</version> .... <configuration> <systemPropertyVariables> <integration-test.url>http://localhost:${tomcat.http.port}/${project.build.finalName}/</integration-test.url> </systemPropertyVariables> </configuration> </plugin>
Java code
public class DownloadAreaIT { private static final String URL = System.getProperty("integration-test.url"); }
redsolo Sep 26 '12 at 19:44 2012-09-26 19:44
source share