Add missing license headers
[packetcable.git] / packetcable-driver / src / test / java / org / pcmm / gates / impl / TransactionIDTest.java
1 /*
2  * Copyright (c) 2015 Cable Television Laboratories, Inc and others.  All rights reserved.
3  *
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
7  */
8 package org.pcmm.gates.impl;
9
10 import org.junit.Assert;
11 import org.junit.Test;
12 import org.pcmm.gates.ITransactionID.GateCommandType;
13 import org.umu.cops.stack.COPSMsgParser;
14
15 /**
16  * Tests the data holder class TransactionID to ensure both construction and byte parsing result in correct object
17  * creation.
18  */
19 public class TransactionIDTest {
20
21     @Test(expected = IllegalArgumentException.class)
22     public void nullCommandType() {
23         new TransactionID((short)9, null);
24     }
25
26     @Test
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])));
34     }
35
36     @Test
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);
41     }
42
43 }