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.rfxcom.internal.messages;
15 import static org.junit.jupiter.api.Assertions.*;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.junit.jupiter.api.Test;
19 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
20 import org.openhab.binding.rfxcom.internal.exceptions.RFXComMessageTooLongException;
21 import org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType;
22 import org.openhab.core.util.HexUtils;
25 * Test for RFXCom-binding
27 * @author Martin van Wingerden - Initial contribution
28 * @author James Hewitt-Thomas - Added first actual tests
31 public class RFXComUndecodedRFMessageTest {
33 private void testMessage(String hexMsg, RFXComUndecodedRFMessage.SubType subType, int seqNbr, String rawPayload)
34 throws RFXComException {
35 final RFXComUndecodedRFMessage msg = (RFXComUndecodedRFMessage) RFXComMessageFactory
36 .createMessage(HexUtils.hexToBytes(hexMsg));
37 assertEquals(subType, msg.subType, "SubType");
38 assertEquals(seqNbr, (short) (msg.seqNbr & 0xFF), "Seq Number");
39 assertEquals("UNDECODED", msg.getDeviceId(), "Device Id");
40 assertEquals(rawPayload, HexUtils.bytesToHex(msg.rawPayload), "Payload");
42 byte[] decoded = msg.decodeMessage();
44 assertEquals(hexMsg, HexUtils.bytesToHex(decoded), "Message converted back");
48 public void testSomeMessages() throws RFXComException {
49 testMessage("070301271356ECC0", RFXComUndecodedRFMessage.SubType.ARC, 0x27, "1356ECC0");
53 public void testLongMessage() throws RFXComException {
54 RFXComUndecodedRFMessage msg = (RFXComUndecodedRFMessage) RFXComMessageFactory
55 .createMessage(PacketType.UNDECODED_RF_MESSAGE);
56 msg.subType = RFXComUndecodedRFMessage.SubType.ARC;
58 msg.rawPayload = HexUtils.hexToBytes("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021");
60 assertThrows(RFXComMessageTooLongException.class, () -> msg.decodeMessage());