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.WSSystemInfo;
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 IhcConfigurationServiceTest {
39 private IhcConfigurationService ihcConfigurationService;
40 private final String host = "1.1.1.1";
41 private final String url = "https://1.1.1.1/ws/ConfigurationService";
42 final String query = ResourceFileUtils.getFileContent("EmptyQuery.xml");
43 private Map<String, String> requestProps = new HashMap<>();
44 private final int timeout = 100;
47 public void setUp() throws IhcExecption, SocketTimeoutException {
48 ihcConfigurationService = spy(new IhcConfigurationService(host, timeout, new IhcConnectionPool()));
50 requestProps.put("SOAPAction", "getSystemInfo");
54 public void testv2() throws IhcExecption {
55 final String response = ResourceFileUtils.getFileContent("GetSystemInfoResponse.xml");
57 doReturn(response).when(ihcConfigurationService).sendQuery(eq(url), eq(requestProps), eq(query), eq(timeout));
59 final WSSystemInfo result = ihcConfigurationService.getSystemInfo();
61 assertEquals(false, result.getApplicationIsWithoutViewer());
62 assertEquals("ELKOFI", result.getBrand());
63 assertEquals("6.2", result.getHwRevision());
64 assertEquals(LocalDateTime.parse("2018-06-28T17:02:29", DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss")),
65 result.getRealTimeClock().toLocalDateTime());
66 assertEquals("1234567890", result.getSerialNumber());
67 assertEquals(LocalDateTime.parse("2011-03-04T09:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss")),
68 result.getSwDate().toLocalDateTime());
69 assertEquals(3980146956L, result.getUptime());
70 assertEquals("2.7.144", result.getVersion());
71 assertEquals("2011-04-28T09:00:00Z", result.getProductionDate());
72 assertEquals("", result.getDatalineVersion());
73 assertEquals("", result.getRfModuleSoftwareVersion());
74 assertEquals("", result.getRfModuleSerialNumber());
78 public void testv3() throws IhcExecption {
79 final String response = ResourceFileUtils.getFileContent("GetSystemInfoResponse2.xml");
80 doReturn(response).when(ihcConfigurationService).sendQuery(eq(url), eq(requestProps), eq(query), eq(timeout));
82 final WSSystemInfo result = ihcConfigurationService.getSystemInfo();
84 assertEquals(false, result.getApplicationIsWithoutViewer());
85 assertEquals("LK", result.getBrand());
86 assertEquals("7.1", result.getHwRevision());
88 LocalDateTime.parse("2018-12-15T13:15:00Z", DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'")),
89 result.getRealTimeClock().toLocalDateTime());
90 assertEquals("CN1734000000", result.getSerialNumber());
92 LocalDateTime.parse("2018-07-23T10:00:00Z", DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'")),
93 result.getSwDate().toLocalDateTime());
94 assertEquals(164057634L, result.getUptime());
95 assertEquals("3.3.9", result.getVersion());
96 assertEquals("2017/34", result.getProductionDate());
97 assertEquals("IOB.B.03.02.01", result.getDatalineVersion());
98 assertEquals("3.06.c", result.getRfModuleSoftwareVersion());
99 assertEquals("640C10140000", result.getRfModuleSerialNumber());