KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > extension > test > SpecificationTestCase


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.extension.test;
19
20 import java.io.InputStream JavaDoc;
21 import java.util.jar.Manifest JavaDoc;
22
23 import junit.framework.TestCase;
24
25 import org.apache.avalon.extension.Specification;
26
27 /**
28  * TestCases for Specification.
29  *
30  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
31  * @version $Revision: 1.2 $ $Date: 2004/02/24 22:39:31 $
32  */

33 public class SpecificationTestCase
34     extends TestCase
35 {
36     private static final String JavaDoc MF1_STITLE = "org.realityforge.dve";
37     private static final String JavaDoc MF1_SVERSION = "1.0.2";
38     private static final String JavaDoc MF1_SVENDOR = "Peter Donald";
39     private static final String JavaDoc MF1_ITITLE = "DVE vi OS3P";
40     private static final String JavaDoc MF1_IVENDOR = "Peter Donald";
41     private static final String JavaDoc MF1_IVERSION = "1.0.2Alpha";
42
43     private static final String JavaDoc MF2_STITLE = "org.apache.phoenix";
44     private static final String JavaDoc MF2_SVERSION = "1.0.2";
45     private static final String JavaDoc MF2_SVENDOR = "Apache";
46     private static final String JavaDoc MF2_ITITLE = "Apache Phoenix";
47     private static final String JavaDoc MF2_IVENDOR = "Apache";
48     private static final String JavaDoc MF2_IVERSION = "1.0.2";
49
50     public SpecificationTestCase( String JavaDoc name )
51     {
52         super( name );
53     }
54
55     private Manifest JavaDoc getManifest( final String JavaDoc name )
56         throws Exception JavaDoc
57     {
58         final InputStream JavaDoc inputStream = getClass().getResourceAsStream( name );
59         return new Manifest JavaDoc( inputStream );
60     }
61
62     private Specification[] getPackageSpecifcations( final String JavaDoc name )
63         throws Exception JavaDoc
64     {
65         final Manifest JavaDoc manifest = getManifest( name );
66         return Specification.getSpecifications( manifest );
67     }
68
69     private void checkMissing( final int manifestID, final String JavaDoc attribute )
70     {
71         try
72         {
73             getPackageSpecifcations( "specification-" + manifestID + ".mf" );
74         }
75         catch( final Throwable JavaDoc t )
76         {
77             return;
78         }
79         fail( "Missing " + attribute + " parsed" );
80     }
81
82     public void testSpecifications()
83         throws Exception JavaDoc
84     {
85         final Specification[] specifications = getPackageSpecifcations( "specification-1.mf" );
86
87         assertEquals( "Count", 1, specifications.length );
88         assertEquals( "Name", MF1_STITLE, specifications[ 0 ].getSpecificationTitle() );
89         assertEquals( "SpecVendor", MF1_SVENDOR, specifications[ 0 ].getSpecificationVendor() );
90         assertEquals( "SpecVersion", MF1_SVERSION,
91                       specifications[ 0 ].getSpecificationVersion().toString() );
92         assertEquals( "ImpVendor", MF1_IVENDOR, specifications[ 0 ].getImplementationVendor() );
93         assertEquals( "ImpTitle", MF1_ITITLE, specifications[ 0 ].getImplementationTitle() );
94         assertEquals( "ImpVersion", MF1_IVERSION,
95                       specifications[ 0 ].getImplementationVersion().toString() );
96     }
97
98     public void testSpaceAtEOL()
99         throws Exception JavaDoc
100     {
101         //Note that manifest 7 is just manifest 1 with
102
//spaces added to the end of each line
103
final Specification[] specifications = getPackageSpecifcations( "specification-7.mf" );
104
105         assertEquals( "Count", 1, specifications.length );
106         assertEquals( "Name", MF1_STITLE, specifications[ 0 ].getSpecificationTitle() );
107         assertEquals( "SpecVendor", MF1_SVENDOR, specifications[ 0 ].getSpecificationVendor() );
108         assertEquals( "SpecVersion", MF1_SVERSION,
109                       specifications[ 0 ].getSpecificationVersion().toString() );
110         assertEquals( "ImpVendor", MF1_IVENDOR, specifications[ 0 ].getImplementationVendor() );
111         assertEquals( "ImpTitle", MF1_ITITLE, specifications[ 0 ].getImplementationTitle() );
112         assertEquals( "ImpVersion", MF1_IVERSION,
113                       specifications[ 0 ].getImplementationVersion().toString() );
114     }
115
116     public void testMultiSection()
117         throws Exception JavaDoc
118     {
119         final Specification[] specifications = getPackageSpecifcations( "specification-8.mf" );
120
121         assertEquals( "Count", 1, specifications.length );
122         assertEquals( "Name", MF1_STITLE, specifications[ 0 ].getSpecificationTitle() );
123         assertEquals( "SpecVendor", MF1_SVENDOR, specifications[ 0 ].getSpecificationVendor() );
124         assertEquals( "SpecVersion", MF1_SVERSION,
125                       specifications[ 0 ].getSpecificationVersion().toString() );
126         assertEquals( "ImpVendor", MF1_IVENDOR, specifications[ 0 ].getImplementationVendor() );
127         assertEquals( "ImpTitle", MF1_ITITLE, specifications[ 0 ].getImplementationTitle() );
128         assertEquals( "ImpVersion", MF1_IVERSION,
129                       specifications[ 0 ].getImplementationVersion().toString() );
130     }
131
132     public void testMultiSectionMultiSpec()
133         throws Exception JavaDoc
134     {
135         final Specification[] specifications = getPackageSpecifcations( "specification-9.mf" );
136
137         assertEquals( "Count", 2, specifications.length );
138         assertEquals( "Name", MF1_STITLE, specifications[ 0 ].getSpecificationTitle() );
139         assertEquals( "SpecVendor", MF1_SVENDOR, specifications[ 0 ].getSpecificationVendor() );
140         assertEquals( "SpecVersion", MF1_SVERSION,
141                       specifications[ 0 ].getSpecificationVersion().toString() );
142         assertEquals( "ImpVendor", MF1_IVENDOR, specifications[ 0 ].getImplementationVendor() );
143         assertEquals( "ImpTitle", MF1_ITITLE, specifications[ 0 ].getImplementationTitle() );
144         assertEquals( "ImpVersion", MF1_IVERSION,
145                       specifications[ 0 ].getImplementationVersion().toString() );
146
147         assertEquals( "Name", MF2_STITLE, specifications[ 1 ].getSpecificationTitle() );
148         assertEquals( "SpecVendor", MF2_SVENDOR, specifications[ 1 ].getSpecificationVendor() );
149         assertEquals( "SpecVersion", MF2_SVERSION,
150                       specifications[ 1 ].getSpecificationVersion().toString() );
151         assertEquals( "ImpVendor", MF2_IVENDOR, specifications[ 1 ].getImplementationVendor() );
152         assertEquals( "ImpTitle", MF2_ITITLE, specifications[ 1 ].getImplementationTitle() );
153         assertEquals( "ImpVersion", MF2_IVERSION,
154                       specifications[ 1 ].getImplementationVersion().toString() );
155     }
156
157     public void testMissingSPecVersion()
158         throws Exception JavaDoc
159     {
160         checkMissing( 2, "SpecVersion" );
161     }
162
163     public void testMissingSpecVendor()
164         throws Exception JavaDoc
165     {
166         checkMissing( 3, "SpecVendor" );
167     }
168
169     public void testMissingImplTitle()
170         throws Exception JavaDoc
171     {
172         checkMissing( 4, "ImplTitle" );
173     }
174
175     public void testMissingImplVendor()
176         throws Exception JavaDoc
177     {
178         checkMissing( 5, "ImplVendor" );
179     }
180
181     public void testMissingImplVersion()
182         throws Exception JavaDoc
183     {
184         checkMissing( 6, "ImplVersion" );
185     }
186
187     public void testCompatible()
188         throws Exception JavaDoc
189     {
190         final Specification req1 =
191             new Specification( MF1_STITLE, MF1_SVERSION, MF1_SVENDOR,
192                                MF1_ITITLE, MF1_IVERSION, MF1_IVENDOR );
193         final Specification req2 =
194             new Specification( MF1_STITLE, MF1_SVERSION, MF1_SVENDOR,
195                                null, null, null );
196         final Specification req3 =
197             new Specification( MF1_STITLE, "1.0.1", MF1_SVENDOR,
198                                null, null, null );
199         final Specification req4 =
200             new Specification( MF1_STITLE, MF1_SVERSION, null,
201                                null, null, null );
202         final Specification req5 =
203             new Specification( "another title", MF1_SVERSION, MF1_SVENDOR,
204                                MF1_ITITLE, MF1_IVERSION, MF1_IVENDOR );
205
206         final Specification avail1 =
207             new Specification( MF1_STITLE, MF1_SVERSION, MF1_SVENDOR,
208                                MF1_ITITLE, MF1_IVERSION, MF1_IVENDOR );
209         final Specification avail2 =
210             new Specification( MF1_STITLE, MF1_SVERSION, MF1_SVENDOR,
211                                MF1_ITITLE, "another version", MF1_IVENDOR );
212         final Specification avail3 =
213             new Specification( MF1_STITLE, MF1_SVERSION, MF1_SVENDOR,
214                                MF1_ITITLE, MF1_IVERSION, "another vendor" );
215
216         assertTrue( "avail1.isCompatibleWith( req1 )", avail1.isCompatibleWith( req1 ) );
217         assertTrue( "avail1.isCompatibleWith( req2 )", avail1.isCompatibleWith( req2 ) );
218         assertTrue( "avail1.isCompatibleWith( req3 )", avail1.isCompatibleWith( req3 ) );
219         assertTrue( "avail1.isCompatibleWith( req4 )", avail1.isCompatibleWith( req4 ) );
220         assertTrue( "!avail1.isCompatibleWith( req5 )", !avail1.isCompatibleWith( req5 ) );
221
222         assertTrue( "!avail2.isCompatibleWith( req1 )", !avail2.isCompatibleWith( req1 ) );
223         assertTrue( "avail2.isCompatibleWith( req2 )", avail2.isCompatibleWith( req2 ) );
224         assertTrue( "avail2.isCompatibleWith( req3 )", avail2.isCompatibleWith( req3 ) );
225         assertTrue( "avail2.isCompatibleWith( req4 )", avail2.isCompatibleWith( req4 ) );
226         assertTrue( "!avail2.isCompatibleWith( req5 )", !avail2.isCompatibleWith( req5 ) );
227
228         assertTrue( "!avail3.isCompatibleWith( req1 )", !avail3.isCompatibleWith( req1 ) );
229         assertTrue( "avail3.isCompatibleWith( req2 )", avail3.isCompatibleWith( req2 ) );
230         assertTrue( "avail3.isCompatibleWith( req3 )", avail3.isCompatibleWith( req3 ) );
231         assertTrue( "avail3.isCompatibleWith( req4 )", avail3.isCompatibleWith( req4 ) );
232         assertTrue( "!avail3.isCompatibleWith( req5 )", !avail3.isCompatibleWith( req5 ) );
233     }
234 }
235
Popular Tags