*/
@Test
public void testComplexTreeDeletion() throws LdapException
{
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" );
dnLookupTree.add( dn1, dn1 );
dnLookupTree.add( dn2, dn2 );
dnLookupTree.add( dn3, dn3 );
dnLookupTree.add( dn4, dn4 );
dnLookupTree.add( dn5, dn5 );
dnLookupTree.add( dn6, dn6 );
assertEquals( 11, dnLookupTree.size() );
dnLookupTree.remove( dn3 );
assertEquals( 10, dnLookupTree.size() );
assertTrue( dnLookupTree.hasParent( dn1 ) );
assertTrue( dnLookupTree.hasParent( dn2 ) );
assertTrue( dnLookupTree.hasParent( dn4 ) );
assertTrue( dnLookupTree.hasParent( dn5 ) );
assertTrue( dnLookupTree.hasParent( dn6 ) );
assertTrue( dnLookupTree.hasParent( new Dn( "dc=nothing,dc=empty" ) ) );
assertFalse( dnLookupTree.hasParent( new Dn( "dc=directory,dc=apache,dc=root" ) ) );
dnLookupTree.remove( dn6 );
assertEquals( 9, dnLookupTree.size() );
assertTrue( dnLookupTree.hasParent( dn1 ) );
assertTrue( dnLookupTree.hasParent( dn2 ) );
assertTrue( dnLookupTree.hasParent( dn4 ) );
assertTrue( dnLookupTree.hasParent( dn5 ) );
assertFalse( dnLookupTree.hasParent( new Dn( "dc=nothing,dc=empty" ) ) );
assertFalse( dnLookupTree.hasParent( new Dn( "dc=directory,dc=apache,dc=root" ) ) );
dnLookupTree.remove( dn1 );
assertEquals( 8, dnLookupTree.size() );
assertTrue( dnLookupTree.hasParent( dn2 ) );
assertTrue( dnLookupTree.hasParent( dn4 ) );
assertTrue( dnLookupTree.hasParent( dn5 ) );
assertFalse( dnLookupTree.hasParent( new Dn( "dc=nothing,dc=empty" ) ) );
assertFalse( dnLookupTree.hasParent( new Dn( "dc=directory,dc=apache,dc=root" ) ) );
// Should not change anything
dnLookupTree.remove( dn3 );
assertEquals( 8, dnLookupTree.size() );
assertTrue( dnLookupTree.hasParent( dn2 ) );
assertTrue( dnLookupTree.hasParent( dn4 ) );
assertTrue( dnLookupTree.hasParent( dn5 ) );
assertFalse( dnLookupTree.hasParent( new Dn( "dc=nothing,dc=empty" ) ) );
assertFalse( dnLookupTree.hasParent( new Dn( "dc=directory,dc=apache,dc=root" ) ) );
dnLookupTree.remove( dn5 );
assertEquals( 6, dnLookupTree.size() );
assertTrue( dnLookupTree.hasParent( dn2 ) );
assertTrue( dnLookupTree.hasParent( dn4 ) );
assertFalse( dnLookupTree.hasParent( new Dn( "dc=nothing,dc=empty" ) ) );
assertFalse( dnLookupTree.hasParent( new Dn( "dc=directory,dc=apache,dc=root" ) ) );
dnLookupTree.remove( dn2 );
assertEquals( 3, dnLookupTree.size() );
assertTrue( dnLookupTree.hasParent( dn4 ) );
assertFalse( dnLookupTree.hasParent( new Dn( "dc=nothing,dc=empty" ) ) );
assertFalse( dnLookupTree.hasParent( new Dn( "dc=directory,dc=apache,dc=root" ) ) );
dnLookupTree.remove( dn4 );
assertEquals( 1, dnLookupTree.size() );
assertFalse( dnLookupTree.hasParent( new Dn( "dc=nothing,dc=empty" ) ) );
assertFalse( dnLookupTree.hasParent( new Dn( "dc=directory,dc=apache,dc=root" ) ) );
}