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.boschshc.internal.devices.bridge;
15 import static org.junit.jupiter.api.Assertions.*;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.eclipse.jetty.client.api.Request;
20 import org.eclipse.jetty.http.HttpMethod;
21 import org.eclipse.jetty.util.ssl.SslContextFactory;
22 import org.junit.jupiter.api.BeforeAll;
23 import org.junit.jupiter.api.BeforeEach;
24 import org.junit.jupiter.api.Test;
25 import org.openhab.binding.boschshc.internal.devices.bridge.dto.SubscribeResult;
26 import org.openhab.binding.boschshc.internal.exceptions.PairingFailedException;
29 * Tests cases for {@link BoschHttpClient}.
31 * @author Gerd Zanker - Initial contribution
34 class BoschHttpClientTest {
37 private BoschHttpClient httpClient;
40 static void beforeAll() {
41 BoschSslUtilTest.prepareTempFolderForKeyStore();
45 void beforeEach() throws PairingFailedException {
46 SslContextFactory sslFactory = new BoschSslUtil("127.0.0.1").getSslContextFactory();
47 httpClient = new BoschHttpClient("127.0.0.1", "dummy", sslFactory);
48 assertNotNull(httpClient);
52 void getPublicInformationUrl() {
53 assertEquals("https://127.0.0.1:8446/smarthome/public/information", httpClient.getPublicInformationUrl());
57 void getPairingUrl() {
58 assertEquals("https://127.0.0.1:8443/smarthome/clients", httpClient.getPairingUrl());
62 void getBoschShcUrl() {
63 assertEquals("https://127.0.0.1:8444/testEndpoint", httpClient.getBoschShcUrl("testEndpoint"));
67 void getBoschSmartHomeUrl() {
68 assertEquals("https://127.0.0.1:8444/smarthome/endpointForTest",
69 httpClient.getBoschSmartHomeUrl("endpointForTest"));
73 void getServiceUrl() {
74 assertEquals("https://127.0.0.1:8444/smarthome/devices/testDevice/services/testService",
75 httpClient.getServiceUrl("testService", "testDevice"));
79 void getServiceStateUrl() {
80 assertEquals("https://127.0.0.1:8444/smarthome/devices/testDevice/services/testService/state",
81 httpClient.getServiceStateUrl("testService", "testDevice"));
85 void isAccessPossible() throws InterruptedException {
86 assertFalse(httpClient.isAccessPossible());
90 void isOnline() throws InterruptedException {
91 assertFalse(httpClient.isOnline());
95 void doPairing() throws InterruptedException {
96 assertFalse(httpClient.doPairing());
100 void createRequest() {
101 Request request = httpClient.createRequest("https://127.0.0.1", HttpMethod.GET);
102 assertNotNull(request);
106 void createRequestWithObject() {
107 Request request = httpClient.createRequest("https://127.0.0.1", HttpMethod.GET, "someData");
108 assertNotNull(request);
113 Request request = httpClient.createRequest("https://127.0.0.1", HttpMethod.GET);
114 // Null pointer exception is expected, because localhost will not answer request
115 assertThrows(NullPointerException.class, () -> {
116 httpClient.sendRequest(request, SubscribeResult.class, SubscribeResult::isValid, null);