]> git.basschouten.com Git - openhab-addons.git/blob
89eb6ccc4142f3954fdef5b7ab5fcb707723c622
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.rfxcom.internal.messages;
14
15 import static org.junit.jupiter.api.Assertions.*;
16 import static org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType.RFY;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.junit.jupiter.api.Test;
20 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
21 import org.openhab.binding.rfxcom.internal.messages.RFXComRfyMessage.Commands;
22 import org.openhab.binding.rfxcom.internal.messages.RFXComRfyMessage.SubType;
23 import org.openhab.core.util.HexUtils;
24
25 /**
26  * Test for RFXCom-binding
27  *
28  * @author Martin van Wingerden - Initial contribution
29  */
30 @NonNullByDefault
31 public class RFXComRfyMessageTest {
32
33     @Test
34     public void basicBoundaryCheck() throws RFXComException {
35         RFXComRfyMessage message = (RFXComRfyMessage) RFXComMessageFactory.createMessage(RFY);
36
37         message.subType = SubType.RFY;
38         message.command = Commands.UP;
39
40         RFXComTestHelper.basicBoundaryCheck(RFY, message);
41     }
42
43     private void testMessage(SubType subType, Commands command, String deviceId, String data) throws RFXComException {
44         RFXComRfyMessage message = (RFXComRfyMessage) RFXComMessageFactory.createMessage(RFY);
45         message.setSubType(subType);
46         message.command = command;
47         message.setDeviceId(deviceId);
48
49         assertArrayEquals(HexUtils.hexToBytes(data), message.decodeMessage());
50     }
51
52     @Test
53     public void testMessage1() throws RFXComException {
54         testMessage(SubType.RFY, Commands.UP_SHORT, "66051.4", "0C1A0000010203040F00000000");
55     }
56
57     @Test
58     public void testMessage2() throws RFXComException {
59         testMessage(SubType.ASA, Commands.DOWN_LONG, "66051.4", "0C1A0300010203041200000000");
60     }
61 }