]> git.basschouten.com Git - openhab-addons.git/blob
d275b720b98ce1258574146b1f49235dac17c34f
[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.doorbird.internal;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.junit.jupiter.api.Test;
19 import org.openhab.binding.doorbird.internal.api.DoorbirdInfo;
20
21 /**
22  * The {@link DoorbirdInfoTest} is responsible for testing the functionality
23  * of Doorbird "info" message parsing.
24  *
25  * @author Mark Hilbush - Initial contribution
26  */
27 @NonNullByDefault
28 public class DoorbirdInfoTest {
29
30     private final String infoWithControllerId =
31     //@formatter:off
32     """
33     {\
34     'BHA': {\
35     'RETURNCODE': '1',\
36     'VERSION': [{\
37     'FIRMWARE': '000109',\
38     'BUILD_NUMBER': '15120529',\
39     'PRIMARY_MAC_ADDR': '1CCAE3711111',\
40     'WIFI_MAC_ADDR': '1CCAE3799999',\
41     'RELAYS': ['1', '2', 'gggaaa@1', 'gggaaa@2'],\
42     'DEVICE-TYPE': 'DoorBird D101'\
43     }]\
44     }\
45     }\
46     """;
47     //@formatter:on
48
49     private final String infoWithoutControllerId =
50     //@formatter:off
51     """
52     {\
53     'BHA': {\
54     'RETURNCODE': '1',\
55     'VERSION': [{\
56     'FIRMWARE': '000109',\
57     'BUILD_NUMBER': '15120529',\
58     'PRIMARY_MAC_ADDR': '1CCAE3711111',\
59     'WIFI_MAC_ADDR': '1CCAE3799999',\
60     'RELAYS': ['1', '2'],\
61     'DEVICE-TYPE': 'DoorBird D101'\
62     }]\
63     }\
64     }\
65     """;
66     //@formatter:on
67
68     @Test
69     public void testParsingWithoutControllerId() {
70         DoorbirdInfo info = new DoorbirdInfo(infoWithoutControllerId);
71
72         assertEquals("1", info.getReturnCode());
73         assertEquals("000109", info.getFirmwareVersion());
74         assertEquals("15120529", info.getBuildNumber());
75         assertEquals("1CCAE3711111", info.getPrimaryMacAddress());
76         assertEquals("1CCAE3799999", info.getWifiMacAddress());
77         assertEquals("DoorBird D101", info.getDeviceType());
78
79         assertTrue(info.getRelays().contains("1"));
80         assertTrue(info.getRelays().contains("2"));
81         assertFalse(info.getRelays().contains("3"));
82     }
83
84     @Test
85     public void testGetControllerId() {
86         DoorbirdInfo info = new DoorbirdInfo(infoWithControllerId);
87
88         assertEquals("gggaaa", info.getControllerId(null));
89
90         assertTrue(info.getRelays().contains("gggaaa@1"));
91         assertTrue(info.getRelays().contains("gggaaa@2"));
92         assertFalse(info.getRelays().contains("unknown"));
93     }
94
95     @Test
96     public void testControllerIdIsNull() {
97         DoorbirdInfo info = new DoorbirdInfo(infoWithoutControllerId);
98
99         assertNull(info.getControllerId(null));
100     }
101 }