use of org.apache.directory.api.ldap.util.tree.DnNode in project directory-ldap-api by apache.
the class TestDnNode method testRename.
@Test
public void testRename() throws Exception {
DnNode<Dn> rootNode = new DnNode<Dn>();
Dn dn = new Dn("dc=directory,dc=apache,dc=org");
rootNode.add(dn);
Rdn childRdn = new Rdn("dc=org");
DnNode<Dn> child = rootNode.getChild(childRdn);
assertNotNull(child);
Rdn newChildRdn = new Rdn("dc=neworg");
child.rename(newChildRdn);
assertNull(rootNode.getChild(childRdn));
assertEquals(new Dn("dc=neworg"), child.getDn());
DnNode<Dn> child2 = child.getChild(new Rdn("dc=apache"));
assertEquals(new Dn("dc=apache,dc=neworg"), child2.getDn());
assertEquals(new Dn("dc=directory,dc=apache,dc=neworg"), child2.getChild(new Rdn("dc=directory")).getDn());
assertNotNull(rootNode.getChild(newChildRdn));
}
use of org.apache.directory.api.ldap.util.tree.DnNode in project directory-ldap-api by apache.
the class TestDnNode method testGetElementDN.
// ---------------------------------------------------------------------------
// Test the getElement(Dn) method
// ---------------------------------------------------------------------------
@Test
public void testGetElementDN() throws Exception {
DnNode<Dn> tree = new DnNode<Dn>();
Dn dn1 = new Dn("dc=c,dc=b,dc=a");
tree.add(dn1, dn1);
Dn dn2 = new Dn("dc=e,dc=a");
tree.add(dn2, dn2);
assertNull(tree.getElement(Dn.EMPTY_DN));
assertNull(tree.getElement(new Dn("dc=a")));
assertNull(tree.getElement(new Dn("dc=b,dc=a")));
assertEquals(dn1, tree.getElement(dn1));
assertEquals(dn2, tree.getElement(dn2));
assertEquals(dn2, tree.getElement(new Dn("dc=g,dc=f,dc=e,dc=a")));
}
use of org.apache.directory.api.ldap.util.tree.DnNode in project directory-ldap-api by apache.
the class ApiLdapExtrasUtilOsgiTest method useBundleClasses.
@Override
protected void useBundleClasses() throws Exception {
Dn dn = new Dn("cn=foo");
Name name = JndiUtils.toName(dn);
assertEquals(name.toString(), dn.toString());
new DnNode<Object>().add(dn).getParent();
}
use of org.apache.directory.api.ldap.util.tree.DnNode in project directory-ldap-api by apache.
the class TestDnNode method testAdd2OverlappingDNsNoElem.
/**
* Test the addition of two overlapping DNs
*/
@Test
public void testAdd2OverlappingDNsNoElem() throws LdapException {
DnNode<Dn> tree = new DnNode<Dn>();
Dn dn1 = new Dn("dc=b,dc=a");
Dn dn2 = new Dn("dc=f,dc=a");
tree.add(dn1);
tree.add(dn2);
assertNotNull(tree);
Map<String, DnNode<Dn>> children = tree.getChildren();
assertNotNull(children);
assertEquals(1, children.size());
assertNull(tree.getElement());
DnNode<Dn> level1 = children.get(new Rdn("dc=a").getNormName());
DnNode<Dn> level2 = level1.getChildren().get(new Rdn("dc=b").getNormName());
Map<String, DnNode<Dn>> childrenDn1 = level1.getChildren();
assertNotNull(childrenDn1);
assertEquals(2, childrenDn1.size());
assertNull(level1.getElement());
assertNotNull(level2);
assertFalse(level2.hasElement());
level1 = children.get(new Rdn("dc=a").getNormName());
level2 = level1.getChildren().get(new Rdn("dc=f").getNormName());
assertNotNull(level2);
assertFalse(level2.hasElement());
}
use of org.apache.directory.api.ldap.util.tree.DnNode in project directory-ldap-api by apache.
the class TestDnNode method testHasParentElement.
// ---------------------------------------------------------------------------
// Test the hasParentElement(Dn) method
// ---------------------------------------------------------------------------
@Test
public void testHasParentElement() throws Exception {
DnNode<Dn> dnLookupTree = new DnNode<Dn>();
Dn dn1 = new Dn("dc=directory,dc=apache,dc=org");
Dn dn2 = new Dn("dc=mina,dc=apache,dc=org");
Dn dn3 = new Dn("dc=test,dc=com");
Dn dn4 = new Dn("dc=acme,dc=com");
Dn dn5 = new Dn("dc=acme,c=us,dc=com");
Dn dn6 = new Dn("dc=empty");
Dn org = new Dn("dc=org");
dnLookupTree.add(dn1, dn1);
dnLookupTree.add(dn2, dn2);
dnLookupTree.add(dn3, dn3);
dnLookupTree.add(dn4, dn4);
dnLookupTree.add(dn5);
dnLookupTree.add(dn6, dn6);
// Inject some intermediary nodes
dnLookupTree.add(org, org);
assertTrue(dnLookupTree.hasParentElement(new Dn("dc=apache,dc=org")));
// Check that org has at least one descendant containing an element
assertTrue(dnLookupTree.hasDescendantElement(org));
// check that for one node which has no children with any element, we get false
assertFalse(dnLookupTree.hasDescendantElement(new Dn("c=us,dc=com")));
// Check that we correctly get back all the children
Dn dn7 = new Dn("dc=elem,dc=mina,dc=apache,dc=org");
dnLookupTree.add(dn7, dn7);
// With dc=org, we should get back dn1 and dn3
List<Dn> dns = dnLookupTree.getDescendantElements(org);
assertNotNull(dns);
assertEquals(2, dns.size());
assertTrue(dns.contains(dn1));
assertTrue(dns.contains(dn2));
// Same, with a node not having any descendants
dns = dnLookupTree.getDescendantElements(dn6);
assertEquals(0, dns.size());
}