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("");
39 @SuppressWarnings("null")
41 void testParseWithDptMultipleWithRead() {
42 ChannelConfiguration res = ct.parse("5.001:<1/3/22+0/3/22+<0/8/15");
44 assertEquals("5.001", res.getDPT());
45 assertEquals("1/3/22", res.getMainGA().getGA());
46 assertTrue(res.getMainGA().isRead());
47 assertEquals(3, res.getListenGAs().size());
48 assertEquals(2, res.getReadGAs().size());
51 @SuppressWarnings("null")
53 void testParseWithDptMultipleWithoutRead() {
54 ChannelConfiguration res = ct.parse("5.001:1/3/22+0/3/22+0/8/15");
56 assertEquals("5.001", res.getDPT());
57 assertEquals("1/3/22", res.getMainGA().getGA());
58 assertFalse(res.getMainGA().isRead());
59 assertEquals(3, res.getListenGAs().size());
60 assertEquals(0, res.getReadGAs().size());
63 @SuppressWarnings("null")
65 void testParseWithoutDptSingleWithoutRead() {
66 ChannelConfiguration res = ct.parse("1/3/22");
68 assertNull(res.getDPT());
69 assertEquals("1/3/22", res.getMainGA().getGA());
70 assertFalse(res.getMainGA().isRead());
71 assertEquals(1, res.getListenGAs().size());
72 assertEquals(0, res.getReadGAs().size());
75 @SuppressWarnings("null")
77 void testParseWithoutDptSingleWitRead() {
78 ChannelConfiguration res = ct.parse("<1/3/22");
80 assertNull(res.getDPT());
81 assertEquals("1/3/22", res.getMainGA().getGA());
82 assertTrue(res.getMainGA().isRead());
83 assertEquals(1, res.getListenGAs().size());
84 assertEquals(1, res.getReadGAs().size());
87 @SuppressWarnings("null")
89 void testParseTwoLevel() {
90 ChannelConfiguration res = ct.parse("5.001:<3/1024+<4/1025");
91 assertEquals("3/1024", res.getMainGA().getGA());
92 assertEquals(2, res.getListenGAs().size());
93 assertEquals(2, res.getReadGAs().size());
96 @SuppressWarnings("null")
98 void testParseFreeLevel() {
99 ChannelConfiguration res = ct.parse("5.001:<4610+<4611");
100 assertEquals("4610", res.getMainGA().getGA());
101 assertEquals(2, res.getListenGAs().size());
102 assertEquals(2, res.getReadGAs().size());
105 private static class MyKNXChannelType extends KNXChannelType {
106 public MyKNXChannelType(String channelTypeID) {
107 super(channelTypeID);
111 protected Set<String> getAllGAKeys() {
112 return Collections.emptySet();
116 protected String getDefaultDPT(String gaConfigKey) {