KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright (C) The Apache Software Foundation. All rights reserved.
3  *
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE.txt file.
7  */

8 package org.apache.avalon.excalibur.extension.test;
9
10 import java.io.InputStream JavaDoc;
11 import java.util.jar.Manifest JavaDoc;
12 import java.util.ArrayList JavaDoc;
13 import junit.framework.TestCase;
14 import org.apache.avalon.excalibur.extension.Extension;
15
16 /**
17  * TestCases for Extension.
18  *
19  * @author <a HREF="mailto:peter@apache.org">Peter Donald</a>
20  * @version $Revision: 1.8 $ $Date: 2001/12/11 09:53:35 $
21  */

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