Introduced AbstractLdapTemplateIntegrationTest to have the internal LDAP database cleaned between each test instance.

This commit is contained in:
Mattias Arthursson
2007-02-18 12:20:55 +00:00
parent b99bdffd1e
commit 1ac17cca6b
14 changed files with 69 additions and 28 deletions

View File

@@ -0,0 +1,34 @@
/*
* Copyright 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
public abstract class AbstractLdapTemplateIntegrationTest extends
AbstractDependencyInjectionSpringContextTests {
private LdapServerManager ldapServerManager;
protected void onSetUp() throws Exception {
super.onSetUp();
ldapServerManager.cleanAndSetup("setup_data.ldif");
}
public void setLdapServerManager(LdapServerManager ldapServerManager) {
this.ldapServerManager = ldapServerManager;
}
}

View File

@@ -27,12 +27,12 @@ import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.directory.server.core.configuration.ShutdownConfiguration;
import org.apache.directory.server.jndi.ServerContextFactory;
import org.apache.directory.server.protocol.shared.store.LdifFileLoader;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.ldap.core.ContextSource;
import org.springframework.ldap.core.DefaultDirObjectFactory;
import org.springframework.ldap.core.DistinguishedName;
@@ -44,7 +44,8 @@ import org.springframework.ldap.core.DistinguishedName;
* @author Mattias Arthursson
*
*/
public class LdapServerManager implements InitializingBean, DisposableBean {
public class LdapServerManager implements DisposableBean {
private static Log log = LogFactory.getLog(LdapServerManager.class);
private ContextSource contextSource;
@@ -66,7 +67,7 @@ public class LdapServerManager implements InitializingBean, DisposableBean {
new InitialContext(env);
}
public void afterPropertiesSet() throws Exception {
public void cleanAndSetup(String ldifFile) throws Exception {
DirContext ctx = contextSource.getReadWriteContext();
// First of all, make sure the database is empty.
@@ -82,9 +83,11 @@ public class LdapServerManager implements InitializingBean, DisposableBean {
}
try {
log.info("Cleaning all present data.");
clearSubContexts(ctx, startingPoint);
// Load the ldif to the recently started server
LdifFileLoader loader = new LdifFileLoader(ctx, "setup_data.ldif");
log.info("Loading setup data");
LdifFileLoader loader = new LdifFileLoader(ctx, ldifFile);
loader.execute();
} finally {
ctx.close();

View File

@@ -25,7 +25,6 @@ import javax.naming.directory.Attributes;
import org.springframework.ldap.core.AttributesMapper;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
/**
* Tests the attributes mapper search method.
@@ -33,7 +32,7 @@ import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
* @author Mattias Arthursson
*/
public class LdapTemplateAttributesMapperITest extends
AbstractDependencyInjectionSpringContextTests {
AbstractLdapTemplateIntegrationTest {
private LdapTemplate tested;
protected String[] getConfigLocations() {

View File

@@ -23,7 +23,6 @@ import javax.naming.directory.BasicAttributes;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
/**
* Tests the bind and unbind methods of LdapTemplate. The test methods in this
@@ -37,7 +36,7 @@ import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
* @author Mattias Arthursson
*/
public class LdapTemplateBindUnbindITest extends
AbstractDependencyInjectionSpringContextTests {
AbstractLdapTemplateIntegrationTest {
private LdapTemplate tested;
private static String DN = "cn=Some Person4,ou=company1,c=Sweden";

View File

@@ -21,7 +21,6 @@ import javax.naming.directory.DirContext;
import org.springframework.ldap.core.ContextExecutor;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
/**
* Tests for LdapTemplate's context executor methods.
@@ -29,7 +28,7 @@ import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
* @author Mattias Arthursson
*/
public class LdapTemplateContextExecutorTest extends
AbstractDependencyInjectionSpringContextTests {
AbstractLdapTemplateIntegrationTest {
private LdapTemplate tested;

View File

@@ -21,7 +21,6 @@ import java.util.List;
import org.springframework.ldap.core.ContextMapper;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
/**
* Tests the ContextMapper search method. In its way this method also
@@ -30,7 +29,7 @@ import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
* @author Mattias Arthursson
*/
public class LdapTemplateContextMapperITest extends
AbstractDependencyInjectionSpringContextTests {
AbstractLdapTemplateIntegrationTest {
private LdapTemplate tested;
protected String[] getConfigLocations() {

View File

@@ -20,7 +20,6 @@ import java.util.List;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.CountNameClassPairCallbackHandler;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
/**
* Tests for LdapTemplate's list methods.
@@ -28,7 +27,7 @@ import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
* @author Ulrik Sandberg
*/
public class LdapTemplateListITest extends
AbstractDependencyInjectionSpringContextTests {
AbstractLdapTemplateIntegrationTest {
private LdapTemplate tested;

View File

@@ -24,7 +24,6 @@ import org.springframework.ldap.core.ContextMapper;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
/**
* Tests the lookup methods of LdapTemplate.
@@ -33,7 +32,7 @@ import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
* @author Ulrik Sandberg
*/
public class LdapTemplateLookupITest extends
AbstractDependencyInjectionSpringContextTests {
AbstractLdapTemplateIntegrationTest {
private LdapTemplate tested;

View File

@@ -25,7 +25,6 @@ import javax.naming.directory.ModificationItem;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
/**
* Tests the modification methods (rebind and modifyAttributes) of LdapTemplate.
@@ -41,7 +40,7 @@ import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
* @author Ulrik Sandberg
*/
public class LdapTemplateModifyITest extends
AbstractDependencyInjectionSpringContextTests {
AbstractLdapTemplateIntegrationTest {
private LdapTemplate tested;
private static String PERSON4_DN = "cn=Some Person4,ou=company1,c=Sweden";
@@ -53,6 +52,8 @@ public class LdapTemplateModifyITest extends
}
protected void onSetUp() throws Exception {
super.onSetUp();
DirContextAdapter adapter = new DirContextAdapter();
adapter.setAttributeValues("objectclass", new String[] { "top",
"person" });

View File

@@ -19,7 +19,6 @@ package org.springframework.ldap;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.CountNameClassPairCallbackHandler;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
/**
* Tests to verify that not setting a base suffix on the ContextSource (as
@@ -30,7 +29,7 @@ import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
* @author Mattias Arthursson
*/
public class LdapTemplateNoBaseSuffixITest extends
AbstractDependencyInjectionSpringContextTests {
AbstractLdapTemplateIntegrationTest {
private LdapTemplate tested;
protected String[] getConfigLocations() {

View File

@@ -21,7 +21,6 @@ import javax.naming.Name;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
/**
* Tests the recursive modification methods (unbind and the protected delete
@@ -31,7 +30,7 @@ import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
* @author Ulrik Sandberg
*/
public class LdapTemplateRecursiveDeleteITest extends
AbstractDependencyInjectionSpringContextTests {
AbstractLdapTemplateIntegrationTest {
private LdapTemplate tested;
private static DistinguishedName DN = new DistinguishedName(
@@ -48,6 +47,8 @@ public class LdapTemplateRecursiveDeleteITest extends
}
protected void onSetUp() throws Exception {
super.onSetUp();
DirContextAdapter adapter = new DirContextAdapter();
adapter.setAttributeValues("objectclass", new String[] { "top",
"person" });

View File

@@ -21,7 +21,6 @@ import javax.naming.Name;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
/**
* Tests the rename methods of LdapTemplate.
@@ -32,7 +31,7 @@ import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
* @author Ulrik Sandberg
*/
public class LdapTemplateRenameITest extends
AbstractDependencyInjectionSpringContextTests {
AbstractLdapTemplateIntegrationTest {
private LdapTemplate tested;
private static String DN = "cn=Some Person6,ou=company1,c=Sweden";
@@ -44,6 +43,8 @@ public class LdapTemplateRenameITest extends
}
protected void onSetUp() throws Exception {
super.onSetUp();
DirContextAdapter adapter = new DirContextAdapter();
adapter.setAttributeValues("objectclass", new String[] { "top",
"person" });

View File

@@ -15,7 +15,6 @@
*/
package org.springframework.ldap;
import org.ddsteps.spring.DDStepsSpringTestCase;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
@@ -50,6 +49,16 @@ public class LdapTemplateSearchCountITest extends DDStepsSpringTestCase {
private LdapTemplate tested;
private LdapServerManager manager;
public void setManager(LdapServerManager manager) {
this.manager = manager;
}
public void setUpMethod() throws Exception {
manager.cleanAndSetup("setup_data.ldif");
}
protected String[] getConfigLocations() {
return new String[] { "/conf/ldapTemplateNoBaseSuffixTestContext.xml" };
}

View File

@@ -22,7 +22,6 @@ import javax.naming.directory.SearchControls;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
/**
* Tests for LdapTemplate's search methods. This test class tests all the
@@ -32,7 +31,7 @@ import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
* @author Mattias Arthursson
*/
public class LdapTemplateSearchResultITest extends
AbstractDependencyInjectionSpringContextTests {
AbstractLdapTemplateIntegrationTest {
private LdapTemplate tested;