]> git.basschouten.com Git - openhab-addons.git/blob
842520c645b12345b034704081bc669ad0c9fac1
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.openwebnet.handler;
14
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16 import static org.mockito.Mockito.mock;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.junit.jupiter.api.Test;
20 import org.openhab.core.thing.Bridge;
21 import org.openwebnet4j.message.Lighting;
22 import org.openwebnet4j.message.Where;
23 import org.openwebnet4j.message.WhereLightAutom;
24 import org.openwebnet4j.message.WhereZigBee;
25 import org.openwebnet4j.message.Who;
26
27 /**
28  * Test class for {@link OpenWebNetBridgeHandler#ownID} and ThingID calculation using {@link OpenWebNetBridgeHandler}
29  * methods: normalizeWhere(), ownIdFromWhoWhere(), ownIdFromMessage(), thingIdFromWhere()
30  *
31  * @author Massimo Valla - Initial contribution
32  */
33 @NonNullByDefault
34 public class OwnIdTest {
35
36  // @formatter:off
37     /**
38      *
39      *                                      deviceWhere
40      *                                      (DevAddrParam)
41      * TYPE                 WHERE           = normalizeWhere()  ownId           ThingID
42      * ---------------------------------------------------------------------------------
43      * Zigbee Switch        789309801#9     789309800h9         1.789309800h9   789309800h9
44      * Zigbee Switch_2u u1  789301201#9     789301200h9         1.789309800h9   789309800h9
45      * Zigbee Switch_2u u2  789301202#9     789301200h9         1.789309800h9   789309800h9
46      * BUS Switch           51              51                  1.51            51
47      * BUS Local Bus        25#4#01         25h4h01             1.25h4h01       25h4h01
48      * BUS Autom            93              93                  2.93            93
49      * BUS Thermo           #1 or 1         1                   4.1             1
50      * BUS TempSensor       500             500                 4.500           500
51      * BUS Energy           51              51                  18.51           51
52      * BUS CEN              51              51                  15.51           51
53      * BUS CEN+             212             212                 25.212          212
54      * BUS DryContact       399             399                 25.399          399
55      *
56      */
57 // @formatter:on
58
59     public enum TEST {
60         zb_switch(new WhereZigBee("789309801#9"), Who.fromValue(1), "789309800h9", "1.789309800h9", "789309800h9"),
61         zb_switch_2u_1(new WhereZigBee("789301201#9"), Who.fromValue(1), "789301200h9", "1.789301200h9", "789301200h9"),
62         zb_switch_2u_2(new WhereZigBee("789301202#9"), Who.fromValue(1), "789301200h9", "1.789301200h9", "789301200h9"),
63         bus_switch(new WhereLightAutom("51"), Who.fromValue(1), "51", "1.51", "51"),
64         bus_localbus(new WhereLightAutom("25#4#01"), Who.fromValue(1), "25h4h01", "1.25h4h01", "25h4h01");
65         // bus_thermo("#1", "4", "1", "4.1", "1"),
66         // bus_tempSensor("500", "4", "500", "4.500", "500"),
67         // bus_energy("51", "18", "51", "18.51", "51");
68
69         public final Where where;
70         public final Who who;
71         public final String norm, ownId, thingId;
72
73         private TEST(Where where, Who who, String norm, String ownId, String thingId) {
74             this.where = where;
75             this.who = who;
76             this.norm = norm;
77             this.ownId = ownId;
78             this.thingId = thingId;
79         }
80     }
81
82     @Test
83     public void testOwnId() {
84         Bridge mockBridge = mock(Bridge.class);
85         OpenWebNetBridgeHandler brH = new OpenWebNetBridgeHandler(mockBridge);
86
87         for (int i = 0; i < TEST.values().length; i++) {
88             TEST test = TEST.values()[i];
89             // System.out.println("testing where=" + test.where);
90             assertEquals(test.norm, brH.normalizeWhere(test.where));
91             assertEquals(test.ownId, brH.ownIdFromWhoWhere(test.who, test.where));
92             assertEquals(test.ownId, brH.ownIdFromMessage(Lighting.requestTurnOn(test.where.value())));
93             assertEquals(test.thingId, brH.thingIdFromWhere(test.where));
94         }
95     }
96 }