Skip to content

Commit

Permalink
Uses build-helper-maven-plugin to reserve unused ports, which are the…
Browse files Browse the repository at this point in the history
…n used in

the jetty-maven-plugin configuration and made available to test classes via the
system property "test.port".
  • Loading branch information
Edwin Shin committed Apr 11, 2013
1 parent a9aad0a commit 79658a6
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 17 deletions.
70 changes: 63 additions & 7 deletions fcrepo-webapp/pom.xml
Expand Up @@ -10,6 +10,11 @@
<artifactId>fcrepo-webapp</artifactId>
<packaging>war</packaging>
<name>fcrepo webapp</name>

<properties>
<!-- integration test properties -->
<test.context.path>/rest</test.context.path>
</properties>

<dependencies>
<dependency>
Expand Down Expand Up @@ -90,29 +95,80 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<test.port>${jetty.port}</test.port>
<test.context.path>${test.context.path}</test.context.path>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<configuration>
<portNames>
<portName>jetty.port</portName>
<portName>jetty.port.stop</portName>
</portNames>
</configuration>
<executions>
<execution>
<id>reserve-port</id>
<phase>pre-integration-test</phase>
<goals>
<goal>reserve-network-port</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.9.v20130131</version>
<configuration>
<scanIntervalSeconds>2</scanIntervalSeconds>
<webApp>
<contextPath>/</contextPath>
</webApp>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>${jetty.port}</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
<loginServices>
<loginService implementation="org.eclipse.jetty.security.HashLoginService">
<name>fcrepo</name>
<config>${project.build.directory}/test-classes/jetty-users.properties</config>
</loginService>
</loginServices>
<scanIntervalSeconds>2</scanIntervalSeconds>
<stopKey>STOP</stopKey>
<stopPort>${jetty.port.stop}</stopPort>
<webApp>
<contextPath>${test.context.path}</contextPath>
</webApp>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>stop</goal>
<goal>start</goal>
</goals>
<configuration>
<daemon>true</daemon>
<webAppSourceDirectory>${project.build.directory}/test-classes</webAppSourceDirectory>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
@@ -1,6 +1,11 @@
package org.fcrepo.integration;


import static org.junit.Assert.assertEquals;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
Expand All @@ -15,29 +20,34 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import static org.junit.Assert.assertEquals;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"/spring/repo.xml", "/spring/eventing.xml", "/spring/jms.xml", "/spring/generator.xml", "/spring-test/rest.xml"})
public class SanityCheckIT {

/**
* The server port of the application, set as system property by
* maven-failsafe-plugin.
*/
private static final String SERVER_PORT = System.getProperty("test.port");

/**
* The context path of the application (including the leading "/"), set as
* system property by maven-failsafe-plugin.
*/
private static final String CONTEXT_PATH = System
.getProperty("test.context.path");

protected Logger logger;

@Before
public void setLogger() {
logger = LoggerFactory.getLogger(this.getClass());
}

protected static final int SERVER_PORT = Integer.parseInt(System
.getProperty("test.port", "8080"));

protected static final String HOSTNAME = "localhost";

protected static final String serverAddress = "http://" + HOSTNAME + ":" +
SERVER_PORT + "/rest/";
SERVER_PORT + CONTEXT_PATH;

protected static final PoolingClientConnectionManager connectionManager =
new PoolingClientConnectionManager();
Expand All @@ -54,7 +64,7 @@ public void setLogger() {
@Test
public void doASanityCheck() throws IOException {
assertEquals(200, getStatus(new HttpGet(serverAddress +
"describe")));
"/describe")));
}


Expand Down
10 changes: 10 additions & 0 deletions pom.xml
Expand Up @@ -376,6 +376,11 @@
<artifactId>maven-enunciate-cxf-plugin</artifactId>
<version>1.26.2</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
Expand Down Expand Up @@ -438,6 +443,11 @@
</lifecycleMappingMetadata>
</configuration>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.10.v20130312</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
Expand Down

0 comments on commit 79658a6

Please sign in to comment.