You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2009/04/11 03:03:25 UTC
svn commit: r764131 [16/16] - in /directory: apacheds/trunk/
apacheds/trunk/core-avl/
apacheds/trunk/core-avl/src/main/java/org/apache/directory/server/core/avltree/
apacheds/trunk/core-avl/src/test/java/org/apache/directory/server/core/avltree/
apache...
Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/LdapUrlTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/LdapUrlTest.java?rev=764131&r1=764130&r2=764131&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/LdapUrlTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/LdapUrlTest.java Sat Apr 11 01:03:00 2009
@@ -26,13 +26,16 @@
import javax.naming.InvalidNameException;
import javax.naming.directory.SearchControls;
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
import org.apache.directory.shared.ldap.codec.util.LdapURLEncodingException;
import org.apache.directory.shared.ldap.name.LdapDN;
import org.apache.directory.shared.ldap.util.LdapURL.Extension;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertFalse;
/**
@@ -40,43 +43,37 @@
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-public class LdapUrlTest extends TestCase
+public class LdapUrlTest
{
// ~ Methods
// ------------------------------------------------------------------------------------
-
- /**
- * Setup the test
- */
- protected void setUp()
- {
- }
-
-
/**
* Test a null LdapURL
*/
+ @Test
public void testLdapUrlNull()
{
- Assert.assertEquals( "ldap:///", new LdapURL().toString() );
+ assertEquals( "ldap:///", new LdapURL().toString() );
}
/**
* test an empty LdapURL
*/
+ @Test
public void testLdapDNEmpty() throws LdapURLEncodingException
{
- Assert.assertEquals( "ldap:///", new LdapURL( "" ).toString() );
+ assertEquals( "ldap:///", new LdapURL( "" ).toString() );
}
/**
* test a simple LdapURL
*/
+ @Test
public void testLdapDNSimple() throws LdapURLEncodingException
{
- Assert.assertEquals( "ldap://directory.apache.org:80/", new LdapURL( "ldap://directory.apache.org:80/" )
+ assertEquals( "ldap://directory.apache.org:80/", new LdapURL( "ldap://directory.apache.org:80/" )
.toString() );
}
@@ -84,15 +81,17 @@
/**
* test a LdapURL host 1
*/
+ @Test
public void testLdapDNWithMinus() throws LdapURLEncodingException
{
- Assert.assertEquals( "ldap://d-a.org:80/", new LdapURL( "ldap://d-a.org:80/" ).toString() );
+ assertEquals( "ldap://d-a.org:80/", new LdapURL( "ldap://d-a.org:80/" ).toString() );
}
/**
* test a LdapURL with a bad port
*/
+ @Test
public void testLdapDNBadPort()
{
try
@@ -101,17 +100,18 @@
}
catch ( LdapURLEncodingException luee )
{
- Assert.assertTrue( true );
+ assertTrue( true );
return;
}
- Assert.fail();
+ fail();;
}
/**
* test a LdapURL with a bad port 2
*/
+ @Test
public void testLdapDNBadPort2()
{
try
@@ -120,17 +120,18 @@
}
catch ( LdapURLEncodingException luee )
{
- Assert.assertTrue( true );
+ assertTrue( true );
return;
}
- Assert.fail();
+ fail();;
}
/**
* test a LdapURL with a bad port 3
*/
+ @Test
public void testLdapDNBadPort3()
{
try
@@ -139,17 +140,18 @@
}
catch ( LdapURLEncodingException luee )
{
- Assert.assertTrue( true );
+ assertTrue( true );
return;
}
- Assert.fail();
+ fail();;
}
/**
* test a LdapURL with a bad port 4
*/
+ @Test
public void testLdapDNBadPort4()
{
try
@@ -158,26 +160,28 @@
}
catch ( LdapURLEncodingException luee )
{
- Assert.assertTrue( true );
+ assertTrue( true );
return;
}
- Assert.fail();
+ fail();;
}
/**
* test a LdapURL with no host
*/
+ @Test
public void testLdapDNBadHost1() throws LdapURLEncodingException
{
- Assert.assertEquals( "ldap:///", new LdapURL( "ldap:///" ).toString() );
+ assertEquals( "ldap:///", new LdapURL( "ldap:///" ).toString() );
}
/**
* test a LdapURL with a bad host 2
*/
+ @Test
public void testLdapDNBadHost2()
{
try
@@ -186,17 +190,18 @@
}
catch ( LdapURLEncodingException luee )
{
- Assert.assertTrue( true );
+ assertTrue( true );
return;
}
- Assert.fail();
+ fail();;
}
/**
* test a LdapURL with a bad host 3
*/
+ @Test
public void testLdapDNBadHost3()
{
try
@@ -205,17 +210,18 @@
}
catch ( LdapURLEncodingException luee )
{
- Assert.assertTrue( true );
+ assertTrue( true );
return;
}
- Assert.fail();
+ fail();;
}
/**
* test a LdapURL with a bad host 4
*/
+ @Test
public void testLdapDNBadHost4()
{
try
@@ -224,17 +230,18 @@
}
catch ( LdapURLEncodingException luee )
{
- Assert.assertTrue( true );
+ assertTrue( true );
return;
}
- Assert.fail();
+ fail();;
}
/**
* test a LdapURL with a bad host 5
*/
+ @Test
public void testLdapDNBadHost5()
{
try
@@ -243,17 +250,18 @@
}
catch ( LdapURLEncodingException luee )
{
- Assert.assertTrue( true );
+ assertTrue( true );
return;
}
- Assert.fail();
+ fail();;
}
/**
* test a LdapURL with a bad host 6
*/
+ @Test
public void testLdapDNBadHost6()
{
try
@@ -262,17 +270,18 @@
}
catch ( LdapURLEncodingException luee )
{
- Assert.assertTrue( true );
+ assertTrue( true );
return;
}
- Assert.fail();
+ fail();;
}
/**
* test a LdapURL with a bad host 7
*/
+ @Test
public void testLdapDNBadHost7()
{
try
@@ -281,35 +290,38 @@
}
catch ( LdapURLEncodingException luee )
{
- Assert.assertTrue( true );
+ assertTrue( true );
return;
}
- Assert.fail();
+ fail();;
}
/**
* test a LdapURL IP host
*/
+ @Test
public void testLdapDNIPHost() throws LdapURLEncodingException
{
- Assert.assertEquals( "ldap://1.2.3.4/", new LdapURL( "ldap://1.2.3.4/" ).toString() );
+ assertEquals( "ldap://1.2.3.4/", new LdapURL( "ldap://1.2.3.4/" ).toString() );
}
/**
* test a LdapURL IP host and port
*/
+ @Test
public void testLdapDNIPHostPort() throws LdapURLEncodingException
{
- Assert.assertEquals( "ldap://1.2.3.4:80/", new LdapURL( "ldap://1.2.3.4:80/" ).toString() );
+ assertEquals( "ldap://1.2.3.4:80/", new LdapURL( "ldap://1.2.3.4:80/" ).toString() );
}
/**
* test a LdapURL with a bad IP host 1
*/
+ @Test
public void testLdapDNBadHostIP1()
{
try
@@ -318,17 +330,18 @@
}
catch ( LdapURLEncodingException luee )
{
- Assert.assertTrue( true );
+ assertTrue( true );
return;
}
- Assert.fail();
+ fail();;
}
/**
* test a LdapURL with a bad IP host 2
*/
+ @Test
public void testLdapDNBadHostIP2()
{
try
@@ -337,17 +350,18 @@
}
catch ( LdapURLEncodingException luee )
{
- Assert.assertTrue( true );
+ assertTrue( true );
return;
}
- Assert.fail();
+ fail();;
}
/**
* test a LdapURL with a bad IP host 3
*/
+ @Test
public void testLdapDNBadHostIP3()
{
try
@@ -356,17 +370,18 @@
}
catch ( LdapURLEncodingException luee )
{
- Assert.assertTrue( true );
+ assertTrue( true );
return;
}
- Assert.fail();
+ fail();;
}
/**
* test a LdapURL with a bad IP host 4
*/
+ @Test
public void testLdapDNBadHostIP4()
{
try
@@ -375,29 +390,31 @@
}
catch ( LdapURLEncodingException luee )
{
- Assert.assertTrue( true );
+ assertTrue( true );
return;
}
- Assert.fail();
+ fail();;
}
/**
* test a LdapURL with a valid host hich is not an IP
*/
+ @Test
public void testLdapDNNotAnIP() throws LdapURLEncodingException
{
- Assert.assertEquals( "ldap://1.1.1.100000.a/", new LdapURL( "ldap://1.1.1.100000.a/" ).toString() );
+ assertEquals( "ldap://1.1.1.100000.a/", new LdapURL( "ldap://1.1.1.100000.a/" ).toString() );
}
/**
* test a LdapURL with valid simpleDN
*/
+ @Test
public void testLdapDNSimpleDN() throws LdapURLEncodingException
{
- Assert.assertEquals( "ldap://directory.apache.org:389/dc=example,dc=org/", new LdapURL(
+ assertEquals( "ldap://directory.apache.org:389/dc=example,dc=org/", new LdapURL(
"ldap://directory.apache.org:389/dc=example,dc=org/" ).toString() );
}
@@ -405,9 +422,10 @@
/**
* test a LdapURL with valid simpleDN 2
*/
+ @Test
public void testLdapDNSimpleDN2() throws LdapURLEncodingException
{
- Assert.assertEquals( "ldap://directory.apache.org:389/dc=example", new LdapURL(
+ assertEquals( "ldap://directory.apache.org:389/dc=example", new LdapURL(
"ldap://directory.apache.org:389/dc=example" ).toString() );
}
@@ -415,9 +433,10 @@
/**
* test a LdapURL with a valid encoded DN
*/
+ @Test
public void testLdapDNSimpleDNEncoded() throws LdapURLEncodingException
{
- Assert.assertEquals( "ldap://directory.apache.org:389/dc=example%202,dc=org", new LdapURL(
+ assertEquals( "ldap://directory.apache.org:389/dc=example%202,dc=org", new LdapURL(
"ldap://directory.apache.org:389/dc=example%202,dc=org" ).toString() );
}
@@ -425,6 +444,7 @@
/**
* test a LdapURL with an invalid DN
*/
+ @Test
public void testLdapDNInvalidDN()
{
try
@@ -433,7 +453,7 @@
}
catch ( LdapURLEncodingException luee )
{
- Assert.assertTrue( true );
+ assertTrue( true );
return;
}
}
@@ -442,6 +462,7 @@
/**
* test a LdapURL with an invalid DN 2
*/
+ @Test
public void testLdapDNInvalidDN2()
{
try
@@ -450,7 +471,7 @@
}
catch ( LdapURLEncodingException luee )
{
- Assert.assertTrue( true );
+ assertTrue( true );
return;
}
}
@@ -459,9 +480,10 @@
/**
* test a LdapURL with valid unique attributes
*/
+ @Test
public void testLdapDNUniqueAttribute() throws LdapURLEncodingException
{
- Assert.assertEquals( "ldap://directory.apache.org:389/dc=example,dc=org?ou", new LdapURL(
+ assertEquals( "ldap://directory.apache.org:389/dc=example,dc=org?ou", new LdapURL(
"ldap://directory.apache.org:389/dc=example,dc=org?ou" ).toString() );
}
@@ -469,9 +491,10 @@
/**
* test a LdapURL with valid attributes
*/
+ @Test
public void testLdapDNAttributes() throws LdapURLEncodingException
{
- Assert.assertEquals( "ldap://directory.apache.org:389/dc=example,dc=org?ou,objectclass,dc", new LdapURL(
+ assertEquals( "ldap://directory.apache.org:389/dc=example,dc=org?ou,objectclass,dc", new LdapURL(
"ldap://directory.apache.org:389/dc=example,dc=org?ou,objectclass,dc" ).toString() );
}
@@ -479,9 +502,10 @@
/**
* test a LdapURL with valid duplicated attributes
*/
+ @Test
public void testLdapDNDuplicatedAttributes() throws LdapURLEncodingException
{
- Assert.assertEquals( "ldap://directory.apache.org:389/dc=example,dc=org?ou,dc", new LdapURL(
+ assertEquals( "ldap://directory.apache.org:389/dc=example,dc=org?ou,dc", new LdapURL(
"ldap://directory.apache.org:389/dc=example,dc=org?ou,dc,ou" ).toString() );
}
@@ -489,6 +513,7 @@
/**
* test a LdapURL with invalid attributes
*/
+ @Test
public void testLdapInvalideAttributes()
{
try
@@ -497,7 +522,7 @@
}
catch ( LdapURLEncodingException luee )
{
- Assert.assertTrue( true );
+ assertTrue( true );
return;
}
}
@@ -506,6 +531,7 @@
/**
* test a LdapURL with attributes but no DN
*/
+ @Test
public void testLdapNoDNAttributes()
{
try
@@ -514,7 +540,7 @@
}
catch ( LdapURLEncodingException luee )
{
- Assert.assertTrue( true );
+ assertTrue( true );
return;
}
}
@@ -523,9 +549,10 @@
/**
* test 1 from RFC 2255 LdapURL
*/
+ @Test
public void testLdapRFC2255_1() throws LdapURLEncodingException
{
- Assert.assertEquals( "ldap:///o=University%20of%20Michigan,c=US", new LdapURL(
+ assertEquals( "ldap:///o=University%20of%20Michigan,c=US", new LdapURL(
"ldap:///o=University%20of%20Michigan,c=US" ).toString() );
}
@@ -533,9 +560,10 @@
/**
* test 2 from RFC 2255 LdapURL
*/
+ @Test
public void testLdapRFC2255_2() throws LdapURLEncodingException
{
- Assert.assertEquals( "ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US", new LdapURL(
+ assertEquals( "ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US", new LdapURL(
"ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US" ).toString() );
}
@@ -543,9 +571,10 @@
/**
* test 3 from RFC 2255 LdapURL
*/
+ @Test
public void testLdapRFC2255_3() throws LdapURLEncodingException
{
- Assert.assertEquals( "ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US?postalAddress", new LdapURL(
+ assertEquals( "ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US?postalAddress", new LdapURL(
"ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US?postalAddress" ).toString() );
}
@@ -553,9 +582,10 @@
/**
* test 4 from RFC 2255 LdapURL
*/
+ @Test
public void testLdapRFC2255_4() throws LdapURLEncodingException
{
- Assert.assertEquals( "ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Babs%20Jensen)",
+ assertEquals( "ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Babs%20Jensen)",
new LdapURL( "ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Babs%20Jensen)" ).toString() );
}
@@ -563,9 +593,10 @@
/**
* test 5 from RFC 2255 LdapURL
*/
+ @Test
public void testLdapRFC2255_5() throws LdapURLEncodingException
{
- Assert.assertEquals( "ldap://ldap.itd.umich.edu/c=GB?objectClass?one", new LdapURL(
+ assertEquals( "ldap://ldap.itd.umich.edu/c=GB?objectClass?one", new LdapURL(
"ldap://ldap.itd.umich.edu/c=GB?objectClass?one" ).toString() );
}
@@ -573,9 +604,10 @@
/**
* test 6 from RFC 2255 LdapURL
*/
+ @Test
public void testLdapRFC2255_6() throws LdapURLEncodingException
{
- Assert.assertEquals( "ldap://ldap.question.com/o=Question%3f,c=US?mail", new LdapURL(
+ assertEquals( "ldap://ldap.question.com/o=Question%3f,c=US?mail", new LdapURL(
"ldap://ldap.question.com/o=Question%3f,c=US?mail" ).toString() );
}
@@ -583,9 +615,10 @@
/**
* test 7 from RFC 2255 LdapURL
*/
+ @Test
public void testLdapRFC2255_7() throws LdapURLEncodingException
{
- Assert.assertEquals( "ldap://ldap.netscape.com/o=Babsco,c=US???(int=%5c00%5c00%5c00%5c04)", new LdapURL(
+ assertEquals( "ldap://ldap.netscape.com/o=Babsco,c=US???(int=%5c00%5c00%5c00%5c04)", new LdapURL(
"ldap://ldap.netscape.com/o=Babsco,c=US???(int=%5c00%5c00%5c00%5c04)" ).toString() );
}
@@ -593,9 +626,10 @@
/**
* test 8 from RFC 2255 LdapURL
*/
+ @Test
public void testLdapRFC2255_8() throws LdapURLEncodingException
{
- Assert.assertEquals( "ldap:///??sub??bindname=cn=Manager%2co=Foo", new LdapURL(
+ assertEquals( "ldap:///??sub??bindname=cn=Manager%2co=Foo", new LdapURL(
"ldap:///??sub??bindname=cn=Manager%2co=Foo" ).toString() );
}
@@ -603,9 +637,10 @@
/**
* test 9 from RFC 2255 LdapURL
*/
+ @Test
public void testLdapRFC2255_9() throws LdapURLEncodingException
{
- Assert.assertEquals( "ldap:///??sub??!bindname=cn=Manager%2co=Foo", new LdapURL(
+ assertEquals( "ldap:///??sub??!bindname=cn=Manager%2co=Foo", new LdapURL(
"ldap:///??sub??!bindname=cn=Manager%2co=Foo" ).toString() );
}
@@ -613,18 +648,20 @@
/**
* test an empty ldaps:// LdapURL
*/
+ @Test
public void testLdapDNEmptyLdaps() throws LdapURLEncodingException
{
- Assert.assertEquals( "ldaps:///", new LdapURL( "ldaps:///" ).toString() );
+ assertEquals( "ldaps:///", new LdapURL( "ldaps:///" ).toString() );
}
/**
* test an simple ldaps:// LdapURL
*/
+ @Test
public void testLdapDNSimpleLdaps() throws LdapURLEncodingException
{
- Assert.assertEquals( "ldaps://directory.apache.org:80/", new LdapURL( "ldaps://directory.apache.org:80/" )
+ assertEquals( "ldaps://directory.apache.org:80/", new LdapURL( "ldaps://directory.apache.org:80/" )
.toString() );
}
@@ -632,160 +669,167 @@
/**
* test the setScheme() method
*/
+ @Test
public void testLdapDNSetScheme() throws LdapURLEncodingException
{
LdapURL url = new LdapURL();
- Assert.assertEquals( "ldap://", url.getScheme() );
+ assertEquals( "ldap://", url.getScheme() );
url.setScheme( "invalid" );
- Assert.assertEquals( "ldap://", url.getScheme() );
+ assertEquals( "ldap://", url.getScheme() );
url.setScheme( "ldap://" );
- Assert.assertEquals( "ldap://", url.getScheme() );
+ assertEquals( "ldap://", url.getScheme() );
url.setScheme( "ldaps://" );
- Assert.assertEquals( "ldaps://", url.getScheme() );
+ assertEquals( "ldaps://", url.getScheme() );
url.setScheme( null );
- Assert.assertEquals( "ldap://", url.getScheme() );
+ assertEquals( "ldap://", url.getScheme() );
}
/**
* test the setHost() method
*/
+ @Test
public void testLdapDNSetHost() throws LdapURLEncodingException
{
LdapURL url = new LdapURL();
- Assert.assertNull( url.getHost() );
+ assertNull( url.getHost() );
url.setHost( "ldap.apache.org" );
- Assert.assertEquals( "ldap.apache.org", url.getHost() );
- Assert.assertEquals( "ldap://ldap.apache.org/", url.toString() );
+ assertEquals( "ldap.apache.org", url.getHost() );
+ assertEquals( "ldap://ldap.apache.org/", url.toString() );
url.setHost( null );
- Assert.assertNull( url.getHost() );
- Assert.assertEquals( "ldap:///", url.toString() );
+ assertNull( url.getHost() );
+ assertEquals( "ldap:///", url.toString() );
}
/**
* test the setPort() method
*/
+ @Test
public void testLdapDNSetPort() throws LdapURLEncodingException
{
LdapURL url = new LdapURL();
- Assert.assertEquals( -1, url.getPort() );
+ assertEquals( -1, url.getPort() );
url.setPort( 389 );
- Assert.assertEquals( 389, url.getPort() );
- Assert.assertEquals( "ldap://:389/", url.toString() );
+ assertEquals( 389, url.getPort() );
+ assertEquals( "ldap://:389/", url.toString() );
url.setPort( 0 );
- Assert.assertEquals( -1, url.getPort() );
- Assert.assertEquals( "ldap:///", url.toString() );
+ assertEquals( -1, url.getPort() );
+ assertEquals( "ldap:///", url.toString() );
url.setPort( 65536 );
- Assert.assertEquals( -1, url.getPort() );
- Assert.assertEquals( "ldap:///", url.toString() );
+ assertEquals( -1, url.getPort() );
+ assertEquals( "ldap:///", url.toString() );
}
/**
* test the setDn() method
*/
+ @Test
public void testLdapDNSetDn() throws LdapURLEncodingException, InvalidNameException
{
LdapURL url = new LdapURL();
- Assert.assertNull( url.getDn() );
+ assertNull( url.getDn() );
LdapDN dn = new LdapDN( "dc=example,dc=com" );
url.setDn( dn );
- Assert.assertEquals( dn, url.getDn() );
- Assert.assertEquals( "ldap:///dc=example,dc=com", url.toString() );
+ assertEquals( dn, url.getDn() );
+ assertEquals( "ldap:///dc=example,dc=com", url.toString() );
url.setDn( null );
- Assert.assertNull( url.getDn() );
- Assert.assertEquals( "ldap:///", url.toString() );
+ assertNull( url.getDn() );
+ assertEquals( "ldap:///", url.toString() );
}
/**
* test the setAttributes() method
*/
+ @Test
public void testLdapDNSetAttributes() throws LdapURLEncodingException, InvalidNameException
{
LdapURL url = new LdapURL();
- Assert.assertNotNull( url.getAttributes() );
- Assert.assertTrue( url.getAttributes().isEmpty() );
+ assertNotNull( url.getAttributes() );
+ assertTrue( url.getAttributes().isEmpty() );
List<String> attributes = new ArrayList<String>();
url.setDn( new LdapDN( "dc=example,dc=com" ) );
url.setAttributes( null );
- Assert.assertNotNull( url.getAttributes() );
- Assert.assertTrue( url.getAttributes().isEmpty() );
- Assert.assertEquals( "ldap:///dc=example,dc=com", url.toString() );
+ assertNotNull( url.getAttributes() );
+ assertTrue( url.getAttributes().isEmpty() );
+ assertEquals( "ldap:///dc=example,dc=com", url.toString() );
attributes.add( "cn" );
url.setAttributes( attributes );
- Assert.assertNotNull( url.getAttributes() );
- Assert.assertEquals( 1, url.getAttributes().size() );
- Assert.assertEquals( "ldap:///dc=example,dc=com?cn", url.toString() );
+ assertNotNull( url.getAttributes() );
+ assertEquals( 1, url.getAttributes().size() );
+ assertEquals( "ldap:///dc=example,dc=com?cn", url.toString() );
attributes.add( "userPassword;binary" );
url.setAttributes( attributes );
- Assert.assertNotNull( url.getAttributes() );
- Assert.assertEquals( 2, url.getAttributes().size() );
- Assert.assertEquals( "ldap:///dc=example,dc=com?cn,userPassword;binary", url.toString() );
+ assertNotNull( url.getAttributes() );
+ assertEquals( 2, url.getAttributes().size() );
+ assertEquals( "ldap:///dc=example,dc=com?cn,userPassword;binary", url.toString() );
}
/**
* test the setScope() method
*/
+ @Test
public void testLdapDNSetScope() throws LdapURLEncodingException, InvalidNameException
{
LdapURL url = new LdapURL();
- Assert.assertEquals( SearchControls.OBJECT_SCOPE, url.getScope() );
+ assertEquals( SearchControls.OBJECT_SCOPE, url.getScope() );
url.setDn( new LdapDN( "dc=example,dc=com" ) );
url.setScope( SearchControls.ONELEVEL_SCOPE );
- Assert.assertEquals( SearchControls.ONELEVEL_SCOPE, url.getScope() );
- Assert.assertEquals( "ldap:///dc=example,dc=com??one", url.toString() );
+ assertEquals( SearchControls.ONELEVEL_SCOPE, url.getScope() );
+ assertEquals( "ldap:///dc=example,dc=com??one", url.toString() );
url.setScope( SearchControls.SUBTREE_SCOPE );
- Assert.assertEquals( SearchControls.SUBTREE_SCOPE, url.getScope() );
- Assert.assertEquals( "ldap:///dc=example,dc=com??sub", url.toString() );
+ assertEquals( SearchControls.SUBTREE_SCOPE, url.getScope() );
+ assertEquals( "ldap:///dc=example,dc=com??sub", url.toString() );
url.setScope( -1 );
- Assert.assertEquals( SearchControls.OBJECT_SCOPE, url.getScope() );
- Assert.assertEquals( "ldap:///dc=example,dc=com", url.toString() );
+ assertEquals( SearchControls.OBJECT_SCOPE, url.getScope() );
+ assertEquals( "ldap:///dc=example,dc=com", url.toString() );
}
/**
* test the setFilter() method
*/
+ @Test
public void testLdapDNSetFilter() throws LdapURLEncodingException, InvalidNameException
{
LdapURL url = new LdapURL();
- Assert.assertNull( url.getFilter() );
+ assertNull( url.getFilter() );
url.setDn( new LdapDN( "dc=example,dc=com" ) );
url.setFilter( "(objectClass=person)" );
- Assert.assertEquals( "(objectClass=person)", url.getFilter() );
- Assert.assertEquals( "ldap:///dc=example,dc=com???(objectClass=person)", url.toString() );
+ assertEquals( "(objectClass=person)", url.getFilter() );
+ assertEquals( "ldap:///dc=example,dc=com???(objectClass=person)", url.toString() );
url.setFilter( "(cn=Babs Jensen)" );
- Assert.assertEquals( "(cn=Babs Jensen)", url.getFilter() );
- Assert.assertEquals( "ldap:///dc=example,dc=com???(cn=Babs%20Jensen)", url.toString() );
+ assertEquals( "(cn=Babs Jensen)", url.getFilter() );
+ assertEquals( "ldap:///dc=example,dc=com???(cn=Babs%20Jensen)", url.toString() );
url.setFilter( null );
- Assert.assertNull( url.getFilter() );
- Assert.assertEquals( "ldap:///dc=example,dc=com", url.toString() );
+ assertNull( url.getFilter() );
+ assertEquals( "ldap:///dc=example,dc=com", url.toString() );
}
Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/NamespaceToolsTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/NamespaceToolsTest.java?rev=764131&r1=764130&r2=764131&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/NamespaceToolsTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/NamespaceToolsTest.java Sat Apr 11 01:03:00 2009
@@ -20,53 +20,60 @@
package org.apache.directory.shared.ldap.util;
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
import javax.naming.Name;
import javax.naming.NamingException;
import org.apache.directory.shared.ldap.name.LdapDN;
import org.apache.directory.shared.ldap.util.NamespaceTools;
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
/**
* Test the NameToolsTest class
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-public class NamespaceToolsTest extends TestCase
+public class NamespaceToolsTest
{
+ @Test
public void testNullRealm()
{
- Assert.assertEquals( "", NamespaceTools.inferLdapName( null ) );
+ assertEquals( "", NamespaceTools.inferLdapName( null ) );
}
+ @Test
public void testEmptyRealm()
{
- Assert.assertEquals( "", NamespaceTools.inferLdapName( "" ) );
+ assertEquals( "", NamespaceTools.inferLdapName( "" ) );
}
+ @Test
public void testSingleElemRealm()
{
- Assert.assertEquals( "dc=test", NamespaceTools.inferLdapName( "test" ) );
+ assertEquals( "dc=test", NamespaceTools.inferLdapName( "test" ) );
}
+ @Test
public void testTwoElemsRealm()
{
- Assert.assertEquals( "dc=test,dc=com", NamespaceTools.inferLdapName( "test.com" ) );
+ assertEquals( "dc=test,dc=com", NamespaceTools.inferLdapName( "test.com" ) );
}
+ @Test
public void testFullRealm()
{
- Assert.assertEquals( "dc=CS,dc=UCL,dc=AC,dc=UK", NamespaceTools.inferLdapName( "CS.UCL.AC.UK" ) );
+ assertEquals( "dc=CS,dc=UCL,dc=AC,dc=UK", NamespaceTools.inferLdapName( "CS.UCL.AC.UK" ) );
}
+ @Test
public void testHasCompositeComponents() throws NamingException
{
assertTrue( NamespaceTools.hasCompositeComponents( "givenName=Alex+sn=Karasulu" ) );
@@ -76,6 +83,7 @@
}
+ @Test
public void testGetCompositeComponents() throws NamingException
{
String[] args = NamespaceTools.getCompositeComponents( "givenName=Alex+sn=Karasulu" );
@@ -99,6 +107,7 @@
}
+ @Test
public void testGetRelativeName() throws NamingException
{
// test the basis case first with the root
Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/StringToolsTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/StringToolsTest.java?rev=764131&r1=764130&r2=764131&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/StringToolsTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/StringToolsTest.java Sat Apr 11 01:03:00 2009
@@ -29,9 +29,12 @@
import javax.naming.NamingException;
import org.apache.directory.shared.ldap.util.StringTools;
+import org.junit.Test;
-import junit.framework.Assert;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
/**
@@ -40,8 +43,9 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$
*/
-public class StringToolsTest extends TestCase
+public class StringToolsTest
{
+ @Test
public void testDecodeEscapedHex() throws Exception
{
assertEquals( "Ferry", StringTools.decodeEscapedHex( "\\46\\65\\72\\72\\79" ) );
@@ -50,6 +54,7 @@
assertEquals( "Ferry", StringTools.decodeEscapedHex( "Fe\\72ry" ) );
}
+ @Test
public void testDecodeHexString() throws Exception
{
// weird stuff - corner cases
@@ -62,6 +67,7 @@
}
+ @Test
public void testTrimConsecutiveToOne()
{
String input = null;
@@ -94,77 +100,86 @@
}
+ @Test
public void testOneByteChar()
{
char res = StringTools.bytesToChar( new byte[]
{ 0x30 } );
- Assert.assertEquals( '0', res );
+ assertEquals( '0', res );
}
+ @Test
public void testOneByteChar00()
{
char res = StringTools.bytesToChar( new byte[]
{ 0x00 } );
- Assert.assertEquals( 0x00, res );
+ assertEquals( 0x00, res );
}
+ @Test
public void testOneByteChar7F()
{
char res = StringTools.bytesToChar( new byte[]
{ 0x7F } );
- Assert.assertEquals( 0x7F, res );
+ assertEquals( 0x7F, res );
}
+ @Test
public void testTwoBytesChar()
{
char res = StringTools.bytesToChar( new byte[]
{ ( byte ) 0xCE, ( byte ) 0x91 } );
- Assert.assertEquals( 0x0391, res );
+ assertEquals( 0x0391, res );
}
+ @Test
public void testThreeBytesChar()
{
char res = StringTools.bytesToChar( new byte[]
{ ( byte ) 0xE2, ( byte ) 0x89, ( byte ) 0xA2 } );
- Assert.assertEquals( 0x2262, res );
+ assertEquals( 0x2262, res );
}
+ @Test
public void testcharToBytesOne()
{
- Assert.assertEquals( "0x00 ", StringTools.dumpBytes( StringTools.charToBytes( ( char ) 0x0000 ) ) );
- Assert.assertEquals( "0x61 ", StringTools.dumpBytes( StringTools.charToBytes( 'a' ) ) );
- Assert.assertEquals( "0x7F ", StringTools.dumpBytes( StringTools.charToBytes( ( char ) 0x007F ) ) );
+ assertEquals( "0x00 ", StringTools.dumpBytes( StringTools.charToBytes( ( char ) 0x0000 ) ) );
+ assertEquals( "0x61 ", StringTools.dumpBytes( StringTools.charToBytes( 'a' ) ) );
+ assertEquals( "0x7F ", StringTools.dumpBytes( StringTools.charToBytes( ( char ) 0x007F ) ) );
}
+ @Test
public void testcharToBytesTwo()
{
- Assert.assertEquals( "0xC2 0x80 ", StringTools.dumpBytes( StringTools.charToBytes( ( char ) 0x0080 ) ) );
- Assert.assertEquals( "0xC3 0xBF ", StringTools.dumpBytes( StringTools.charToBytes( ( char ) 0x00FF ) ) );
- Assert.assertEquals( "0xC4 0x80 ", StringTools.dumpBytes( StringTools.charToBytes( ( char ) 0x0100 ) ) );
- Assert.assertEquals( "0xDF 0xBF ", StringTools.dumpBytes( StringTools.charToBytes( ( char ) 0x07FF ) ) );
+ assertEquals( "0xC2 0x80 ", StringTools.dumpBytes( StringTools.charToBytes( ( char ) 0x0080 ) ) );
+ assertEquals( "0xC3 0xBF ", StringTools.dumpBytes( StringTools.charToBytes( ( char ) 0x00FF ) ) );
+ assertEquals( "0xC4 0x80 ", StringTools.dumpBytes( StringTools.charToBytes( ( char ) 0x0100 ) ) );
+ assertEquals( "0xDF 0xBF ", StringTools.dumpBytes( StringTools.charToBytes( ( char ) 0x07FF ) ) );
}
+ @Test
public void testcharToBytesThree()
{
- Assert.assertEquals( "0xE0 0xA0 0x80 ", StringTools.dumpBytes( StringTools.charToBytes( ( char ) 0x0800 ) ) );
- Assert.assertEquals( "0xE0 0xBF 0xBF ", StringTools.dumpBytes( StringTools.charToBytes( ( char ) 0x0FFF ) ) );
- Assert.assertEquals( "0xE1 0x80 0x80 ", StringTools.dumpBytes( StringTools.charToBytes( ( char ) 0x1000 ) ) );
- Assert.assertEquals( "0xEF 0xBF 0xBF ", StringTools.dumpBytes( StringTools.charToBytes( ( char ) 0xFFFF ) ) );
+ assertEquals( "0xE0 0xA0 0x80 ", StringTools.dumpBytes( StringTools.charToBytes( ( char ) 0x0800 ) ) );
+ assertEquals( "0xE0 0xBF 0xBF ", StringTools.dumpBytes( StringTools.charToBytes( ( char ) 0x0FFF ) ) );
+ assertEquals( "0xE1 0x80 0x80 ", StringTools.dumpBytes( StringTools.charToBytes( ( char ) 0x1000 ) ) );
+ assertEquals( "0xEF 0xBF 0xBF ", StringTools.dumpBytes( StringTools.charToBytes( ( char ) 0xFFFF ) ) );
}
+ @Test
public void testListToString()
{
List<String> list = new ArrayList<String>();
@@ -173,10 +188,11 @@
list.add( "elem2" );
list.add( "elem3" );
- Assert.assertEquals( "elem1, elem2, elem3", StringTools.listToString( list ) );
+ assertEquals( "elem1, elem2, elem3", StringTools.listToString( list ) );
}
+ @Test
public void testMapToString()
{
class Value
@@ -214,10 +230,11 @@
|| "elem3 = '[name3, 3]', elem1 = '[name1, 1]', elem2 = '[name2, 2]'".equals( result )
|| "elem3 = '[name3, 3]', elem2 = '[name2, 2]', elem1 = '[name1, 1]'".equals( result );
- Assert.assertTrue( res );
+ assertTrue( res );
}
+ @Test
public void testGetRegexpEmpty() throws Exception
{
Pattern pattern = StringTools.getRegex( "", new String[]
@@ -229,6 +246,7 @@
}
+ @Test
public void testGetRegexpInitial() throws Exception
{
Pattern pattern = StringTools.getRegex( "Test", new String[]
@@ -244,6 +262,7 @@
}
+ @Test
public void testGetRegexpFinal() throws Exception
{
Pattern pattern = StringTools.getRegex( "", new String[]
@@ -259,6 +278,7 @@
}
+ @Test
public void testGetRegexpAny() throws Exception
{
Pattern pattern = StringTools.getRegex( "", new String[]
@@ -274,6 +294,7 @@
}
+ @Test
public void testGetRegexpFull() throws Exception
{
Pattern pattern = StringTools.getRegex( "Test", new String[]
@@ -292,6 +313,7 @@
/**
* Tests StringTools.getRegex() with some LDAP filter special characters.
*/
+ @Test
public void testGetRegexpWithLdapFilterSpecialChars() throws Exception
{
Pattern[] patterns = new Pattern[]
@@ -312,6 +334,7 @@
}
+ @Test
public void testDeepTrim()
{
assertEquals( "", StringTools.deepTrim( " ", false ) );
@@ -329,6 +352,7 @@
assertEquals( "a b", StringTools.deepTrim( "a b ", false ) );
}
+ @Test
public void testTrim()
{
assertEquals( "", StringTools.trim( (String)null ) );
@@ -340,6 +364,7 @@
assertEquals( "a", StringTools.trim( " a " ) );
}
+ @Test
public void testTrimLeft()
{
assertEquals( "", StringTools.trimLeft( (String)null ) );
@@ -351,6 +376,7 @@
assertEquals( "a ", StringTools.trimLeft( " a " ) );
}
+ @Test
public void testTrimRight()
{
assertEquals( "", StringTools.trimRight( (String)null ) );
Modified: directory/shared/trunk/pom.xml
URL: http://svn.apache.org/viewvc/directory/shared/trunk/pom.xml?rev=764131&r1=764130&r2=764131&view=diff
==============================================================================
--- directory/shared/trunk/pom.xml (original)
+++ directory/shared/trunk/pom.xml Sat Apr 11 01:03:00 2009
@@ -55,6 +55,8 @@
<module>ldap-constants</module>
<module>asn1-codec</module>
<module>convert</module>
+ <module>client-api</module>
+ <module>cursor</module>
</modules>
<dependencyManagement>