1 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 ; 11 import java.io.ByteArrayOutputStream ; 12 import java.io.ObjectInputStream ; 13 import java.io.ObjectOutputStream ; 14 15 16 public class LogicalAddressTest1_4 extends TestCase { 17 LogicalAddress1_4 a, b, c; 18 19 20 public LogicalAddressTest1_4(String name) { 21 super(name); 22 } 23 24 25 public void setUp() throws CloneNotSupportedException { 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 { 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 { 57 ByteArrayOutputStream bos=new ByteArrayOutputStream (); 58 ObjectOutputStream oos=new ObjectOutputStream (bos); 59 byte[] buf=null; 60 ByteArrayInputStream bis=null; 61 ObjectInputStream 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 (buf); 72 ois=new ObjectInputStream (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 (b2.getAdditionalData()))); 81 } 82 83 84 public void testExternalizationAdditionalData() throws Exception { 85 ByteArrayOutputStream bos=new ByteArrayOutputStream (); 86 ObjectOutputStream oos=new ObjectOutputStream (bos); 87 byte[] buf=null; 88 ByteArrayInputStream bis=null; 89 ObjectInputStream 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 (buf); 98 ois=new ObjectInputStream (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 [] args) { 116 junit.textui.TestRunner.run(suite()); 117 } 118 } 119 | Popular Tags |