Search in sources :

Example 1 with DnNode

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

the class TestDnNode method testAdd3LevelDN.

/**
 * Test the addition of a Dn with three Rdn
 */
@Test
public void testAdd3LevelDN() throws LdapException {
    DnNode<Dn> tree = new DnNode<Dn>();
    Dn dn = new Dn("dc=c,dc=b,dc=a");
    tree.add(dn, dn);
    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());
    DnNode<Dn> level3 = level2.getChildren().get(new Rdn("dc=c").getNormName());
    assertNotNull(level3);
    assertEquals(dn, level3.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 2 with DnNode

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

the class TestDnNode method testIsLeafDN.

// ---------------------------------------------------------------------------
// Test the isLeaf(Dn) method
// ---------------------------------------------------------------------------
@Test
public void testIsLeafDN() 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.isLeaf(Dn.EMPTY_DN));
    assertFalse(tree.isLeaf(new Dn("dc=a")));
    assertFalse(tree.isLeaf(new Dn("dc=b,dc=a")));
    assertTrue(tree.isLeaf(dn1));
    assertTrue(tree.isLeaf(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)

Example 3 with DnNode

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

the class TestDnNode method testMoveToAnAncestor.

@Test
public void testMoveToAnAncestor() throws Exception {
    DnNode<Dn> rootNode = new DnNode<Dn>();
    Dn dn = new Dn("dc=vysper,dc=mina,dc=directory,dc=apache,dc=org");
    rootNode.add(dn);
    Rdn minaRdn = new Rdn("dc=mina");
    DnNode<Dn> apacheNode = rootNode.getChild(new Rdn("dc=org")).getChild(new Rdn("dc=apache"));
    DnNode<Dn> directoryNode = apacheNode.getChild(new Rdn("dc=directory"));
    DnNode<Dn> minaNode = directoryNode.getChild(minaRdn);
    assertNotNull(minaNode);
    assertEquals(directoryNode, minaNode.getParent());
    assertTrue(directoryNode.contains(minaRdn));
    Dn newParent = new Dn("dc=apache,dc=org");
    minaNode.move(newParent);
    minaNode = apacheNode.getChild(minaRdn);
    assertNotNull(minaNode);
    assertNull(directoryNode.getChild(minaRdn));
    assertNotNull(apacheNode.getChild(minaRdn));
    assertFalse(directoryNode.contains(minaRdn));
    assertTrue(apacheNode.contains(minaRdn));
    assertEquals(new Dn("dc=mina,dc=apache,dc=org"), minaNode.getDn());
    assertEquals(new Dn("dc=vysper,dc=mina,dc=apache,dc=org"), minaNode.getChild(new Rdn("dc=vysper")).getDn());
}
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 4 with DnNode

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

the class TestDnNode method testGetElement.

// ---------------------------------------------------------------------------
// Test the getElement() method
// ---------------------------------------------------------------------------
@Test
public void testGetElement() throws Exception {
    DnNode<Dn> tree = new DnNode<Dn>();
    Dn dn = new Dn("dc=c,dc=b,dc=a");
    tree.add(dn, dn);
    assertNull(tree.getElement());
    DnNode<Dn> child = tree.getChild(new Rdn("dc=a"));
    assertNull(child.getElement());
    child = child.getChild(new Rdn("dc=b"));
    assertNull(child.getElement());
    child = child.getChild(new Rdn("dc=c"));
    assertEquals(dn, child.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 5 with DnNode

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

the class TestDnNode method testGetChildRdn.

// ---------------------------------------------------------------------------
// Test the getChild(Rdn) method
// ---------------------------------------------------------------------------
@Test
public void testGetChildRdn() throws Exception {
    DnNode<Dn> tree = new DnNode<Dn>();
    Dn dn = new Dn("dc=c,dc=b,dc=a");
    tree.add(dn, dn);
    Rdn rdnA = new Rdn("dc=a");
    Rdn rdnB = new Rdn("dc=b");
    Rdn rdnC = new Rdn("dc=c");
    DnNode<Dn> child = tree.getChild(rdnA);
    assertNotNull(child);
    assertEquals(rdnA, child.getRdn());
    child = child.getChild(rdnB);
    assertNotNull(child);
    assertEquals(rdnB, child.getRdn());
    child = child.getChild(rdnC);
    assertNotNull(child);
    assertEquals(rdnC, child.getRdn());
}
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)

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