diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/AbstractLdapTemplateIntegrationTest.java b/spring-ldap/src/itest/java/org/springframework/ldap/AbstractLdapTemplateIntegrationTest.java new file mode 100644 index 00000000..858f3e2b --- /dev/null +++ b/spring-ldap/src/itest/java/org/springframework/ldap/AbstractLdapTemplateIntegrationTest.java @@ -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; + } +} diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/LdapServerManager.java b/spring-ldap/src/itest/java/org/springframework/ldap/LdapServerManager.java index 3a04e9b2..7513e319 100644 --- a/spring-ldap/src/itest/java/org/springframework/ldap/LdapServerManager.java +++ b/spring-ldap/src/itest/java/org/springframework/ldap/LdapServerManager.java @@ -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(); diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateAttributesMapperITest.java b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateAttributesMapperITest.java index 0dc0713c..f11da8f6 100644 --- a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateAttributesMapperITest.java +++ b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateAttributesMapperITest.java @@ -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() { diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateBindUnbindITest.java b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateBindUnbindITest.java index 3e739eec..1a0d7dda 100644 --- a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateBindUnbindITest.java +++ b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateBindUnbindITest.java @@ -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"; diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateContextExecutorTest.java b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateContextExecutorTest.java index be0689d7..6358b041 100644 --- a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateContextExecutorTest.java +++ b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateContextExecutorTest.java @@ -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; diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateContextMapperITest.java b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateContextMapperITest.java index c6488ef8..20d1e1ac 100644 --- a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateContextMapperITest.java +++ b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateContextMapperITest.java @@ -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() { diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateListITest.java b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateListITest.java index 2a0bcbdf..bab73f0a 100644 --- a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateListITest.java +++ b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateListITest.java @@ -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; diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateLookupITest.java b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateLookupITest.java index eebb5e93..f0b6d70b 100644 --- a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateLookupITest.java +++ b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateLookupITest.java @@ -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; diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateModifyITest.java b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateModifyITest.java index 52cd53e1..5f9a67cb 100644 --- a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateModifyITest.java +++ b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateModifyITest.java @@ -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" }); diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateNoBaseSuffixITest.java b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateNoBaseSuffixITest.java index 15fbaa99..30ffd084 100644 --- a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateNoBaseSuffixITest.java +++ b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateNoBaseSuffixITest.java @@ -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() { diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateRecursiveDeleteITest.java b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateRecursiveDeleteITest.java index 1cbcb931..a3ca56da 100644 --- a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateRecursiveDeleteITest.java +++ b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateRecursiveDeleteITest.java @@ -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" }); diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateRenameITest.java b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateRenameITest.java index 486ae652..9cde451c 100644 --- a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateRenameITest.java +++ b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateRenameITest.java @@ -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" }); diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateSearchCountITest.java b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateSearchCountITest.java index 2fe55d31..30ed1eb9 100644 --- a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateSearchCountITest.java +++ b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateSearchCountITest.java @@ -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" }; } diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateSearchResultITest.java b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateSearchResultITest.java index 7e045af1..bd955bc0 100644 --- a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateSearchResultITest.java +++ b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateSearchResultITest.java @@ -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;