1 50 package org.apache.avalon.meta.info.test; 51 52 import junit.framework.TestCase; 53 import org.apache.avalon.meta.info.EntryDescriptor; 54 55 import java.io.*; 56 57 63 public class EntryDescriptorTestCase extends TestCase 64 { 65 private static final String m_key = "key"; 66 private static final String m_alias = "otherVal"; 67 private static final String m_type = EntryDescriptor.class.getName(); 68 private static final boolean m_optional = true; 69 private static final boolean m_volatile = true; 70 71 public EntryDescriptorTestCase( String name ) 72 { 73 super( name ); 74 } 75 76 public void testEntryDescriptor() 77 { 78 EntryDescriptor entry = new EntryDescriptor(m_key, m_type, m_optional, m_volatile, m_alias); 79 checkEntry(entry, m_key, m_type, m_optional, m_volatile, m_alias ); 80 81 entry = new EntryDescriptor(m_key, m_type); 82 checkEntry(entry, m_key, m_type, false, false, null ); 83 84 entry = new EntryDescriptor(m_key, m_type, m_optional); 85 checkEntry(entry, m_key, m_type, m_optional, false, null ); 86 87 entry = new EntryDescriptor( m_key, m_type, m_optional, m_volatile ); 88 checkEntry( entry, m_key, m_type, m_optional, m_volatile, null ); 89 90 try 91 { 92 new EntryDescriptor(null, m_type); 93 fail("Did not throw expected NullPointerException"); 94 } 95 catch(NullPointerException npe) 96 { 97 } 99 100 try 101 { 102 new EntryDescriptor( m_key, null ); 103 fail( "Did not throw expected NullPointerException" ); 104 } 105 catch ( NullPointerException npe ) 106 { 107 } 109 } 110 111 private void checkEntry(EntryDescriptor desc, String key, String type, boolean isOptional, boolean isVolatile, String alias) 112 { 113 assertNotNull( desc ); 114 assertEquals( key, desc.getKey() ); 115 if( alias == null ) 116 { 117 assertEquals( key, desc.getAlias() ); 118 } 119 else 120 { 121 assertEquals( alias, desc.getAlias() ); 122 } 123 assertEquals( type, desc.getClassname() ); 124 assertEquals( isOptional, desc.isOptional() ); 125 assertEquals( ! isOptional, desc.isRequired() ); 126 assertEquals( isVolatile, desc.isVolatile() ); 127 } 128 129 public void testSerialization() throws IOException, ClassNotFoundException ![JavaDoc](../../../../../../../cmn/javadoc.gif) 130 { 131 EntryDescriptor entry = new EntryDescriptor( m_key, m_type, m_optional, m_volatile, m_alias ); 132 checkEntry( entry, m_key, m_type, m_optional, m_volatile, m_alias ); 133 134 File file = new File( "test.out" ); 135 ObjectOutputStream oos = new ObjectOutputStream( new FileOutputStream( file ) ); 136 oos.writeObject( entry ); 137 oos.close(); 138 139 ObjectInputStream ois = new ObjectInputStream( new FileInputStream( file ) ); 140 EntryDescriptor serialized = (EntryDescriptor) ois.readObject(); 141 ois.close(); 142 file.delete(); 143 144 checkEntry( serialized, m_key, m_type, m_optional, m_volatile, m_alias ); 145 146 assertEquals( entry, serialized ); 147 assertEquals( entry.hashCode(), serialized.hashCode() ); 148 } 149 } | Popular Tags |