directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1778695 - /directory/apacheds/branches/apacheds-value/server-integ/src/test/java/org/apache/directory/server/operations/compare/CompareIT.java
Date Sat, 14 Jan 2017 01:25:38 GMT
Author: elecharny
Date: Sat Jan 14 01:25:37 2017
New Revision: 1778695

URL: http://svn.apache.org/viewvc?rev=1778695&view=rev
Log:
Used try-with-resources

Modified:
    directory/apacheds/branches/apacheds-value/server-integ/src/test/java/org/apache/directory/server/operations/compare/CompareIT.java

Modified: directory/apacheds/branches/apacheds-value/server-integ/src/test/java/org/apache/directory/server/operations/compare/CompareIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-value/server-integ/src/test/java/org/apache/directory/server/operations/compare/CompareIT.java?rev=1778695&r1=1778694&r2=1778695&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-value/server-integ/src/test/java/org/apache/directory/server/operations/compare/CompareIT.java
(original)
+++ directory/apacheds/branches/apacheds-value/server-integ/src/test/java/org/apache/directory/server/operations/compare/CompareIT.java
Sat Jan 14 01:25:37 2017
@@ -104,18 +104,18 @@ public class CompareIT extends AbstractL
     @Test
     public void testNormalCompare() throws Exception
     {
-        LdapConnection conn = getAdminConnection( getLdapServer() );
-
-        // comparison success
-        boolean response = conn.compare( "uid=akarasulu,ou=users,ou=system", "sn", "karasulu"
);
-        assertTrue( response );
-
-        // comparison failure
-        response = conn.compare( "uid=akarasulu,ou=users,ou=system", "sn", "lecharny" );
-        assertFalse( response );
-
-        conn.unBind();
-        conn.close();
+        try ( LdapConnection conn = getAdminConnection( getLdapServer() ) )
+        {
+            // comparison success
+            boolean response = conn.compare( "uid=akarasulu,ou=users,ou=system", "sn", "karasulu"
);
+            assertTrue( response );
+    
+            // comparison failure
+            response = conn.compare( "uid=akarasulu,ou=users,ou=system", "sn", "lecharny"
);
+            assertFalse( response );
+    
+            conn.unBind();
+        }
     }
 
 
@@ -127,23 +127,22 @@ public class CompareIT extends AbstractL
     @Test
     public void testNormalCompareMissingAttribute() throws Exception
     {
-        LdapConnection conn = getWiredConnection( getLdapServer() );
-
-        // comparison success
-        assertTrue( conn.compare( "uid=akarasulu,ou=users,ou=system", "sn", "karasulu" )
);
-
-        // non-existing attribute
-        try
-        {
-            conn.compare( "uid=akarasulu,ou=users,ou=system", "mail", "akarasulu@apache.org"
);
-            fail( "Should never get here" );
-        }
-        catch ( LdapOperationException e )
+        try ( LdapConnection conn = getWiredConnection( getLdapServer() ) )
         {
-            assertEquals( ResultCodeEnum.NO_SUCH_ATTRIBUTE, e.getResultCode() );
+            // comparison success
+            assertTrue( conn.compare( "uid=akarasulu,ou=users,ou=system", "sn", "karasulu"
) );
+    
+            // non-existing attribute
+            try
+            {
+                conn.compare( "uid=akarasulu,ou=users,ou=system", "mail", "akarasulu@apache.org"
);
+                fail( "Should never get here" );
+            }
+            catch ( LdapOperationException e )
+            {
+                assertEquals( ResultCodeEnum.NO_SUCH_ATTRIBUTE, e.getResultCode() );
+            }
         }
-
-        conn.close();
     }
 
 
@@ -153,24 +152,23 @@ public class CompareIT extends AbstractL
     @Test
     public void testOnReferralWithManageDsaITControl() throws Exception
     {
-        LdapConnection conn = getWiredConnection( getLdapServer() );
-
-        // comparison success
-        assertTrue( conn.compare( "uid=akarasuluref,ou=users,ou=system", "uid", "akarasuluref"
) );
-
-        // comparison failure
-        CompareRequest compareRequest = new CompareRequestImpl();
-        compareRequest.setName( new Dn( "uid=akarasuluref,ou=users,ou=system" ) );
-        compareRequest.setAttributeId( "uid" );
-        compareRequest.setAssertionValue( "elecharny" );
-        ManageDsaIT manageDSAIT = new ManageDsaITImpl();
-        manageDSAIT.setCritical( true );
-        compareRequest.addControl( manageDSAIT );
-
-        CompareResponse compareResponse = conn.compare( compareRequest );
-        assertEquals( ResultCodeEnum.COMPARE_FALSE, compareResponse.getLdapResult().getResultCode()
);
-
-        conn.close();
+        try ( LdapConnection conn = getWiredConnection( getLdapServer() ) )
+        {
+            // comparison success
+            assertTrue( conn.compare( "uid=akarasuluref,ou=users,ou=system", "uid", "akarasuluref"
) );
+    
+            // comparison failure
+            CompareRequest compareRequest = new CompareRequestImpl();
+            compareRequest.setName( new Dn( "uid=akarasuluref,ou=users,ou=system" ) );
+            compareRequest.setAttributeId( "uid" );
+            compareRequest.setAssertionValue( "elecharny" );
+            ManageDsaIT manageDSAIT = new ManageDsaITImpl();
+            manageDSAIT.setCritical( true );
+            compareRequest.addControl( manageDSAIT );
+    
+            CompareResponse compareResponse = conn.compare( compareRequest );
+            assertEquals( ResultCodeEnum.COMPARE_FALSE, compareResponse.getLdapResult().getResultCode()
);
+        }
     }
 
 
@@ -182,37 +180,36 @@ public class CompareIT extends AbstractL
     @Test
     public void testOnReferral() throws Exception
     {
-        LdapConnection conn = getWiredConnection( getLdapServer() );
-
-        // comparison success
-        CompareRequest compareRequest = new CompareRequestImpl();
-        compareRequest.setName( new Dn( "uid=akarasulu,ou=users,ou=system" ) );
-        compareRequest.setAttributeId( "uid" );
-        compareRequest.setAssertionValue( "akarasulu" );
-        ManageDsaIT manageDSAIT = new ManageDsaITImpl();
-        manageDSAIT.setCritical( false );
-        compareRequest.addControl( manageDSAIT );
-
-        CompareResponse compareResponse = conn.compare( compareRequest );
-        assertEquals( ResultCodeEnum.COMPARE_TRUE, compareResponse.getLdapResult().getResultCode()
);
-
-        // referrals failure
-        compareRequest = new CompareRequestImpl();
-        compareRequest.setName( new Dn( "uid=akarasuluREF,ou=users,ou=system" ) );
-        compareRequest.setAttributeId( "uid" );
-        compareRequest.setAssertionValue( "akarasulu" );
-
-        compareResponse = conn.compare( compareRequest );
-        assertEquals( ResultCodeEnum.REFERRAL, compareResponse.getLdapResult().getResultCode()
);
-
-        assertTrue( compareResponse.getLdapResult().getReferral().getLdapUrls()
-            .contains( "ldap://localhost:10389/uid=akarasulu,ou=users,ou=system" ) );
-        assertTrue( compareResponse.getLdapResult().getReferral().getLdapUrls()
-            .contains( "ldap://foo:10389/uid=akarasulu,ou=users,ou=system" ) );
-        assertTrue( compareResponse.getLdapResult().getReferral().getLdapUrls()
-            .contains( "ldap://bar:10389/uid=akarasulu,ou=users,ou=system" ) );
-
-        conn.close();
+        try ( LdapConnection conn = getWiredConnection( getLdapServer() ) )
+        {
+            // comparison success
+            CompareRequest compareRequest = new CompareRequestImpl();
+            compareRequest.setName( new Dn( "uid=akarasulu,ou=users,ou=system" ) );
+            compareRequest.setAttributeId( "uid" );
+            compareRequest.setAssertionValue( "akarasulu" );
+            ManageDsaIT manageDSAIT = new ManageDsaITImpl();
+            manageDSAIT.setCritical( false );
+            compareRequest.addControl( manageDSAIT );
+    
+            CompareResponse compareResponse = conn.compare( compareRequest );
+            assertEquals( ResultCodeEnum.COMPARE_TRUE, compareResponse.getLdapResult().getResultCode()
);
+    
+            // referrals failure
+            compareRequest = new CompareRequestImpl();
+            compareRequest.setName( new Dn( "uid=akarasuluREF,ou=users,ou=system" ) );
+            compareRequest.setAttributeId( "uid" );
+            compareRequest.setAssertionValue( "akarasulu" );
+    
+            compareResponse = conn.compare( compareRequest );
+            assertEquals( ResultCodeEnum.REFERRAL, compareResponse.getLdapResult().getResultCode()
);
+    
+            assertTrue( compareResponse.getLdapResult().getReferral().getLdapUrls()
+                .contains( "ldap://localhost:10389/uid=akarasulu,ou=users,ou=system" ) );
+            assertTrue( compareResponse.getLdapResult().getReferral().getLdapUrls()
+                .contains( "ldap://foo:10389/uid=akarasulu,ou=users,ou=system" ) );
+            assertTrue( compareResponse.getLdapResult().getReferral().getLdapUrls()
+                .contains( "ldap://bar:10389/uid=akarasulu,ou=users,ou=system" ) );
+        }
     }
 
 
@@ -281,24 +278,23 @@ public class CompareIT extends AbstractL
     {
         LOG.debug( "" );
 
-        LdapConnection conn = getWiredConnection( getLdapServer() );
-
-        // referrals failure
-        CompareRequest compareRequest = new CompareRequestImpl();
-        compareRequest.setName( new Dn( "ou=Computers,uid=akarasuluref,ou=users,ou=system"
) );
-        compareRequest.setAttributeId( "ou" );
-        compareRequest.setAssertionValue( "Computers" );
-
-        CompareResponse compareResponse = conn.compare( compareRequest );
-        assertEquals( ResultCodeEnum.REFERRAL, compareResponse.getLdapResult().getResultCode()
);
-
-        assertTrue( compareResponse.getLdapResult().getReferral().getLdapUrls()
-            .contains( "ldap://localhost:10389/ou=Computers,uid=akarasulu,ou=users,ou=system"
) );
-        assertTrue( compareResponse.getLdapResult().getReferral().getLdapUrls()
-            .contains( "ldap://foo:10389/ou=Computers,uid=akarasulu,ou=users,ou=system" )
);
-        assertTrue( compareResponse.getLdapResult().getReferral().getLdapUrls()
-            .contains( "ldap://bar:10389/ou=Computers,uid=akarasulu,ou=users,ou=system" )
);
-
-        conn.close();
+        try ( LdapConnection conn = getWiredConnection( getLdapServer() ) )
+        {
+            // referrals failure
+            CompareRequest compareRequest = new CompareRequestImpl();
+            compareRequest.setName( new Dn( "ou=Computers,uid=akarasuluref,ou=users,ou=system"
) );
+            compareRequest.setAttributeId( "ou" );
+            compareRequest.setAssertionValue( "Computers" );
+    
+            CompareResponse compareResponse = conn.compare( compareRequest );
+            assertEquals( ResultCodeEnum.REFERRAL, compareResponse.getLdapResult().getResultCode()
);
+    
+            assertTrue( compareResponse.getLdapResult().getReferral().getLdapUrls()
+                .contains( "ldap://localhost:10389/ou=Computers,uid=akarasulu,ou=users,ou=system"
) );
+            assertTrue( compareResponse.getLdapResult().getReferral().getLdapUrls()
+                .contains( "ldap://foo:10389/ou=Computers,uid=akarasulu,ou=users,ou=system"
) );
+            assertTrue( compareResponse.getLdapResult().getReferral().getLdapUrls()
+                .contains( "ldap://bar:10389/ou=Computers,uid=akarasulu,ou=users,ou=system"
) );
+        }
     }
 }



Mime
View raw message