From c6f3a1ee40e281333836a3d141298a9c0c0b8567 Mon Sep 17 00:00:00 2001 From: Ulrik Sandberg Date: Sun, 20 Jul 2008 16:58:50 +0000 Subject: [PATCH] ApacheDS 1.0.2 has the following schemas installed by default: [CoreSchema, InetorgpersonSchema, CollectiveSchema, SystemSchema, ApacheSchema, JavaSchema, CosineSchema] In order to be able to add extra schemas, this change in the test utils was made. Currently, only NisSchema is added, but others can be added by changing the TestContextSourceFactoryBean. --- .../ldap/test/LdapTestUtils.java | 18 ++++++++++++++++-- .../test/TestContextSourceFactoryBean.java | 10 ++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/mvn-build/test-support/src/main/java/org/springframework/ldap/test/LdapTestUtils.java b/mvn-build/test-support/src/main/java/org/springframework/ldap/test/LdapTestUtils.java index cffba3d0..83ce4834 100644 --- a/mvn-build/test-support/src/main/java/org/springframework/ldap/test/LdapTestUtils.java +++ b/mvn-build/test-support/src/main/java/org/springframework/ldap/test/LdapTestUtils.java @@ -22,6 +22,7 @@ import java.io.InputStream; import java.util.Collections; import java.util.Hashtable; import java.util.Properties; +import java.util.Set; import javax.naming.Binding; import javax.naming.Context; @@ -75,12 +76,14 @@ public class LdapTestUtils { * @param principal The principal to use when starting the directory server. * @param credentials The credentials to use when starting the directory * server. + * @param extraSchemas Set of extra schemas to add to the bootstrap schemas + * of ApacheDS. May be null. * @return A DirContext to be used for working against the started directory * server. * @throws NamingException If anything goes wrong when starting the server. */ public static DirContext startApacheDirectoryServer(int port, String defaultPartitionSuffix, - String defaultPartitionName, String principal, String credentials) throws NamingException { + String defaultPartitionName, String principal, String credentials, Set extraSchemas) throws NamingException { MutableServerStartupConfiguration cfg = new MutableServerStartupConfiguration(); @@ -89,6 +92,12 @@ public class LdapTestUtils { cfg.setWorkingDirectory(new File(tempDir)); cfg.setLdapPort(port); + + if (extraSchemas != null) { + Set schemas = cfg.getBootstrapSchemas(); + schemas.addAll(extraSchemas); + cfg.setBootstrapSchemas(schemas); + } MutableBTreePartitionConfiguration partitionConfiguration = new MutableBTreePartitionConfiguration(); partitionConfiguration.setSuffix(defaultPartitionSuffix); @@ -103,6 +112,12 @@ public class LdapTestUtils { return new InitialDirContext(env); } + public static DirContext startApacheDirectoryServer(int port, String defaultPartitionSuffix, + String defaultPartitionName, String principal, String credentials) throws NamingException { + return LdapTestUtils.startApacheDirectoryServer(port, defaultPartitionSuffix, defaultPartitionName, principal, + credentials, null); + } + /** * Shut down the in-process Apache Directory Server. * @@ -259,5 +274,4 @@ public class LdapTestUtils { return attributes; } - } diff --git a/mvn-build/test-support/src/main/java/org/springframework/ldap/test/TestContextSourceFactoryBean.java b/mvn-build/test-support/src/main/java/org/springframework/ldap/test/TestContextSourceFactoryBean.java index d356b332..db895f74 100644 --- a/mvn-build/test-support/src/main/java/org/springframework/ldap/test/TestContextSourceFactoryBean.java +++ b/mvn-build/test-support/src/main/java/org/springframework/ldap/test/TestContextSourceFactoryBean.java @@ -15,6 +15,10 @@ */ package org.springframework.ldap.test; +import java.util.HashSet; +import java.util.Set; + +import org.apache.directory.server.core.schema.bootstrap.NisSchema; import org.springframework.beans.factory.config.AbstractFactoryBean; import org.springframework.core.io.Resource; import org.springframework.ldap.core.AuthenticationSource; @@ -88,8 +92,10 @@ public class TestContextSourceFactoryBean extends AbstractFactoryBean { } protected Object createInstance() throws Exception { - LdapTestUtils.startApacheDirectoryServer(port, defaultPartitionSuffix, defaultPartitionName, principal, - password); + Set extraSchemas = new HashSet(); + extraSchemas.add(new NisSchema()); + + LdapTestUtils.startApacheDirectoryServer(port, defaultPartitionSuffix, defaultPartitionName, principal, password, extraSchemas); LdapContextSource targetContextSource = new LdapContextSource(); if (baseOnTarget) {