2 * Copyright (c) 2010-2023 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.modbus.e3dc.dto;
15 import static org.junit.jupiter.api.Assertions.*;
17 import java.util.Optional;
19 import org.junit.jupiter.api.BeforeEach;
20 import org.junit.jupiter.api.Test;
21 import org.openhab.binding.modbus.e3dc.internal.dto.InfoBlock;
22 import org.openhab.binding.modbus.e3dc.internal.modbus.Data;
23 import org.openhab.binding.modbus.e3dc.internal.modbus.Data.DataType;
24 import org.openhab.binding.modbus.e3dc.internal.modbus.Parser;
27 * The {@link InfoTest} Test Data Transfer Objects of Information Block
29 * @author Bernd Weymann - Initial contribution
31 public class InfoTest {
36 byte[] infoBlock = new byte[] { -29, -36, 1, 2, 0, -120, 69, 51, 47, 68, 67, 32, 71, 109, 98, 72, 0, 0, 0, 0, 0,
37 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 49, 48, 32, 69, 32, 65, 73, 79, 0, 0, 0, 0, 0, 0,
38 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 85, 78, 73, 78, 73, 84, 73, 65, 76, 73, 90, 69, 68,
39 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 49, 48, 95, 50, 48, 50, 48, 95, 48, 52, 0,
40 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
41 mc = new Parser(DataType.INFO);
42 mc.setArray(infoBlock);
46 public void testvalidInformationBlock() {
47 Optional<Data> infoOpt = mc.parse(DataType.INFO);
48 assertTrue(infoOpt.isPresent());
49 InfoBlock b = (InfoBlock) infoOpt.get();
51 assertEquals("E3DC", b.modbusId.toString(), "MagicByte");
52 assertEquals("S10 E AIO", b.modelName.toString(), "Model");
53 assertEquals("S10_2020_04", b.firmware.toString(), "Firmware");
54 assertEquals("E3/DC GmbH", b.manufacturer.toString(), "Manufacturer");
58 public void testWrongQuery() {
59 Optional<Data> dataOpt = mc.parse(DataType.POWER);
60 assertFalse(dataOpt.isPresent());
64 public void testInvalidBlockSize() {
65 byte[] infoBlock = new byte[] { -29, -36, 1, 2, 0, -120, 69, 51, 47, 68, 67, 32, 71, 109, 98, 72, 0, 0, 0, 0, 0,
66 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 49, 48, 32, 69, 32, 65, 73, 79, 0, 0, 0, 0, 0, 0,
67 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 85, 78, 73, 78, 73, 84, 73, 65, 76, 73, 90, 69, 68,
68 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 49, 48, 95, 50, 48, 50, 48, 95, 48 };
69 Parser mc = new Parser(DataType.INFO);
70 mc.setArray(infoBlock);
71 Optional<Data> infoOpt = mc.parse(DataType.INFO);
72 InfoBlock b = (InfoBlock) infoOpt.get();
73 // block still valid but data maybe corrupted => logged in warnings
74 assertTrue(infoOpt.isPresent());