]> git.basschouten.com Git - openhab-addons.git/blob
3c61340c1fa64ef8af8603563d775cbdd6791ca2
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.boschshc.internal.devices.bridge;
14
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;
22
23 import java.util.concurrent.ExecutionException;
24 import java.util.concurrent.TimeoutException;
25
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;
34
35 /**
36  * Unit tests for the {@link BridgeHandler}.
37  * 
38  * @author David Pace - Initial contribution
39  *
40  */
41 @NonNullByDefault
42 class BridgeHandlerTest {
43
44     @Nullable
45     private BridgeHandler fixture;
46
47     @Nullable
48     private BoschHttpClient httpClient;
49
50     @BeforeEach
51     void beforeEach() {
52         Bridge bridge = mock(Bridge.class);
53         fixture = new BridgeHandler(bridge);
54         httpClient = mock(BoschHttpClient.class);
55         fixture.httpClient = httpClient;
56     }
57
58     @Test
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";
67
68         fixture.postAction(endpoint, request);
69         verify(httpClient).createRequest(eq(url), same(HttpMethod.POST), same(request));
70         verify(mockRequest).send();
71     }
72 }