String path = "CN=Jimmy Blooptoop,OU=Someplace,OU=Employees,DC=Bloopsoft-Inc"; DistinguishedName dn = new DistinguishedName(path); String cn = dn.getValue("cn"); // Jimmy Blooptoop
@Test public void testGetValue() throws Exception { DistinguishedName dn = new DistinguishedName("cn=john doe, ou=Some company, c=SE"); String value = dn.getValue("ou"); assertThat(value).isEqualTo("Some company"); }
@Test(expected = IllegalArgumentException.class) public void testGetValueNoMatchingKeyThrowsException() throws Exception { DistinguishedName dn = new DistinguishedName("cn=john doe, ou=Some company, c=SE"); dn.getValue("nosuchkey"); }
/** * Test for http://forum.springsource.org/showthread.php?t=86640. */ @Test public void testDistinguishedNameWithDotParsesProperly() { DistinguishedName name = new DistinguishedName("cn=first.last,OU=DevTest Users,DC=xyz,DC=com"); assertThat(name.toCompactString()).isEqualTo("cn=first.last,ou=DevTest Users,dc=xyz,dc=com"); DistinguishedName dn = new DistinguishedName(); dn.parse("cn=first.last,OU=DevTest Users,DC=xyz,DC=com"); assertThat(dn.getValue("cn")).isEqualTo("first.last"); assertThat(dn.getValue("ou")).isEqualTo("DevTest Users"); assertThat(dn.getLdapRdn(1).getValue()).isEqualTo("xyz"); assertThat(dn.getLdapRdn(0).getValue()).isEqualTo("com"); }
DistinguishedName relative = config.relativeDN(grpName); String nameAttr = config.getGroupAttribute("name"); grpName = relative.getValue(nameAttr);