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.
This commit is contained in:
Ulrik Sandberg
2008-07-20 16:58:50 +00:00
parent 0e60d717bb
commit c6f3a1ee40
2 changed files with 24 additions and 4 deletions

View File

@@ -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 <code>null</code>.
* @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;
}
}

View File

@@ -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) {