KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgroups > tests > LogicalAddressTest1_4


1 // $Id
2

3 package org.jgroups.tests;
4
5 import junit.framework.Test;
6 import junit.framework.TestCase;
7 import junit.framework.TestSuite;
8 import org.jgroups.stack.LogicalAddress1_4;
9
10 import java.io.ByteArrayInputStream JavaDoc;
11 import java.io.ByteArrayOutputStream JavaDoc;
12 import java.io.ObjectInputStream JavaDoc;
13 import java.io.ObjectOutputStream JavaDoc;
14
15
16 public class LogicalAddressTest1_4 extends TestCase {
17     LogicalAddress1_4 a, b, c;
18
19
20     public LogicalAddressTest1_4(String JavaDoc name) {
21         super(name);
22     }
23
24
25     public void setUp() throws CloneNotSupportedException JavaDoc {
26         a=new LogicalAddress1_4("host1", null);
27         b=new LogicalAddress1_4("host1", null);
28         c=(LogicalAddress1_4)a.clone();
29     }
30
31     public void tearDown() {
32
33     }
34
35
36     public void testEquality() throws Exception JavaDoc {
37         assertFalse(a.equals(b));
38         assertFalse(c.equals(b));
39         assertTrue(a.equals(c));
40         assertTrue(c.equals(a));
41     }
42
43
44     public void testMcast() {
45         assertFalse(a.isMulticastAddress());
46     }
47
48
49     public void testCompareTo() {
50         assertTrue(a.compareTo(c) == 0);
51         assertTrue(a.compareTo(b) < 0);
52         assertTrue(b.compareTo(a) > 0);
53     }
54
55
56     public void testExternalization() throws Exception JavaDoc {
57         ByteArrayOutputStream JavaDoc bos=new ByteArrayOutputStream JavaDoc();
58         ObjectOutputStream JavaDoc oos=new ObjectOutputStream JavaDoc(bos);
59         byte[] buf=null;
60         ByteArrayInputStream JavaDoc bis=null;
61         ObjectInputStream JavaDoc ois;
62         LogicalAddress1_4 a2, b2;
63
64         a.setAdditionalData(null);
65         b.setAdditionalData("Bela Ban".getBytes());
66         oos.writeObject(a);
67         oos.writeObject(b);
68
69
70         buf=bos.toByteArray();
71         bis=new ByteArrayInputStream JavaDoc(buf);
72         ois=new ObjectInputStream JavaDoc(bis);
73         a2=(LogicalAddress1_4)ois.readObject();
74         b2=(LogicalAddress1_4)ois.readObject();
75
76         assertTrue(a.equals(a2));
77         assertTrue(b.equals(b2));
78
79         assertTrue(a2.getAdditionalData() == null);
80         assertTrue("Bela Ban".equals(new String JavaDoc(b2.getAdditionalData())));
81     }
82
83
84     public void testExternalizationAdditionalData() throws Exception JavaDoc {
85         ByteArrayOutputStream JavaDoc bos=new ByteArrayOutputStream JavaDoc();
86         ObjectOutputStream JavaDoc oos=new ObjectOutputStream JavaDoc(bos);
87         byte[] buf=null;
88         ByteArrayInputStream JavaDoc bis=null;
89         ObjectInputStream JavaDoc ois;
90         LogicalAddress1_4 a2, b2, c2;
91
92         oos.writeObject(a);
93         oos.writeObject(b);
94         oos.writeObject(c);
95
96         buf=bos.toByteArray();
97         bis=new ByteArrayInputStream JavaDoc(buf);
98         ois=new ObjectInputStream JavaDoc(bis);
99         a2=(LogicalAddress1_4)ois.readObject();
100         b2=(LogicalAddress1_4)ois.readObject();
101         c2=(LogicalAddress1_4)ois.readObject();
102
103         assertTrue(a.equals(a2));
104         assertTrue(b.equals(b2));
105         assertTrue(c.equals(c2));
106         assertTrue(c2.equals(a2));
107     }
108
109
110     public static Test suite() {
111         TestSuite s=new TestSuite(LogicalAddressTest1_4.class);
112         return s;
113     }
114
115     public static void main(String JavaDoc[] args) {
116         junit.textui.TestRunner.run(suite());
117     }
118 }
119
Popular Tags