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.IClassifier.Protocol;
10 import org.pcmm.gates.IExtendedClassifier.ActivationState;
12 import java.net.Inet4Address;
13 import java.net.InetAddress;
14 import java.net.UnknownHostException;
17 * Tests the data holder class ExtendedClassifier to ensure both construction and byte parsing result in correct object
20 public class ExtendedClassifierTest {
22 @Test(expected = IllegalArgumentException.class)
23 public void nullProtocol() throws UnknownHostException {
24 new ExtendedClassifier(null, (byte)1, (byte)1, (Inet4Address) InetAddress.getByName("localhost"),
25 (Inet4Address)InetAddress.getByName("localhost"), (short)1, (short)2, (byte)4,
26 (Inet4Address) InetAddress.getByName("localhost"), (Inet4Address) InetAddress.getByName("localhost"),
27 (short)5, (short)6, (short)7, ActivationState.ACTIVE, (byte)9);
30 @Test(expected = IllegalArgumentException.class)
31 public void nullSrcAddr() throws UnknownHostException {
32 new ExtendedClassifier(Protocol.NONE, (byte)1, (byte)1, null,
33 (Inet4Address)InetAddress.getByName("localhost"), (short)1, (short)2, (byte)4,
34 (Inet4Address) InetAddress.getByName("localhost"), (Inet4Address) InetAddress.getByName("localhost"),
35 (short)5, (short)6, (short)7, ActivationState.ACTIVE, (byte)9);
38 @Test(expected = IllegalArgumentException.class)
39 public void nullDstAddr() throws UnknownHostException {
40 new ExtendedClassifier(Protocol.NONE, (byte)1, (byte)1, (Inet4Address) InetAddress.getByName("localhost"),
41 null, (short)1, (short)2, (byte)4,
42 (Inet4Address) InetAddress.getByName("localhost"), (Inet4Address) InetAddress.getByName("localhost"),
43 (short)5, (short)6, (short)7, ActivationState.ACTIVE, (byte)9);
46 @Test(expected = IllegalArgumentException.class)
47 public void nullSrcMask() throws UnknownHostException {
48 new ExtendedClassifier(Protocol.NONE, (byte)1, (byte)1, (Inet4Address) InetAddress.getByName("localhost"),
49 (Inet4Address)InetAddress.getByName("localhost"), (short)1, (short)2, (byte)4,
50 null, (Inet4Address) InetAddress.getByName("localhost"),
51 (short)5, (short)6, (short)7, ActivationState.ACTIVE, (byte)9);
54 @Test(expected = IllegalArgumentException.class)
55 public void nullDstMask() throws UnknownHostException {
56 new ExtendedClassifier(Protocol.NONE, (byte)1, (byte)1, (Inet4Address) InetAddress.getByName("localhost"),
57 (Inet4Address)InetAddress.getByName("localhost"), (short)1, (short)2, (byte)4,
58 (Inet4Address) InetAddress.getByName("localhost"), null,
59 (short)5, (short)6, (short)7, ActivationState.ACTIVE, (byte)9);
62 @Test(expected = IllegalArgumentException.class)
63 public void nullActivationState() throws UnknownHostException {
64 new ExtendedClassifier(Protocol.NONE, (byte)1, (byte)1, (Inet4Address) InetAddress.getByName("localhost"),
65 (Inet4Address)InetAddress.getByName("localhost"), (short)1, (short)2, (byte)4,
66 (Inet4Address) InetAddress.getByName("localhost"), (Inet4Address) InetAddress.getByName("localhost"),
67 (short)5, (short)6, (short)7, null, (byte)9);
71 public void constructionActive() throws UnknownHostException {
72 final ExtendedClassifier classifier = new ExtendedClassifier(Protocol.NONE, (byte)1, (byte)10,
73 (Inet4Address) InetAddress.getByName("localhost"),
74 (Inet4Address)InetAddress.getByName("localhost"), (short)11, (short)12, (byte)14,
75 (Inet4Address) InetAddress.getByName("localhost"), (Inet4Address) InetAddress.getByName("localhost"),
76 (short)15, (short)16, (short)17, ActivationState.ACTIVE, (byte)19);
77 Assert.assertEquals(Protocol.NONE, classifier.getProtocol());
78 Assert.assertEquals((byte)1, classifier.getDSCPTOS());
79 Assert.assertEquals(InetAddress.getByName("localhost"), classifier.getSourceIPAddress());
80 Assert.assertEquals(InetAddress.getByName("localhost"), classifier.getDestinationIPAddress());
81 Assert.assertEquals((short) 11, classifier.getSourcePort());
82 Assert.assertEquals((short) 12, classifier.getDestinationPort());
83 Assert.assertEquals((byte) 14, classifier.getPriority());
84 Assert.assertEquals(InetAddress.getByName("localhost"), classifier.getIPSourceMask());
85 Assert.assertEquals(InetAddress.getByName("localhost"), classifier.getIPDestinationMask());
86 Assert.assertEquals((short) 15, classifier.getSourcePortEnd());
87 Assert.assertEquals((short) 16, classifier.getDestinationPortEnd());
88 Assert.assertEquals((short) 17, classifier.getClassifierID());
89 Assert.assertEquals(ActivationState.ACTIVE, classifier.getActivationState());
90 Assert.assertEquals((byte) 19, classifier.getAction());
94 public void constructionInactive() throws UnknownHostException {
95 final ExtendedClassifier classifier = new ExtendedClassifier(Protocol.NONE, (byte)1, (byte)10,
96 (Inet4Address) InetAddress.getByName("localhost"),
97 (Inet4Address)InetAddress.getByName("localhost"), (short)11, (short)12, (byte)14,
98 (Inet4Address) InetAddress.getByName("localhost"), (Inet4Address) InetAddress.getByName("localhost"),
99 (short)15, (short)16, (short)17, ActivationState.INACTIVE, (byte)19);
100 Assert.assertEquals(Protocol.NONE, classifier.getProtocol());
101 Assert.assertEquals((byte)1, classifier.getDSCPTOS());
102 Assert.assertEquals(InetAddress.getByName("localhost"), classifier.getSourceIPAddress());
103 Assert.assertEquals(InetAddress.getByName("localhost"), classifier.getDestinationIPAddress());
104 Assert.assertEquals((short) 11, classifier.getSourcePort());
105 Assert.assertEquals((short) 12, classifier.getDestinationPort());
106 Assert.assertEquals((byte) 14, classifier.getPriority());
107 Assert.assertEquals(InetAddress.getByName("localhost"), classifier.getIPSourceMask());
108 Assert.assertEquals(InetAddress.getByName("localhost"), classifier.getIPDestinationMask());
109 Assert.assertEquals((short) 15, classifier.getSourcePortEnd());
110 Assert.assertEquals((short) 16, classifier.getDestinationPortEnd());
111 Assert.assertEquals((short) 17, classifier.getClassifierID());
112 Assert.assertEquals(ActivationState.INACTIVE, classifier.getActivationState());
113 Assert.assertEquals((byte) 19, classifier.getAction());
117 public void byteParsingActive() throws UnknownHostException {
118 final ExtendedClassifier classifier = new ExtendedClassifier(Protocol.NONE, (byte)1, (byte)20,
119 (Inet4Address) InetAddress.getByName("localhost"),
120 (Inet4Address)InetAddress.getByName("localhost"), (short)21, (short)22, (byte)24,
121 (Inet4Address) InetAddress.getByName("localhost"), (Inet4Address) InetAddress.getByName("localhost"),
122 (short)25, (short)26, (short)27, ActivationState.ACTIVE, (byte)29);
123 final ExtendedClassifier parsed = ExtendedClassifier.parse(classifier.getBytes());
124 Assert.assertEquals(classifier, parsed);
128 public void byteParsingInactive() throws UnknownHostException {
129 final ExtendedClassifier classifier = new ExtendedClassifier(Protocol.NONE, (byte)1, (byte)20,
130 (Inet4Address) InetAddress.getByName("localhost"),
131 (Inet4Address)InetAddress.getByName("localhost"), (short)21, (short)22, (byte)24,
132 (Inet4Address) InetAddress.getByName("localhost"), (Inet4Address) InetAddress.getByName("localhost"),
133 (short)25, (short)26, (short)27, ActivationState.INACTIVE, (byte)29);
134 final ExtendedClassifier parsed = ExtendedClassifier.parse(classifier.getBytes());
135 Assert.assertEquals(classifier, parsed);