DistinguishedName implements Name { public String toString() { String spacedFormatting = System.getProperty(SPACED_DN_FORMAT_PROPERTY); if (!StringUtils.hasText(spacedFormatting)) { return format(COMPACT); } else { return format(NON_COMPACT); } } DistinguishedName();  DistinguishedName(String path);  DistinguishedName(List list);  DistinguishedName(Name name); LdapRdn getLdapRdn(int index); LdapRdn getLdapRdn(String key); String getValue(String key); List getNames(); String toString(); String toCompactString(); String encode(); String toUrl(); boolean contains(DistinguishedName path); DistinguishedName append(DistinguishedName path); DistinguishedName append(String key, String value); void prepend(DistinguishedName path); LdapRdn removeFirst(); void removeFirst(Name path); Object clone(); boolean equals(Object obj); int hashCode(); int compareTo(Object obj); int size(); boolean isEmpty(); Enumeration getAll(); String get(int index); Name getPrefix(int index); Name getSuffix(int index); boolean startsWith(Name name); boolean endsWith(Name name); Name addAll(Name name); Name addAll(int arg0, Name name); Name add(String string); Name add(int index, String string); Object remove(int arg0); LdapRdn removeLast(); void add(String key, String value); void add(LdapRdn rdn); void add(int idx, LdapRdn rdn); DistinguishedName immutableDistinguishedName(); static final DistinguishedName immutableDistinguishedName(String dnString); static final String SPACED_DN_FORMAT_PROPERTY; static final String KEY_CASE_FOLD_PROPERTY; static final String KEY_CASE_FOLD_LOWER; static final String KEY_CASE_FOLD_UPPER; static final String KEY_CASE_FOLD_NONE; static final DistinguishedName EMPTY_PATH; }
@Test public void testToStringCompact() { try { DistinguishedName name = new DistinguishedName("cn=john doe, ou=company"); assertThat(name.toString()).isEqualTo("cn=john doe,ou=company"); System.setProperty(DistinguishedName.SPACED_DN_FORMAT_PROPERTY, "true"); assertThat(name.toString()).isEqualTo("cn=john doe, ou=company"); } finally { System.setProperty(DistinguishedName.SPACED_DN_FORMAT_PROPERTY, ""); } }
@Test public void testKeyCaseFoldNoneShouldEqualOriginalCasedKeys() throws Exception { try { String dnString = "ou=foo,Ou=bar,oU=baz,OU=bim"; DistinguishedName name = new DistinguishedName(dnString); assertThat(name.toString()).isEqualTo("ou=foo,ou=bar,ou=baz,ou=bim"); System.setProperty(DistinguishedName.KEY_CASE_FOLD_PROPERTY, DistinguishedName.KEY_CASE_FOLD_NONE); name = new DistinguishedName(dnString); System.out.println(dnString + " folded as \"" + DistinguishedName.KEY_CASE_FOLD_NONE + "\": " + name); assertThat(name.toString()).isEqualTo(dnString); } finally { System.clearProperty(DistinguishedName.KEY_CASE_FOLD_PROPERTY); } }
@Test public void testKeyCaseFoldUpperShouldEqualUpperCasedKeys() throws Exception { try { String dnString = "ou=foo,Ou=bar,oU=baz,OU=bim"; DistinguishedName name = new DistinguishedName(dnString); assertThat(name.toString()).isEqualTo("ou=foo,ou=bar,ou=baz,ou=bim"); System.setProperty(DistinguishedName.KEY_CASE_FOLD_PROPERTY, DistinguishedName.KEY_CASE_FOLD_UPPER); name = new DistinguishedName(dnString); System.out.println(dnString + " folded as \"" + DistinguishedName.KEY_CASE_FOLD_UPPER + "\": " + name); assertThat(name.toString()).isEqualTo("OU=foo,OU=bar,OU=baz,OU=bim"); } finally { System.clearProperty(DistinguishedName.KEY_CASE_FOLD_PROPERTY); } }
@Test public void testKeyCaseFoldLowerShouldEqualLowerCasedKeys() throws Exception { try { String dnString = "ou=foo,Ou=bar,oU=baz,OU=bim"; DistinguishedName name = new DistinguishedName(dnString); assertThat(name.toString()).isEqualTo("ou=foo,ou=bar,ou=baz,ou=bim"); System.setProperty(DistinguishedName.KEY_CASE_FOLD_PROPERTY, DistinguishedName.KEY_CASE_FOLD_LOWER); name = new DistinguishedName(dnString); System.out.println(dnString + " folded as \"" + DistinguishedName.KEY_CASE_FOLD_LOWER + "\": " + name); assertThat(name.toString()).isEqualTo("ou=foo,ou=bar,ou=baz,ou=bim"); } finally { System.clearProperty(DistinguishedName.KEY_CASE_FOLD_PROPERTY); } }
@Test public void testKeyCaseFoldNonsenseShoulddefaultToLowerCasedKeysAndLogWarning() throws Exception { try { String dnString = "ou=foo,Ou=bar,oU=baz,OU=bim"; DistinguishedName name = new DistinguishedName(dnString); assertThat(name.toString()).isEqualTo("ou=foo,ou=bar,ou=baz,ou=bim"); System.setProperty(DistinguishedName.KEY_CASE_FOLD_PROPERTY, "whatever"); name = new DistinguishedName(dnString); System.out.println(dnString + " folded as \"whatever\": " + name); assertThat(name.toString()).isEqualTo("ou=foo,ou=bar,ou=baz,ou=bim"); } finally { System.clearProperty(DistinguishedName.KEY_CASE_FOLD_PROPERTY); } }
@Test public void testDistinguishedName_CompositeWithSlash() throws Exception { Name testPath = new CompositeName("cn=foo\\/bar"); DistinguishedName path = new DistinguishedName(testPath); assertThat(path.toString()).isEqualTo("cn=foo/bar"); }
@Test public void testDistinguishedName_CompositeWithSlashAsString() throws Exception { Name testPath = new CompositeName("cn=foo\\/bar"); DistinguishedName path = new DistinguishedName(testPath.toString()); assertThat(path.toString()).isEqualTo("cn=foo/bar"); }
@Test public void testDistinguishedName_Ldap237_NotDestroyedByCompositeName() throws InvalidNameException { DistinguishedName path = new DistinguishedName("ou=Roger \\\"Bunny\\\" Rabbit,dc=somecompany,dc=com"); assertThat(path.toString()).isEqualTo("ou=Roger \\\"Bunny\\\" Rabbit,dc=somecompany,dc=com"); }
@Test public void testDistinguishedName_Ldap237_DestroyedByCompositeName() throws InvalidNameException { DistinguishedName path = new DistinguishedName("ou=Roger \\\\\"Bunny\\\\\" Rabbit,dc=somecompany,dc=com"); assertThat(path.toString()).isEqualTo("ou=Roger \\\"Bunny\\\" Rabbit,dc=somecompany,dc=com"); }