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.nibeheatpump.internal.message;
15 import static org.junit.Assert.assertEquals;
17 import org.junit.Test;
18 import org.openhab.binding.nibeheatpump.internal.NibeHeatPumpException;
19 import org.openhab.core.util.HexUtils;
22 * Tests cases for {@link ModbusReadRequestMessage}.
24 * @author Pauli Anttila - Initial contribution
26 public class ModbusReadResponseMessageTest {
28 private final int coilAddress = 513;
29 private final int value = 100992003;
30 private final String okMessage = "5C00206A060102030405064B";
33 public void createMessageTest() throws NibeHeatPumpException {
34 ModbusReadResponseMessage m = new ModbusReadResponseMessage.MessageBuilder().coilAddress(coilAddress)
35 .value(value).build();
36 byte[] byteMessage = m.decodeMessage();
37 assertEquals(okMessage, HexUtils.bytesToHex(byteMessage));
41 public void parseMessageTest() throws NibeHeatPumpException {
42 byte[] msg = HexUtils.hexToBytes(okMessage);
43 ModbusReadResponseMessage m = (ModbusReadResponseMessage) MessageFactory.getMessage(msg);
44 assertEquals(coilAddress, m.getCoilAddress());
45 assertEquals(value, m.getValue());
48 @Test(expected = NibeHeatPumpException.class)
49 public void badCrcTest() throws NibeHeatPumpException {
50 final String strMessage = "5C00206A060102030405064C";
51 final byte[] byteMessage = HexUtils.hexToBytes(strMessage);
52 MessageFactory.getMessage(byteMessage);
55 @Test(expected = NibeHeatPumpException.class)
56 public void notReadResponseMessageTest() throws NibeHeatPumpException {
57 final String strMessage = "5C00206B060102030405064A";
58 final byte[] byteMessage = HexUtils.hexToBytes(strMessage);
59 new ModbusReadResponseMessage(byteMessage);