Search in sources :

Example 21 with DnNode

use of org.apache.directory.api.ldap.util.tree.DnNode in project directory-ldap-api by apache.

the class TestDnNode method testHasElement.

// ---------------------------------------------------------------------------
// Test the hasElement() method
// ---------------------------------------------------------------------------
@Test
public void testHasElement() throws Exception {
    DnNode<Dn> tree = new DnNode<Dn>();
    Dn dn = new Dn("dc=c,dc=b,dc=a");
    tree.add(dn, dn);
    assertFalse(tree.hasElement());
    DnNode<Dn> child = tree.getChild(new Rdn("dc=a"));
    assertFalse(child.hasElement());
    child = child.getChild(new Rdn("dc=b"));
    assertFalse(child.hasElement());
    child = child.getChild(new Rdn("dc=c"));
    assertTrue(child.hasElement());
}
Also used : DnNode(org.apache.directory.api.ldap.util.tree.DnNode) Dn(org.apache.directory.api.ldap.model.name.Dn) Rdn(org.apache.directory.api.ldap.model.name.Rdn) Test(org.junit.Test)

Example 22 with DnNode

use of org.apache.directory.api.ldap.util.tree.DnNode in project directory-ldap-api by apache.

the class TestDnNode method testGetParent.

// ---------------------------------------------------------------------------
// Test the getParent() method
// ---------------------------------------------------------------------------
@Test
public void testGetParent() throws Exception {
    DnNode<Dn> tree = new DnNode<Dn>();
    Dn dn = new Dn("dc=c,dc=b,dc=a");
    tree.add(dn, dn);
    assertNull(tree.getParent());
    DnNode<Dn> child = tree.getChild(new Rdn("dc=a"));
    assertEquals(tree, child.getParent());
    DnNode<Dn> child1 = child.getChild(new Rdn("dc=b"));
    assertEquals(child, child1.getParent());
    child = child1.getChild(new Rdn("dc=c"));
    assertEquals(child1, child.getParent());
}
Also used : DnNode(org.apache.directory.api.ldap.util.tree.DnNode) Dn(org.apache.directory.api.ldap.model.name.Dn) Rdn(org.apache.directory.api.ldap.model.name.Rdn) Test(org.junit.Test)

Example 23 with DnNode

use of org.apache.directory.api.ldap.util.tree.DnNode in project directory-ldap-api by apache.

the class TestDnNode method testHasChildren.

// ---------------------------------------------------------------------------
// Test the hasChildren method
// ---------------------------------------------------------------------------
@Test
public void testHasChildren() throws Exception {
    DnNode<Dn> tree = new DnNode<Dn>();
    Dn dn1 = new Dn("dc=b,dc=a");
    tree.add(dn1);
    assertTrue(tree.hasChildren());
    Map<String, DnNode<Dn>> children = tree.getChildren();
    assertNotNull(children);
    DnNode<Dn> child = children.get(new Rdn("dc=a").getNormName());
    assertTrue(child.hasChildren());
    children = child.getChildren();
    child = children.get(new Rdn("dc=b").getNormName());
    assertFalse(child.hasChildren());
}
Also used : DnNode(org.apache.directory.api.ldap.util.tree.DnNode) Dn(org.apache.directory.api.ldap.model.name.Dn) Rdn(org.apache.directory.api.ldap.model.name.Rdn) Test(org.junit.Test)

Example 24 with DnNode

use of org.apache.directory.api.ldap.util.tree.DnNode in project directory-ldap-api by apache.

the class TestDnNode method testAdd2DistinctDNs.

/**
 * Test the addition of two DNs not overlapping
 */
@Test
public void testAdd2DistinctDNs() throws LdapException {
    DnNode<Dn> tree = new DnNode<Dn>();
    Dn dn1 = new Dn("dc=b,dc=a");
    Dn dn2 = new Dn("dc=f,dc=e");
    tree.add(dn1, dn1);
    tree.add(dn2, dn2);
    assertNotNull(tree);
    Map<String, DnNode<Dn>> children = tree.getChildren();
    assertNotNull(children);
    assertEquals(2, 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());
    assertNotNull(level2);
    assertEquals(dn1, level2.getElement());
    level1 = children.get(new Rdn("dc=e").getNormName());
    level2 = level1.getChildren().get(new Rdn("dc=f").getNormName());
    assertNotNull(level2);
    assertEquals(dn2, level2.getElement());
}
Also used : DnNode(org.apache.directory.api.ldap.util.tree.DnNode) Dn(org.apache.directory.api.ldap.model.name.Dn) Rdn(org.apache.directory.api.ldap.model.name.Rdn) Test(org.junit.Test)

Example 25 with DnNode

use of org.apache.directory.api.ldap.util.tree.DnNode in project directory-ldap-api by apache.

the class TestDnNode method testHasElementDN.

// ---------------------------------------------------------------------------
// Test the hasElement(Dn) method
// ---------------------------------------------------------------------------
@Test
public void testHasElementDN() 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);
    assertFalse(tree.hasElement(Dn.EMPTY_DN));
    assertFalse(tree.hasElement(new Dn("dc=a")));
    assertFalse(tree.hasElement(new Dn("dc=b,dc=a")));
    assertTrue(tree.hasElement(dn1));
    assertFalse(tree.hasElement(dn2));
}
Also used : DnNode(org.apache.directory.api.ldap.util.tree.DnNode) Dn(org.apache.directory.api.ldap.model.name.Dn) Test(org.junit.Test)

Aggregations

Dn (org.apache.directory.api.ldap.model.name.Dn)30 DnNode (org.apache.directory.api.ldap.util.tree.DnNode)30 Test (org.junit.Test)29 Rdn (org.apache.directory.api.ldap.model.name.Rdn)19 Name (javax.naming.Name)1