]> git.basschouten.com Git - openhab-addons.git/commitdiff
[mielecloud] Run integration tests on random unoccupied port (#11448)
authorBjörn Lange <bjoern.lange@udo.edu>
Mon, 25 Oct 2021 12:02:16 +0000 (14:02 +0200)
committerGitHub <noreply@github.com>
Mon, 25 Oct 2021 12:02:16 +0000 (14:02 +0200)
Signed-off-by: Björn Lange <bjoern.lange@tu-dortmund.de>
itests/org.openhab.binding.mielecloud.tests/itest.bndrun
itests/org.openhab.binding.mielecloud.tests/pom.xml
itests/org.openhab.binding.mielecloud.tests/src/main/java/org/openhab/binding/mielecloud/internal/config/ConfigFlowTest.java
itests/org.openhab.binding.mielecloud.tests/src/main/java/org/openhab/binding/mielecloud/internal/util/WebsiteCrawler.java

index 47773da6de74d5caa355784bb71603a16b7055cb..0fa85e225e0a59cb8eae09f536d09fa4bc2e5ae4 100644 (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
 #
index a21efcf275a76053265b44a41687dddc2cbc2a1d..bc399d0d5a9e5c5897d4223592967043d295ea0c 100644 (file)
     </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>
index 70f545ca9b4a62e24850b9d747a0dff2db378460..ecb396aef4016d96a040e00977476e89dce3859c 100644 (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="
index 50ab0ccaafbea1cf6e83160139d289962bfcf9df..c2801d792795a5340e4f46f1891ff5b849015d59 100644 (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);
+    }
 }