2 * (c) 2015 Cable Television Laboratories, Inc. All rights reserved.
5 package org.pcmm.gates.impl;
7 import org.junit.Assert;
10 import java.net.Inet4Address;
11 import java.net.Inet6Address;
12 import java.net.InetAddress;
13 import java.net.UnknownHostException;
16 * Tests the data holder class SubscriberId to ensure both construction and byte parsing result in correct object
19 public class SubscriberIDTest {
21 @Test(expected = NullPointerException.class)
22 public void nullConstArg() {
23 new SubscriberID(null);
27 public void constructorIpv4() {
28 final InetAddress addr;
30 addr = InetAddress.getByName("127.0.0.1");
31 if (addr instanceof Inet6Address) Assert.fail("Address should be IPv4");
32 } catch (UnknownHostException e) {
33 throw new RuntimeException("host not found");
35 final SubscriberID subId = new SubscriberID(addr);
36 Assert.assertEquals(addr, subId.getSourceIPAddress());
40 public void byteParsingIpv4() {
41 final InetAddress addr;
43 addr = InetAddress.getByName("127.0.0.1");
44 if (addr instanceof Inet6Address) Assert.fail("Address should be IPv4");
45 } catch (UnknownHostException e) {
46 throw new RuntimeException("host not found");
48 final SubscriberID subId = new SubscriberID(addr);
49 final SubscriberID parsed = SubscriberID.parse(subId.getBytes());
50 Assert.assertEquals(subId, parsed);
54 public void constructorIpv6() {
55 final InetAddress addr;
57 addr = InetAddress.getByName("00:00:00:00:00:00:00:01");
58 if (addr instanceof Inet4Address) Assert.fail("Address should be IPv6");
59 } catch (UnknownHostException e) {
60 throw new RuntimeException("host not found");
62 final SubscriberID subId = new SubscriberID(addr);
63 Assert.assertEquals(addr, subId.getSourceIPAddress());
67 public void byteParsingIpv6() {
68 final InetAddress addr;
70 addr = InetAddress.getByName("00:00:00:00:00:00:00:01");
71 if (addr instanceof Inet4Address) Assert.fail("Address should be IPv6");
72 } catch (UnknownHostException e) {
73 throw new RuntimeException("host not found");
75 final SubscriberID subId = new SubscriberID(addr);
76 final SubscriberID parsed = SubscriberID.parse(subId.getBytes());
77 Assert.assertEquals(subId, parsed);