KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > loom > classman > reader > test > ReaderTestCase


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

8 package org.codehaus.loom.classman.reader.test;
9
10 import org.codehaus.loom.classman.metadata.ClassLoaderSetMetaData;
11 import org.codehaus.loom.classman.test.AbstractLoaderTestCase;
12
13 /**
14  * TestCase for {@link org.codehaus.loom.classman.reader.ClassLoaderSetReader}.
15  *
16  * @author Peter Donald
17  */

18 public class ReaderTestCase
19     extends AbstractLoaderTestCase
20 {
21     public void testConfig1()
22         throws Exception JavaDoc
23     {
24         final ClassLoaderSetMetaData defs =
25             buildFromResource( "config1.xml" );
26
27         assertEquals( "ClassLoader Predefined Count",
28                       1,
29                       defs.getPredefined().length );
30         assertEquals( "ClassLoader Predefined",
31                       "*system*",
32                       defs.getPredefined()[ 0 ] );
33         assertEquals( "ClassLoader Default",
34                       "join2",
35                       defs.getDefault() );
36         assertEquals( "ClassLoader Count",
37                       2,
38                       defs.getClassLoaders().length );
39         assertEquals( "Join Count",
40                       2,
41                       defs.getJoins().length );
42         assertNotNull( "ClassLoader cl1",
43                        defs.getClassLoader( "cl1" ) );
44         assertNotNull( "ClassLoader cl2",
45                        defs.getClassLoader( "cl2" ) );
46         assertNotNull( "Join join1",
47                        defs.getJoin( "join1" ) );
48         assertNotNull( "Join join2",
49                        defs.getJoin( "join2" ) );
50
51         assertEquals( "ClassLoader cl1.entrys Name",
52                       defs.getClassLoader( "cl1" ).getName(),
53                       "cl1" );
54         assertEquals( "ClassLoader cl1.entrys Count",
55                       defs.getClassLoader( "cl1" ).getEntrys().length,
56                       2 );
57         assertEquals( "ClassLoader cl1.filesets Count",
58                       defs.getClassLoader( "cl1" ).getFilesets().length,
59                       1 );
60         assertEquals( "ClassLoader cl1.extensions Count",
61                       defs.getClassLoader( "cl1" ).getExtensions().length,
62                       1 );
63         assertEquals( "ClassLoader cl1.fileset[0] Dir",
64                       defs.getClassLoader( "cl1" ).getFilesets()[ 0 ].getBaseDirectory(),
65                       "someDir" );
66         assertEquals( "ClassLoader cl1.fileset[0] Include count",
67                       defs.getClassLoader( "cl1" ).getFilesets()[ 0 ].getIncludes().length,
68                       2 );
69         assertEquals( "ClassLoader cl1.fileset[0] Exclude count",
70                       defs.getClassLoader( "cl1" ).getFilesets()[ 0 ].getExcludes().length,
71                       1 );
72         assertEquals( "ClassLoader cl1.fileset[0].include[0] name",
73                       defs.getClassLoader( "cl1" ).getFilesets()[ 0 ].getIncludes()[ 0 ],
74                       "**/*.jar" );
75         assertEquals( "ClassLoader cl1.fileset[0].include[1] name",
76                       defs.getClassLoader( "cl1" ).getFilesets()[ 0 ].getIncludes()[ 1 ],
77                       "**/*.bar" );
78         assertEquals( "ClassLoader cl1.fileset[0].exclude[0] name",
79                       defs.getClassLoader( "cl1" ).getFilesets()[ 0 ].getExcludes()[ 0 ],
80                       "**/unwanted/*" );
81         assertEquals( "ClassLoader cl1.entrys[0] Location",
82                       defs.getClassLoader( "cl1" ).getEntrys()[ 0 ],
83                       "someFile.jar" );
84         assertEquals( "ClassLoader cl1.entrys[1] Location",
85                       defs.getClassLoader( "cl1" ).getEntrys()[ 1 ],
86                       "someOtherFile.jar" );
87
88         assertEquals( "ClassLoader cl2.entrys Name",
89                       defs.getClassLoader( "cl2" ).getName(),
90                       "cl2" );
91         assertEquals( "ClassLoader cl2.entrys Count",
92                       defs.getClassLoader( "cl2" ).getEntrys().length,
93                       1 );
94         assertEquals( "ClassLoader cl2.filesets Count",
95                       defs.getClassLoader( "cl2" ).getFilesets().length,
96                       0 );
97         assertEquals( "ClassLoader cl2.extensions Count",
98                       defs.getClassLoader( "cl2" ).getExtensions().length,
99                       0 );
100         assertEquals( "ClassLoader cl2.entrys[0] Location",
101                       defs.getClassLoader( "cl2" ).getEntrys()[ 0 ],
102                       "aFile.jar" );
103
104         assertEquals( "Join join1.refs Name",
105                       defs.getJoin( "join1" ).getName(),
106                       "join1" );
107         assertEquals( "Join join1.refs Count",
108                       defs.getJoin( "join1" ).getClassloaders().length,
109                       1 );
110         assertEquals( "Join join1.refs[0] Name",
111                       defs.getJoin( "join1" ).getClassloaders()[ 0 ],
112                       "cl1" );
113
114         assertEquals( "Join join2.refs Name",
115                       defs.getJoin( "join2" ).getName(),
116                       "join2" );
117         assertEquals( "Join join2.refs Count",
118                       defs.getJoin( "join2" ).getClassloaders().length,
119                       2 );
120         assertEquals( "Join join2.refs[0] Name",
121                       defs.getJoin( "join2" ).getClassloaders()[ 0 ],
122                       "cl1" );
123         assertEquals( "Join join2.refs[1] Name",
124                       defs.getJoin( "join2" ).getClassloaders()[ 1 ],
125                       "cl2" );
126     }
127
128     public void testConfig2()
129         throws Exception JavaDoc
130     {
131         try
132         {
133             buildFromResource( "config2.xml" );
134         }
135         catch( final Throwable JavaDoc t )
136         {
137             return;
138         }
139         fail( "Should have failed as loaded a " +
140               "configuration with no default set" );
141     }
142
143     public void testConfig3()
144         throws Exception JavaDoc
145     {
146         try
147         {
148             buildFromResource( "config3.xml" );
149         }
150         catch( final Throwable JavaDoc t )
151         {
152             return;
153         }
154         fail( "Should have failed as loaded a " +
155               "configuration with no version set" );
156     }
157
158     public void testConfig4()
159         throws Exception JavaDoc
160     {
161         try
162         {
163             buildFromResource( "config4.xml" );
164         }
165         catch( final Throwable JavaDoc t )
166         {
167             return;
168         }
169         fail( "Should have failed as loaded a " +
170               "configuration with bad version" );
171     }
172
173     public void testConfig5()
174         throws Exception JavaDoc
175     {
176         try
177         {
178             buildFromResource( "config5.xml" );
179         }
180         catch( final Throwable JavaDoc t )
181         {
182             return;
183         }
184         fail( "Should have failed as loaded a " +
185               "configuration with extension with null name" );
186     }
187 }
188
Popular Tags