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.time.LocalDateTime;
21 import java.time.format.DateTimeFormatter;
22 import java.util.HashMap;
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;
33 * Test for IHC / ELKO binding
35 * @author Pauli Anttila - Initial contribution
37 public class IhcTimeServiceTest {
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;
46 public void setUp() throws IhcExecption, SocketTimeoutException {
47 ihcTimeService = spy(new IhcTimeService(host, timeout, new IhcConnectionPool()));
49 final String query = ResourceFileUtils.getFileContent("EmptyQuery.xml");
50 final String response = ResourceFileUtils.getFileContent("GetSettingsResponse.xml");
53 requestProps.put("SOAPAction", "getSettings");
55 doReturn(response).when(ihcTimeService).sendQuery(eq(url), eq(requestProps), eq(query), eq(timeout));
59 public void test() throws IhcExecption {
60 final WSTimeManagerSettings result = ihcTimeService.getTimeSettings();
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());