1 50 package org.apache.avalon.meta.info.test; 51 52 import org.apache.avalon.framework.Version; 53 import org.apache.avalon.meta.info.ContextDescriptor; 54 import org.apache.avalon.meta.info.Descriptor; 55 import org.apache.avalon.meta.info.EntryDescriptor; 56 import org.apache.avalon.meta.info.ReferenceDescriptor; 57 58 64 public class ContextDescriptorTestCase extends AbstractDescriptorTestCase 65 { 66 private String m_classname; 67 private EntryDescriptor[] m_entries; 68 69 public ContextDescriptorTestCase( String name ) 70 { 71 super( name ); 72 } 73 74 protected Descriptor getDescriptor() 75 { 76 return new ContextDescriptor( m_classname, m_entries, getProperties() ); 77 } 78 79 protected void checkDescriptor( Descriptor desc ) 80 { 81 super.checkDescriptor( desc ); 82 ContextDescriptor ctxd = (ContextDescriptor) desc; 83 84 assertEquals( m_classname, ctxd.getContextInterfaceClassname() ); 85 assertEquals( m_entries.length, ctxd.getEntries().length ); 86 87 EntryDescriptor[] entries = ctxd.getEntries(); 88 89 for ( int i = 0; i < m_entries.length; i++ ) 90 { 91 assertEquals( m_entries[i], entries[i] ); 92 assertEquals( m_entries[i], ctxd.getEntry( m_entries[i].getKey() ) ); 93 } 94 } 95 96 public void testJoin() 97 { 98 ContextDescriptor desc = (ContextDescriptor) getDescriptor(); 99 EntryDescriptor[] good = new EntryDescriptor[]{ 100 new EntryDescriptor( "key", String .class.getName() ), 101 new EntryDescriptor( "no conflict", String .class.getName() ) 102 }; 103 EntryDescriptor[] bad = new EntryDescriptor[]{ 104 new EntryDescriptor( "key", Integer .class.getName() ) 105 }; 106 107 checkDescriptor( desc ); 108 EntryDescriptor[] merged = desc.merge( good ); 109 checkDescriptor( desc ); 110 111 assertEquals( good[0], merged[0] ); 113 assertEquals( good[1], merged[1] ); 114 assertEquals( m_entries[0], merged[2] ); 115 116 try 117 { 118 desc.merge( bad ); 119 fail( "Did not throw expected IllegalArgumentException" ); 120 } 121 catch ( IllegalArgumentException iae ) 122 { 123 } 125 } 126 127 public void setUp() 128 { 129 m_classname = "org.apache.avalon.playground.MyContext"; 130 m_entries = new EntryDescriptor[]{ 131 new EntryDescriptor( "key", String .class.getName() ) 132 }; 133 } 134 } | Popular Tags |