/** * Add a new {@link LdapRdn} using the supplied key and value. * * @param key the key of the {@link LdapRdn}. * @param value the value of the {@link LdapRdn}. */ public void add(String key, String value) { names.add(new LdapRdn(key, value)); }
/** * Add a new {@link LdapRdn} using the supplied key and value. * * @param key the key of the {@link LdapRdn}. * @param value the value of the {@link LdapRdn}. */ public void add(String key, String value) { names.add(new LdapRdn(key, value)); }
/** * Add a new {@link LdapRdn} using the supplied key and value. * * @param key the key of the {@link LdapRdn}. * @param value the value of the {@link LdapRdn}. */ public void add(String key, String value) { names.add(new LdapRdn(key, value)); }
/** * Add a new {@link LdapRdn} using the supplied key and value. * * @param key the key of the {@link LdapRdn}. * @param value the value of the {@link LdapRdn}. */ public void add(String key, String value) { names.add(new LdapRdn(key, value)); }
public Name add(int index, String string) throws InvalidNameException { try { names.add(index, new LdapRdn(string)); } catch (BadLdapGrammarException e) { throw new InvalidNameException("Failed to parse rdn '" + string + "'"); } return this; }
@Test(expected = BadLdapGrammarException.class) public void testLdapRdn_parse_trailingBackslash() { new LdapRdn("foo=bar\\"); }
@Test(expected = IllegalArgumentException.class) public void testGetValueNoKeyWithCorrectValue() { LdapRdn tested = new LdapRdn("cn=john doe"); tested.getValue("sn"); }
@Test public void testGetLdapRdnForKey() throws Exception { DistinguishedName dn = new DistinguishedName("cn=john doe, ou=Some company, c=SE"); LdapRdn ldapRdn = dn.getLdapRdn("ou"); assertThat(ldapRdn).isEqualTo(new LdapRdn("ou=Some company")); }
@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 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_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_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(expected = UnsupportedOperationException.class) public void testUnmodifiableDistinguishedNameFailsToAddRdn() throws Exception { DistinguishedName result = DistinguishedName.immutableDistinguishedName("cn=john doe"); result.add(new LdapRdn("somekey", "somevalue")); }