KickJava   Java API By Example, From Geeks To Geeks.

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


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.Extension;
26
27 /**
28  * TestCases for Extension.
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 ExtensionTestCase
34     extends TestCase
35 {
36     private static final String JavaDoc MF1_NAME = "avalon.extension";
37     private static final String JavaDoc MF1_SVERSION = "1.0.1";
38     private static final String JavaDoc MF1_SVENDOR = "Avalon Apache";
39     private static final String JavaDoc MF1_IVENDORID = "org.apache.avalon";
40     private static final String JavaDoc MF1_IVENDOR = "Avalon Apache Project";
41     private static final String JavaDoc MF1_IVERSION = "1.0.2";
42     private static final String JavaDoc MF1_IURL = null;
43
44     private static final String JavaDoc MF2_NAME = "avalon.extension";
45     private static final String JavaDoc MF2_SVERSION = "1.0.1";
46     private static final String JavaDoc MF2_SVENDOR = "Avalon Apache";
47     private static final String JavaDoc MF2_IVENDORID = "org.apache.avalon";
48     private static final String JavaDoc MF2_IVENDOR = "Avalon Apache Project";
49     private static final String JavaDoc MF2_IVERSION = "1.0.2";
50     private static final String JavaDoc MF2_IURL = null;
51
52     private static final String JavaDoc MFR1_NAME = "avalon.required1";
53     private static final String JavaDoc MFR1_SVERSION = "1.0";
54     private static final String JavaDoc MFR1_SVENDOR = null;
55     private static final String JavaDoc MFR1_IVENDORID = "org.apache.avalon";
56     private static final String JavaDoc MFR1_IVENDOR = null;
57     private static final String JavaDoc MFR1_IVERSION = "1.0.2";
58     private static final String JavaDoc MFR1_IURL = "http://avalon.apache.org/extension/required1.jar";
59
60     private static final String JavaDoc MF3_NAME = "avalon.required1";
61     private static final String JavaDoc MF3_SVERSION = "1.1";
62     private static final String JavaDoc MF3_SVENDOR = "Avalon Apache";
63     private static final String JavaDoc MF3_IVENDORID = "org.apache.avalon";
64     private static final String JavaDoc MF3_IVENDOR = "Avalon Apache Project";
65     private static final String JavaDoc MF3_IVERSION = "1.0.2";
66     private static final String JavaDoc MF3_IURL = null;
67
68     private static final String JavaDoc MF4_NAME = "avalon.required1";
69     private static final String JavaDoc MF4_SVERSION = "1.0";
70     private static final String JavaDoc MF4_SVENDOR = "Avalon Apache";
71     private static final String JavaDoc MF4_IVENDORID = "org.apache.avalon";
72     private static final String JavaDoc MF4_IVENDOR = "Avalon Apache Project";
73     private static final String JavaDoc MF4_IVERSION = "1.0.3";
74     private static final String JavaDoc MF4_IURL = null;
75
76     public ExtensionTestCase( String JavaDoc name )
77     {
78         super( name );
79     }
80
81     private Manifest JavaDoc getManifest( final String JavaDoc name )
82         throws Exception JavaDoc
83     {
84         final InputStream JavaDoc inputStream = getClass().getResourceAsStream( name );
85         return new Manifest JavaDoc( inputStream );
86     }
87
88     public void testAvailable()
89             throws Exception JavaDoc
90     {
91         final Manifest JavaDoc manifest = getManifest( "manifest-1.mf" );
92         final Extension[] available = Extension.getAvailable( manifest );
93
94         assertEquals( "Available Count", 1, available.length );
95         assertEquals( "Available Name", MF1_NAME, available[0].getExtensionName() );
96         assertEquals( "Available SpecVendor", MF1_SVENDOR, available[0].getSpecificationVendor() );
97         assertEquals( "Available SpecVersion", MF1_SVERSION,
98                 available[0].getSpecificationVersion().toString() );
99         assertEquals( "Available URL", MF1_IURL, available[0].getImplementationURL() );
100         assertEquals( "Available ImpVendor", MF1_IVENDOR, available[0].getImplementationVendor() );
101         assertEquals( "Available ImpVendorId", MF1_IVENDORID, available[0].getImplementationVendorID() );
102         assertEquals( "Available ImpVersion", MF1_IVERSION,
103                 available[0].getImplementationVersion().toString() );
104     }
105
106     public void testAvailableQuoted()
107             throws Exception JavaDoc
108     {
109         final Manifest JavaDoc manifest = getManifest( "manifest-quoted.mf" );
110         final Extension[] available = Extension.getAvailable( manifest );
111
112         assertEquals( "Available Count", 1, available.length );
113         assertEquals( "Available Name", MF1_NAME, available[0].getExtensionName() );
114         assertEquals( "Available SpecVendor", MF1_SVENDOR, available[0].getSpecificationVendor() );
115         assertEquals( "Available SpecVersion", MF1_SVERSION,
116                 available[0].getSpecificationVersion().toString() );
117         assertEquals( "Available URL", MF1_IURL, available[0].getImplementationURL() );
118         assertEquals( "Available ImpVendor", MF1_IVENDOR, available[0].getImplementationVendor() );
119         assertEquals( "Available ImpVendorId", MF1_IVENDORID, available[0].getImplementationVendorID() );
120         assertEquals( "Available ImpVersion", MF1_IVERSION,
121                 available[0].getImplementationVersion().toString() );
122     }
123
124     public void testRequired()
125         throws Exception JavaDoc
126     {
127         final Manifest JavaDoc manifest = getManifest( "manifest-2.mf" );
128         final Extension[] available = Extension.getAvailable( manifest );
129
130         assertEquals( "Available Count", 1, available.length );
131         assertEquals( "Available Name", MF2_NAME, available[ 0 ].getExtensionName() );
132         assertEquals( "Available SpecVendor", MF2_SVENDOR, available[ 0 ].getSpecificationVendor() );
133         assertEquals( "Available SpecVersion", MF2_SVERSION,
134                       available[ 0 ].getSpecificationVersion().toString() );
135         assertEquals( "Available URL", MF2_IURL, available[ 0 ].getImplementationURL() );
136         assertEquals( "Available ImpVendor", MF2_IVENDOR, available[ 0 ].getImplementationVendor() );
137         assertEquals( "Available ImpVendorId", MF2_IVENDORID, available[ 0 ].getImplementationVendorID() );
138         assertEquals( "Available ImpVersion", MF2_IVERSION,
139                       available[ 0 ].getImplementationVersion().toString() );
140
141         final Extension[] required = Extension.getRequired( manifest );
142         assertEquals( "Available Count", 1, required.length );
143         assertEquals( "required Name", MFR1_NAME, required[ 0 ].getExtensionName() );
144         assertEquals( "required SpecVendor", MFR1_SVENDOR, required[ 0 ].getSpecificationVendor() );
145         assertEquals( "required SpecVersion", MFR1_SVERSION,
146                       required[ 0 ].getSpecificationVersion().toString() );
147         assertEquals( "required URL", MFR1_IURL, required[ 0 ].getImplementationURL() );
148         assertEquals( "required ImpVendor", MFR1_IVENDOR, required[ 0 ].getImplementationVendor() );
149         assertEquals( "required ImpVendorId", MFR1_IVENDORID, required[ 0 ].getImplementationVendorID() );
150         assertEquals( "required ImpVersion", MFR1_IVERSION,
151                       required[ 0 ].getImplementationVersion().toString() );
152     }
153
154     public void testManifest3()
155         throws Exception JavaDoc
156     {
157         final Manifest JavaDoc manifest = getManifest( "manifest-3.mf" );
158         final Extension[] available = Extension.getAvailable( manifest );
159
160         assertEquals( "Available Count", 1, available.length );
161         assertEquals( "Available Name", MF3_NAME, available[ 0 ].getExtensionName() );
162         assertEquals( "Available SpecVendor", MF3_SVENDOR, available[ 0 ].getSpecificationVendor() );
163         assertEquals( "Available SpecVersion", MF3_SVERSION,
164                       available[ 0 ].getSpecificationVersion().toString() );
165         assertEquals( "Available URL", MF3_IURL, available[ 0 ].getImplementationURL() );
166         assertEquals( "Available ImpVendor", MF3_IVENDOR, available[ 0 ].getImplementationVendor() );
167         assertEquals( "Available ImpVendorId", MF3_IVENDORID, available[ 0 ].getImplementationVendorID() );
168         assertEquals( "Available ImpVersion", MF3_IVERSION,
169                       available[ 0 ].getImplementationVersion().toString() );
170
171         final Extension[] required = Extension.getRequired( manifest );
172         assertEquals( "Required Count", 1, required.length );
173     }
174
175     public void testManifest4()
176         throws Exception JavaDoc
177     {
178         final Manifest JavaDoc manifest = getManifest( "manifest-4.mf" );
179         final Extension[] available = Extension.getAvailable( manifest );
180
181         assertEquals( "Available Count", 1, available.length );
182         assertEquals( "Available Name", MF4_NAME, available[ 0 ].getExtensionName() );
183         assertEquals( "Available SpecVendor", MF4_SVENDOR, available[ 0 ].getSpecificationVendor() );
184         assertEquals( "Available SpecVersion", MF4_SVERSION,
185                       available[ 0 ].getSpecificationVersion().toString() );
186         assertEquals( "Available URL", MF4_IURL, available[ 0 ].getImplementationURL() );
187         assertEquals( "Available ImpVendor", MF4_IVENDOR, available[ 0 ].getImplementationVendor() );
188         assertEquals( "Available ImpVendorId", MF4_IVENDORID, available[ 0 ].getImplementationVendorID() );
189         assertEquals( "Available ImpVersion", MF4_IVERSION,
190                       available[ 0 ].getImplementationVersion().toString() );
191
192         final Extension[] required = Extension.getRequired( manifest );
193         assertEquals( "Available Count", 0, required.length );
194     }
195
196     public void testCompatible()
197         throws Exception JavaDoc
198     {
199         final Manifest JavaDoc manifest2 = getManifest( "manifest-2.mf" );
200         final Manifest JavaDoc manifest3 = getManifest( "manifest-3.mf" );
201         final Manifest JavaDoc manifest4 = getManifest( "manifest-4.mf" );
202         final Manifest JavaDoc manifest5 = getManifest( "manifest-5.mf" );
203         final Manifest JavaDoc manifest6 = getManifest( "manifest-6.mf" );
204         final Manifest JavaDoc manifest7 = getManifest( "manifest-7.mf" );
205
206         final Extension req1 = Extension.getRequired( manifest2 )[ 0 ];
207         final Extension req2 = Extension.getRequired( manifest5 )[ 0 ];
208         final Extension req3 = Extension.getRequired( manifest6 )[ 0 ];
209         final Extension req4 = Extension.getRequired( manifest7 )[ 0 ];
210
211         final Extension avail3 = Extension.getAvailable( manifest3 )[ 0 ];
212         final Extension avail4 = Extension.getAvailable( manifest4 )[ 0 ];
213
214         assertTrue( "avail3.isCompatibleWith( req1 )", avail3.isCompatibleWith( req1 ) );
215         assertTrue( "avail4.isCompatibleWith( req1 )", avail4.isCompatibleWith( req1 ) );
216         assertTrue( "avail3.isCompatibleWith( req2 )", avail3.isCompatibleWith( req2 ) );
217         assertTrue( "avail4.isCompatibleWith( req2 )", avail4.isCompatibleWith( req2 ) );
218         assertTrue( "avail3.isCompatibleWith( req3 )", avail3.isCompatibleWith( req3 ) );
219         assertTrue( "!avail4.isCompatibleWith( req3 )", !avail4.isCompatibleWith( req3 ) );
220         assertTrue( "avail3.isCompatibleWith( req4 )", avail3.isCompatibleWith( req4 ) );
221         assertTrue( "avail4.isCompatibleWith( req4 )", avail4.isCompatibleWith( req4 ) );
222     }
223
224     public void testSpacesAfterAttributes()
225         throws Exception JavaDoc
226     {
227         //Note that manifest 9 is just manifest 1 with
228
//spaces added to the end of each line
229
final Manifest JavaDoc manifest = getManifest( "manifest-9.mf" );
230         final Extension[] available = Extension.getAvailable( manifest );
231
232         assertEquals( "Available Count", 1, available.length );
233         assertEquals( "Available Name", MF1_NAME, available[ 0 ].getExtensionName() );
234         assertEquals( "Available SpecVendor", MF1_SVENDOR, available[ 0 ].getSpecificationVendor() );
235         assertEquals( "Available SpecVersion", MF1_SVERSION,
236                       available[ 0 ].getSpecificationVersion().toString() );
237         assertEquals( "Available URL", MF1_IURL, available[ 0 ].getImplementationURL() );
238         assertEquals( "Available ImpVendor", MF1_IVENDOR, available[ 0 ].getImplementationVendor() );
239         assertEquals( "Available ImpVendorId", MF1_IVENDORID, available[ 0 ].getImplementationVendorID() );
240         assertEquals( "Available ImpVersion", MF1_IVERSION,
241                       available[ 0 ].getImplementationVersion().toString() );
242     }
243 }
244
Popular Tags