LDAP-267: Added integration tests and modified samples to use new xml namespace.
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.ldap.test;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.directory.server.core.DefaultDirectoryService;
|
||||
import org.apache.directory.server.core.DirectoryService;
|
||||
import org.apache.directory.server.core.entry.ServerEntry;
|
||||
@@ -33,6 +35,8 @@ import java.io.File;
|
||||
* @since 1.3.2
|
||||
*/
|
||||
public class EmbeddedLdapServer {
|
||||
private static final Log log = LogFactory.getLog(EmbeddedLdapServer.class);
|
||||
|
||||
private final DirectoryService directoryService;
|
||||
private final LdapServer ldapServer;
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.springframework.ldap.test;
|
||||
|
||||
import org.springframework.beans.factory.config.AbstractFactoryBean;
|
||||
|
||||
/**
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class EmbeddedLdapServerFactoryBean extends AbstractFactoryBean<EmbeddedLdapServer> {
|
||||
private int port;
|
||||
private String partitionName;
|
||||
private String partitionSuffix;
|
||||
|
||||
@Override
|
||||
public Class<?> getObjectType() {
|
||||
return EmbeddedLdapServer.class;
|
||||
}
|
||||
|
||||
public void setPartitionName(String partitionName) {
|
||||
this.partitionName = partitionName;
|
||||
}
|
||||
|
||||
public void setPartitionSuffix(String partitionSuffix) {
|
||||
this.partitionSuffix = partitionSuffix;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EmbeddedLdapServer createInstance() throws Exception {
|
||||
return EmbeddedLdapServer.newEmbeddedServer(partitionName, partitionSuffix, port);
|
||||
}
|
||||
}
|
||||
@@ -189,10 +189,10 @@ public class LdapTestUtils {
|
||||
childName = LdapUtils.prepend(childName, name);
|
||||
|
||||
try {
|
||||
ctx.destroySubcontext(childName);
|
||||
ctx.unbind(childName);
|
||||
} catch (ContextNotEmptyException e) {
|
||||
clearSubContexts(ctx, childName);
|
||||
ctx.destroySubcontext(childName);
|
||||
ctx.unbind(childName);
|
||||
}
|
||||
}
|
||||
} catch (NamingException e) {
|
||||
|
||||
@@ -48,6 +48,8 @@ public class TestContextSourceFactoryBean extends AbstractFactoryBean {
|
||||
|
||||
private AuthenticationSource authenticationSource;
|
||||
|
||||
private ContextSource contextSource;
|
||||
|
||||
public void setAuthenticationSource(AuthenticationSource authenticationSource) {
|
||||
this.authenticationSource = authenticationSource;
|
||||
}
|
||||
@@ -88,37 +90,48 @@ public class TestContextSourceFactoryBean extends AbstractFactoryBean {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
protected Object createInstance() throws Exception {
|
||||
public void setContextSource(ContextSource contextSource) {
|
||||
this.contextSource = contextSource;
|
||||
}
|
||||
|
||||
protected Object createInstance() throws Exception {
|
||||
LdapTestUtils.startEmbeddedServer(port, defaultPartitionSuffix, defaultPartitionName);
|
||||
|
||||
LdapContextSource targetContextSource = new LdapContextSource();
|
||||
if (baseOnTarget) {
|
||||
targetContextSource.setBase(defaultPartitionSuffix);
|
||||
}
|
||||
if (contextSource == null) {
|
||||
// If not explicitly configured, create a new instance.
|
||||
LdapContextSource targetContextSource = new LdapContextSource();
|
||||
if (baseOnTarget) {
|
||||
targetContextSource.setBase(defaultPartitionSuffix);
|
||||
}
|
||||
|
||||
targetContextSource.setUrl("ldap://localhost:" + port);
|
||||
targetContextSource.setUserDn(principal);
|
||||
targetContextSource.setPassword(password);
|
||||
targetContextSource.setDirObjectFactory(dirObjectFactory);
|
||||
targetContextSource.setPooled(pooled);
|
||||
targetContextSource.setUrl("ldap://localhost:" + port);
|
||||
targetContextSource.setUserDn(principal);
|
||||
targetContextSource.setPassword(password);
|
||||
targetContextSource.setDirObjectFactory(dirObjectFactory);
|
||||
targetContextSource.setPooled(pooled);
|
||||
|
||||
if (authenticationSource != null) {
|
||||
targetContextSource.setAuthenticationSource(authenticationSource);
|
||||
}
|
||||
targetContextSource.afterPropertiesSet();
|
||||
if (authenticationSource != null) {
|
||||
targetContextSource.setAuthenticationSource(authenticationSource);
|
||||
}
|
||||
targetContextSource.afterPropertiesSet();
|
||||
|
||||
if (baseOnTarget) {
|
||||
LdapTestUtils.clearSubContexts(targetContextSource, LdapUtils.emptyLdapName());
|
||||
contextSource = targetContextSource;
|
||||
}
|
||||
|
||||
Thread.sleep(1000);
|
||||
|
||||
if (baseOnTarget) {
|
||||
LdapTestUtils.clearSubContexts(contextSource, LdapUtils.emptyLdapName());
|
||||
}
|
||||
else {
|
||||
LdapTestUtils.clearSubContexts(targetContextSource, LdapUtils.newLdapName(defaultPartitionSuffix));
|
||||
LdapTestUtils.clearSubContexts(contextSource, LdapUtils.newLdapName(defaultPartitionSuffix));
|
||||
}
|
||||
|
||||
if (ldifFile != null) {
|
||||
LdapTestUtils.loadLdif(targetContextSource, ldifFile);
|
||||
LdapTestUtils.loadLdif(contextSource, ldifFile);
|
||||
}
|
||||
|
||||
return targetContextSource;
|
||||
return contextSource;
|
||||
}
|
||||
|
||||
public Class getObjectType() {
|
||||
|
||||
Reference in New Issue
Block a user