2 * Copyright (c) 2015 Cable Television Laboratories, Inc and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.pcmm.gates.impl;
10 import org.junit.Assert;
11 import org.junit.Test;
12 import org.pcmm.gates.ITransactionID.GateCommandType;
13 import org.umu.cops.stack.COPSMsgParser;
16 * Tests the data holder class TransactionID to ensure both construction and byte parsing result in correct object
19 public class TransactionIDTest {
21 @Test(expected = IllegalArgumentException.class)
22 public void nullCommandType() {
23 new TransactionID((short)9, null);
27 public void construction() {
28 final TransactionID transID = new TransactionID((short)9, GateCommandType.GATE_CMD_ERR);
29 final byte[] dataBytes = transID.getBytes();
30 Assert.assertEquals(4, dataBytes.length);
31 Assert.assertEquals(9, COPSMsgParser.bytesToShort(dataBytes[0], dataBytes[1]));
32 Assert.assertEquals(GateCommandType.GATE_CMD_ERR,
33 GateCommandType.valueOf(COPSMsgParser.bytesToShort(dataBytes[2], dataBytes[3])));
37 public void byteParsing() {
38 final TransactionID transID = new TransactionID((short)11, GateCommandType.GATE_DELETE_ACK);
39 final TransactionID parsed = TransactionID.parse(transID.getBytes());
40 Assert.assertEquals(transID, parsed);