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.knx.internal.channel;
15 import static org.junit.jupiter.api.Assertions.*;
17 import java.util.Collections;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.junit.jupiter.api.BeforeEach;
22 import org.junit.jupiter.api.Test;
26 * @author Simon Kaufmann - initial contribution and API.
30 class KNXChannelTypeTest {
32 private KNXChannelType ct = new MyKNXChannelType("");
36 ct = new MyKNXChannelType("");
40 void testParseWithDptMultipleWithRead() {
41 ChannelConfiguration res = ct.parse("5.001:<1/3/22+0/3/22+<0/8/15");
48 assertEquals("5.001", res.getDPT());
49 assertEquals("1/3/22", res.getMainGA().getGA());
50 assertTrue(res.getMainGA().isRead());
51 assertEquals(3, res.getListenGAs().size());
52 assertEquals(2, res.getReadGAs().size());
56 void testParseWithDptMultipleWithoutRead() {
57 ChannelConfiguration res = ct.parse("5.001:1/3/22+0/3/22+0/8/15");
64 assertEquals("5.001", res.getDPT());
65 assertEquals("1/3/22", res.getMainGA().getGA());
66 assertFalse(res.getMainGA().isRead());
67 assertEquals(3, res.getListenGAs().size());
68 assertEquals(0, res.getReadGAs().size());
72 void testParseWithoutDptSingleWithoutRead() {
73 ChannelConfiguration res = ct.parse("1/3/22");
80 assertNull(res.getDPT());
81 assertEquals("1/3/22", res.getMainGA().getGA());
82 assertFalse(res.getMainGA().isRead());
83 assertEquals(1, res.getListenGAs().size());
84 assertEquals(0, res.getReadGAs().size());
88 void testParseWithoutDptSingleWitRead() {
89 ChannelConfiguration res = ct.parse("<1/3/22");
96 assertNull(res.getDPT());
97 assertEquals("1/3/22", res.getMainGA().getGA());
98 assertTrue(res.getMainGA().isRead());
99 assertEquals(1, res.getListenGAs().size());
100 assertEquals(1, res.getReadGAs().size());
104 void testParseTwoLevel() {
105 ChannelConfiguration res = ct.parse("5.001:<3/1024+<4/1025");
112 assertEquals("3/1024", res.getMainGA().getGA());
113 assertEquals(2, res.getListenGAs().size());
114 assertEquals(2, res.getReadGAs().size());
118 void testParseFreeLevel() {
119 ChannelConfiguration res = ct.parse("5.001:<4610+<4611");
126 assertEquals("4610", res.getMainGA().getGA());
127 assertEquals(2, res.getListenGAs().size());
128 assertEquals(2, res.getReadGAs().size());
131 private static class MyKNXChannelType extends KNXChannelType {
132 public MyKNXChannelType(String channelTypeID) {
133 super(channelTypeID);
137 protected Set<String> getAllGAKeys() {
138 return Collections.emptySet();
142 protected String getDefaultDPT(String gaConfigKey) {