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.converters;
15 import static org.junit.jupiter.api.Assertions.*;
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.WSDateValue;
20 import org.openhab.binding.ihc.internal.ws.resourcevalues.WSResourceValue;
21 import org.openhab.core.library.types.DateTimeType;
22 import org.openhab.core.types.Type;
25 * Test for IHC / ELKO binding
27 * @author Pauli Anttila - Initial contribution
29 public class DateTimeTypeWSDateValueConverterTest {
32 public void testConversion() throws ConversionException {
33 final DateTimeType dateTimeType = new DateTimeType("2000-12-30T00:00:00");
34 WSDateValue val = new WSDateValue(12345, (short) 1999, (byte) 1, (byte) 1);
36 val = convertFromOHType(val, dateTimeType, null);
37 assertEquals(12345, val.resourceID);
38 assertEquals(2000, val.year);
39 assertEquals(12, val.month);
40 assertEquals(30, val.day);
42 DateTimeType type = convertFromResourceValue(val, null);
43 assertEquals(dateTimeType.format("yyyy-MM-dd"), type.format("yyyy-MM-dd"));
46 private WSDateValue convertFromOHType(WSDateValue IHCvalue, Type OHval,
47 ConverterAdditionalInfo converterAdditionalInfo) throws ConversionException {
48 Converter<WSResourceValue, Type> converter = ConverterFactory.getInstance().getConverter(IHCvalue.getClass(),
50 return (WSDateValue) converter.convertFromOHType(OHval, IHCvalue, converterAdditionalInfo);
53 private DateTimeType convertFromResourceValue(WSDateValue IHCvalue, ConverterAdditionalInfo converterAdditionalInfo)
54 throws ConversionException {
55 Converter<WSResourceValue, Type> converter = ConverterFactory.getInstance().getConverter(IHCvalue.getClass(),
57 return (DateTimeType) converter.convertFromResourceValue(IHCvalue, converterAdditionalInfo);