]> git.basschouten.com Git - openhab-addons.git/blob
dce27e1fcdce2ecb3aaacdc1fb1cd5627a625e33
[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         "'BHA': {" +
34             "'RETURNCODE': '1'," +
35             "'VERSION': [{" +
36                 "'FIRMWARE': '000109'," +
37                 "'BUILD_NUMBER': '15120529'," +
38                 "'PRIMARY_MAC_ADDR': '1CCAE3711111'," +
39                 "'WIFI_MAC_ADDR': '1CCAE3799999'," +
40                 "'RELAYS': ['1', '2', 'gggaaa@1', 'gggaaa@2']," +
41                 "'DEVICE-TYPE': 'DoorBird D101'" +
42             "}]" +
43         "}" +
44     "}";
45     //@formatter:on
46
47     private final String infoWithoutControllerId =
48     //@formatter:off
49     "{" +
50         "'BHA': {" +
51             "'RETURNCODE': '1'," +
52             "'VERSION': [{" +
53                 "'FIRMWARE': '000109'," +
54                 "'BUILD_NUMBER': '15120529'," +
55                 "'PRIMARY_MAC_ADDR': '1CCAE3711111'," +
56                 "'WIFI_MAC_ADDR': '1CCAE3799999'," +
57                 "'RELAYS': ['1', '2']," +
58                 "'DEVICE-TYPE': 'DoorBird D101'" +
59             "}]" +
60         "}" +
61     "}";
62     //@formatter:on
63
64     @Test
65     public void testParsingWithoutControllerId() {
66         DoorbirdInfo info = new DoorbirdInfo(infoWithoutControllerId);
67
68         assertEquals("1", info.getReturnCode());
69         assertEquals("000109", info.getFirmwareVersion());
70         assertEquals("15120529", info.getBuildNumber());
71         assertEquals("1CCAE3711111", info.getPrimaryMacAddress());
72         assertEquals("1CCAE3799999", info.getWifiMacAddress());
73         assertEquals("DoorBird D101", info.getDeviceType());
74
75         assertTrue(info.getRelays().contains("1"));
76         assertTrue(info.getRelays().contains("2"));
77         assertFalse(info.getRelays().contains("3"));
78     }
79
80     @Test
81     public void testGetControllerId() {
82         DoorbirdInfo info = new DoorbirdInfo(infoWithControllerId);
83
84         assertEquals("gggaaa", info.getControllerId(null));
85
86         assertTrue(info.getRelays().contains("gggaaa@1"));
87         assertTrue(info.getRelays().contains("gggaaa@2"));
88         assertFalse(info.getRelays().contains("unknown"));
89     }
90
91     @Test
92     public void testControllerIdIsNull() {
93         DoorbirdInfo info = new DoorbirdInfo(infoWithoutControllerId);
94
95         assertNull(info.getControllerId(null));
96     }
97 }