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 java.util.ArrayList;
19 import org.junit.jupiter.api.Test;
20 import org.openhab.binding.ihc.internal.ws.exeptions.ConversionException;
21 import org.openhab.binding.ihc.internal.ws.projectfile.IhcEnumValue;
22 import org.openhab.binding.ihc.internal.ws.resourcevalues.WSEnumValue;
23 import org.openhab.binding.ihc.internal.ws.resourcevalues.WSResourceValue;
24 import org.openhab.core.library.types.StringType;
25 import org.openhab.core.types.Type;
28 * Test for IHC / ELKO binding
30 * @author Pauli Anttila - Initial contribution
32 public class StringTypeWSEnumValueConverterTest {
35 public void test() throws ConversionException {
36 ArrayList<IhcEnumValue> enumValues = new ArrayList<>();
37 enumValues.add(new IhcEnumValue(101, "testA"));
38 enumValues.add(new IhcEnumValue(102, "testB"));
39 enumValues.add(new IhcEnumValue(103, "testC"));
40 enumValues.add(new IhcEnumValue(104, "testD"));
42 WSEnumValue val = new WSEnumValue(12345, 5555, 0, "");
44 val = convertFromOHType(val, new StringType("testC"), new ConverterAdditionalInfo(enumValues, false, null));
45 assertEquals(12345, val.resourceID);
46 assertEquals(5555, val.definitionTypeID);
47 assertEquals(103, val.enumValueID);
48 assertEquals("testC", val.enumName);
50 StringType type = convertFromResourceValue(val, new ConverterAdditionalInfo(enumValues, false, null));
51 assertEquals(new StringType("testC"), type);
54 private WSEnumValue convertFromOHType(WSEnumValue IHCvalue, Type OHval,
55 ConverterAdditionalInfo converterAdditionalInfo) throws ConversionException {
56 Converter<WSResourceValue, Type> converter = ConverterFactory.getInstance().getConverter(IHCvalue.getClass(),
58 return (WSEnumValue) converter.convertFromOHType(OHval, IHCvalue, converterAdditionalInfo);
61 private StringType convertFromResourceValue(WSEnumValue IHCvalue, ConverterAdditionalInfo converterAdditionalInfo)
62 throws ConversionException {
63 Converter<WSResourceValue, Type> converter = ConverterFactory.getInstance().getConverter(IHCvalue.getClass(),
65 return (StringType) converter.convertFromResourceValue(IHCvalue, converterAdditionalInfo);