KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > repository > meta > MetaTest


1 /*
2  * Copyright 2004 Apache Software Foundation
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12  * implied.
13  *
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.avalon.repository.meta;
19
20 import java.util.NoSuchElementException JavaDoc;
21 import javax.naming.directory.Attributes JavaDoc;
22 import javax.naming.directory.BasicAttributes JavaDoc;
23 import javax.naming.directory.Attribute JavaDoc;
24 import javax.naming.NamingException JavaDoc;
25
26 import junit.framework.TestCase;
27
28
29 /**
30  *
31  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
32  * @version $Revision: 1.3 $
33  */

34 public class MetaTest extends TestCase
35 {
36
37     public static void main(String JavaDoc[] args)
38     {
39         junit.textui.TestRunner.run( MetaTest.class );
40     }
41
42     /**
43      * Constructor for ArtifactReferenceTest.
44      * @param arg0
45      */

46     public MetaTest( String JavaDoc name )
47     {
48         super( name );
49     }
50     
51     public void testConstructor() throws Exception JavaDoc
52     {
53         try
54         {
55             ArtifactDescriptor meta = new ArtifactDescriptor( null );
56             fail( "constructor using null should throw an NPE" );
57         }
58         catch( NullPointerException JavaDoc e )
59         {
60             assertTrue( true );
61         }
62         catch( Throwable JavaDoc e )
63         {
64             fail( "NPE expected by encountered: " + e );
65         }
66     }
67
68     public void testEmptyAttribute() throws Exception JavaDoc
69     {
70         Attributes JavaDoc attributes = new BasicAttributes JavaDoc();
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 JavaDoc e )
81         {
82             fail( "Unexpected error: " + e );
83         }
84     }
85
86     public void testIntegrity() throws Exception JavaDoc
87     {
88         String JavaDoc domain = "aaa";
89         String JavaDoc version = "123";
90
91         Attributes JavaDoc attributes = new BasicAttributes JavaDoc();
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 JavaDoc e )
103         {
104             fail( "unexpected error: " + e );
105         }
106     }
107 }
108
Popular Tags