1 17 18 package org.apache.avalon.repository.meta; 19 20 import java.util.NoSuchElementException ; 21 import javax.naming.directory.Attributes ; 22 import javax.naming.directory.BasicAttributes ; 23 import javax.naming.directory.Attribute ; 24 import javax.naming.NamingException ; 25 26 import junit.framework.TestCase; 27 28 29 34 public class MetaTest extends TestCase 35 { 36 37 public static void main(String [] args) 38 { 39 junit.textui.TestRunner.run( MetaTest.class ); 40 } 41 42 46 public MetaTest( String name ) 47 { 48 super( name ); 49 } 50 51 public void testConstructor() throws Exception 52 { 53 try 54 { 55 ArtifactDescriptor meta = new ArtifactDescriptor( null ); 56 fail( "constructor using null should throw an NPE" ); 57 } 58 catch( NullPointerException e ) 59 { 60 assertTrue( true ); 61 } 62 catch( Throwable e ) 63 { 64 fail( "NPE expected by encountered: " + e ); 65 } 66 } 67 68 public void testEmptyAttribute() throws Exception 69 { 70 Attributes attributes = new BasicAttributes (); 71 try 72 { 73 ArtifactDescriptor meta = new ArtifactDescriptor( attributes ); 74 fail( "missing attributes should fail" ); 75 } 76 catch( MetaException e ) 77 { 78 assertTrue( true ); 79 } 80 catch( Throwable e ) 81 { 82 fail( "Unexpected error: " + e ); 83 } 84 } 85 86 public void testIntegrity() throws Exception 87 { 88 String domain = "aaa"; 89 String version = "123"; 90 91 Attributes attributes = new BasicAttributes (); 92 attributes.put( ArtifactDescriptor.DOMAIN_KEY, domain ); 93 attributes.put( ArtifactDescriptor.VERSION_KEY, version ); 94 95 try 96 { 97 ArtifactDescriptor meta = new ArtifactDescriptor( attributes ); 98 assertEquals( "domain", meta.getDomain(), domain ); 99 assertEquals( "version", meta.getVersion(), version ); 100 assertEquals( "equals", meta, meta ); 101 } 102 catch( Throwable e ) 103 { 104 fail( "unexpected error: " + e ); 105 } 106 } 107 } 108 | Popular Tags |