1
2
3
4
5
6
7
8
9
10
11
12
13
14
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;
24 import java.io.PrintWriter;
25 import java.io.StringWriter;
26 import java.util.List;
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: 159259 $
34 */
35 public class BootstrapSchemaLoaderTest extends TestCase
36 {
37 BootstrapRegistries registries;
38
39
40 protected void setUp() throws Exception
41 {
42 super.setUp();
43 registries = new BootstrapRegistries();
44 }
45
46
47 protected void tearDown() throws Exception
48 {
49 super.tearDown();
50 registries = null;
51 }
52
53
54 public void testLoadAll() throws NamingException
55 {
56 BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
57 String[] 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
73 type = registries.getAttributeTypeRegistry().lookup( "automountInformation" );
74 assertNotNull( type );
75
76
77 type = registries.getAttributeTypeRegistry().lookup( "knowledgeInformation" );
78 assertNotNull( type );
79
80
81 type = registries.getAttributeTypeRegistry().lookup( "textEncodedORAddress" );
82 assertNotNull( type );
83
84
85 type = registries.getAttributeTypeRegistry().lookup( "corbaRepositoryId" );
86 assertNotNull( type );
87
88
89 type = registries.getAttributeTypeRegistry().lookup( "apacheAlias" );
90 assertNotNull( type );
91
92
93 type = registries.getAttributeTypeRegistry().lookup( "carLicense" );
94 assertNotNull( type );
95
96
97 type = registries.getAttributeTypeRegistry().lookup( "javaClassName" );
98 assertNotNull( type );
99
100
101 type = registries.getAttributeTypeRegistry().lookup( "krb5PrincipalName" );
102 assertNotNull( type );
103
104
105 type = registries.getAttributeTypeRegistry().lookup( "homeDirectory" );
106 assertNotNull( type );
107
108
109 type = registries.getAttributeTypeRegistry().lookup( "distinguishedName" );
110 assertNotNull( type );
111
112 }
113
114
115 public void testSystemSchemaLoad() throws NamingException
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
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
154 {
155 BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
156 String[] 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
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
194 {
195 BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
196 String[] 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
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
234 {
235 BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
236 String[] 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
255 {
256 BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
257 String[] 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
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 errors = registries.checkRefInteg();
292 assertNotNull( errors );
293
294 StringBuffer buf = new StringBuffer();
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 out = new StringWriter();
306 Exception e = ( Exception ) errors.get( 0 );
307 e.printStackTrace( new PrintWriter( out ) );
308 buf.append( "\nfirst exception trace:\n" + out.getBuffer().toString() );
309 }
310
311 assertTrue( buf.toString(), errors.isEmpty() );
312 }
313 }
314