KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ldap > server > schema > bootstrap > BootstrapSchemaLoaderTest


1 /*
2  * Copyright 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17 package org.apache.ldap.server.schema.bootstrap;
18
19
20 import junit.framework.TestCase;
21 import org.apache.ldap.common.schema.AttributeType;
22
23 import javax.naming.NamingException JavaDoc;
24 import java.io.PrintWriter JavaDoc;
25 import java.io.StringWriter JavaDoc;
26 import java.util.List JavaDoc;
27
28
29 /**
30  * A unit test case for the BootstrapSchemaLoader class.
31  *
32  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
33  * @version $Rev: 169198 $
34  */

35 public class BootstrapSchemaLoaderTest extends TestCase
36 {
37     BootstrapRegistries registries;
38
39
40     protected void setUp() throws Exception JavaDoc
41     {
42         super.setUp();
43         registries = new BootstrapRegistries();
44     }
45
46
47     protected void tearDown() throws Exception JavaDoc
48     {
49         super.tearDown();
50         registries = null;
51     }
52
53
54     public void testLoadAll() throws NamingException JavaDoc
55     {
56         BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
57         String JavaDoc[] schemaClasses = {
58             "org.apache.ldap.server.schema.bootstrap.AutofsSchema",
59             "org.apache.ldap.server.schema.bootstrap.CoreSchema",
60             "org.apache.ldap.server.schema.bootstrap.CosineSchema",
61             "org.apache.ldap.server.schema.bootstrap.CorbaSchema",
62             "org.apache.ldap.server.schema.bootstrap.ApacheSchema",
63             "org.apache.ldap.server.schema.bootstrap.InetorgpersonSchema",
64             "org.apache.ldap.server.schema.bootstrap.JavaSchema",
65             "org.apache.ldap.server.schema.bootstrap.Krb5kdcSchema",
66             "org.apache.ldap.server.schema.bootstrap.NisSchema",
67             "org.apache.ldap.server.schema.bootstrap.SystemSchema"
68         };
69         loader.load( schemaClasses, registries );
70         AttributeType type;
71
72         // from autofs.schema
73
type = registries.getAttributeTypeRegistry().lookup( "automountInformation" );
74         assertNotNull( type );
75
76         // from core.schema
77
type = registries.getAttributeTypeRegistry().lookup( "knowledgeInformation" );
78         assertNotNull( type );
79
80         // from cosine.schema
81
type = registries.getAttributeTypeRegistry().lookup( "textEncodedORAddress" );
82         assertNotNull( type );
83
84         // from corba.schema
85
type = registries.getAttributeTypeRegistry().lookup( "corbaRepositoryId" );
86         assertNotNull( type );
87
88         // from eve.schema
89
type = registries.getAttributeTypeRegistry().lookup( "apacheAlias" );
90         assertNotNull( type );
91
92         // from inetorgperson.schema
93
type = registries.getAttributeTypeRegistry().lookup( "carLicense" );
94         assertNotNull( type );
95
96         // from java.schema
97
type = registries.getAttributeTypeRegistry().lookup( "javaClassName" );
98         assertNotNull( type );
99
100         // from krb5kdc.schema
101
type = registries.getAttributeTypeRegistry().lookup( "krb5PrincipalName" );
102         assertNotNull( type );
103
104         // from nis.schema
105
type = registries.getAttributeTypeRegistry().lookup( "homeDirectory" );
106         assertNotNull( type );
107
108         // from system.schema
109
type = registries.getAttributeTypeRegistry().lookup( "distinguishedName" );
110         assertNotNull( type );
111
112     }
113
114
115     public void testSystemSchemaLoad() throws NamingException JavaDoc
116     {
117         SystemSchema systemSchema = new SystemSchema();
118         BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
119         loader.load( systemSchema, registries );
120
121         AttributeType type;
122         type = registries.getAttributeTypeRegistry().lookup( "distinguishedName" );
123         assertNotNull( type );
124
125         type = registries.getAttributeTypeRegistry().lookup( "objectClass" );
126         assertNotNull( type );
127
128         type = registries.getAttributeTypeRegistry().lookup( "modifyTimestamp" );
129         assertNotNull( type );
130     }
131
132
133     public void testApacheSchemaLoad() throws NamingException JavaDoc
134     {
135         testSystemSchemaLoad();
136
137         ApacheSchema apacheSchema = new ApacheSchema();
138         BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
139         loader.load( apacheSchema, registries );
140
141         AttributeType type;
142         type = registries.getAttributeTypeRegistry().lookup( "apacheNdn" );
143         assertNotNull( type );
144
145         type = registries.getAttributeTypeRegistry().lookup( "apacheAlias" );
146         assertNotNull( type );
147
148         type = registries.getAttributeTypeRegistry().lookup( "apacheUpdn" );
149         assertNotNull( type );
150     }
151
152
153     public void testEveDepsSchemaLoad() throws NamingException JavaDoc
154     {
155         BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
156         String JavaDoc[] schemaClasses = {
157             "org.apache.ldap.server.schema.bootstrap.ApacheSchema",
158             "org.apache.ldap.server.schema.bootstrap.SystemSchema"
159         };
160         loader.load( schemaClasses, registries );
161         AttributeType type;
162         type = registries.getAttributeTypeRegistry().lookup( "apacheNdn" );
163         assertNotNull( type );
164
165         type = registries.getAttributeTypeRegistry().lookup( "apacheAlias" );
166         assertNotNull( type );
167
168         type = registries.getAttributeTypeRegistry().lookup( "apacheUpdn" );
169         assertNotNull( type );
170     }
171
172
173     public void testCoreSchemaLoad() throws NamingException JavaDoc
174     {
175         testSystemSchemaLoad();
176
177         CoreSchema coreSchema = new CoreSchema();
178         BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
179         loader.load( coreSchema, registries );
180
181         AttributeType type;
182         type = registries.getAttributeTypeRegistry().lookup( "knowledgeInformation" );
183         assertNotNull( type );
184
185         type = registries.getAttributeTypeRegistry().lookup( "countryName" );
186         assertNotNull( type );
187
188         type = registries.getAttributeTypeRegistry().lookup( "serialNumber" );
189         assertNotNull( type );
190     }
191
192
193     public void testCoreDepsSchemaLoad() throws NamingException JavaDoc
194     {
195         BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
196         String JavaDoc[] schemaClasses = {
197             "org.apache.ldap.server.schema.bootstrap.CoreSchema",
198             "org.apache.ldap.server.schema.bootstrap.SystemSchema"
199         };
200         loader.load( schemaClasses, registries );
201         AttributeType type;
202         type = registries.getAttributeTypeRegistry().lookup( "knowledgeInformation" );
203         assertNotNull( type );
204
205         type = registries.getAttributeTypeRegistry().lookup( "countryName" );
206         assertNotNull( type );
207
208         type = registries.getAttributeTypeRegistry().lookup( "serialNumber" );
209         assertNotNull( type );
210     }
211
212
213     public void testJavaSchemaLoad() throws NamingException JavaDoc
214     {
215         testCoreSchemaLoad();
216
217         JavaSchema javaSchema = new JavaSchema();
218         BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
219         loader.load( javaSchema, registries );
220
221         AttributeType type;
222         type = registries.getAttributeTypeRegistry().lookup( "javaFactory" );
223         assertNotNull( type );
224
225         type = registries.getAttributeTypeRegistry().lookup( "javaSerializedData" );
226         assertNotNull( type );
227
228         type = registries.getAttributeTypeRegistry().lookup( "javaClassNames" );
229         assertNotNull( type );
230     }
231
232
233     public void testJavaDepsSchemaLoad() throws NamingException JavaDoc
234     {
235         BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
236         String JavaDoc[] schemaClasses = {
237             "org.apache.ldap.server.schema.bootstrap.CoreSchema",
238             "org.apache.ldap.server.schema.bootstrap.JavaSchema",
239             "org.apache.ldap.server.schema.bootstrap.SystemSchema"
240         };
241         loader.load( schemaClasses, registries );
242         AttributeType type;
243         type = registries.getAttributeTypeRegistry().lookup( "javaFactory" );
244         assertNotNull( type );
245
246         type = registries.getAttributeTypeRegistry().lookup( "javaSerializedData" );
247         assertNotNull( type );
248
249         type = registries.getAttributeTypeRegistry().lookup( "javaClassNames" );
250         assertNotNull( type );
251     }
252
253
254     public void testEveAndJavaDepsSchemaLoad() throws NamingException JavaDoc
255     {
256         BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
257         String JavaDoc[] schemaClasses = {
258             "org.apache.ldap.server.schema.bootstrap.ApacheSchema",
259             "org.apache.ldap.server.schema.bootstrap.CoreSchema",
260             "org.apache.ldap.server.schema.bootstrap.JavaSchema",
261             "org.apache.ldap.server.schema.bootstrap.SystemSchema"
262         };
263         loader.load( schemaClasses, registries );
264         AttributeType type;
265         type = registries.getAttributeTypeRegistry().lookup( "apacheAlias" );
266         assertNotNull( type );
267
268         type = registries.getAttributeTypeRegistry().lookup( "apacheNdn" );
269         assertNotNull( type );
270
271         type = registries.getAttributeTypeRegistry().lookup( "apacheUpdn" );
272         assertNotNull( type );
273     }
274
275
276     /**
277      * Attempts to resolve the dependent schema objects of all entities that
278      * refer to other objects within the registries.
279      *
280      * @throws NamingException if there are problems.
281      */

282     public void testReferentialIntegrity() throws NamingException JavaDoc
283     {
284         if ( System.getProperties().containsKey( "ignore.ref.integ.test" ) )
285         {
286             System.err.println( "REFERENTIAL INTEGRITY TESTS BYPASSED!!!" );
287             return;
288         }
289
290         testLoadAll();
291         List JavaDoc errors = registries.checkRefInteg();
292         assertNotNull( errors );
293
294         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
295
296         if ( ! errors.isEmpty() )
297         {
298             buf.append( "expected empty erorrs but got " )
299                     .append( errors.size() ).append( " errors:\n" );
300             for ( int ii = 0; ii < errors.size(); ii++ )
301             {
302                 buf.append( '\t' ).append( errors.get( ii ).toString() ).append( '\n' );
303             }
304
305             StringWriter JavaDoc out = new StringWriter JavaDoc();
306             Exception JavaDoc e = ( Exception JavaDoc ) errors.get( 0 );
307             e.printStackTrace( new PrintWriter JavaDoc( out ) );
308             buf.append( "\nfirst exception trace:\n" + out.getBuffer().toString() );
309         }
310
311         assertTrue( buf.toString(), errors.isEmpty() );
312     }
313 }
314                                    
Popular Tags