]> git.basschouten.com Git - openhab-addons.git/blob
14bbbb1b7910dec49530f94ff0b6ba5d3cfe8125
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.knx.internal.channel;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import java.util.Collections;
18 import java.util.Set;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.junit.jupiter.api.BeforeEach;
22 import org.junit.jupiter.api.Test;
23
24 /**
25  *
26  * @author Simon Kaufmann - initial contribution and API.
27  *
28  */
29 @NonNullByDefault
30 class KNXChannelTypeTest {
31
32     private KNXChannelType ct = new MyKNXChannelType("");
33
34     @BeforeEach
35     void setup() {
36         ct = new MyKNXChannelType("");
37     }
38
39     @Test
40     void testParseWithDptMultipleWithRead() {
41         ChannelConfiguration res = ct.parse("5.001:<1/3/22+0/3/22+<0/8/15");
42
43         if (res == null) {
44             fail();
45             return;
46         }
47
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());
53     }
54
55     @Test
56     void testParseWithDptMultipleWithoutRead() {
57         ChannelConfiguration res = ct.parse("5.001:1/3/22+0/3/22+0/8/15");
58
59         if (res == null) {
60             fail();
61             return;
62         }
63
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());
69     }
70
71     @Test
72     void testParseWithoutDptSingleWithoutRead() {
73         ChannelConfiguration res = ct.parse("1/3/22");
74
75         if (res == null) {
76             fail();
77             return;
78         }
79
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());
85     }
86
87     @Test
88     void testParseWithoutDptSingleWitRead() {
89         ChannelConfiguration res = ct.parse("<1/3/22");
90
91         if (res == null) {
92             fail();
93             return;
94         }
95
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());
101     }
102
103     @Test
104     void testParseTwoLevel() {
105         ChannelConfiguration res = ct.parse("5.001:<3/1024+<4/1025");
106
107         if (res == null) {
108             fail();
109             return;
110         }
111
112         assertEquals("3/1024", res.getMainGA().getGA());
113         assertEquals(2, res.getListenGAs().size());
114         assertEquals(2, res.getReadGAs().size());
115     }
116
117     @Test
118     void testParseFreeLevel() {
119         ChannelConfiguration res = ct.parse("5.001:<4610+<4611");
120
121         if (res == null) {
122             fail();
123             return;
124         }
125
126         assertEquals("4610", res.getMainGA().getGA());
127         assertEquals(2, res.getListenGAs().size());
128         assertEquals(2, res.getReadGAs().size());
129     }
130
131     private static class MyKNXChannelType extends KNXChannelType {
132         public MyKNXChannelType(String channelTypeID) {
133             super(channelTypeID);
134         }
135
136         @Override
137         protected Set<String> getAllGAKeys() {
138             return Collections.emptySet();
139         }
140
141         @Override
142         protected String getDefaultDPT(String gaConfigKey) {
143             return "";
144         }
145     }
146 }