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.paradoxalarm.internal;
15 import static org.junit.jupiter.api.Assertions.*;
17 import java.util.Arrays;
19 import org.junit.jupiter.api.Test;
20 import org.openhab.binding.paradoxalarm.internal.communication.messages.CommandPayload;
21 import org.openhab.binding.paradoxalarm.internal.communication.messages.EpromRequestPayload;
22 import org.openhab.binding.paradoxalarm.internal.communication.messages.HeaderCommand;
23 import org.openhab.binding.paradoxalarm.internal.communication.messages.IPayload;
24 import org.openhab.binding.paradoxalarm.internal.communication.messages.ParadoxIPPacket;
25 import org.openhab.binding.paradoxalarm.internal.communication.messages.PartitionCommand;
26 import org.openhab.binding.paradoxalarm.internal.exceptions.ParadoxException;
27 import org.openhab.binding.paradoxalarm.internal.util.ParadoxUtil;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
32 * The {@link TestGetBytes} This test tests creation of IP packet and it's getBytes() method
34 * @author Konstantin Polihronov - Initial contribution
36 public class TestGetBytes {
38 private static final int PARTITION_NUMBER = 1;
41 System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "TRACE");
44 private static final Logger logger = LoggerFactory.getLogger(ParadoxUtil.class);
46 private static final byte[] EXPECTED1 = { (byte) 0xAA, 0x0A, 0x00, 0x03, 0x08, (byte) 0xF0, 0x00, 0x00, 0x01,
47 (byte) 0xEE, (byte) 0xEE, (byte) 0xEE, (byte) 0xEE, (byte) 0xEE, (byte) 0xEE, (byte) 0xEE, 0x01, 0x02, 0x03,
48 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10 };
50 private static final byte[] PAYLOAD = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10 };
53 public void testParadoxIPPacket() {
54 ParadoxIPPacket paradoxIPPacket = new ParadoxIPPacket(PAYLOAD, false)
55 .setCommand(HeaderCommand.CONNECT_TO_IP_MODULE);
56 final byte[] packetBytes = paradoxIPPacket.getBytes();
58 ParadoxUtil.printByteArray("Expected =", EXPECTED1);
59 ParadoxUtil.printByteArray("Packet =", packetBytes);
61 assertTrue(Arrays.equals(packetBytes, EXPECTED1));
64 private static final byte[] EXPECTED_COMMAND_PAYLOAD = { 0x40, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
65 0x00, 0x00, 0x00, 0x00, 0x00 };
68 public void testCommandPayload() {
69 CommandPayload payload = new CommandPayload(PARTITION_NUMBER, PartitionCommand.ARM);
70 final byte[] packetBytes = payload.getBytes();
72 ParadoxUtil.printByteArray("Expected =", EXPECTED_COMMAND_PAYLOAD);
73 ParadoxUtil.printByteArray("Result =", packetBytes);
75 assertTrue(Arrays.equals(packetBytes, EXPECTED_COMMAND_PAYLOAD));
78 private static final byte[] EXPECTED_MEMORY_PAYLOAD = { (byte) 0xAA, 0x0A, 0x00, 0x03, 0x08, (byte) 0xF0, 0x00,
79 0x00, 0x01, (byte) 0xEE, (byte) 0xEE, (byte) 0xEE, (byte) 0xEE, (byte) 0xEE, (byte) 0xEE, (byte) 0xEE, 0x01,
80 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10 };
83 public void testMemoryRequestPayload() throws ParadoxException {
84 int address = 0x3A6B + (PARTITION_NUMBER) * 107;
85 byte labelLength = 16;
86 IPayload payload = new EpromRequestPayload(address, labelLength);
87 byte[] bytes = payload.getBytes();
88 ParadoxUtil.printByteArray("Expected =", EXPECTED_MEMORY_PAYLOAD);
89 ParadoxUtil.printByteArray("Result =", bytes);