Skip to content

Commit 402f12c

Browse files
authored
Always run HTTP server on random port in CachingHttpClientTest (#472)
This will prevent the test from failing whenever something else uses port 9090. Signed-off-by: Wouter Born <github@maindrain.net>
1 parent de0e268 commit 402f12c

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

custom-checks/checkstyle/pom.xml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,36 @@
7676
<scope>test</scope>
7777
</dependency>
7878
</dependencies>
79+
80+
<build>
81+
<plugins>
82+
<plugin>
83+
<groupId>org.codehaus.mojo</groupId>
84+
<artifactId>build-helper-maven-plugin</artifactId>
85+
<executions>
86+
<execution>
87+
<id>reserve-network-port</id>
88+
<goals>
89+
<goal>reserve-network-port</goal>
90+
</goals>
91+
<configuration>
92+
<portNames>
93+
<portName>http.port</portName>
94+
</portNames>
95+
</configuration>
96+
</execution>
97+
</executions>
98+
</plugin>
99+
<plugin>
100+
<groupId>org.apache.maven.plugins</groupId>
101+
<artifactId>maven-surefire-plugin</artifactId>
102+
<configuration>
103+
<systemPropertyVariables>
104+
<http.port>${http.port}</http.port>
105+
</systemPropertyVariables>
106+
</configuration>
107+
</plugin>
108+
</plugins>
109+
</build>
110+
79111
</project>

custom-checks/checkstyle/src/test/java/org/openhab/tools/analysis/utils/CachingHttpClientTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class CachingHttpClientTest {
5555

5656
private static final String PATH_TO_RESOURCE = "/found";
5757
private static final String PATH_TO_MISSING_RESOURCE = "/notFound";
58-
private static final int TEST_PORT = 9090;
58+
private static final int TEST_PORT = Integer.getInteger("http.port", 9090);
5959
private static final String TEST_HOST = "localhost";
6060
private static final int TEST_TIMEOUT = 1000;
6161
private static final String SERVER_RESPONSE = "content";

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,12 @@
253253
<version>3.4.0</version>
254254
</plugin>
255255

256+
<plugin>
257+
<groupId>org.codehaus.mojo</groupId>
258+
<artifactId>build-helper-maven-plugin</artifactId>
259+
<version>3.6.0</version>
260+
</plugin>
261+
256262
<plugin>
257263
<groupId>org.openhab.tools.sat</groupId>
258264
<artifactId>sat-plugin</artifactId>

0 commit comments

Comments
 (0)