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.Assert.assertEquals;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.junit.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", subType, msg.subType);
38 assertEquals("Seq Number", seqNbr, (short) (msg.seqNbr & 0xFF));
39 assertEquals("Device Id", "UNDECODED", msg.getDeviceId());
40 assertEquals("Payload", rawPayload, HexUtils.bytesToHex(msg.rawPayload));
42 byte[] decoded = msg.decodeMessage();
44 assertEquals("Message converted back", hexMsg, HexUtils.bytesToHex(decoded));
48 public void testSomeMessages() throws RFXComException {
49 testMessage("070301271356ECC0", RFXComUndecodedRFMessage.SubType.ARC, 0x27, "1356ECC0");
52 @Test(expected = RFXComMessageTooLongException.class)
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");