KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > loom > components > extension > ComparatorTestCase


1 /* ====================================================================
2  * Loom Software License, version 1.1
3  *
4  * Copyright (c) 2003, Loom Group. All rights reserved.
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  *
17  * 3. Neither the name of the Loom Group nor the name "Loom" nor
18  * the names of its contributors may be used to endorse or promote
19  * products derived from this software without specific prior
20  * written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *
35  * ====================================================================
36  *
37  * Loom includes code from the Apache Software Foundation
38  *
39  * ====================================================================
40  * The Apache Software License, Version 1.1
41  *
42  * Copyright (c) 1997-2003 The Apache Software Foundation. All rights
43  * reserved.
44  *
45  * Redistribution and use in source and binary forms, with or without
46  * modification, are permitted provided that the following conditions
47  * are met:
48  *
49  * 1. Redistributions of source code must retain the above copyright
50  * notice, this list of conditions and the following disclaimer.
51  *
52  * 2. Redistributions in binary form must reproduce the above copyright
53  * notice, this list of conditions and the following disclaimer in
54  * the documentation and/or other materials provided with the
55  * distribution.
56  *
57  * 3. The end-user documentation included with the redistribution,
58  * if any, must include the following acknowledgment:
59  * "This product includes software developed by the
60  * Apache Software Foundation (http://www.apache.org/)."
61  * Alternately, this acknowledgment may appear in the software
62  * itself, if and wherever such third-party acknowledgments
63  * normally appear.
64  *
65  * 4. The names "Jakarta", "Avalon", and "Apache Software Foundation"
66  * must not be used to endorse or promote products derived from this
67  * software without prior written permission. For written
68  * permission, please contact apache@apache.org.
69  *
70  * 5. Products derived from this software may not be called "Apache",
71  * nor may "Apache" appear in their name, without prior written
72  * permission of the Apache Software Foundation.
73  *
74  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
75  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
76  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
77  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
78  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
79  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
80  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
81  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
82  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
83  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
84  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
85  * SUCH DAMAGE.
86  */

87 package org.codehaus.loom.components.extension;
88
89 import java.io.File JavaDoc;
90 import junit.framework.TestCase;
91
92 import org.codehaus.loom.components.extensions.pkgmgr.ExtensionManager;
93 import org.codehaus.loom.components.extensions.pkgmgr.OptionalPackage;
94 import org.codehaus.loom.components.extensions.pkgmgr.impl.DelegatingExtensionManager;
95 import org.codehaus.loom.extension.Extension;
96
97 /**
98  * A basic test case for comparator.
99  *
100  * @author Peter Donald
101  * @version $Revision: 1.3 $ $Date: 2004/08/17 23:14:33 $
102  */

103 public class ComparatorTestCase
104     extends TestCase
105 {
106     private static final String JavaDoc NAME = "Extension1";
107     private static final String JavaDoc VENDOR1 = "Vendor1";
108     private static final String JavaDoc VENDOR2 = "Vendor2";
109
110     public ComparatorTestCase( final String JavaDoc name )
111     {
112         super( name );
113     }
114
115     public void testAllNull()
116     {
117         runCompareTest( null, null, null, null, VENDOR1, VENDOR2 );
118     }
119
120     public void testSpecNonNullV1()
121     {
122         runCompareTest( "1.0", null, "1.1", null, VENDOR2, VENDOR1 );
123     }
124
125     public void testSpecNonNullV2()
126     {
127         runCompareTest( "1.1", null, "1.0", null, VENDOR1, VENDOR2 );
128     }
129
130     public void testSpecNonNullV3()
131     {
132         runCompareTest( "1.1", null, "1.1", null, VENDOR1, VENDOR2 );
133     }
134
135     public void testSpec1Null()
136     {
137         runCompareTest( null, null, "1.1", null, VENDOR2, VENDOR1 );
138     }
139
140     public void testSpec2Null()
141     {
142         runCompareTest( "1.1", null, null, null, VENDOR1, VENDOR2 );
143     }
144
145     public void testImplNull()
146     {
147         runCompareTest( "1.0", null, "1.0", null, VENDOR1, VENDOR2 );
148     }
149
150     public void testImplNonNullV1()
151     {
152         runCompareTest( "1.0", "1.1", "1.0", "1.0", VENDOR1, VENDOR2 );
153     }
154
155     public void testImplNonNullV2()
156     {
157         runCompareTest( "1.0", "1.0", "1.0", "1.1", VENDOR2, VENDOR1 );
158     }
159
160     public void testImplNonNullV3()
161     {
162         runCompareTest( "1.0", "1.1", "1.0", "1.1", VENDOR1, VENDOR2 );
163     }
164
165     public void testImpl1Null()
166     {
167         runCompareTest( "1.0", null, "1.0", "1.1", VENDOR2, VENDOR1 );
168     }
169
170     public void testImpl2Null()
171     {
172         runCompareTest( "1.0", "1.1", "1.0", null, VENDOR1, VENDOR2 );
173     }
174
175     private void runCompareTest( final String JavaDoc specVersion1,
176                                  final String JavaDoc implVersion1,
177                                  final String JavaDoc specVersion2,
178                                  final String JavaDoc implVersion2,
179                                  final String JavaDoc vendor1,
180                                  final String JavaDoc vendor2 )
181     {
182         final ExtensionManager manager =
183             createExtensionManager( specVersion1,
184                                     implVersion1,
185                                     specVersion2,
186                                     implVersion2 );
187         final OptionalPackage[] pkgs = getOptionalPackages( manager );
188
189         assertEquals( "pkgs.length", 2, pkgs.length );
190
191         final Extension extension1 = pkgs[ 0 ].getAvailableExtensions()[ 0 ];
192         final Extension extension2 = pkgs[ 1 ].getAvailableExtensions()[ 0 ];
193         assertEquals( "pkgs[0].vendor",
194                       vendor1,
195                       extension1.getImplementationVendor() );
196         assertEquals( "pkgs[1].vendor",
197                       vendor2,
198                       extension2.getImplementationVendor() );
199     }
200
201     private OptionalPackage[] getOptionalPackages(
202         final ExtensionManager manager )
203     {
204         return manager.getOptionalPackages(
205             new Extension( NAME, null, null, null, null, null, null ) );
206     }
207
208     private ExtensionManager createExtensionManager( final String JavaDoc specVersion1,
209                                                      final String JavaDoc implVersion1,
210                                                      final String JavaDoc specVersion2,
211                                                      final String JavaDoc implVersion2 )
212     {
213         final OptionalPackage optionalPackage1 =
214             createPackage( VENDOR1, specVersion1, implVersion1 );
215         final OptionalPackage optionalPackage2 =
216             createPackage( VENDOR2, specVersion2, implVersion2 );
217         final OptionalPackage[] pkgs =
218             new OptionalPackage[]{optionalPackage1, optionalPackage2};
219         return createExtensionManager( pkgs );
220     }
221
222     private OptionalPackage createPackage( final String JavaDoc vendor,
223                                            final String JavaDoc specVersion,
224                                            final String JavaDoc implVersion )
225     {
226         final Extension extension = new Extension( NAME,
227                                                    specVersion, null,
228                                                    implVersion, vendor, null,
229                                                    null );
230         final File JavaDoc file = new File JavaDoc( "." );
231         final Extension[] available = new Extension[]{extension};
232         final Extension[] required = new Extension[ 0 ];
233         return new OptionalPackage( file, available, required );
234     }
235
236     private ExtensionManager createExtensionManager(
237         final OptionalPackage[] packages )
238     {
239         final TestExtensionManager manager =
240             new TestExtensionManager( packages );
241         return new DelegatingExtensionManager( new ExtensionManager[]{manager} );
242     }
243 }
244
Popular Tags