Added GateInfo to Op Ds and RPCs to support gate update requests
[packetcable.git] / packetcable-driver / src / test / java / org / pcmm / gates / impl / PCMMErrorTest.java
1 /*
2  * (c) 2015 Cable Television Laboratories, Inc.  All rights reserved.
3  */
4
5 package org.pcmm.gates.impl;
6
7 import org.junit.Assert;
8 import org.junit.Test;
9 import org.pcmm.gates.IPCMMError.ErrorCode;
10 import org.umu.cops.stack.COPSMsgParser;
11
12 /**
13  * Tests the data holder class PCMMError to ensure both construction and byte parsing result in correct object
14  * creation.
15  */
16 public class PCMMErrorTest {
17
18     @Test(expected = IllegalArgumentException.class)
19     public void nullErrorAndSubCodes() {
20         new PCMMError(null, (short)0);
21     }
22
23     @Test(expected = IllegalArgumentException.class)
24     public void nullErrorCode() {
25         new PCMMError(null, (short)0);
26     }
27
28     @Test(expected = IllegalArgumentException.class)
29     public void naErrorCode() {
30         new PCMMError(ErrorCode.NA);
31     }
32
33     @Test
34     public void construction() {
35         final PCMMError error = new PCMMError(ErrorCode.TRANSPORT_ERROR, (short)0);
36         Assert.assertEquals(ErrorCode.TRANSPORT_ERROR, error.getErrorCode());
37         Assert.assertEquals(ErrorCode.NA.getCode(), error.getErrorSubcode());
38
39         final byte[] dataBytes = error.getBytes();
40         Assert.assertEquals(4, dataBytes.length);
41         Assert.assertEquals(ErrorCode.TRANSPORT_ERROR,
42                 ErrorCode.valueOf(COPSMsgParser.bytesToShort(dataBytes[0], dataBytes[1])));
43         final short subCodeVal = COPSMsgParser.bytesToShort(dataBytes[2], dataBytes[3]);
44         Assert.assertEquals(ErrorCode.NA,
45                 ErrorCode.valueOf(COPSMsgParser.bytesToShort(dataBytes[2], dataBytes[3])));
46     }
47
48     @Test
49     public void byteParsing() {
50         final PCMMError error = new PCMMError(ErrorCode.INVALID_FIELD, ErrorCode.INVALID_SUB_ID.getCode());
51         final PCMMError parsed = PCMMError.parse(error.getBytes());
52         Assert.assertEquals(error, parsed);
53     }
54
55 }