2 * Copyright (c) 2010-2022 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.NonNull;
21 import org.junit.jupiter.api.BeforeEach;
22 import org.junit.jupiter.api.Test;
26 * @author Simon Kaufmann - initial contribution and API.
29 public class KNXChannelTypeTest {
31 private KNXChannelType ct;
35 ct = new MyKNXChannelType("");
39 public void testParse_withDPT_multiple_withRead() {
40 ChannelConfiguration res = ct.parse("5.001:<1/3/22+0/3/22+<0/8/15");
42 assertEquals("5.001", res.getDPT());
43 assertEquals("1/3/22", res.getMainGA().getGA());
44 assertTrue(res.getMainGA().isRead());
45 assertEquals(3, res.getListenGAs().size());
46 assertEquals(2, res.getReadGAs().size());
50 public void testParse_withDPT_multiple_withoutRead() {
51 ChannelConfiguration res = ct.parse("5.001:1/3/22+0/3/22+0/8/15");
53 assertEquals("5.001", res.getDPT());
54 assertEquals("1/3/22", res.getMainGA().getGA());
55 assertFalse(res.getMainGA().isRead());
56 assertEquals(3, res.getListenGAs().size());
57 assertEquals(0, res.getReadGAs().size());
61 public void testParse_withoutDPT_single_withoutRead() {
62 ChannelConfiguration res = ct.parse("1/3/22");
64 assertNull(res.getDPT());
65 assertEquals("1/3/22", res.getMainGA().getGA());
66 assertFalse(res.getMainGA().isRead());
67 assertEquals(1, res.getListenGAs().size());
68 assertEquals(0, res.getReadGAs().size());
72 public void testParse_withoutDPT_single_witRead() {
73 ChannelConfiguration res = ct.parse("<1/3/22");
75 assertNull(res.getDPT());
76 assertEquals("1/3/22", res.getMainGA().getGA());
77 assertTrue(res.getMainGA().isRead());
78 assertEquals(1, res.getListenGAs().size());
79 assertEquals(1, res.getReadGAs().size());
83 public void testParse_twoLevel() {
84 ChannelConfiguration res = ct.parse("5.001:<3/1024+<4/1025");
85 assertEquals("3/1024", res.getMainGA().getGA());
86 assertEquals(2, res.getListenGAs().size());
87 assertEquals(2, res.getReadGAs().size());
91 public void testParse_freeLevel() {
92 ChannelConfiguration res = ct.parse("5.001:<4610+<4611");
93 assertEquals("4610", res.getMainGA().getGA());
94 assertEquals(2, res.getListenGAs().size());
95 assertEquals(2, res.getReadGAs().size());
98 private static class MyKNXChannelType extends KNXChannelType {
99 public MyKNXChannelType(String channelTypeID) {
100 super(channelTypeID);
104 protected @NonNull Set<@NonNull String> getAllGAKeys() {
105 return Collections.emptySet();
109 protected @NonNull String getDefaultDPT(@NonNull String gaConfigKey) {