From bf2c3af0a2d24d9bffc44e52b47dc0dd16068892 Mon Sep 17 00:00:00 2001 From: Mattias Arthursson Date: Tue, 25 Nov 2008 15:24:05 +0000 Subject: [PATCH] Made sure integration tests for article sample automatically start in-process LDAP server. DirContextAdapter#setDn() now throws IllegalStateException if setDn is called on an instance in update mode (this was previously silently ignored) Fixed problem in LdapTreeBuilder caused by the new behaviour of DN in DirContextAdapter (i.e. that the actual DN instance of the DirContextAdapter is no longer returned by getDn()). --- changelog.txt | 10 +++++- core/pom.xml | 4 +++ .../ldap/core/DirContextAdapter.java | 5 +++ .../src/test/resources/config/testContext.xml | 13 ++++--- .../src/test/resources/setup_data.ldif | 35 +++++++++++++++++++ .../ldap/samples/utils/LdapTreeBuilder.java | 24 +++++++------ 6 files changed, 74 insertions(+), 17 deletions(-) create mode 100644 samples/article/src/test/resources/setup_data.ldif diff --git a/changelog.txt b/changelog.txt index d65e644f..cdffca00 100644 --- a/changelog.txt +++ b/changelog.txt @@ -24,6 +24,14 @@ Changes in version 1.3.0 (Nov 2008) * Made sure DirContextOperations#addAttributeValue(String, Object) does not add any duplicate values per default; added alternate method: DirContextOperations#addAttributeValue(String, Object, boolean) to enable behavior other than the default (i.e. allowing duplicates). + +* Made sure that DirContextAdapter#setDn() throws exception if in update mode + (The value is not set anyway, and this was previously silently ignored). + +* Made sure article sample tests are possible to run without running web + application (i.e. tests automatically start internal LDAP server) (LDAP-143). + +* Added spring-tx as required dependency (the DataAccessExceptions require this). Changes in version 1.3.0.RC1 (Oct 2008) ------------------------------------------- @@ -42,7 +50,7 @@ Changes in version 1.3.0.RC1 (Oct 2008) * The hard dependency on LDAP Booster Pack has now been completely removed, preventing NoClassDefFoundErrors when using Paged Results without that - library on the classpath. (LDAP-110, LDAP-118) + library on the classpath. (LDAP-110, LDAP-118) * The dreaded problem with '\' in Distinguished Names is now resolved. (LDAP-50, LDAP-109) diff --git a/core/pom.xml b/core/pom.xml index 87ff05a5..928489f0 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -68,6 +68,10 @@ org.springframework spring-beans + + org.springframework + spring-tx + org.springframework spring-context diff --git a/core/src/main/java/org/springframework/ldap/core/DirContextAdapter.java b/core/src/main/java/org/springframework/ldap/core/DirContextAdapter.java index e3b8e098..0b44fc09 100644 --- a/core/src/main/java/org/springframework/ldap/core/DirContextAdapter.java +++ b/core/src/main/java/org/springframework/ldap/core/DirContextAdapter.java @@ -1262,6 +1262,11 @@ public class DirContextAdapter implements DirContextOperations { if (!updateMode) { this.dn = new DistinguishedName(dn.toString()); } + else { + throw new IllegalStateException( + "Not possible to call setDn() on a DirContextAdapter in update mode"); + } + } /** diff --git a/samples/article/src/test/resources/config/testContext.xml b/samples/article/src/test/resources/config/testContext.xml index b9a60eea..4a762506 100644 --- a/samples/article/src/test/resources/config/testContext.xml +++ b/samples/article/src/test/resources/config/testContext.xml @@ -8,11 +8,14 @@ - - - + + + + - + + @@ -26,7 +29,7 @@ - + diff --git a/samples/article/src/test/resources/setup_data.ldif b/samples/article/src/test/resources/setup_data.ldif new file mode 100644 index 00000000..e6d7dce6 --- /dev/null +++ b/samples/article/src/test/resources/setup_data.ldif @@ -0,0 +1,35 @@ +dn: c=Sweden,dc=jayway,dc=se +objectclass: top +objectclass: country +c: Sweden +description: The country of Sweden + +dn: ou=company1,c=Sweden,dc=jayway,dc=se +objectclass: top +objectclass: organizationalUnit +ou: company1 +description: First company in Sweden + +dn: cn=Some Person,ou=company1,c=Sweden,dc=jayway,dc=se +objectclass: top +objectclass: person +objectclass: organizationalPerson +objectclass: inetOrgPerson +uid: some.person +userPassword: password +cn: Some Person +sn: Person +description: Sweden, Company1, Some Person +telephoneNumber: +46 555-123456 + +dn: cn=Some Person2,ou=company1,c=Sweden,dc=jayway,dc=se +objectclass: top +objectclass: person +objectclass: organizationalPerson +objectclass: inetOrgPerson +uid: some.person2 +userPassword: password +cn: Some Person2 +sn: Person2 +description: Sweden, Company1, Some Person2 +telephoneNumber: +46 555-654321 diff --git a/samples/samples-utils/src/main/java/org/springframework/ldap/samples/utils/LdapTreeBuilder.java b/samples/samples-utils/src/main/java/org/springframework/ldap/samples/utils/LdapTreeBuilder.java index 8359faa9..d06033cc 100644 --- a/samples/samples-utils/src/main/java/org/springframework/ldap/samples/utils/LdapTreeBuilder.java +++ b/samples/samples-utils/src/main/java/org/springframework/ldap/samples/utils/LdapTreeBuilder.java @@ -14,22 +14,24 @@ public class LdapTreeBuilder { } public LdapTree getLdapTree(DistinguishedName root) { - DirContextOperations context = ldapTemplate.lookupContext(root.toString()); + DirContextOperations context = ldapTemplate.lookupContext(root + .toString()); return getLdapTree(context); } private LdapTree getLdapTree(final DirContextOperations rootContext) { final LdapTree ldapTree = new LdapTree(rootContext); - ldapTemplate.listBindings(rootContext.getDn(), new AbstractContextMapper() { - @Override - protected Object doMapFromContext(DirContextOperations ctx) { - DistinguishedName dn = (DistinguishedName) ctx.getDn(); - dn.prepend((DistinguishedName) rootContext.getDn()); - - ldapTree.addSubTree(getLdapTree(ctx)); - return null; - } - }); + ldapTemplate.listBindings(rootContext.getDn(), + new AbstractContextMapper() { + @Override + protected Object doMapFromContext(DirContextOperations ctx) { + DistinguishedName dn = (DistinguishedName) ctx.getDn(); + dn.prepend((DistinguishedName) rootContext.getDn()); + ldapTree.addSubTree(getLdapTree(ldapTemplate + .lookupContext(dn))); + return null; + } + }); return ldapTree; }