1 17 package org.apache.servicemix.jbi.framework; 18 19 import java.io.ByteArrayInputStream ; 20 import java.io.ByteArrayOutputStream ; 21 import java.io.ObjectInputStream ; 22 import java.io.ObjectOutputStream ; 23 24 import org.apache.servicemix.jbi.framework.ComponentNameSpace; 25 26 import junit.framework.TestCase; 27 28 public class ComponentNameSpaceTest extends TestCase { 29 30 33 public void testAccessors() { 34 ComponentNameSpace cns = new ComponentNameSpace(); 35 assertNull(cns.getContainerName()); 36 assertNull(cns.getName()); 37 cns.setContainerName("container"); 38 assertEquals("container", cns.getContainerName()); 39 cns.setName("name"); 40 assertEquals("name", cns.getName()); 41 } 42 43 47 public void testHashCodeEqualsObject() { 48 ComponentNameSpace cns1 = new ComponentNameSpace("container", "name"); 49 ComponentNameSpace cns2 = new ComponentNameSpace("container", "name"); 50 assertTrue(cns1.equals(cns2)); 51 assertTrue(cns1.hashCode() == cns2.hashCode()); 52 53 ComponentNameSpace cns3 = new ComponentNameSpace("container1", "name"); 54 ComponentNameSpace cns4 = new ComponentNameSpace("container2", "name"); 55 assertFalse(cns3.equals(cns4)); 56 assertFalse(cns3.hashCode() == cns4.hashCode()); 57 58 ComponentNameSpace cns5 = new ComponentNameSpace("container", "name1"); 59 ComponentNameSpace cns6 = new ComponentNameSpace("container", "name2"); 60 assertFalse(cns5.equals(cns6)); 61 assertFalse(cns5.hashCode() == cns6.hashCode()); 62 } 63 64 68 public void testSerialize() throws Exception { 69 ComponentNameSpace cns = new ComponentNameSpace("container", "name"); 70 71 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 72 ObjectOutputStream oos = new ObjectOutputStream (baos); 73 oos.writeObject(cns); 74 oos.close(); 75 76 ByteArrayInputStream bais = new ByteArrayInputStream (baos.toByteArray()); 77 ObjectInputStream ois = new ObjectInputStream (bais); 78 Object out = ois.readObject(); 79 80 assertNotNull(out); 81 assertTrue(out instanceof ComponentNameSpace); 82 ComponentNameSpace cnsOut = (ComponentNameSpace) out; 83 assertEquals(cns, cnsOut); 84 assertEquals(cns.getName(), cnsOut.getName()); 85 } 86 87 90 public void testCopy() { 91 ComponentNameSpace cns1 = new ComponentNameSpace("container", "name"); 92 ComponentNameSpace cns2 = cns1.copy(); 93 assertEquals(cns1, cns1); 94 assertEquals(cns1.getName(), cns2.getName()); 95 } 96 97 } 98 | Popular Tags |