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.ihc.internal.ws.services;
15 import static org.junit.jupiter.api.Assertions.*;
16 import static org.mockito.ArgumentMatchers.eq;
17 import static org.mockito.Mockito.*;
19 import java.net.SocketTimeoutException;
20 import java.util.HashMap;
21 import java.util.List;
24 import org.junit.jupiter.api.BeforeEach;
25 import org.junit.jupiter.api.Test;
26 import org.openhab.binding.ihc.internal.ws.ResourceFileUtils;
27 import org.openhab.binding.ihc.internal.ws.datatypes.WSRFDevice;
28 import org.openhab.binding.ihc.internal.ws.exeptions.IhcExecption;
29 import org.openhab.binding.ihc.internal.ws.http.IhcConnectionPool;
32 * Test for IHC / ELKO binding
34 * @author Pauli Anttila - Initial contribution
36 public class IhcAirlinkManagementServiceTest {
38 private IhcAirlinkManagementService ihcAirlinkManagementService;
39 private final String host = "1.1.1.1";
40 private final String url = "https://1.1.1.1/ws/AirlinkManagementService";
41 private Map<String, String> requestProps = new HashMap<>();
43 private final int timeout = 100;
46 public void setUp() throws IhcExecption, SocketTimeoutException {
47 ihcAirlinkManagementService = spy(new IhcAirlinkManagementService(host, timeout, new IhcConnectionPool()));
49 query = ResourceFileUtils.getFileContent("EmptyQuery.xml");
52 requestProps.put("SOAPAction", "getDetectedDeviceList");
56 public void test() throws IhcExecption {
57 final String response = ResourceFileUtils.getFileContent("GetDetectedDeviceListResponse.xml");
58 doReturn(response).when(ihcAirlinkManagementService).sendQuery(eq(url), eq(requestProps), eq(query),
61 final List<WSRFDevice> result = ihcAirlinkManagementService.getDetectedDeviceList();
63 assertEquals(1, result.size());
65 assertEquals(1, result.get(0).getBatteryLevel());
66 assertEquals(true, result.get(0).getDetected());
67 assertEquals(2049, result.get(0).getDeviceType());
68 assertEquals(123456789, result.get(0).getSerialNumber());
69 assertEquals(10, result.get(0).getSignalStrength());
70 assertEquals(1, result.get(0).getVersion());
74 public void testEmptyList() throws IhcExecption {
75 final String response = ResourceFileUtils.getFileContent("GetEmptyDetectedDeviceListResponse.xml");
76 doReturn(response).when(ihcAirlinkManagementService).sendQuery(eq(url), eq(requestProps), eq(query),
79 final List<WSRFDevice> result = ihcAirlinkManagementService.getDetectedDeviceList();
81 assertEquals(0, result.size());