]> git.basschouten.com Git - openhab-addons.git/blob
3d423084b192ea4d2423752dc4534f6bd0bd3d45
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.NonNull;
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 public class KNXChannelTypeTest {
30
31     private KNXChannelType ct;
32
33     @BeforeEach
34     public void setup() {
35         ct = new MyKNXChannelType("");
36     }
37
38     @Test
39     public void testParse_withDPT_multiple_withRead() {
40         ChannelConfiguration res = ct.parse("5.001:<1/3/22+0/3/22+<0/8/15");
41
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());
47     }
48
49     @Test
50     public void testParse_withDPT_multiple_withoutRead() {
51         ChannelConfiguration res = ct.parse("5.001:1/3/22+0/3/22+0/8/15");
52
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());
58     }
59
60     @Test
61     public void testParse_withoutDPT_single_withoutRead() {
62         ChannelConfiguration res = ct.parse("1/3/22");
63
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());
69     }
70
71     @Test
72     public void testParse_withoutDPT_single_witRead() {
73         ChannelConfiguration res = ct.parse("<1/3/22");
74
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());
80     }
81
82     @Test
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());
88     }
89
90     @Test
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());
96     }
97
98     private static class MyKNXChannelType extends KNXChannelType {
99         public MyKNXChannelType(String channelTypeID) {
100             super(channelTypeID);
101         }
102
103         @Override
104         protected @NonNull Set<@NonNull String> getAllGAKeys() {
105             return Collections.emptySet();
106         }
107
108         @Override
109         protected @NonNull String getDefaultDPT(@NonNull String gaConfigKey) {
110             return "";
111         }
112     }
113 }