2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.mielecloud.internal.util;
15 import static org.junit.jupiter.api.Assertions.assertEquals;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jetty.client.HttpClient;
19 import org.eclipse.jetty.client.api.ContentResponse;
20 import org.openhab.core.io.net.http.HttpClientFactory;
23 * Allows for requesting website content from URLs.
25 * @author Björn Lange - Initial Contribution
28 public final class WebsiteCrawler {
29 private HttpClient httpClient;
31 public WebsiteCrawler(HttpClientFactory httpClientFactory) {
32 this.httpClient = httpClientFactory.getCommonHttpClient();
36 * Gets a website relative to the address of the openHAB installation running in test mode during integration tests.
38 * @param relativeUrl The relative URL.
39 * @return The website.
40 * @throws Exception if anything goes wrong.
42 public Website doGetRelative(String relativeUrl) throws Exception {
43 ContentResponse response = httpClient.GET("http://127.0.0.1:" + getServerPort() + relativeUrl);
44 assertEquals(200, response.getStatus());
45 return new Website(response.getContentAsString());
49 * Gets the port the webserver for this integration test instance is running on. The port is reserved in the pom.xml
50 * by the build-helper-maven-plugin.
52 public static int getServerPort() {
53 return Integer.getInteger("org.osgi.service.http.port", 8080);