Add missing license headers
[packetcable.git] / packetcable-driver / src / test / java / org / pcmm / gates / impl / ClassifierTest.java
1 /*
2  * Copyright (c) 2015 Cable Television Laboratories, Inc and others.  All rights reserved.
3  *
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
7  */
8 package org.pcmm.gates.impl;
9
10 import org.junit.Assert;
11 import org.junit.Test;
12 import org.pcmm.gates.IClassifier.Protocol;
13
14 import java.net.Inet4Address;
15 import java.net.InetAddress;
16 import java.net.UnknownHostException;
17
18 /**
19  * Tests the data holder class Classifier to ensure both construction and byte parsing result in correct object
20  * creation.
21  */
22 public class ClassifierTest {
23
24     @Test(expected = IllegalArgumentException.class)
25     public void nullProtocol() throws UnknownHostException {
26         new Classifier(null, (byte)1, (byte)1, (Inet4Address)InetAddress.getByName("localhost"),
27                 (Inet4Address)InetAddress.getByName("localhost"), (short)1, (short)2, (byte)4);
28     }
29
30     @Test(expected = IllegalArgumentException.class)
31     public void nullSrcAddr() throws UnknownHostException {
32         new Classifier(Protocol.NONE, (byte)1, (byte)1, null, (Inet4Address)InetAddress.getByName("localhost"),
33                 (short)1, (short)2, (byte)4);
34     }
35
36     @Test(expected = IllegalArgumentException.class)
37     public void nullDstAddr() throws UnknownHostException {
38         new Classifier(Protocol.NONE, (byte)1, (byte)1, (Inet4Address)InetAddress.getByName("localhost"), null,
39                 (short)1, (short)2, (byte)4);
40     }
41
42     @Test
43     public void construction() throws UnknownHostException {
44         final Classifier classifier = new Classifier(Protocol.NONE, (byte)1, (byte)1,
45                 (Inet4Address)InetAddress.getByName("localhost"), (Inet4Address)InetAddress.getByName("localhost"),
46                 (short)1, (short)2, (byte)4);
47         Assert.assertEquals(Protocol.NONE, classifier.getProtocol());
48         Assert.assertEquals((byte)1, classifier.getDSCPTOS());
49         Assert.assertEquals(InetAddress.getByName("localhost"), classifier.getSourceIPAddress());
50         Assert.assertEquals(InetAddress.getByName("localhost"), classifier.getDestinationIPAddress());
51         Assert.assertEquals((short) 1, classifier.getSourcePort());
52         Assert.assertEquals((short) 2, classifier.getDestinationPort());
53         Assert.assertEquals((byte) 4, classifier.getPriority());
54     }
55
56     @Test
57     public void byteParsing() throws UnknownHostException {
58         final Classifier classifier = new Classifier(Protocol.NONE, (byte)1, (byte)4,
59                 (Inet4Address)InetAddress.getByName("localhost"), (Inet4Address)InetAddress.getByName("localhost"),
60                 (short)5, (short)6, (byte)7);
61         final Classifier parsed = Classifier.parse(classifier.getBytes());
62         Assert.assertEquals(classifier, parsed);
63     }
64
65 }