/** * Get the value of this LdapRdn. Note that if this Rdn is multi-value the * first value will be returned. E.g. for the Rdn * <code>cn=john doe+sn=doe</code>, the return value would be * <code>john doe</code>. * * @return the (first) value of this LdapRdn. * @throws IndexOutOfBoundsException if there are no components in this Rdn. */ public String getValue() { return getComponent().getValue(); }
/** * Get the key of this LdapRdn. Note that if this Rdn is multi-value the * first key will be returned. E.g. for the Rdn * <code>cn=john doe+sn=doe</code>, the return value would be * <code>cn</code>. * * @return the (first) key of this LdapRdn. * @throws IndexOutOfBoundsException if there are no components in this Rdn. */ public String getKey() { return getComponent().getKey(); }
/** * Get the value of this LdapRdn. Note that if this Rdn is multi-value the * first value will be returned. E.g. for the Rdn * <code>cn=john doe+sn=doe</code>, the return value would be * <code>john doe</code>. * * @return the (first) value of this LdapRdn. * @throws IndexOutOfBoundsException if there are no components in this Rdn. */ public String getValue() { return getComponent().getValue(); }
/** * Get the value of this LdapRdn. Note that if this Rdn is multi-value the * first value will be returned. E.g. for the Rdn * <code>cn=john doe+sn=doe</code>, the return value would be * <code>john doe</code>. * * @return the (first) value of this LdapRdn. * @throws IndexOutOfBoundsException if there are no components in this Rdn. */ public String getValue() { return getComponent().getValue(); }
/** * Get the key of this LdapRdn. Note that if this Rdn is multi-value the * first key will be returned. E.g. for the Rdn * <code>cn=john doe+sn=doe</code>, the return value would be * <code>cn</code>. * * @return the (first) key of this LdapRdn. * @throws IndexOutOfBoundsException if there are no components in this Rdn. */ public String getKey() { return getComponent().getKey(); }
/** * Get the key of this LdapRdn. Note that if this Rdn is multi-value the * first key will be returned. E.g. for the Rdn * <code>cn=john doe+sn=doe</code>, the return value would be * <code>cn</code>. * * @return the (first) key of this LdapRdn. * @throws IndexOutOfBoundsException if there are no components in this Rdn. */ public String getKey() { return getComponent().getKey(); }
/** * Get the key of this LdapRdn. Note that if this Rdn is multi-value the * first key will be returned. E.g. for the Rdn * <code>cn=john doe+sn=doe</code>, the return value would be * <code>cn</code>. * * @return the (first) key of this LdapRdn. * @throws IndexOutOfBoundsException if there are no components in this Rdn. */ public String getKey() { return getComponent().getKey(); }
/** * Get the value of this LdapRdn. Note that if this Rdn is multi-value the * first value will be returned. E.g. for the Rdn * <code>cn=john doe+sn=doe</code>, the return value would be * <code>john doe</code>. * * @return the (first) value of this LdapRdn. * @throws IndexOutOfBoundsException if there are no components in this Rdn. */ public String getValue() { return getComponent().getValue(); }
@Test public void testLdapRdn_parse_spaces() { LdapRdn rdn = new LdapRdn(" foo = bar "); assertThat(rdn.getComponent().getKey()).isEqualTo("foo"); assertThat(rdn.getComponent().getValue()).isEqualTo("bar"); assertThat(rdn.getComponent().getLdapEncoded()).isEqualTo("foo=bar"); }
@Test public void testLdapRdn_KeyValue_simple() { LdapRdn rdn = new LdapRdn("foo", "bar"); assertThat(rdn.getComponent().getKey()).isEqualTo("foo"); assertThat(rdn.getComponent().getValue()).isEqualTo("bar"); assertThat(rdn.getComponent().getLdapEncoded()).isEqualTo("foo=bar"); }
@Test public void testLdapRdn_parse_hexEscape() { LdapRdn rdn = new LdapRdn("foo=bar\\0dfum"); assertThat(rdn.getComponent().getKey()).isEqualTo("foo"); assertThat(rdn.getComponent().getValue()).isEqualTo("bar\rfum"); assertThat(rdn.getComponent().getLdapEncoded()).isEqualTo("foo=bar\\0Dfum"); }
@Test public void testLdapRdn_parse_spaces_escape() { LdapRdn rdn = new LdapRdn(" foo = \\ bar\\20 \\ "); assertThat(rdn.getComponent().getKey()).isEqualTo("foo"); assertThat(rdn.getComponent().getValue()).isEqualTo(" bar "); assertThat(rdn.getComponent().getLdapEncoded()).isEqualTo("foo=\\ bar \\ "); }
@Test public void testLdapRdn_parse_escape() { LdapRdn rdn = new LdapRdn("foo=bar\\=fum"); assertThat(rdn.getComponent().getKey()).isEqualTo("foo"); assertThat(rdn.getComponent().getValue()).isEqualTo("bar=fum"); assertThat(rdn.getComponent().getLdapEncoded()).isEqualTo("foo=bar\\=fum"); }
@Test public void testLdapRdn_parse_slash() { LdapRdn rdn = new LdapRdn("ou=Clerical / Secretarial Staff"); assertThat(rdn.getComponent().getKey()).isEqualTo("ou"); assertThat(rdn.getComponent().getValue()).isEqualTo("Clerical / Secretarial Staff"); assertThat(rdn.getComponent().getLdapEncoded()).isEqualTo("ou=Clerical / Secretarial Staff"); }
@Test public void testLdapRdn_KeyValue_valueNeedsEscape() { LdapRdn rdn = new LdapRdn("foo", "bar\\"); assertThat(rdn.getComponent().getKey()).isEqualTo("foo"); assertThat(rdn.getComponent().getValue()).isEqualTo("bar\\"); assertThat(rdn.getComponent().getLdapEncoded()).isEqualTo("foo=bar\\\\"); }
@Test public void testLdapRdn_parse_simple() { LdapRdn rdn = new LdapRdn("foo=bar"); assertThat(rdn.getComponent().getKey()).isEqualTo("foo"); assertThat(rdn.getComponent().getValue()).isEqualTo("bar"); assertThat(rdn.getComponent().getLdapEncoded()).isEqualTo("foo=bar"); assertThat(rdn.getKey()).isEqualTo("foo"); assertThat(rdn.getValue()).isEqualTo("bar"); }
@Test public void testLdapRdn_Parse_MultipleComponents() { LdapRdn rdn = new LdapRdn("cn=John Doe+sn=Doe"); assertThat(rdn.getComponent(0).encodeLdap()).isEqualTo("cn=John Doe"); assertThat(rdn.getComponent(1).encodeLdap()).isEqualTo("sn=Doe"); assertThat(rdn.getLdapEncoded()).isEqualTo("cn=John Doe+sn=Doe"); assertThat(rdn.getKey()).isEqualTo("cn"); assertThat(rdn.getValue()).isEqualTo("John Doe"); assertThat(rdn.getValue("cn")).isEqualTo("John Doe"); assertThat(rdn.getValue("sn")).isEqualTo("Doe"); }
@Test public void testDistinguishedName() { String testPath = "cn=foo\\,bar,OU=FOO\\,bar , OU=foo\\;bar;OU=foo\\;bar" + " ; ou=foo\\,,ou=foo\\,;ou=foo\\;;ou=foo\\,;ou=bar\\,"; System.out.println(testPath); DistinguishedName path = new DistinguishedName(testPath); assertThat(path.getLdapRdn(8).getComponent().getKey()).isEqualTo("cn"); assertThat(path.getLdapRdn(8).getComponent().getValue()).isEqualTo("foo,bar"); assertThat(path.getLdapRdn(7).getComponent().getKey()).isEqualTo("ou"); assertThat(path.getLdapRdn(7).getComponent().getValue()).isEqualTo("FOO,bar"); assertThat(path.getLdapRdn(6).getComponent().getKey()).isEqualTo("ou"); assertThat(path.getLdapRdn(6).getComponent().getValue()).isEqualTo("foo;bar"); assertThat(path.getLdapRdn(5).getComponent().getKey()).isEqualTo("ou"); assertThat(path.getLdapRdn(5).getComponent().getValue()).isEqualTo("foo;bar"); assertThat(path.getLdapRdn(4).getComponent().getKey()).isEqualTo("ou"); assertThat(path.getLdapRdn(4).getComponent().getValue()).isEqualTo("foo,"); assertThat(path.getLdapRdn(3).getComponent().getKey()).isEqualTo("ou"); assertThat(path.getLdapRdn(3).getComponent().getValue()).isEqualTo("foo,"); assertThat(path.getLdapRdn(2).getComponent().getKey()).isEqualTo("ou"); assertThat(path.getLdapRdn(2).getComponent().getValue()).isEqualTo("foo;"); assertThat(path.getLdapRdn(1).getComponent().getKey()).isEqualTo("ou"); assertThat(path.getLdapRdn(1).getComponent().getValue()).isEqualTo("foo,"); assertThat(path.getLdapRdn(0).getComponent().getKey()).isEqualTo("ou"); assertThat(path.getLdapRdn(0).getComponent().getValue()).isEqualTo("bar,"); }
@Test(expected = UnsupportedOperationException.class) public void testUnmodifiableDistinguishedNameFailsToModifyRdnComponentKey() throws Exception { DistinguishedName result = DistinguishedName.immutableDistinguishedName("cn=john doe"); LdapRdnComponent component = result.getLdapRdn(0).getComponent(); component.setKey("somekey"); }
@Test(expected = UnsupportedOperationException.class) public void testUnmodifiableDistinguishedNameFailsToModifyRdnComponentValue() throws Exception { DistinguishedName result = DistinguishedName.immutableDistinguishedName("cn=john doe"); LdapRdnComponent component = result.getLdapRdn(0).getComponent(); component.setValue("somevalue"); }