]> git.basschouten.com Git - openhab-addons.git/blob
eaa33e041cf63821c17277e90908e24a491429ec
[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     @SuppressWarnings("null")
40     @Test
41     void testParseWithDptMultipleWithRead() {
42         ChannelConfiguration res = ct.parse("5.001:<1/3/22+0/3/22+<0/8/15");
43
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());
49     }
50
51     @SuppressWarnings("null")
52     @Test
53     void testParseWithDptMultipleWithoutRead() {
54         ChannelConfiguration res = ct.parse("5.001:1/3/22+0/3/22+0/8/15");
55
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());
61     }
62
63     @SuppressWarnings("null")
64     @Test
65     void testParseWithoutDptSingleWithoutRead() {
66         ChannelConfiguration res = ct.parse("1/3/22");
67
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());
73     }
74
75     @SuppressWarnings("null")
76     @Test
77     void testParseWithoutDptSingleWitRead() {
78         ChannelConfiguration res = ct.parse("<1/3/22");
79
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());
85     }
86
87     @SuppressWarnings("null")
88     @Test
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());
94     }
95
96     @SuppressWarnings("null")
97     @Test
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());
103     }
104
105     private static class MyKNXChannelType extends KNXChannelType {
106         public MyKNXChannelType(String channelTypeID) {
107             super(channelTypeID);
108         }
109
110         @Override
111         protected Set<String> getAllGAKeys() {
112             return Collections.emptySet();
113         }
114
115         @Override
116         protected String getDefaultDPT(String gaConfigKey) {
117             return "";
118         }
119     }
120 }