[mielecloud] Run integration tests on random unoccupied port (#11448)

Signed-off-by: Björn Lange <bjoern.lange@tu-dortmund.de>
This commit is contained in:
Björn Lange 2021-10-25 14:02:16 +02:00 committed by GitHub
parent fbdecad174
commit a1f2e236e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 2 deletions

View File

@ -12,6 +12,8 @@ Fragment-Host: org.openhab.binding.mielecloud
bnd.identity;id='org.openhab.core.storage.json',\
bnd.identity;id='org.openhab.core.storage.mapdb'
-runvm: -Dorg.osgi.service.http.port=${org.osgi.service.http.port}
#
# done
#

View File

@ -22,4 +22,27 @@
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>reserve-network-port</id>
<goals>
<goal>reserve-network-port</goal>
</goals>
<phase>process-resources</phase>
<configuration>
<portNames>
<portName>org.osgi.service.http.port</portName>
</portNames>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -29,6 +29,7 @@ import org.openhab.binding.mielecloud.internal.util.AbstractConfigFlowTest;
import org.openhab.binding.mielecloud.internal.util.MieleCloudBindingIntegrationTestConstants;
import org.openhab.binding.mielecloud.internal.util.ReflectionUtil;
import org.openhab.binding.mielecloud.internal.util.Website;
import org.openhab.binding.mielecloud.internal.util.WebsiteCrawler;
import org.openhab.binding.mielecloud.internal.webservice.MieleWebservice;
import org.openhab.binding.mielecloud.internal.webservice.MieleWebserviceFactory;
import org.openhab.core.thing.Thing;
@ -87,7 +88,8 @@ public class ConfigFlowTest extends AbstractConfigFlowTest {
+ ForwardToLoginServlet.BRIDGE_ID_PARAMETER_NAME + "="
+ MieleCloudBindingIntegrationTestConstants.BRIDGE_ID + "&" + ForwardToLoginServlet.EMAIL_PARAMETER_NAME
+ "=" + MieleCloudBindingIntegrationTestConstants.EMAIL);
String redirectionUrl = mieleLoginSite.getValueOfInput("redirect_uri").replace("http://127.0.0.1:8080", "");
String redirectionUrl = mieleLoginSite.getValueOfInput("redirect_uri")
.replace("http://127.0.0.1:" + WebsiteCrawler.getServerPort(), "");
String state = mieleLoginSite.getValueOfInput("state");
Website resultSite = getCrawler().doGetRelative(redirectionUrl + "?code="

View File

@ -40,8 +40,16 @@ public final class WebsiteCrawler {
* @throws Exception if anything goes wrong.
*/
public Website doGetRelative(String relativeUrl) throws Exception {
ContentResponse response = httpClient.GET("http://127.0.0.1:8080" + relativeUrl);
ContentResponse response = httpClient.GET("http://127.0.0.1:" + getServerPort() + relativeUrl);
assertEquals(200, response.getStatus());
return new Website(response.getContentAsString());
}
/**
* Gets the port the webserver for this integration test instance is running on. The port is reserved in the pom.xml
* by the build-helper-maven-plugin.
*/
public static int getServerPort() {
return Integer.getInteger("org.osgi.service.http.port", 8080);
}
}