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.mockito.ArgumentMatchers.any;
16 import static org.mockito.ArgumentMatchers.anyString;
17 import static org.mockito.ArgumentMatchers.eq;
18 import static org.mockito.ArgumentMatchers.same;
19 import static org.mockito.Mockito.mock;
20 import static org.mockito.Mockito.verify;
21 import static org.mockito.Mockito.when;
23 import java.util.concurrent.ExecutionException;
24 import java.util.concurrent.TimeoutException;
26 import org.eclipse.jdt.annotation.NonNullByDefault;
27 import org.eclipse.jdt.annotation.Nullable;
28 import org.eclipse.jetty.client.api.Request;
29 import org.eclipse.jetty.http.HttpMethod;
30 import org.junit.jupiter.api.BeforeEach;
31 import org.junit.jupiter.api.Test;
32 import org.openhab.binding.boschshc.internal.services.intrusion.actions.arm.dto.ArmActionRequest;
33 import org.openhab.core.thing.Bridge;
36 * Unit tests for the {@link BridgeHandler}.
38 * @author David Pace - Initial contribution
42 class BridgeHandlerTest {
45 private BridgeHandler fixture;
48 private BoschHttpClient httpClient;
52 Bridge bridge = mock(Bridge.class);
53 fixture = new BridgeHandler(bridge);
54 httpClient = mock(BoschHttpClient.class);
55 fixture.httpClient = httpClient;
59 void postAction() throws InterruptedException, TimeoutException, ExecutionException {
60 String endpoint = "/intrusion/actions/arm";
61 String url = "https://127.0.0.1:8444/smarthome/intrusion/actions/arm";
62 when(httpClient.getBoschSmartHomeUrl(endpoint)).thenReturn(url);
63 Request mockRequest = mock(Request.class);
64 when(httpClient.createRequest(anyString(), any(), any())).thenReturn(mockRequest);
65 ArmActionRequest request = new ArmActionRequest();
66 request.profileId = "0";
68 fixture.postAction(endpoint, request);
69 verify(httpClient).createRequest(eq(url), same(HttpMethod.POST), same(request));
70 verify(mockRequest).send();