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.IClassifier.Protocol;
14 import java.net.Inet4Address;
15 import java.net.InetAddress;
16 import java.net.UnknownHostException;
19 * Tests the data holder class Classifier to ensure both construction and byte parsing result in correct object
22 public class ClassifierTest {
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);
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);
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);
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());
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);