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.IPCMMError.ErrorCode;
13 import org.umu.cops.stack.COPSMsgParser;
16 * Tests the data holder class PCMMError to ensure both construction and byte parsing result in correct object
19 public class PCMMErrorTest {
21 @Test(expected = IllegalArgumentException.class)
22 public void nullErrorAndSubCodes() {
23 new PCMMError(null, (short)0);
26 @Test(expected = IllegalArgumentException.class)
27 public void nullErrorCode() {
28 new PCMMError(null, (short)0);
31 @Test(expected = IllegalArgumentException.class)
32 public void naErrorCode() {
33 new PCMMError(ErrorCode.NA);
37 public void construction() {
38 final PCMMError error = new PCMMError(ErrorCode.TRANSPORT_ERROR, (short)0);
39 Assert.assertEquals(ErrorCode.TRANSPORT_ERROR, error.getErrorCode());
40 Assert.assertEquals(ErrorCode.NA.getCode(), error.getErrorSubcode());
42 final byte[] dataBytes = error.getBytes();
43 Assert.assertEquals(4, dataBytes.length);
44 Assert.assertEquals(ErrorCode.TRANSPORT_ERROR,
45 ErrorCode.valueOf(COPSMsgParser.bytesToShort(dataBytes[0], dataBytes[1])));
46 final short subCodeVal = COPSMsgParser.bytesToShort(dataBytes[2], dataBytes[3]);
47 Assert.assertEquals(ErrorCode.NA,
48 ErrorCode.valueOf(COPSMsgParser.bytesToShort(dataBytes[2], dataBytes[3])));
52 public void byteParsing() {
53 final PCMMError error = new PCMMError(ErrorCode.INVALID_FIELD, ErrorCode.INVALID_SUB_ID.getCode());
54 final PCMMError parsed = PCMMError.parse(error.getBytes());
55 Assert.assertEquals(error, parsed);