1 package org.umu.cops.stack;
3 import org.junit.Assert;
5 import org.umu.cops.stack.COPSObjHeader.CNum;
6 import org.umu.cops.stack.COPSObjHeader.CType;
8 import java.io.ByteArrayOutputStream;
11 * Tests for the first constructor of the COPSIpv6OutInterfaceTest class.
12 * Should any of these tests be inaccurate it is due to the fact that they have been written after COPSAcctTimer had been
13 * released and my assumptions may be incorrect.
15 public class COPSIpv6OutInterfaceTest {
17 @Test(expected = IllegalArgumentException.class)
18 public void nullAddress() {
19 new COPSIpv6OutInterface(null, 0);
22 @Test(expected = IllegalArgumentException.class)
23 public void nullHeader() throws Exception {
24 new COPSIpv6OutInterface(null, new COPSIpv6Address("localhost"), 0);
27 @Test(expected = IllegalArgumentException.class)
28 public void nullAddressWithHeader() {
29 new COPSIpv6OutInterface(new COPSObjHeader(CNum.OUTINTF, CType.STATELESS), null, 0);
32 @Test(expected = IllegalArgumentException.class)
33 public void invalidCNum() {
34 new COPSIpv6OutInterface(new COPSObjHeader(CNum.HANDLE, CType.STATELESS), null, 0);
37 @Test(expected = IllegalArgumentException.class)
38 public void invalidCType() {
39 new COPSIpv6OutInterface(new COPSObjHeader(CNum.OUTINTF, CType.DEF), null, 0);
43 public void valid() throws Exception {
44 final COPSIpv6Address address = new COPSIpv6Address("localhost");
45 final COPSIpv6OutInterface intf = new COPSIpv6OutInterface(address, 5);
46 Assert.assertEquals(new COPSObjHeader(CNum.OUTINTF, CType.STATELESS), intf.getHeader());
47 Assert.assertEquals(20, intf.getDataLength());
48 Assert.assertEquals(address, intf._addr);
49 Assert.assertEquals(5, intf._ifindex);
51 final ByteArrayOutputStream os = new ByteArrayOutputStream();
54 final String out = new String(os.toByteArray());
55 System.out.println(out);
56 final String[] lines = out.split("\n");
57 Assert.assertEquals(5, lines.length);
58 Assert.assertEquals("**Out-Interface**", lines[0]);
59 Assert.assertEquals("C-num: OUTINTF", lines[1]);
60 Assert.assertEquals("C-type: STATELESS", lines[2]);
61 Assert.assertEquals("Address: localhost", lines[3]);
62 Assert.assertEquals("ifindex: 5", lines[4]);
65 // The writeData() method will be tested implicitly via any of the COPSMsg tests