use of org.apache.directory.api.ldap.model.name.Dn 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());
}
use of org.apache.directory.api.ldap.model.name.Dn 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());
}
use of org.apache.directory.api.ldap.model.name.Dn 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());
}
use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.
the class DefaultEntry method readExternal.
/**
* {@inheritDoc}
*/
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
// Read the Dn
dn = new Dn(schemaManager);
dn.readExternal(in);
// Read the number of attributes
int nbAttributes = in.readInt();
// Read the attributes
for (int i = 0; i < nbAttributes; i++) {
// Read each attribute
Attribute attribute = new DefaultAttribute();
attribute.readExternal(in);
if (schemaManager != null) {
try {
AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry(attribute.getId());
attribute.apply(attributeType);
attributes.put(attributeType.getOid(), attribute);
} catch (LdapException le) {
String message = le.getLocalizedMessage();
LOG.error(message);
throw new IOException(message, le);
}
} else {
attributes.put(attribute.getId(), attribute);
}
}
}
use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.
the class TestDnNode method testHasChildrenDN.
// ---------------------------------------------------------------------------
// Test the hasChildren(Dn) method
// ---------------------------------------------------------------------------
@Test
public void testHasChildrenDN() throws Exception {
DnNode<Dn> tree = new DnNode<Dn>();
Dn dn1 = new Dn("dc=b,dc=a");
tree.add(dn1);
assertTrue(tree.hasChildren(new Dn("dc=a")));
assertFalse(tree.hasChildren(dn1));
}
Aggregations