2 * Copyright (c) 2010-2022 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.core.util.HexUtils;
24 * Test for RFXCom-binding
26 * @author Martin van Wingerden - Initial contribution
27 * @author James Hewitt-Thomas - Added first actual tests
30 public class RFXComUndecodedRFMessageTest {
32 private void testMessage(String hexMsg, RFXComUndecodedRFMessage.SubType subType, int seqNbr, String rawPayload)
33 throws RFXComException {
34 final RFXComUndecodedRFMessage msg = (RFXComUndecodedRFMessage) RFXComMessageFactoryImpl.INSTANCE
35 .createMessage(HexUtils.hexToBytes(hexMsg));
36 assertEquals(subType, msg.subType, "SubType");
37 assertEquals(seqNbr, (short) (msg.seqNbr & 0xFF), "Seq Number");
38 assertEquals("UNDECODED", msg.getDeviceId(), "Device Id");
39 assertEquals(rawPayload, HexUtils.bytesToHex(msg.rawPayload), "Payload");
41 byte[] decoded = msg.decodeMessage();
43 assertEquals(hexMsg, HexUtils.bytesToHex(decoded), "Message converted back");
47 public void testSomeMessages() throws RFXComException {
48 testMessage("070301271356ECC0", RFXComUndecodedRFMessage.SubType.ARC, 0x27, "1356ECC0");
52 public void testLongMessage() throws RFXComException {
53 assertThrows(RFXComMessageTooLongException.class,
54 () -> testMessage("25030101000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021",
55 RFXComUndecodedRFMessage.SubType.ARC, 0x01,
56 "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021"));