]> git.basschouten.com Git - openhab-addons.git/blob
333492f06413006c38d9ea4b20490b0b244e98d3
[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.ihc.internal.ws.services;
14
15 import static org.junit.jupiter.api.Assertions.*;
16 import static org.mockito.ArgumentMatchers.eq;
17 import static org.mockito.Mockito.*;
18
19 import java.net.SocketTimeoutException;
20 import java.time.LocalDateTime;
21 import java.time.format.DateTimeFormatter;
22 import java.util.HashMap;
23 import java.util.Map;
24
25 import org.junit.jupiter.api.BeforeEach;
26 import org.junit.jupiter.api.Test;
27 import org.openhab.binding.ihc.internal.ws.ResourceFileUtils;
28 import org.openhab.binding.ihc.internal.ws.datatypes.WSTimeManagerSettings;
29 import org.openhab.binding.ihc.internal.ws.exeptions.IhcExecption;
30 import org.openhab.binding.ihc.internal.ws.http.IhcConnectionPool;
31
32 /**
33  * Test for IHC / ELKO binding
34  *
35  * @author Pauli Anttila - Initial contribution
36  */
37 public class IhcTimeServiceTest {
38
39     private IhcTimeService ihcTimeService;
40     private final String host = "1.1.1.1";
41     private final String url = "https://1.1.1.1/ws/TimeManagerService";
42     private Map<String, String> requestProps = new HashMap<>();
43     private final int timeout = 100;
44
45     @BeforeEach
46     public void setUp() throws IhcExecption, SocketTimeoutException {
47         ihcTimeService = spy(new IhcTimeService(host, timeout, new IhcConnectionPool()));
48
49         final String query = ResourceFileUtils.getFileContent("EmptyQuery.xml");
50         final String response = ResourceFileUtils.getFileContent("GetSettingsResponse.xml");
51
52         requestProps.clear();
53         requestProps.put("SOAPAction", "getSettings");
54
55         doReturn(response).when(ihcTimeService).sendQuery(eq(url), eq(requestProps), eq(query), eq(timeout));
56     }
57
58     @Test
59     public void test() throws IhcExecption {
60         final WSTimeManagerSettings result = ihcTimeService.getTimeSettings();
61
62         assertEquals(true, result.getSynchroniseTimeAgainstServer());
63         assertEquals(true, result.getUseDST());
64         assertEquals(2, result.getGmtOffsetInHours());
65         assertEquals("192.168.1.10", result.getServerName());
66         assertEquals(24, result.getSyncIntervalInHours());
67         assertEquals(LocalDateTime.parse("2018-12-07T08:20:10", DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss")),
68                 result.getTimeAndDateInUTC().getAsLocalDateTime());
69     }
70 }