2 * (c) 2015 Cable Television Laboratories, Inc. All rights reserved.
5 package org.pcmm.gates.impl;
7 import org.junit.Assert;
9 import org.pcmm.gates.IPCMMError.ErrorCode;
10 import org.umu.cops.stack.COPSMsgParser;
13 * Tests the data holder class PCMMError to ensure both construction and byte parsing result in correct object
16 public class PCMMErrorTest {
18 @Test(expected = IllegalArgumentException.class)
19 public void nullErrorAndSubCodes() {
20 new PCMMError(null, (short)0);
23 @Test(expected = IllegalArgumentException.class)
24 public void nullErrorCode() {
25 new PCMMError(null, (short)0);
28 @Test(expected = IllegalArgumentException.class)
29 public void naErrorCode() {
30 new PCMMError(ErrorCode.NA);
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());
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])));
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);