directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r936490 - in /directory/shared/trunk/ldap/src: main/java/org/apache/directory/shared/ldap/name/DN.java test/java/org/apache/directory/shared/ldap/name/DNTest.java
Date Wed, 21 Apr 2010 20:37:55 GMT
Author: seelmann
Date: Wed Apr 21 20:37:54 2010
New Revision: 936490

URL: http://svn.apache.org/viewvc?rev=936490&view=rev
Log:
added DN.getParent() method

Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/DNTest.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java?rev=936490&r1=936489&r2=936490&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java
Wed Apr 21 20:37:54 2010
@@ -1265,6 +1265,24 @@ public class DN implements Cloneable, Se
 
 
     /**
+     * Gets the parent DN of this DN. Null if this DN doesn't have a parent, i.e. because
it
+     * is the empty DN.
+     *
+     * @return the parent DN of this DN
+     * @throws LdapInvalidDnException
+     */
+    public DN getParent() throws LdapInvalidDnException
+    {
+        if ( isEmpty() )
+        {
+            return null;
+        }
+
+        return getPrefix( size() - 1 );
+    }
+
+
+    /**
      * {@inheritDoc}
      */
     public Object clone()

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/DNTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/DNTest.java?rev=936490&r1=936489&r2=936490&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/DNTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/DNTest.java
Wed Apr 21 20:37:54 2010
@@ -20,6 +20,8 @@
 package org.apache.directory.shared.ldap.name;
 
 
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertNull;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertSame;
@@ -2358,6 +2360,41 @@ public class DNTest
 
 
     /**
+     * Tests getParent().
+     */
+    @Test
+    public void testGetParent() throws Exception
+    {
+        DN empty = new DN();
+        assertNull( empty.getParent() );
+
+        DN one = new DN( "cn=test" );
+        assertNotNull( one.getParent() );
+        assertTrue( one.getParent().isEmpty() );
+
+        DN two = new DN( "cn=test,o=acme" );
+        assertNotNull( two.getParent() );
+        assertFalse( two.getParent().isEmpty() );
+        assertEquals( "o=acme", two.getParent().getName() );
+
+        DN three = new DN( "cn=test,dc=example,dc=com" );
+        three.normalize( oids );
+        DN threeParent = three.getParent();
+        assertNotNull( threeParent );
+        assertFalse( threeParent.isEmpty() );
+        assertEquals( "dc=example,dc=com", threeParent.getName() );
+        assertEquals( 2, threeParent.getRdns().size() );
+
+        DN five = new DN( "uid=user1,ou=sales,ou=users,dc=example,dc=com" );
+        DN fiveParent = five.getParent();
+        assertNotNull( fiveParent );
+        assertFalse( fiveParent.isEmpty() );
+        assertEquals( "ou=sales,ou=users,dc=example,dc=com", fiveParent.getName() );
+        assertEquals( 4, fiveParent.getRdns().size() );
+    }
+
+
+    /**
      * Class to test for boolean equals(Object)
      *
      * @throws Exception



Mime
View raw message