From 4c72019b3566cb8dd88a890bf003b71037a97cd9 Mon Sep 17 00:00:00 2001 From: Mattias Arthursson Date: Wed, 15 Aug 2007 11:26:07 +0000 Subject: [PATCH] Fix for LDAP-74: Change the append method in DistinguishedName. --- .../ldap/core/DistinguishedName.java | 18 +++++++++++++++++- .../ldap/core/DistinguishedNameTest.java | 9 ++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/spring-ldap/src/main/java/org/springframework/ldap/core/DistinguishedName.java b/spring-ldap/src/main/java/org/springframework/ldap/core/DistinguishedName.java index 4506ef5e..7d0682da 100644 --- a/spring-ldap/src/main/java/org/springframework/ldap/core/DistinguishedName.java +++ b/spring-ldap/src/main/java/org/springframework/ldap/core/DistinguishedName.java @@ -347,9 +347,25 @@ public class DistinguishedName implements Name { * * @param path * the path to append. + * @return this instance. */ - public void append(DistinguishedName path) { + public DistinguishedName append(DistinguishedName path) { getNames().addAll(path.getNames()); + return this; + } + + /** + * Append a new LdapRdn using the supplied key and value. + * + * @param key + * the key of the LdapRdn. + * @param value + * the value of the LdapRdn. + * @return this instance. + */ + public DistinguishedName append(String key, String value){ + add(key, value); + return this; } /** diff --git a/spring-ldap/src/test/java/org/springframework/ldap/core/DistinguishedNameTest.java b/spring-ldap/src/test/java/org/springframework/ldap/core/DistinguishedNameTest.java index 13f5fa2c..921c28e3 100644 --- a/spring-ldap/src/test/java/org/springframework/ldap/core/DistinguishedNameTest.java +++ b/spring-ldap/src/test/java/org/springframework/ldap/core/DistinguishedNameTest.java @@ -519,4 +519,11 @@ public class DistinguishedNameTest extends TestCase { assertTrue(true); } } -} \ No newline at end of file + + public void testAppendChained() { + DistinguishedName tested = new DistinguishedName("dc=mycompany,dc=com"); + tested.append("ou", "company1").append("cn", "john doe"); + + assertEquals("cn=john doe, ou=company1, dc=mycompany, dc=com", tested.toString()); + } +}