2 * Copyright (c) 2010-2020 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.openwebnet.handler;
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16 import static org.mockito.Mockito.mock;
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;
28 * Test class for {@link OpenWebNetBridgeHandler#ownID} and ThingID calculation using {@link OpenWebNetBridgeHandler}
29 * methods: normalizeWhere(), ownIdFromWhoWhere(), ownIdFromMessage(), thingIdFromWhere()
31 * @author Massimo Valla - Initial contribution
34 public class OwnIdTest {
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
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");
69 public final Where where;
71 public final String norm, ownId, thingId;
73 private TEST(Where where, Who who, String norm, String ownId, String thingId) {
78 this.thingId = thingId;
83 public void testOwnId() {
84 Bridge mockBridge = mock(Bridge.class);
85 OpenWebNetBridgeHandler brH = new OpenWebNetBridgeHandler(mockBridge);
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));