]> git.basschouten.com Git - openhab-addons.git/blob
31ff0df31aac4c4d3866fd0c652ad9b8b2824909
[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.converters;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import org.junit.jupiter.api.Test;
18 import org.openhab.binding.ihc.internal.ws.exeptions.ConversionException;
19 import org.openhab.binding.ihc.internal.ws.resourcevalues.WSResourceValue;
20 import org.openhab.binding.ihc.internal.ws.resourcevalues.WSTimeValue;
21 import org.openhab.core.library.types.DateTimeType;
22 import org.openhab.core.types.Type;
23
24 /**
25  * Test for IHC / ELKO binding
26  *
27  * @author Pauli Anttila - Initial contribution
28  */
29 public class DateTimeTypeWSTimeValueConverterTest {
30
31     @Test
32     public void testConversion() throws ConversionException {
33         final DateTimeType dateTimeType = new DateTimeType("2000-12-30T13:59:30");
34         WSTimeValue val = new WSTimeValue(12345, 0, 0, 0);
35
36         val = convertFromOHType(val, dateTimeType, null);
37         assertEquals(12345, val.resourceID);
38         assertEquals(13, val.hours);
39         assertEquals(59, val.minutes);
40         assertEquals(30, val.seconds);
41
42         DateTimeType type = convertFromResourceValue(val, null);
43         assertEquals(dateTimeType.format("HH:mm:ss"), type.format("HH:mm:ss"));
44     }
45
46     private WSTimeValue convertFromOHType(WSTimeValue IHCvalue, Type OHval,
47             ConverterAdditionalInfo converterAdditionalInfo) throws ConversionException {
48         Converter<WSResourceValue, Type> converter = ConverterFactory.getInstance().getConverter(IHCvalue.getClass(),
49                 DateTimeType.class);
50         return (WSTimeValue) converter.convertFromOHType(OHval, IHCvalue, converterAdditionalInfo);
51     }
52
53     private DateTimeType convertFromResourceValue(WSTimeValue IHCvalue, ConverterAdditionalInfo converterAdditionalInfo)
54             throws ConversionException {
55         Converter<WSResourceValue, Type> converter = ConverterFactory.getInstance().getConverter(IHCvalue.getClass(),
56                 DateTimeType.class);
57         return (DateTimeType) converter.convertFromResourceValue(IHCvalue, converterAdditionalInfo);
58     }
59 }