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.IGateSpec.Direction;
13 import org.umu.cops.stack.COPSMsgParser;
16 * Tests the data holder class GateSpec to ensure both construction and byte parsing result in correct object
19 public class GateSpecTest {
21 @Test(expected = IllegalArgumentException.class)
22 public void nullDirection() {
23 new GateSpec(null, (byte)1, (byte)1, new SessionClassID((byte)1),
24 (short)1, (short)2, (short)3, (short)4);
27 @Test(expected = IllegalArgumentException.class)
28 public void nullSessionClassID() {
29 new GateSpec(Direction.UPSTREAM, (byte)1, (byte)1, null,
30 (short)1, (short)2, (short)3, (short)4);
34 public void construction() {
35 final GateSpec spec = new GateSpec(Direction.UPSTREAM, (byte)1, (byte)1, new SessionClassID((byte)1),
36 (short)1, (short)2, (short)3, (short)4);
37 Assert.assertEquals(Direction.UPSTREAM, spec.getDirection());
38 Assert.assertEquals((byte)1, spec.getDSCP_TOSOverwrite());
39 Assert.assertEquals((byte)1, spec.getDSCP_TOSMask());
40 Assert.assertEquals(new SessionClassID((byte) 1), spec.getSessionClassID());
41 Assert.assertEquals((short)1, spec.getTimerT1());
42 Assert.assertEquals((short)2, spec.getTimerT2());
43 Assert.assertEquals((short)3, spec.getTimerT3());
44 Assert.assertEquals((short)4, spec.getTimerT4());
46 final byte[] data = spec.getBytes();
48 Assert.assertEquals(Direction.UPSTREAM, Direction.valueOf(data[0]));
49 Assert.assertEquals((byte)1, data[1]);
50 Assert.assertEquals((byte)1, data[2]);
51 Assert.assertEquals(new SessionClassID((byte)1), new SessionClassID(data[3]));
52 Assert.assertEquals((short)1, COPSMsgParser.bytesToShort(data[4], data[5]));
53 Assert.assertEquals((short)2, COPSMsgParser.bytesToShort(data[6], data[7]));
54 Assert.assertEquals((short)3, COPSMsgParser.bytesToShort(data[8], data[9]));
55 Assert.assertEquals((short)4, COPSMsgParser.bytesToShort(data[10], data[11]));
59 public void byteParsing() {
60 final GateSpec spec = new GateSpec(Direction.DOWNSTREAM, (byte)1, (byte)2, new SessionClassID((byte)3),
61 (short)4, (short)5, (short)6, (short)7);
62 final GateSpec parsed = GateSpec.parse(spec.getBytes());
63 Assert.assertEquals(spec, parsed);