ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1329668 - in /ace/trunk: ace-authentication/ ace-authentication/src/main/java/org/apache/ace/authentication/impl/ ace-authentication/src/test/java/org/apache/ace/authentication/impl/ ace-authenticationprocessor-basicauth/ ace-authenticatio...
Date Tue, 24 Apr 2012 12:23:48 GMT
Author: jawi
Date: Tue Apr 24 12:23:47 2012
New Revision: 1329668

URL: http://svn.apache.org/viewvc?rev=1329668&view=rev
Log:
ACE-255: refactored unit tests to use TestNG instead of JUnit and made the authentication integration tests (yet) more robust.

Added:
    ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/authentication/AuthenticationTestBase.java   (with props)
Modified:
    ace/trunk/ace-authentication/pom.xml
    ace/trunk/ace-authentication/src/main/java/org/apache/ace/authentication/impl/AuthenticationServiceImpl.java
    ace/trunk/ace-authentication/src/test/java/org/apache/ace/authentication/impl/AuthenticationServiceImplTest.java
    ace/trunk/ace-authenticationprocessor-basicauth/pom.xml
    ace/trunk/ace-authenticationprocessor-basicauth/src/test/java/org/apache/ace/authenticationprocessor/basicauth/BasicHttpAuthenticationProcessorTest.java
    ace/trunk/ace-authenticationprocessor-clientcert/pom.xml
    ace/trunk/ace-authenticationprocessor-clientcert/src/test/java/org/apache/ace/authenticationprocessor/clientcert/ClientCertAuthenticationProcessorTest.java
    ace/trunk/ace-authenticationprocessor-password/pom.xml
    ace/trunk/ace-authenticationprocessor-password/src/test/java/org/apache/ace/authenticationprocessor/password/PasswordAuthenticationProcessorTest.java
    ace/trunk/ace-connectionfactory/pom.xml
    ace/trunk/ace-connectionfactory/src/main/java/org/apache/ace/connectionfactory/impl/ConnectionFactoryImpl.java
    ace/trunk/ace-connectionfactory/src/test/java/org/apache/ace/connectionfactory/impl/ConnectionFactoryImplTest.java
    ace/trunk/ace-connectionfactory/src/test/java/org/apache/ace/connectionfactory/impl/UrlCredentialsFactoryTest.java
    ace/trunk/ace-connectionfactory/src/test/java/org/apache/ace/connectionfactory/impl/UrlCredentialsTest.java
    ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/authentication/LogAuthenticationTest.java
    ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/authentication/ObrAuthenticationTest.java
    ace/trunk/pom/pom.xml

Modified: ace/trunk/ace-authentication/pom.xml
URL: http://svn.apache.org/viewvc/ace/trunk/ace-authentication/pom.xml?rev=1329668&r1=1329667&r2=1329668&view=diff
==============================================================================
--- ace/trunk/ace-authentication/pom.xml (original)
+++ ace/trunk/ace-authentication/pom.xml Tue Apr 24 12:23:47 2012
@@ -74,5 +74,10 @@
             <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.dependencymanager</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.ace</groupId>
+            <artifactId>org.apache.ace.util</artifactId>
+            <scope>test</scope>
+        </dependency>
      </dependencies>
 </project>

Modified: ace/trunk/ace-authentication/src/main/java/org/apache/ace/authentication/impl/AuthenticationServiceImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-authentication/src/main/java/org/apache/ace/authentication/impl/AuthenticationServiceImpl.java?rev=1329668&r1=1329667&r2=1329668&view=diff
==============================================================================
--- ace/trunk/ace-authentication/src/main/java/org/apache/ace/authentication/impl/AuthenticationServiceImpl.java (original)
+++ ace/trunk/ace-authentication/src/main/java/org/apache/ace/authentication/impl/AuthenticationServiceImpl.java Tue Apr 24 12:23:47 2012
@@ -128,8 +128,10 @@ public class AuthenticationServiceImpl i
         m_log.log(LogService.LOG_DEBUG, "Authenticating user for: " + context);
 
         final List<AuthenticationProcessor> processors = getProcessors(context);
-        for (AuthenticationProcessor processor : processors) {
-            result = processor.authenticate(m_userAdmin, context);
+        
+        int size = processors.size();
+        for (int i = 0; i < size; i++) {
+            result = processors.get(i).authenticate(m_userAdmin, context);
             if (result != null) {
                 m_log.log(LogService.LOG_DEBUG, "Authenticated user (" + context + ") as: " + result.getName());
                 break;

Modified: ace/trunk/ace-authentication/src/test/java/org/apache/ace/authentication/impl/AuthenticationServiceImplTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-authentication/src/test/java/org/apache/ace/authentication/impl/AuthenticationServiceImplTest.java?rev=1329668&r1=1329667&r2=1329668&view=diff
==============================================================================
--- ace/trunk/ace-authentication/src/test/java/org/apache/ace/authentication/impl/AuthenticationServiceImplTest.java (original)
+++ ace/trunk/ace-authentication/src/test/java/org/apache/ace/authentication/impl/AuthenticationServiceImplTest.java Tue Apr 24 12:23:47 2012
@@ -19,10 +19,7 @@
 
 package org.apache.ace.authentication.impl;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
+import static org.apache.ace.test.utils.TestUtils.UNIT;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyString;
 import static org.mockito.Matchers.eq;
@@ -33,8 +30,6 @@ import java.util.Date;
 import java.util.List;
 
 import org.apache.ace.authentication.api.AuthenticationProcessor;
-import org.junit.Before;
-import org.junit.Test;
 import org.mockito.Mockito;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
@@ -42,6 +37,8 @@ import org.osgi.framework.ServiceReferen
 import org.osgi.service.log.LogService;
 import org.osgi.service.useradmin.User;
 import org.osgi.service.useradmin.UserAdmin;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
 
 /**
  * Test cases for {@link AuthenticationServiceImpl}.
@@ -50,7 +47,7 @@ public class AuthenticationServiceImplTe
     
     private LogService m_log;
 
-    @Before
+    @BeforeMethod(alwaysRun = true)
     public void setUp() {
         m_log = mock(LogService.class);
     }
@@ -58,7 +55,7 @@ public class AuthenticationServiceImplTe
     /**
      * Tests that an exception is thrown if a null context is given.
      */
-    @Test(expected = IllegalArgumentException.class)
+    @Test(groups = { UNIT }, expectedExceptions = IllegalArgumentException.class)
     public void testAuthenticateFailsWithNullContext() {
         new AuthenticationServiceImpl().authenticate((Object[]) null);
     }
@@ -66,15 +63,15 @@ public class AuthenticationServiceImplTe
     /**
      * Tests that without any authentication processors, no authentication will take place.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testAuthenticateFailsWithoutAuthProcessors() {
-        assertNull(createAuthenticationService().authenticate("foo", "bar"));
+        assert createAuthenticationService().authenticate("foo", "bar") == null;
     }
 
     /**
      * Tests that an exception is thrown if no context is given.
      */
-    @Test(expected = IllegalArgumentException.class)
+    @Test(groups = { UNIT }, expectedExceptions = IllegalArgumentException.class)
     public void testAuthenticateFailsWithoutContext() {
         new AuthenticationServiceImpl().authenticate();
     }
@@ -82,7 +79,7 @@ public class AuthenticationServiceImplTe
     /**
      * Tests that with a single authentication processors, no authentication will take place if it is the wrong context.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testAuthenticateFailsWithSingleAuthProcessorAndWrongContext() {
         AuthenticationServiceImpl authService = createAuthenticationService();
         
@@ -91,13 +88,13 @@ public class AuthenticationServiceImplTe
 
         registerAuthProcessor(authService, authProc);
 
-        assertNull(authService.authenticate("foo", "bar"));
+        assert authService.authenticate("foo", "bar") == null;
     }
 
     /**
      * Tests that with multiple authentication processors, authentication will take place if it is given the correct context.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testAuthenticateSucceedsWithMultipleAuthProcessors() {
         Date now = new Date();
         
@@ -128,18 +125,18 @@ public class AuthenticationServiceImplTe
         registerAuthProcessor(authService, authProc2);
 
         User result = authService.authenticate("foo");
-        assertNotNull(result);
-        assertSame(user2, result);
+        assert result != null;
+        assert user2 == result;
         
         result = authService.authenticate(now);
-        assertNotNull(result);
-        assertSame(user1, result);
+        assert result != null;
+        assert user1 == result;
     }
 
     /**
      * Tests that with a single authentication processors, authentication will take place if it is given the correct context.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testAuthenticateSucceedsWithSingleAuthProcessorAndCorrectContext() {
         AuthenticationServiceImpl authService = createAuthenticationService();
 
@@ -151,13 +148,13 @@ public class AuthenticationServiceImplTe
 
         registerAuthProcessor(authService, authProc);
 
-        assertNotNull(authService.authenticate("foo"));
+        assert authService.authenticate("foo") != null;
     }
 
     /**
      * Tests that with multiple authentication processors, the correct ones are returned based on the given context.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testGetProcessorsSelectsCorrectProcessorsBasedOnContext() {
         Date now = new Date();
         
@@ -188,16 +185,16 @@ public class AuthenticationServiceImplTe
         registerAuthProcessor(authService, authProc2);
 
         List<AuthenticationProcessor> processors = authService.getProcessors("foo");
-        assertNotNull(processors);
-        assertEquals(1, processors.size());
+        assert processors != null;
+        assert 1 == processors.size();
         
         processors = authService.getProcessors(now);
-        assertNotNull(processors);
-        assertEquals(1, processors.size());
+        assert processors != null;
+        assert 1 == processors.size();
         
         processors = authService.getProcessors(new Object());
-        assertNotNull(processors);
-        assertEquals(0, processors.size());
+        assert processors != null;
+        assert processors.isEmpty();
     }
 
     /**

Modified: ace/trunk/ace-authenticationprocessor-basicauth/pom.xml
URL: http://svn.apache.org/viewvc/ace/trunk/ace-authenticationprocessor-basicauth/pom.xml?rev=1329668&r1=1329667&r2=1329668&view=diff
==============================================================================
--- ace/trunk/ace-authenticationprocessor-basicauth/pom.xml (original)
+++ ace/trunk/ace-authenticationprocessor-basicauth/pom.xml Tue Apr 24 12:23:47 2012
@@ -82,5 +82,10 @@
 			<groupId>commons-codec</groupId>
 			<artifactId>commons-codec</artifactId>
 		</dependency>
+        <dependency>
+            <groupId>org.apache.ace</groupId>
+            <artifactId>org.apache.ace.util</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>

Modified: ace/trunk/ace-authenticationprocessor-basicauth/src/test/java/org/apache/ace/authenticationprocessor/basicauth/BasicHttpAuthenticationProcessorTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-authenticationprocessor-basicauth/src/test/java/org/apache/ace/authenticationprocessor/basicauth/BasicHttpAuthenticationProcessorTest.java?rev=1329668&r1=1329667&r2=1329668&view=diff
==============================================================================
--- ace/trunk/ace-authenticationprocessor-basicauth/src/test/java/org/apache/ace/authenticationprocessor/basicauth/BasicHttpAuthenticationProcessorTest.java (original)
+++ ace/trunk/ace-authenticationprocessor-basicauth/src/test/java/org/apache/ace/authenticationprocessor/basicauth/BasicHttpAuthenticationProcessorTest.java Tue Apr 24 12:23:47 2012
@@ -18,12 +18,10 @@
  */
 package org.apache.ace.authenticationprocessor.basicauth;
 
-import static org.apache.ace.authenticationprocessor.basicauth.BasicHttpAuthenticationProcessor.*;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.apache.ace.authenticationprocessor.basicauth.BasicHttpAuthenticationProcessor.AUTHORIZATION_HEADER;
+import static org.apache.ace.authenticationprocessor.basicauth.BasicHttpAuthenticationProcessor.PROPERTY_KEY_PASSWORD;
+import static org.apache.ace.authenticationprocessor.basicauth.BasicHttpAuthenticationProcessor.PROPERTY_KEY_USERNAME;
+import static org.apache.ace.test.utils.TestUtils.UNIT;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -33,11 +31,11 @@ import java.util.Properties;
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.commons.codec.binary.Base64;
-import org.junit.Before;
-import org.junit.Test;
 import org.osgi.service.cm.ConfigurationException;
 import org.osgi.service.useradmin.User;
 import org.osgi.service.useradmin.UserAdmin;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
 
 /**
  * Test cases for {@link BasicHttpAuthenticationProcessor}.
@@ -47,7 +45,7 @@ public class BasicHttpAuthenticationProc
     private UserAdmin m_userAdmin;
     private HttpServletRequest m_servletRequest;
 
-    @Before
+    @BeforeMethod(alwaysRun = true)
     public void setUp() {
         m_userAdmin = mock(UserAdmin.class);
         m_servletRequest = mock(HttpServletRequest.class);
@@ -56,16 +54,16 @@ public class BasicHttpAuthenticationProc
     /**
      * Tests that a null authentication header will yield null.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testAuthenticateEmptyAuthenticationHeaderYieldsNull() {
         User result = new BasicHttpAuthenticationProcessor().authenticate(m_userAdmin, m_servletRequest);
-        assertNull(result);
+        assert result == null : "Expected no result!";
     }
 
     /**
      * Tests that an invalid authentication header will yield null.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testAuthenticateInvalidAuthenticationHeaderYieldsNull() {
         when(m_servletRequest.getHeader(AUTHORIZATION_HEADER)).thenReturn(createAuthHeaderValue("bob"));
         
@@ -76,13 +74,13 @@ public class BasicHttpAuthenticationProc
         when(m_userAdmin.getUser(eq("username"), eq("bob"))).thenReturn(user);
         
         User result = new BasicHttpAuthenticationProcessor().authenticate(m_userAdmin, m_servletRequest);
-        assertNull(result);
+        assert result == null : "Expected no result!";
     }
 
     /**
      * Tests that a known user with an invalid password will yield null.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testAuthenticateKnownUserWithInvalidPasswordYieldsNull() {
         when(m_servletRequest.getHeader(AUTHORIZATION_HEADER)).thenReturn(createAuthHeaderValue("bob:secret"));
         
@@ -93,13 +91,13 @@ public class BasicHttpAuthenticationProc
         when(m_userAdmin.getUser(eq("username"), eq("bob"))).thenReturn(user);
 
         User result = new BasicHttpAuthenticationProcessor().authenticate(m_userAdmin, m_servletRequest);
-        assertNull(result);
+        assert result == null : "Expected no result!";
     }
 
     /**
      * Tests that a known user will not yield null.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testAuthenticateKnownUserYieldsValidResult() {
         when(m_servletRequest.getHeader(AUTHORIZATION_HEADER)).thenReturn(createAuthHeaderValue("bob:secret"));
         
@@ -110,26 +108,26 @@ public class BasicHttpAuthenticationProc
         when(m_userAdmin.getUser(eq("username"), eq("bob"))).thenReturn(user);
 
         User result = new BasicHttpAuthenticationProcessor().authenticate(m_userAdmin, m_servletRequest);
-        assertNotNull(result);
+        assert result != null : "Expected a valid user to be returned!";
         
-        assertEquals("bob", user.getName());
+        assert "bob".equals(user.getName()) : "Expected user bob to be returned!";
     }
 
     /**
      * Tests that a non Base64 authentication header will yield null.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testAuthenticateNonBase64AuthenticationHeaderYieldsNull() {
         when(m_servletRequest.getHeader(AUTHORIZATION_HEADER)).thenReturn("foo");
         
         User result = new BasicHttpAuthenticationProcessor().authenticate(m_userAdmin, m_servletRequest);
-        assertNull(result);
+        assert result == null : "Expected no result!";
     }
 
     /**
      * Tests that a class cast exception is thrown for invalid context when calling authenticate.
      */
-    @Test(expected = ClassCastException.class)
+    @Test(groups = { UNIT }, expectedExceptions = ClassCastException.class)
     public void testAuthenticateThrowsClassCastForInvalidContext() {
         new BasicHttpAuthenticationProcessor().authenticate(m_userAdmin, new Object());
     }
@@ -137,26 +135,26 @@ public class BasicHttpAuthenticationProc
     /**
      * Tests that an unknown user will yield null.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testAuthenticateUnknownUserYieldsNull() {
-        when(m_servletRequest.getHeader(AUTHORIZATION_HEADER)).thenReturn(createAuthHeaderValue("bob:secret"));
+        when(m_servletRequest.getHeader(AUTHORIZATION_HEADER)).thenReturn(createAuthHeaderValue("alice:secret"));
         
         User result = new BasicHttpAuthenticationProcessor().authenticate(m_userAdmin, m_servletRequest);
-        assertNull(result);
+        assert result == null : "Expected no result!";
     }
 
     /**
      * Tests that canHandle yields false for any object other than {@link HttpServletRequest}.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testCanHandleDoesAcceptServletRequest() {
-        assertTrue(new BasicHttpAuthenticationProcessor().canHandle(mock(HttpServletRequest.class)));
+        assert new BasicHttpAuthenticationProcessor().canHandle(mock(HttpServletRequest.class));
     }
 
     /**
      * Tests that canHandle throws an {@link IllegalArgumentException} for an empty context.
      */
-    @Test(expected = IllegalArgumentException.class)
+    @Test(groups = { UNIT }, expectedExceptions = IllegalArgumentException.class)
     public void testCanHandleDoesNotAcceptEmptyArray() {
         new BasicHttpAuthenticationProcessor().canHandle(new Object[0]);
     }
@@ -164,7 +162,7 @@ public class BasicHttpAuthenticationProc
     /**
      * Tests that canHandle throws an {@link IllegalArgumentException} for a null context.
      */
-    @Test(expected = IllegalArgumentException.class)
+    @Test(groups = { UNIT }, expectedExceptions = IllegalArgumentException.class)
     public void testCanHandleDoesNotAcceptNull() {
         new BasicHttpAuthenticationProcessor().canHandle((Object[]) null);
     }
@@ -172,15 +170,15 @@ public class BasicHttpAuthenticationProc
     /**
      * Tests that canHandle yields false for any object other than {@link HttpServletRequest}.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testCanHandleDoesNotAcceptUnhandledContext() {
-        assertFalse(new BasicHttpAuthenticationProcessor().canHandle(new Object()));
+        assert new BasicHttpAuthenticationProcessor().canHandle(new Object()) == false;
     }
     
     /**
      * Tests that updated throws an exception for missing "key.username" property. 
      */
-    @Test(expected = ConfigurationException.class)
+    @Test(groups = { UNIT }, expectedExceptions = ConfigurationException.class)
     public void testUpdatedDoesNotAcceptEmptyKeyUsername() throws ConfigurationException {
         Properties props = new Properties();
         props.put(PROPERTY_KEY_USERNAME, "");
@@ -192,7 +190,7 @@ public class BasicHttpAuthenticationProc
     /**
      * Tests that updated throws an exception for missing "key.username" property. 
      */
-    @Test(expected = ConfigurationException.class)
+    @Test(groups = { UNIT }, expectedExceptions = ConfigurationException.class)
     public void testUpdatedDoesNotAcceptMissingKeyUsername() throws ConfigurationException {
         Properties props = new Properties();
         props.put(PROPERTY_KEY_PASSWORD, "foo");
@@ -203,7 +201,7 @@ public class BasicHttpAuthenticationProc
     /**
      * Tests that updated throws an exception for missing "key.password" property. 
      */
-    @Test(expected = ConfigurationException.class)
+    @Test(groups = { UNIT }, expectedExceptions = ConfigurationException.class)
     public void testUpdatedDoesNotAcceptMissingKeyPassword() throws ConfigurationException {
         Properties props = new Properties();
         props.put(PROPERTY_KEY_USERNAME, "foo");
@@ -214,7 +212,7 @@ public class BasicHttpAuthenticationProc
     /**
      * Tests that updated throws an exception for missing "key.password" property. 
      */
-    @Test(expected = ConfigurationException.class)
+    @Test(groups = { UNIT }, expectedExceptions = ConfigurationException.class)
     public void testUpdatedDoesNotAcceptEmptyKeyPassword() throws ConfigurationException {
         Properties props = new Properties();
         props.put(PROPERTY_KEY_USERNAME, "foo");
@@ -226,7 +224,7 @@ public class BasicHttpAuthenticationProc
     /**
      * Tests that updated does not throw an exception for a correct configuration.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testUpdatedDoesAcceptCorrectProperties() throws ConfigurationException {
         final String keyUsername = "foo";
         final String keyPassword = "bar";
@@ -249,9 +247,9 @@ public class BasicHttpAuthenticationProc
         when(m_userAdmin.getUser(eq(keyUsername), eq("bob"))).thenReturn(user);
 
         User result = processor.authenticate(m_userAdmin, m_servletRequest);
-        assertNotNull(result);
+        assert result != null : "Expected a valid user to be returned!";
         
-        assertEquals("bob", user.getName());
+        assert "bob".equals(user.getName()) : "Expected user bob to be returned!";
     }
 
 
@@ -259,6 +257,6 @@ public class BasicHttpAuthenticationProc
      * @return the basic authentication header, never <code>null</code>.
      */
     private String createAuthHeaderValue(String credentials) {
-        return "Basic " + new Base64().encodeAsString(credentials.getBytes());
+        return "Basic " + new Base64().encodeToString(credentials.getBytes());
     }
 }

Modified: ace/trunk/ace-authenticationprocessor-clientcert/pom.xml
URL: http://svn.apache.org/viewvc/ace/trunk/ace-authenticationprocessor-clientcert/pom.xml?rev=1329668&r1=1329667&r2=1329668&view=diff
==============================================================================
--- ace/trunk/ace-authenticationprocessor-clientcert/pom.xml (original)
+++ ace/trunk/ace-authenticationprocessor-clientcert/pom.xml Tue Apr 24 12:23:47 2012
@@ -77,5 +77,10 @@
 			<version>140</version>
 			<scope>test</scope>
 		</dependency>
+        <dependency>
+            <groupId>org.apache.ace</groupId>
+            <artifactId>org.apache.ace.util</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>

Modified: ace/trunk/ace-authenticationprocessor-clientcert/src/test/java/org/apache/ace/authenticationprocessor/clientcert/ClientCertAuthenticationProcessorTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-authenticationprocessor-clientcert/src/test/java/org/apache/ace/authenticationprocessor/clientcert/ClientCertAuthenticationProcessorTest.java?rev=1329668&r1=1329667&r2=1329668&view=diff
==============================================================================
--- ace/trunk/ace-authenticationprocessor-clientcert/src/test/java/org/apache/ace/authenticationprocessor/clientcert/ClientCertAuthenticationProcessorTest.java (original)
+++ ace/trunk/ace-authenticationprocessor-clientcert/src/test/java/org/apache/ace/authenticationprocessor/clientcert/ClientCertAuthenticationProcessorTest.java Tue Apr 24 12:23:47 2012
@@ -22,11 +22,7 @@ import static org.apache.ace.authenticat
 import static org.apache.ace.authenticationprocessor.clientcert.ClientCertAuthenticationProcessor.ATTRIBUTE_X509_CERTIFICATE;
 import static org.apache.ace.authenticationprocessor.clientcert.ClientCertAuthenticationProcessor.PROPERTY_KEY_PUBLICKEY;
 import static org.apache.ace.authenticationprocessor.clientcert.ClientCertAuthenticationProcessor.PROPERTY_KEY_USERNAME;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.apache.ace.test.utils.TestUtils.UNIT;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -40,13 +36,14 @@ import java.util.Properties;
 
 import javax.servlet.http.HttpServletRequest;
 
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.mockito.Mockito;
 import org.osgi.service.cm.ConfigurationException;
 import org.osgi.service.log.LogService;
 import org.osgi.service.useradmin.User;
 import org.osgi.service.useradmin.UserAdmin;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
 
 /**
  * Test cases for {@link ClientCertAuthenticationProcessor}.
@@ -110,7 +107,7 @@ public class ClientCertAuthenticationPro
     /**
      * Creates an in-memory keystore for this test case.
      */
-    @BeforeClass
+    @BeforeClass(alwaysRun = true)
     public static void init() {
         m_keystore = new MemoryKeyStore("cn=testCA", dayBeforeYesterday(), dayAfterTomorrow());
     }
@@ -118,7 +115,7 @@ public class ClientCertAuthenticationPro
     /**
      * Set up for each individual test.
      */
-    @Before
+    @BeforeMethod(alwaysRun = true)
     public void setUp() {
         m_log = mock(LogService.class);
 
@@ -132,27 +129,27 @@ public class ClientCertAuthenticationPro
     /**
      * Tests that a null certificate chain will yield null.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testAuthenticateNoCertificateChainYieldsNull() {
         User result = createAuthorizationProcessor().authenticate(m_userAdmin, m_servletRequest);
-        assertNull(result);
+        assert result == null : "Did not expect a valid user to be returned!";
     }
 
     /**
      * Tests that an empty certificate chain will yield null.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testAuthenticateEmptyCertificateChainYieldsNull() {
         when(m_servletRequest.getAttribute(ATTRIBUTE_X509_CERTIFICATE)).thenReturn(new X509Certificate[0]);
 
         User result = createAuthorizationProcessor().authenticate(m_userAdmin, m_servletRequest);
-        assertNull(result);
+        assert result == null : "Did not expect a valid user to be returned!";
     }
 
     /**
      * Tests that authenticating a known user with an invalid (expired) certificate will yield null.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testAuthenticateKnownUserWithExpiredCertificateYieldsNull() {
         X509Certificate[] certificateChain = createExpiredCertificateChain("bob");
         PublicKey publickey = certificateChain[0].getPublicKey();
@@ -166,13 +163,13 @@ public class ClientCertAuthenticationPro
         when(m_userAdmin.getUser(eq("username"), eq("bob"))).thenReturn(user);
 
         User result = createAuthorizationProcessor().authenticate(m_userAdmin, m_servletRequest);
-        assertNull(result);
+        assert result == null : "Did not expect a valid user to be returned!";
     }
 
     /**
      * Tests that authenticating a known user with an invalid (not valid) certificate will yield null.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testAuthenticateKnownUserWithNotValidCertificateYieldsNull() {
         X509Certificate[] certificateChain = createExpiredCertificateChain("bob");
         PublicKey publickey = certificateChain[0].getPublicKey();
@@ -187,13 +184,13 @@ public class ClientCertAuthenticationPro
         when(m_userAdmin.getUser(eq("username"), eq("bob"))).thenReturn(user);
 
         User result = createAuthorizationProcessor().authenticate(m_userAdmin, m_servletRequest);
-        assertNull(result);
+        assert result == null : "Did not expect a valid user to be returned!";
     }
 
     /**
      * Tests that authenticating a known user with a valid certificate will not yield null.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testAuthenticateKnownUserYieldsValidResult() {
         X509Certificate[] certChain = createValidCertificateChain("bob");
         PublicKey publicKey = certChain[0].getPublicKey();
@@ -207,27 +204,27 @@ public class ClientCertAuthenticationPro
         when(m_userAdmin.getUser(eq("username"), eq("bob"))).thenReturn(user);
 
         User result = createAuthorizationProcessor().authenticate(m_userAdmin, m_servletRequest);
-        assertNotNull(result);
+        assert result != null : "Expected a valid user to be returned!";
 
-        assertEquals("bob", user.getName());
+        assert "bob".equals(user.getName()) : "Expected bob to be returned as user!";
     }
 
     /**
      * Tests that a missing cipher suite header will the authenticate method to yield null.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testAuthenticateMissingCipherSuiteHeaderYieldsNull() {
         when(m_servletRequest.getAttribute(ATTRIBUTE_CIPHER_SUITE)).thenReturn(null);
         when(m_servletRequest.getAttribute(ATTRIBUTE_X509_CERTIFICATE)).thenReturn(createValidCertificateChain("bob"));
 
         User result = createAuthorizationProcessor().authenticate(m_userAdmin, m_servletRequest);
-        assertNull(result);
+        assert result == null : "Did not expect a valid user to be returned!";
     }
 
     /**
      * Tests that a class cast exception is thrown for invalid context when calling authenticate.
      */
-    @Test(expected = ClassCastException.class)
+    @Test(groups = { UNIT }, expectedExceptions = ClassCastException.class)
     public void testAuthenticateThrowsClassCastForInvalidContext() {
         createAuthorizationProcessor().authenticate(m_userAdmin, new Object());
     }
@@ -235,26 +232,26 @@ public class ClientCertAuthenticationPro
     /**
      * Tests that an unknown user will yield null.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testAuthenticateUnknownUserYieldsNull() {
         when(m_servletRequest.getAttribute(ATTRIBUTE_X509_CERTIFICATE)).thenReturn(createValidCertificateChain("bob"));
 
         User result = createAuthorizationProcessor().authenticate(m_userAdmin, m_servletRequest);
-        assertNull(result);
+        assert result == null : "Did not expect a valid user to be returned!";
     }
 
     /**
      * Tests that canHandle yields false for any object other than {@link HttpServletRequest}.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testCanHandleDoesAcceptServletRequest() {
-        assertTrue(createAuthorizationProcessor().canHandle(mock(HttpServletRequest.class)));
+        assert createAuthorizationProcessor().canHandle(mock(HttpServletRequest.class));
     }
 
     /**
      * Tests that canHandle throws an {@link IllegalArgumentException} for an empty context.
      */
-    @Test(expected = IllegalArgumentException.class)
+    @Test(groups = { UNIT }, expectedExceptions = IllegalArgumentException.class)
     public void testCanHandleDoesNotAcceptEmptyArray() {
         createAuthorizationProcessor().canHandle(new Object[0]);
     }
@@ -262,7 +259,7 @@ public class ClientCertAuthenticationPro
     /**
      * Tests that canHandle throws an {@link IllegalArgumentException} for a null context.
      */
-    @Test(expected = IllegalArgumentException.class)
+    @Test(groups = { UNIT }, expectedExceptions = IllegalArgumentException.class)
     public void testCanHandleDoesNotAcceptNull() {
         createAuthorizationProcessor().canHandle((Object[]) null);
     }
@@ -270,18 +267,20 @@ public class ClientCertAuthenticationPro
     /**
      * Tests that canHandle yields false for any object other than {@link HttpServletRequest}.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testCanHandleDoesNotAcceptUnhandledContext() {
-        assertFalse(createAuthorizationProcessor().canHandle(new Object()));
+        assert createAuthorizationProcessor().canHandle(new Object()) == false;
     }
 
     /**
      * Tests that updated does not throw an exception for a correct configuration.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testUpdatedDoesAcceptCorrectProperties() throws ConfigurationException {
         final String keyUsername = "foo";
         final String keyPublicKey = "bar";
+        
+        Mockito.reset(m_userAdmin, m_servletRequest);
 
         Properties props = new Properties();
         props.put(PROPERTY_KEY_USERNAME, keyUsername);
@@ -291,28 +290,29 @@ public class ClientCertAuthenticationPro
 
         processor.updated(props);
 
-        X509Certificate[] certificateChain = createValidCertificateChain("bob");
+        X509Certificate[] certificateChain = createValidCertificateChain("alice");
         PublicKey publickey = certificateChain[0].getPublicKey();
 
         // Test whether we can use the new properties...
         when(m_servletRequest.getAttribute(ATTRIBUTE_X509_CERTIFICATE)).thenReturn(certificateChain);
+        when(m_servletRequest.getAttribute(ATTRIBUTE_CIPHER_SUITE)).thenReturn("bogus-cipher-suite");
 
         User user = mock(User.class);
-        when(user.getName()).thenReturn("bob");
+        when(user.getName()).thenReturn("alice");
         when(user.hasCredential(eq(keyPublicKey), eq(publickey.getEncoded()))).thenReturn(Boolean.TRUE);
 
-        when(m_userAdmin.getUser(eq(keyUsername), eq("bob"))).thenReturn(user);
+        when(m_userAdmin.getUser(eq(keyUsername), eq("alice"))).thenReturn(user);
 
         User result = processor.authenticate(m_userAdmin, m_servletRequest);
-        assertNotNull(result);
+        assert result != null : "Expected a valid user to be returned!";
 
-        assertEquals("bob", user.getName());
+        assert "alice".equals(user.getName()) : "Expected alice to be returned as user!";
     }
 
     /**
      * Tests that updated throws an exception for missing "key.password" property.
      */
-    @Test(expected = ConfigurationException.class)
+    @Test(groups = { UNIT }, expectedExceptions = ConfigurationException.class)
     public void testUpdatedDoesNotAcceptEmptyKeyPassword() throws ConfigurationException {
         Properties props = new Properties();
         props.put(PROPERTY_KEY_USERNAME, "foo");
@@ -324,7 +324,7 @@ public class ClientCertAuthenticationPro
     /**
      * Tests that updated throws an exception for missing "key.username" property.
      */
-    @Test(expected = ConfigurationException.class)
+    @Test(groups = { UNIT }, expectedExceptions = ConfigurationException.class)
     public void testUpdatedDoesNotAcceptEmptyKeyUsername() throws ConfigurationException {
         Properties props = new Properties();
         props.put(PROPERTY_KEY_USERNAME, "");
@@ -336,7 +336,7 @@ public class ClientCertAuthenticationPro
     /**
      * Tests that updated throws an exception for missing "key.password" property.
      */
-    @Test(expected = ConfigurationException.class)
+    @Test(groups = { UNIT }, expectedExceptions = ConfigurationException.class)
     public void testUpdatedDoesNotAcceptMissingKeyPassword() throws ConfigurationException {
         Properties props = new Properties();
         props.put(PROPERTY_KEY_USERNAME, "foo");
@@ -347,7 +347,7 @@ public class ClientCertAuthenticationPro
     /**
      * Tests that updated throws an exception for missing "key.username" property.
      */
-    @Test(expected = ConfigurationException.class)
+    @Test(groups = { UNIT }, expectedExceptions = ConfigurationException.class)
     public void testUpdatedDoesNotAcceptMissingKeyUsername() throws ConfigurationException {
         Properties props = new Properties();
         props.put(PROPERTY_KEY_PUBLICKEY, "foo");

Modified: ace/trunk/ace-authenticationprocessor-password/pom.xml
URL: http://svn.apache.org/viewvc/ace/trunk/ace-authenticationprocessor-password/pom.xml?rev=1329668&r1=1329667&r2=1329668&view=diff
==============================================================================
--- ace/trunk/ace-authenticationprocessor-password/pom.xml (original)
+++ ace/trunk/ace-authenticationprocessor-password/pom.xml Tue Apr 24 12:23:47 2012
@@ -78,5 +78,10 @@
 			<groupId>commons-codec</groupId>
 			<artifactId>commons-codec</artifactId>
 		</dependency>
+        <dependency>
+            <groupId>org.apache.ace</groupId>
+            <artifactId>org.apache.ace.util</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>

Modified: ace/trunk/ace-authenticationprocessor-password/src/test/java/org/apache/ace/authenticationprocessor/password/PasswordAuthenticationProcessorTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-authenticationprocessor-password/src/test/java/org/apache/ace/authenticationprocessor/password/PasswordAuthenticationProcessorTest.java?rev=1329668&r1=1329667&r2=1329668&view=diff
==============================================================================
--- ace/trunk/ace-authenticationprocessor-password/src/test/java/org/apache/ace/authenticationprocessor/password/PasswordAuthenticationProcessorTest.java (original)
+++ ace/trunk/ace-authenticationprocessor-password/src/test/java/org/apache/ace/authenticationprocessor/password/PasswordAuthenticationProcessorTest.java Tue Apr 24 12:23:47 2012
@@ -18,12 +18,10 @@
  */
 package org.apache.ace.authenticationprocessor.password;
 
-import static org.apache.ace.authenticationprocessor.password.PasswordAuthenticationProcessor.*;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.apache.ace.authenticationprocessor.password.PasswordAuthenticationProcessor.PROPERTY_KEY_PASSWORD;
+import static org.apache.ace.authenticationprocessor.password.PasswordAuthenticationProcessor.PROPERTY_KEY_USERNAME;
+import static org.apache.ace.authenticationprocessor.password.PasswordAuthenticationProcessor.PROPERTY_PASSWORD_HASHMETHOD;
+import static org.apache.ace.test.utils.TestUtils.UNIT;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -31,11 +29,12 @@ import static org.mockito.Mockito.when;
 import java.util.Properties;
 
 import org.apache.commons.codec.digest.DigestUtils;
-import org.junit.Before;
-import org.junit.Test;
+import org.mockito.Mockito;
 import org.osgi.service.cm.ConfigurationException;
 import org.osgi.service.useradmin.User;
 import org.osgi.service.useradmin.UserAdmin;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
 
 /**
  * Test cases for {@link PasswordAuthenticationProcessor}.
@@ -44,24 +43,25 @@ public class PasswordAuthenticationProce
     
     private UserAdmin m_userAdmin;
 
-    @Before
+    @BeforeMethod(alwaysRun = true)
     public void setUp() {
         m_userAdmin = mock(UserAdmin.class);
+        Mockito.reset(m_userAdmin);
     }
 
     /**
      * Tests that authenticating with a empty username will yield null.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testAuthenticateEmptyUserNameYieldsNull() {
         User result = new PasswordAuthenticationProcessor().authenticate(m_userAdmin, "", "secret");
-        assertNull(result);
+        assert result == null : "Expected no valid user to be returned!";
     }
 
     /**
      * Tests that authenticating a known user with an invalid password will yield null.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testAuthenticateKnownUserWithInvalidPasswordYieldsNull() {
         User user = mock(User.class);
         when(user.getName()).thenReturn("bob");
@@ -70,13 +70,13 @@ public class PasswordAuthenticationProce
         when(m_userAdmin.getUser(eq("username"), eq("bob"))).thenReturn(user);
 
         User result = new PasswordAuthenticationProcessor().authenticate(m_userAdmin, "bob", "secret");
-        assertNull(result);
+        assert result == null : "Expected no valid user to be returned!";
     }
 
     /**
      * Tests that authenticating a known user with a correct password will not yield null.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testAuthenticateKnownUserYieldsValidResult() {
         User user = mock(User.class);
         when(user.getName()).thenReturn("bob");
@@ -85,33 +85,33 @@ public class PasswordAuthenticationProce
         when(m_userAdmin.getUser(eq("username"), eq("bob"))).thenReturn(user);
 
         User result = new PasswordAuthenticationProcessor().authenticate(m_userAdmin, "bob", "secret");
-        assertNotNull(result);
+        assert result != null : "Expected a valid user to be returned!";
         
-        assertEquals("bob", user.getName());
+        assert "bob".equals(user.getName()) : "Expected bob to be returned!";
     }
 
     /**
      * Tests that authenticating with a null password will yield null.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testAuthenticateNullPasswordYieldsNull() {
         User result = new PasswordAuthenticationProcessor().authenticate(m_userAdmin, "bob", null);
-        assertNull(result);
+        assert result == null : "Expected no valid user to be returned!";
     }
 
     /**
      * Tests that authenticating with a null username will yield null.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testAuthenticateNullUserNameYieldsNull() {
         User result = new PasswordAuthenticationProcessor().authenticate(m_userAdmin, null, "secret");
-        assertNull(result);
+        assert result == null : "Expected no valid user to be returned!";
     }
 
     /**
      * Tests that a class cast exception is thrown for invalid context when calling authenticate.
      */
-    @Test(expected = ClassCastException.class)
+    @Test(groups = { UNIT }, expectedExceptions = ClassCastException.class)
     public void testAuthenticateThrowsClassCastForInvalidContext() {
         new PasswordAuthenticationProcessor().authenticate(m_userAdmin, new Object(), "foo");
     }
@@ -119,32 +119,32 @@ public class PasswordAuthenticationProce
     /**
      * Tests that authenticating an unknown user will yield null.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testAuthenticateUnknownUserYieldsNull() {
-        User result = new PasswordAuthenticationProcessor().authenticate(m_userAdmin, "bob", "secret");
-        assertNull(result);
+        User result = new PasswordAuthenticationProcessor().authenticate(m_userAdmin, "alice", "secret");
+        assert result == null : "Expected no valid user to be returned!";
     }
 
     /**
      * Tests that canHandle yields true for string and byte array.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testCanHandleDoesAcceptStringAndByteArray() {
-        assertTrue(new PasswordAuthenticationProcessor().canHandle("foo", "bar".getBytes()));
+        assert new PasswordAuthenticationProcessor().canHandle("foo", "bar".getBytes()) : "Expected the processor to handle a byte array!";
     }
 
     /**
      * Tests that canHandle yields true for two strings.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testCanHandleDoesAcceptTwoStrings() {
-        assertTrue(new PasswordAuthenticationProcessor().canHandle("foo", "bar"));
+        assert new PasswordAuthenticationProcessor().canHandle("foo", "bar") : "Expected the processor to handle a string!";
     }
 
     /**
      * Tests that canHandle throws an {@link IllegalArgumentException} for an empty context.
      */
-    @Test(expected = IllegalArgumentException.class)
+    @Test(groups = { UNIT }, expectedExceptions = IllegalArgumentException.class)
     public void testCanHandleDoesNotAcceptEmptyArray() {
         new PasswordAuthenticationProcessor().canHandle(new Object[0]);
     }
@@ -152,7 +152,7 @@ public class PasswordAuthenticationProce
     /**
      * Tests that canHandle throws an {@link IllegalArgumentException} for a null context.
      */
-    @Test(expected = IllegalArgumentException.class)
+    @Test(groups = { UNIT }, expectedExceptions = IllegalArgumentException.class)
     public void testCanHandleDoesNotAcceptNull() {
         new PasswordAuthenticationProcessor().canHandle((Object[]) null);
     }
@@ -160,31 +160,31 @@ public class PasswordAuthenticationProce
     /**
      * Tests that canHandle yields false for too few arguments. 
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testCanHandleDoesNotAcceptSingleArgument() {
-        assertFalse(new PasswordAuthenticationProcessor().canHandle(new Object()));
+        assert new PasswordAuthenticationProcessor().canHandle(new Object()) == false : "Expected the processor to NOT handle any object!";
     }
     
     /**
      * Tests that canHandle yields false for a string and other object. 
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testCanHandleDoesNotAcceptStringAndOtherObject() {
-        assertFalse(new PasswordAuthenticationProcessor().canHandle("foo", new Object()));
+        assert new PasswordAuthenticationProcessor().canHandle("foo", new Object()) == false : "Expected the processor to NOT handle any object!";
     }
 
     /**
      * Tests that canHandle yields false for any object other than {@link HttpServletRequest}.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testCanHandleDoesNotAcceptWrongTypes() {
-        assertFalse(new PasswordAuthenticationProcessor().canHandle(new Object(), new Object()));
+        assert new PasswordAuthenticationProcessor().canHandle(new Object(), new Object()) == false : "Expected the processor to NOT handle any object!";
     }
     
     /**
      * Tests that updated does not throw an exception for a correct configuration.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testUpdatedDoesAcceptCorrectProperties() throws ConfigurationException {
         final String keyUsername = "foo";
         final String keyPassword = "bar";
@@ -208,15 +208,15 @@ public class PasswordAuthenticationProce
         when(m_userAdmin.getUser(eq(keyUsername), eq("bob"))).thenReturn(user);
 
         User result = processor.authenticate(m_userAdmin, "bob", "secret");
-        assertNotNull(result);
+        assert result != null : "Expected a valid user to be returned!";
         
-        assertEquals("bob", user.getName());
+        assert "bob".equals(user.getName()) : "Expected bob to be returned!";
     }
     
     /**
      * Tests that updated throws an exception for missing "key.password" property. 
      */
-    @Test(expected = ConfigurationException.class)
+    @Test(groups = { UNIT }, expectedExceptions = ConfigurationException.class)
     public void testUpdatedDoesNotAcceptEmptyKeyPassword() throws ConfigurationException {
         Properties props = new Properties();
         props.put(PROPERTY_KEY_USERNAME, "foo");
@@ -229,7 +229,7 @@ public class PasswordAuthenticationProce
     /**
      * Tests that updated throws an exception for missing "key.username" property. 
      */
-    @Test(expected = ConfigurationException.class)
+    @Test(groups = { UNIT }, expectedExceptions = ConfigurationException.class)
     public void testUpdatedDoesNotAcceptEmptyKeyUsername() throws ConfigurationException {
         Properties props = new Properties();
         props.put(PROPERTY_KEY_USERNAME, "");
@@ -242,7 +242,7 @@ public class PasswordAuthenticationProce
     /**
      * Tests that updated throws an exception for missing "password.hashtype" property. 
      */
-    @Test(expected = ConfigurationException.class)
+    @Test(groups = { UNIT }, expectedExceptions = ConfigurationException.class)
     public void testUpdatedDoesNotAcceptEmptyPasswordHashType() throws ConfigurationException {
         Properties props = new Properties();
         props.put(PROPERTY_KEY_USERNAME, "foo");
@@ -255,7 +255,7 @@ public class PasswordAuthenticationProce
     /**
      * Tests that updated throws an exception for missing "key.password" property. 
      */
-    @Test(expected = ConfigurationException.class)
+    @Test(groups = { UNIT }, expectedExceptions = ConfigurationException.class)
     public void testUpdatedDoesNotAcceptMissingKeyPassword() throws ConfigurationException {
         Properties props = new Properties();
         props.put(PROPERTY_KEY_USERNAME, "foo");
@@ -267,7 +267,7 @@ public class PasswordAuthenticationProce
     /**
      * Tests that updated throws an exception for missing "key.username" property. 
      */
-    @Test(expected = ConfigurationException.class)
+    @Test(groups = { UNIT }, expectedExceptions = ConfigurationException.class)
     public void testUpdatedDoesNotAcceptMissingKeyUsername() throws ConfigurationException {
         Properties props = new Properties();
         props.put(PROPERTY_KEY_PASSWORD, "foo");
@@ -279,7 +279,7 @@ public class PasswordAuthenticationProce
     /**
      * Tests that updated throws an exception for missing "password.hashtype" property. 
      */
-    @Test(expected = ConfigurationException.class)
+    @Test(groups = { UNIT }, expectedExceptions = ConfigurationException.class)
     public void testUpdatedDoesNotAcceptMissingPasswordHashType() throws ConfigurationException {
         Properties props = new Properties();
         props.put(PROPERTY_KEY_USERNAME, "foo");

Modified: ace/trunk/ace-connectionfactory/pom.xml
URL: http://svn.apache.org/viewvc/ace/trunk/ace-connectionfactory/pom.xml?rev=1329668&r1=1329667&r2=1329668&view=diff
==============================================================================
--- ace/trunk/ace-connectionfactory/pom.xml (original)
+++ ace/trunk/ace-connectionfactory/pom.xml Tue Apr 24 12:23:47 2012
@@ -72,5 +72,10 @@
 			<groupId>commons-codec</groupId>
 			<artifactId>commons-codec</artifactId>
 		</dependency>
+        <dependency>
+            <groupId>org.apache.ace</groupId>
+            <artifactId>org.apache.ace.util</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>

Modified: ace/trunk/ace-connectionfactory/src/main/java/org/apache/ace/connectionfactory/impl/ConnectionFactoryImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-connectionfactory/src/main/java/org/apache/ace/connectionfactory/impl/ConnectionFactoryImpl.java?rev=1329668&r1=1329667&r2=1329668&view=diff
==============================================================================
--- ace/trunk/ace-connectionfactory/src/main/java/org/apache/ace/connectionfactory/impl/ConnectionFactoryImpl.java (original)
+++ ace/trunk/ace-connectionfactory/src/main/java/org/apache/ace/connectionfactory/impl/ConnectionFactoryImpl.java Tue Apr 24 12:23:47 2012
@@ -160,7 +160,7 @@ public class ConnectionFactoryImpl imple
      * @param creds the credentials to supply.
      * @return a string that denotes the basic authentication header ("Basic " + encoded credentials), never <code>null</code>.
      */
-    private String getBasicAuthCredentials(UrlCredentials creds) {
+    final String getBasicAuthCredentials(UrlCredentials creds) {
         final Object[] values = creds.getCredentials();
         if (values.length < 2) {
             throw new IllegalArgumentException("Insufficient credentials passed! Expected 2 values, got " + values.length + " values.");
@@ -181,7 +181,7 @@ public class ConnectionFactoryImpl imple
             sb.append(new String((byte[]) values[1]));
         }
 
-        return "Basic " + Base64.encodeBase64String(sb.toString().getBytes());
+        return "Basic " + new String(Base64.encodeBase64(sb.toString().getBytes()));
     }
 
     /**

Modified: ace/trunk/ace-connectionfactory/src/test/java/org/apache/ace/connectionfactory/impl/ConnectionFactoryImplTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-connectionfactory/src/test/java/org/apache/ace/connectionfactory/impl/ConnectionFactoryImplTest.java?rev=1329668&r1=1329667&r2=1329668&view=diff
==============================================================================
--- ace/trunk/ace-connectionfactory/src/test/java/org/apache/ace/connectionfactory/impl/ConnectionFactoryImplTest.java (original)
+++ ace/trunk/ace-connectionfactory/src/test/java/org/apache/ace/connectionfactory/impl/ConnectionFactoryImplTest.java Tue Apr 24 12:23:47 2012
@@ -19,14 +19,14 @@
 
 package org.apache.ace.connectionfactory.impl;
 
-import static org.junit.Assert.*;
+import static org.apache.ace.test.utils.TestUtils.UNIT;
 
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.Properties;
 
-import org.junit.Test;
+import org.testng.annotations.Test;
 
 /**
  * Test cases for {@link ConnectionFactoryImpl}.
@@ -47,7 +47,7 @@ public class ConnectionFactoryImplTest {
     /**
      * Test method for {@link org.apache.ace.connectionfactory.impl.ConnectionFactoryImpl#createConnection(java.net.URL)}.
      */
-    @Test(expected = IllegalArgumentException.class)
+    @Test(groups = { UNIT }, expectedExceptions = IllegalArgumentException.class)
     public void testCreateConnectionNullUrlFail() throws Exception {
         new ConnectionFactoryImpl().createConnection(null);
     }
@@ -55,7 +55,7 @@ public class ConnectionFactoryImplTest {
     /**
      * Test method for {@link org.apache.ace.connectionfactory.impl.ConnectionFactoryImpl#createConnection(java.net.URL, org.osgi.service.useradmin.User)}.
      */
-    @Test(expected = IllegalArgumentException.class)
+    @Test(groups = { UNIT }, expectedExceptions = IllegalArgumentException.class)
     public void testCreateConnectionNullUserFail() throws Exception {
         new ConnectionFactoryImpl().createConnection(new URL("file:///tmp/foo"), null);
     }
@@ -63,16 +63,16 @@ public class ConnectionFactoryImplTest {
     /**
      * Test method for {@link org.apache.ace.connectionfactory.impl.ConnectionFactoryImpl#createConnection(java.net.URL, org.osgi.service.useradmin.User)}.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testCreateConnectionOk() throws Exception {
         URLConnection conn = new ConnectionFactoryImpl().createConnection(new URL("file:///tmp/foo"));
-        assertNotNull(conn);
+        assert conn != null : "Expected valid connection to be created!";
     }
 
     /**
      * Test method for {@link org.apache.ace.connectionfactory.impl.ConnectionFactoryImpl#deleted(java.lang.String)}.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testDeleted() throws Exception {
         ConnectionFactoryImpl connFactory = new ConnectionFactoryImpl();
 
@@ -81,36 +81,56 @@ public class ConnectionFactoryImplTest {
         connFactory.updated("pid1", props);
         
         UrlCredentials credentials = connFactory.getCredentials(TEST_URL);
-        assertNotNull(credentials);
-        
+        assert credentials != null : "Expected valid credentials to be found!";
+
         connFactory.deleted("pid1");
         
         credentials = connFactory.getCredentials(TEST_URL);
-        assertNull(credentials);
+        assert credentials == null : "Expected no credentials to be found!";
+    }
+
+    /**
+     * Test method for {@link org.apache.ace.connectionfactory.impl.ConnectionFactoryImpl#getBasicAuthCredentials(UrlCredentials)}.
+     */
+    @Test(groups = { UNIT })
+    public void testGetBasicAuthCredentialsOk() throws Exception {
+        ConnectionFactoryImpl connFactory = new ConnectionFactoryImpl();
+
+        Properties props = createBasicAuthConfig(TEST_URL.toExternalForm());
+
+        connFactory.updated("pid1", props);
+        
+        UrlCredentials credentials = connFactory.getCredentials(TEST_URL);
+        assert credentials != null : "Expected valid credentials to be found!";
+
+        String header = new ConnectionFactoryImpl().getBasicAuthCredentials(credentials);
+        assert header != null : "Expected valid HTTP header to be returned!";
+        assert header.equals(header.trim()) : "Expected HTTP header not to contain any leading/trailing whitespace!";
+        assert "Basic Zm9vOmJhcg==".equals(header) : "Expected HTTP header to be constant!";
     }
 
     /**
      * Test method for {@link org.apache.ace.connectionfactory.impl.ConnectionFactoryImpl#updated(java.lang.String, java.util.Dictionary)}.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testUpdatedInsertsCredentialsOk() throws Exception {
         ConnectionFactoryImpl connFactory = new ConnectionFactoryImpl();
         
         UrlCredentials credentials = connFactory.getCredentials(TEST_URL);
-        assertNull(credentials);
+        assert credentials == null : "Expected no credentials to be found!";
         
         Properties props = createBasicAuthConfig(TEST_URL.toExternalForm());
 
         connFactory.updated("pid1", props);
         
         credentials = connFactory.getCredentials(TEST_URL);
-        assertNotNull(credentials);
+        assert credentials != null : "Expected valid credentials to be found!";
     }
 
     /**
      * Test method for {@link org.apache.ace.connectionfactory.impl.ConnectionFactoryImpl#updated(java.lang.String, java.util.Dictionary)}.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testUpdatedUpdatesCredentialsOk() throws Exception {
         ConnectionFactoryImpl connFactory = new ConnectionFactoryImpl();
 
@@ -119,7 +139,7 @@ public class ConnectionFactoryImplTest {
         connFactory.updated("pid1", props);
         
         UrlCredentials credentials1 = connFactory.getCredentials(TEST_URL);
-        assertNotNull(credentials1);
+        assert credentials1 != null : "Expected valid credentials to be found!";
         
         URL newURL = new URL("http://localhost:8181/test/");
         props.put(UrlCredentialsFactory.KEY_AUTH_BASE_URL, newURL.toExternalForm());
@@ -127,12 +147,12 @@ public class ConnectionFactoryImplTest {
         connFactory.updated("pid1", props);
 
         UrlCredentials credentials2 = connFactory.getCredentials(TEST_URL);
-        assertNull(credentials2);
+        assert credentials2 == null : "Expected no credentials to be found!";
 
         credentials2 = connFactory.getCredentials(newURL);
-        assertNotNull(credentials2);
+        assert credentials2 != null : "Expected valid credentials to be found!";
         
-        assertNotSame(credentials1, credentials2);
+        assert credentials1 != credentials2 && !credentials1.equals(credentials2) : "Expected not the same credentials to be returned!";
     }
 
     /**

Modified: ace/trunk/ace-connectionfactory/src/test/java/org/apache/ace/connectionfactory/impl/UrlCredentialsFactoryTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-connectionfactory/src/test/java/org/apache/ace/connectionfactory/impl/UrlCredentialsFactoryTest.java?rev=1329668&r1=1329667&r2=1329668&view=diff
==============================================================================
--- ace/trunk/ace-connectionfactory/src/test/java/org/apache/ace/connectionfactory/impl/UrlCredentialsFactoryTest.java (original)
+++ ace/trunk/ace-connectionfactory/src/test/java/org/apache/ace/connectionfactory/impl/UrlCredentialsFactoryTest.java Tue Apr 24 12:23:47 2012
@@ -19,10 +19,12 @@
 
 package org.apache.ace.connectionfactory.impl;
 
+import static org.apache.ace.test.utils.TestUtils.UNIT;
+
 import java.util.Properties;
 
 import org.apache.ace.connectionfactory.impl.UrlCredentialsFactory.MissingValueException;
-import org.junit.Test;
+import org.testng.annotations.Test;
 
 /**
  * Test cases for {@link UrlCredentialsFactory}.
@@ -32,7 +34,7 @@ public class UrlCredentialsFactoryTest {
     /**
      * Test method for {@link org.apache.ace.connectionfactory.impl.UrlCredentialsFactory#getCredentials(java.util.Dictionary)}.
      */
-    @Test(expected = MissingValueException.class)
+    @Test(groups = { UNIT }, expectedExceptions = MissingValueException.class)
     public void testGetCredentialsWithDictionaryBasicTypeMissingPasswordFail() {
         Properties props = new Properties();
         props.put(UrlCredentialsFactory.KEY_AUTH_BASE_URL, "http://localhost:8080/");
@@ -45,7 +47,7 @@ public class UrlCredentialsFactoryTest {
     /**
      * Test method for {@link org.apache.ace.connectionfactory.impl.UrlCredentialsFactory#getCredentials(java.util.Dictionary)}.
      */
-    @Test(expected = MissingValueException.class)
+    @Test(groups = { UNIT }, expectedExceptions = MissingValueException.class)
     public void testGetCredentialsWithDictionaryBasicTypeMissingUserNameFail() {
         Properties props = new Properties();
         props.put(UrlCredentialsFactory.KEY_AUTH_BASE_URL, "http://localhost:8080/");
@@ -58,7 +60,7 @@ public class UrlCredentialsFactoryTest {
     /**
      * Test method for {@link org.apache.ace.connectionfactory.impl.UrlCredentialsFactory#getCredentials(java.util.Dictionary)}.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testGetCredentialsWithDictionaryBasicTypeOk() {
         Properties props = new Properties();
         props.put(UrlCredentialsFactory.KEY_AUTH_BASE_URL, "http://localhost:8080/");
@@ -72,7 +74,7 @@ public class UrlCredentialsFactoryTest {
     /**
      * Test method for {@link org.apache.ace.connectionfactory.impl.UrlCredentialsFactory#getCredentials(java.util.Dictionary)}.
      */
-    @Test(expected = IllegalArgumentException.class)
+    @Test(groups = { UNIT }, expectedExceptions = IllegalArgumentException.class)
     public void testGetCredentialsWithDictionaryInvalidAuthTypeFail() {
         Properties props = new Properties();
         props.put(UrlCredentialsFactory.KEY_AUTH_BASE_URL, "http://localhost:8080/");
@@ -84,7 +86,7 @@ public class UrlCredentialsFactoryTest {
     /**
      * Test method for {@link org.apache.ace.connectionfactory.impl.UrlCredentialsFactory#getCredentials(java.util.Dictionary)}.
      */
-    @Test(expected = MissingValueException.class)
+    @Test(groups = { UNIT }, expectedExceptions = MissingValueException.class)
     public void testGetCredentialsWithDictionaryMissingBaseUrlFail() {
         Properties props = new Properties();
         props.put(UrlCredentialsFactory.KEY_AUTH_TYPE, "none");
@@ -95,7 +97,7 @@ public class UrlCredentialsFactoryTest {
     /**
      * Test method for {@link org.apache.ace.connectionfactory.impl.UrlCredentialsFactory#getCredentials(java.util.Dictionary)}.
      */
-    @Test(expected = IllegalArgumentException.class)
+    @Test(groups = { UNIT }, expectedExceptions = IllegalArgumentException.class)
     public void testGetCredentialsWithNullDictionaryFail() {
         UrlCredentialsFactory.getCredentials(null);
     }
@@ -103,7 +105,7 @@ public class UrlCredentialsFactoryTest {
     /**
      * Test method for {@link org.apache.ace.connectionfactory.impl.UrlCredentialsFactory#getCredentials(java.util.Dictionary, java.lang.String)}.
      */
-    @Test(expected = IllegalArgumentException.class)
+    @Test(groups = { UNIT }, expectedExceptions = IllegalArgumentException.class)
     public void testGetCredentialsWithNullPrefixFail() {
         UrlCredentialsFactory.getCredentials(new Properties(), null);
     }
@@ -111,7 +113,7 @@ public class UrlCredentialsFactoryTest {
     /**
      * Test method for {@link org.apache.ace.connectionfactory.impl.UrlCredentialsFactory#getCredentials(java.util.Dictionary)}.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testGetCredentialsWithValidDictionaryOk() {
         Properties props = new Properties();
         props.put(UrlCredentialsFactory.KEY_AUTH_BASE_URL, "http://localhost:8080/");

Modified: ace/trunk/ace-connectionfactory/src/test/java/org/apache/ace/connectionfactory/impl/UrlCredentialsTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-connectionfactory/src/test/java/org/apache/ace/connectionfactory/impl/UrlCredentialsTest.java?rev=1329668&r1=1329667&r2=1329668&view=diff
==============================================================================
--- ace/trunk/ace-connectionfactory/src/test/java/org/apache/ace/connectionfactory/impl/UrlCredentialsTest.java (original)
+++ ace/trunk/ace-connectionfactory/src/test/java/org/apache/ace/connectionfactory/impl/UrlCredentialsTest.java Tue Apr 24 12:23:47 2012
@@ -18,12 +18,12 @@
  */
 package org.apache.ace.connectionfactory.impl;
 
-import static org.junit.Assert.*;
+import static org.apache.ace.test.utils.TestUtils.UNIT;
 
 import java.net.URL;
 
 import org.apache.ace.connectionfactory.impl.UrlCredentials.AuthType;
-import org.junit.Test;
+import org.testng.annotations.Test;
 
 /**
  * Test cases for {@link UrlCredentials}.
@@ -33,7 +33,7 @@ public class UrlCredentialsTest {
     /**
      * Test method for {@link org.apache.ace.connectionfactory.impl.UrlCredentials#UrlCredentials(java.net.URL)}.
      */
-    @Test(expected = IllegalArgumentException.class)
+    @Test(groups = { UNIT }, expectedExceptions = IllegalArgumentException.class)
     public void testUrlCredentialsNullURLFail() throws Exception {
         new UrlCredentials(null);
     }
@@ -41,7 +41,7 @@ public class UrlCredentialsTest {
     /**
      * Test method for {@link org.apache.ace.connectionfactory.impl.UrlCredentials#UrlCredentials(java.net.URL)}.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testUrlCredentialsURLOk() throws Exception {
         new UrlCredentials(new URL("http://localhost:8080/"));
     }
@@ -49,7 +49,7 @@ public class UrlCredentialsTest {
     /**
      * Test method for {@link org.apache.ace.connectionfactory.impl.UrlCredentials#UrlCredentials(org.apache.ace.connectionfactory.impl.UrlCredentials.AuthType, java.net.URL, java.lang.Object[])}.
      */
-    @Test(expected = IllegalArgumentException.class)
+    @Test(groups = { UNIT }, expectedExceptions = IllegalArgumentException.class)
     public void testUrlCredentialsNullTypeFail() throws Exception {
         new UrlCredentials(null, new URL("http://localhost:8080/"));
     }
@@ -57,7 +57,7 @@ public class UrlCredentialsTest {
     /**
      * Test method for {@link org.apache.ace.connectionfactory.impl.UrlCredentials#UrlCredentials(org.apache.ace.connectionfactory.impl.UrlCredentials.AuthType, java.net.URL, java.lang.Object[])}.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testUrlCredentialsTypeAndURLOk() throws Exception {
         new UrlCredentials(AuthType.NONE, new URL("http://localhost:8080/"));
     }
@@ -65,27 +65,27 @@ public class UrlCredentialsTest {
     /**
      * Test method for {@link org.apache.ace.connectionfactory.impl.UrlCredentials#matches(java.net.URL)}.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testMatchesNullURLOk() throws Exception {
         UrlCredentials creds = new UrlCredentials(AuthType.NONE, new URL("http://localhost:8080/"));
-        assertFalse(creds.matches(null));
+        assert creds.matches(null) == false : "Null URL should never match any credentials!";
     }
 
     /**
      * Test method for {@link org.apache.ace.connectionfactory.impl.UrlCredentials#matches(java.net.URL)}.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testMatchesValidURLOk() throws Exception {
         UrlCredentials creds = new UrlCredentials(AuthType.NONE, new URL("http://localhost:8080/"));
-        assertTrue(creds.matches(new URL("http://localhost:8080/obr")));
-        assertFalse(creds.matches(new URL("http://localhost:8080")));
-        assertFalse(creds.matches(new URL("http://localhost:8081/")));
+        assert creds.matches(new URL("http://localhost:8080/obr")) : "Base URL should match given URL!";
+        assert creds.matches(new URL("http://localhost:8080")) == false : "Base URL shouldn't match given URL!";
+        assert creds.matches(new URL("http://localhost:8081/")) == false : "Base URL shouldn't match given URL!";
     }
 
     /**
      * Test method for {@link org.apache.ace.connectionfactory.impl.UrlCredentials#getCredentials()}.
      */
-    @Test
+    @Test(groups = { UNIT })
     public void testGetCredentialsOk() throws Exception {
         UrlCredentials creds = new UrlCredentials(AuthType.NONE, new URL("http://localhost:8080/"));
         assertArrayEquals(new Object[0], creds.getCredentials());
@@ -99,4 +99,18 @@ public class UrlCredentialsTest {
         creds = new UrlCredentials(AuthType.NONE, new URL("http://localhost:8080/"), (Object) null);
         assertArrayEquals(new Object[] { null }, creds.getCredentials());
     }
+
+    /**
+     * Asserts that two given arrays are equal with respect to their content.
+     * 
+     * @param expected the expected array;
+     * @param given the given array to test.
+     */
+    private void assertArrayEquals(Object[] expected, Object[] given) {
+        assert expected != null && given != null : "Both arrays should never be null!";
+        assert expected.length == given.length : "Length mismatch!";
+        for (int i = 0; i < expected.length; i++) {
+            assert (expected[i] == given[i]) || (expected[i] != null && expected[i].equals(given[i])) : "Elements at index #" + i + " do not match!";
+        }
+    }
 }

Added: ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/authentication/AuthenticationTestBase.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/authentication/AuthenticationTestBase.java?rev=1329668&view=auto
==============================================================================
--- ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/authentication/AuthenticationTestBase.java (added)
+++ ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/authentication/AuthenticationTestBase.java Tue Apr 24 12:23:47 2012
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ace.it.authentication;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+
+import org.apache.ace.connectionfactory.ConnectionFactory;
+import org.apache.ace.it.IntegrationTestBase;
+import org.apache.ace.repository.Repository;
+import org.osgi.service.useradmin.UserAdmin;
+
+/**
+ * Provides a common base class for all authentication integration tests.
+ */
+public class AuthenticationTestBase extends IntegrationTestBase {
+
+    /**
+     * Imports a single user into the user repository.
+     * 
+     * @param userName the name of the user to import;
+     * @param password the password of the user to import.
+     * @throws Exception in case of exceptions during the import.
+     */
+    protected final void importSingleUser(Repository userRepository, String userName, String password) throws Exception {
+        ByteArrayInputStream bis = new ByteArrayInputStream((
+            "<roles>" +
+                "<user name=\"" + userName + "\">" +
+                "<properties><username>" + userName + "</username></properties>" +
+                "<credentials><password type=\"String\">" + password + "</password></credentials>" +
+                "</user>" +
+            "</roles>").getBytes());
+
+        assertTrue("Committing test user data failed!", userRepository.commit(bis, userRepository.getRange().getHigh()));
+    }
+
+    /**
+     * Waits for a HTTP URL to become 'available', will retry every 100 milliseconds until it is available or timeout
+     * has been exceeded. Available in this context means the specified status code is returned when accessing the URL.
+     *
+     * @param url HTTP URL that should be tested for availability.
+     * @param responseCode The response code to be expected on the specified URL when it is available.
+     * @param timeout Amount of milliseconds to keep trying to access the URL.
+     * @return True if the response of the URL has the specified status code within the specified timeout delay, false otherwise.
+     * @throws IllegalArgumentException If the specified URL does not use the HTTP protocol.
+     */
+    protected final boolean waitForURL(ConnectionFactory connectionFactory, URL url, int responseCode, int timeout) {
+        long deadline = System.currentTimeMillis() + timeout;
+        while (System.currentTimeMillis() < deadline) {
+            try {
+                URLConnection connection = connectionFactory.createConnection(url);
+
+                connection.connect();
+
+                if (connection instanceof HttpURLConnection) {
+                    int respCode = ((HttpURLConnection) connection).getResponseCode();
+                    if (respCode == responseCode) {
+                        return true;
+                    }
+                    else {
+                        System.err.println("Got response code " + respCode + " for " + url);
+                    }
+                }
+            } catch (ClassCastException cce) {
+                throw new IllegalArgumentException("Expected url to be an HTTP url, not: " + url.toString(), cce);
+            }
+            catch (IOException ioe) {
+                // retry
+            }
+            try {
+                Thread.sleep(100);
+            }
+            catch (InterruptedException ie) {
+                return false;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Waits until a user with a given name appears in the user admin.
+     * 
+     * @param userAdmin the user admin to use;
+     * @param userName the name of the user to wait for.
+     * @throws Exception in case of exceptions during the wait.
+     */
+    protected final void waitForUser(UserAdmin userAdmin, String userName) throws Exception {
+        int count = 0;
+        while ((userAdmin.getRole(userName) == null) && (count++ < 60)) {
+            Thread.sleep(100);
+        }
+        assertTrue("Failed to obtain user from userAdmin!", count != 60);
+    }
+}

Propchange: ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/authentication/AuthenticationTestBase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/authentication/LogAuthenticationTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/authentication/LogAuthenticationTest.java?rev=1329668&r1=1329667&r2=1329668&view=diff
==============================================================================
--- ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/authentication/LogAuthenticationTest.java (original)
+++ ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/authentication/LogAuthenticationTest.java Tue Apr 24 12:23:47 2012
@@ -25,7 +25,6 @@ import static org.ops4j.pax.exam.CoreOpt
 import static org.ops4j.pax.exam.CoreOptions.provision;
 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
 
-import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
@@ -40,7 +39,6 @@ import org.apache.ace.connectionfactory.
 import org.apache.ace.discovery.property.constants.DiscoveryConstants;
 import org.apache.ace.http.listener.constants.HttpConstants;
 import org.apache.ace.identification.property.constants.IdentificationConstants;
-import org.apache.ace.it.IntegrationTestBase;
 import org.apache.ace.it.Options.Ace;
 import org.apache.ace.it.Options.Felix;
 import org.apache.ace.it.Options.Knopflerfish;
@@ -52,11 +50,11 @@ import org.apache.ace.repository.Reposit
 import org.apache.ace.repository.impl.constants.RepositoryConstants;
 import org.apache.ace.server.log.store.LogStore;
 import org.apache.ace.test.constants.TestConstants;
-import org.apache.ace.test.utils.NetUtils;
 import org.apache.felix.dm.Component;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.container.def.options.CleanCachesOption;
 import org.ops4j.pax.exam.junit.Configuration;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
 import org.osgi.framework.Constants;
@@ -69,7 +67,7 @@ import org.osgi.service.useradmin.UserAd
  * replicated to the server.
  */
 @RunWith(JUnit4TestRunner.class)
-public class LogAuthenticationTest extends IntegrationTestBase {
+public class LogAuthenticationTest extends AuthenticationTestBase {
 
     private static final String AUDITLOG_ENDPOINT = "/auditlog";
 
@@ -90,6 +88,7 @@ public class LogAuthenticationTest exten
     public Option[] configuration() {
         return options(
             systemProperty("org.osgi.service.http.port").value("" + TestConstants.PORT),
+            new CleanCachesOption(),
             provision(
                 // Misc bundles...
                 Osgi.compendium(),
@@ -137,6 +136,30 @@ public class LogAuthenticationTest exten
         );
     }
 
+    @Override
+    public void setupTest() throws Exception {
+        super.setupTest();
+
+        String baseURL = "http://" + HOST + ":" + TestConstants.PORT;
+
+        URL testURL = new URL(baseURL.concat(AUDITLOG_ENDPOINT));
+        assertTrue("Failed to access auditlog in time!", waitForURL(m_connectionFactory, testURL, 401, 15000));
+
+        String userName = "d";
+        String password = "f";
+
+        importSingleUser(m_userRepository, userName, password);
+        waitForUser(m_userAdmin, userName);
+
+        configureFactory("org.apache.ace.connectionfactory", 
+            "authentication.baseURL", baseURL.concat(AUDITLOG_ENDPOINT), 
+            "authentication.type", "basic",
+            "authentication.user.name", userName,
+            "authentication.user.password", password);
+
+        assertTrue("Failed to access auditlog in time!", waitForURL(m_connectionFactory, testURL, 200, 15000));
+    }
+
     /**
      * Tests that accessing the log servlet with authentication works when given the right credentials.
      */
@@ -241,20 +264,6 @@ public class LogAuthenticationTest exten
             "authentication.enabled", "true");
         configureFactory("org.apache.ace.server.log.store.factory",
             "name", "auditlog");
-
-        URL testURL = new URL(baseURL.concat(AUDITLOG_ENDPOINT));
-        assertTrue("Failed to access auditlog in time!", NetUtils.waitForURL(testURL, 401, 15000));
-        
-        String userName = "d";
-        String password = "f";
-
-        importSingleUser(userName, password);
-
-        configureFactory("org.apache.ace.connectionfactory", 
-            "authentication.baseURL", baseURL.concat(AUDITLOG_ENDPOINT), 
-            "authentication.type", "basic",
-            "authentication.user.name", userName,
-            "authentication.user.password", password);
     }
 
     /**
@@ -306,29 +315,4 @@ public class LogAuthenticationTest exten
         }
         return result;
     }
-
-    /**
-     * Imports a single user into the user repository.
-     * 
-     * @param userName the name of the user to import;
-     * @param password the password of the user to import.
-     * @throws Exception in case of exceptions during the import.
-     */
-    private void importSingleUser(String userName, String password) throws Exception {
-        ByteArrayInputStream bis = new ByteArrayInputStream((
-            "<roles>" +
-                "<user name=\"" + userName + "\">" +
-                "<properties><username>" + userName + "</username></properties>" +
-                "<credentials><password type=\"String\">" + password + "</password></credentials>" +
-                "</user>" +
-            "</roles>").getBytes());
-
-        assertTrue("Committing test user data failed!", m_userRepository.commit(bis, m_userRepository.getRange().getHigh()));
-
-        int count = 0;
-        while ((m_userAdmin.getRole(userName) == null) && (count++ < 60)) {
-            Thread.sleep(100);
-        }
-        assertTrue("Failed to obtain user from userAdmin!", count != 60);
-    }
 }

Modified: ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/authentication/ObrAuthenticationTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/authentication/ObrAuthenticationTest.java?rev=1329668&r1=1329667&r2=1329668&view=diff
==============================================================================
--- ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/authentication/ObrAuthenticationTest.java (original)
+++ ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/authentication/ObrAuthenticationTest.java Tue Apr 24 12:23:47 2012
@@ -27,7 +27,6 @@ import static org.ops4j.pax.exam.CoreOpt
 import static org.ops4j.pax.exam.CoreOptions.provision;
 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
 
-import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -41,7 +40,6 @@ import org.apache.ace.client.repository.
 import org.apache.ace.client.repository.helper.bundle.BundleHelper;
 import org.apache.ace.client.repository.repository.ArtifactRepository;
 import org.apache.ace.connectionfactory.ConnectionFactory;
-import org.apache.ace.it.IntegrationTestBase;
 import org.apache.ace.it.Options.Ace;
 import org.apache.ace.it.Options.Felix;
 import org.apache.ace.it.Options.Knopflerfish;
@@ -54,11 +52,10 @@ import org.apache.ace.test.utils.FileUti
 import org.apache.ace.test.utils.NetUtils;
 import org.apache.felix.dm.Component;
 import org.junit.After;
-import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.container.def.options.VMOption;
+import org.ops4j.pax.exam.container.def.options.CleanCachesOption;
 import org.ops4j.pax.exam.junit.Configuration;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
 import org.osgi.framework.Constants;
@@ -70,7 +67,7 @@ import org.osgi.service.useradmin.UserAd
  * rest of ACE has to remain function correctly.
  */
 @RunWith(JUnit4TestRunner.class)
-public class ObrAuthenticationTest extends IntegrationTestBase {
+public class ObrAuthenticationTest extends AuthenticationTestBase {
     
     private volatile String m_endpoint;
     private volatile File m_storeLocation;
@@ -90,7 +87,7 @@ public class ObrAuthenticationTest exten
     public Option[] configuration() {
         return options(
             systemProperty("org.osgi.service.http.port").value("" + TestConstants.PORT),
-            new VMOption("-ea"),
+            new CleanCachesOption(),
             provision(
                 // Misc bundles...
                 Osgi.compendium(),
@@ -129,19 +126,37 @@ public class ObrAuthenticationTest exten
         );
     }
 
-    /**
-     * Sets up of the test case.
-     * 
-     * @throws java.lang.Exception not part of this test case.
-     */
-    @Before
-    public void setUp() throws Exception {
+    @Override
+    public void setupTest() throws Exception {
         m_endpoint = "/obr";
-
+        
         String tmpDir = System.getProperty("java.io.tmpdir");
         m_storeLocation = new File(tmpDir, "store");
         m_storeLocation.delete();
         m_storeLocation.mkdirs();
+        
+        super.setupTest();
+
+        String userName = "d";
+        String password = "f";
+
+        importSingleUser(m_userRepository, userName, password);
+        waitForUser(m_userAdmin, userName);
+
+        URL obrURL = new URL("http://localhost:" + TestConstants.PORT + m_endpoint + "/");
+        m_artifactRepository.setObrBase(obrURL);
+
+        URL testURL = new URL(obrURL, "repository.xml");
+
+        assertTrue("Failed to access OBR in time!", waitForURL(m_connectionFactory, testURL, 401, 15000));
+
+        m_authConfigPID = configureFactory("org.apache.ace.connectionfactory", 
+                "authentication.baseURL", obrURL.toExternalForm(), 
+                "authentication.type", "basic",
+                "authentication.user.name", userName,
+                "authentication.user.password", password);
+
+        assertTrue("Failed to access auditlog in time!", waitForURL(m_connectionFactory, testURL, 200, 15000));
     }
 
     /**
@@ -301,25 +316,6 @@ public class ObrAuthenticationTest exten
         configure("org.apache.ace.obr.storage.file", 
             "OBRInstance", "singleOBRStore",
             OBRFileStoreConstants.FILE_LOCATION_KEY, fileLocation);
-
-        String userName = "d";
-        String password = "f";
-
-        importSingleUser(userName, password);
-
-        URL obrURL = new URL("http://localhost:" + TestConstants.PORT + m_endpoint + "/");
-
-        m_authConfigPID = configureFactory("org.apache.ace.connectionfactory", 
-                "authentication.baseURL", obrURL.toExternalForm(), 
-                "authentication.type", "basic",
-                "authentication.user.name", userName,
-                "authentication.user.password", password);
-
-        URL testURL = new URL(obrURL, "repository.xml");
-
-        assertTrue("Failed to access OBR in time!", NetUtils.waitForURL(testURL, 401, 15000));
-        
-        m_artifactRepository.setObrBase(obrURL);
     }
 
     /**
@@ -338,30 +334,5 @@ public class ObrAuthenticationTest exten
                     .setService(Repository.class, "(&(" + RepositoryConstants.REPOSITORY_NAME + "=users)(" + RepositoryConstants.REPOSITORY_CUSTOMER + "=apache))")
                     .setRequired(true))
         };
-    }           
-
-    /**
-     * Imports a single user into the user repository.
-     * 
-     * @param userName the name of the user to import;
-     * @param password the password of the user to import.
-     * @throws Exception in case of exceptions during the import.
-     */
-    private void importSingleUser(String userName, String password) throws Exception {
-        ByteArrayInputStream bis = new ByteArrayInputStream((
-            "<roles>" +
-                "<user name=\"" + userName + "\">" +
-                "<properties><username>" + userName + "</username></properties>" +
-                "<credentials><password type=\"String\">" + password + "</password></credentials>" +
-                "</user>" +
-            "</roles>").getBytes());
-
-        assertTrue("Committing test user data failed!", m_userRepository.commit(bis, m_userRepository.getRange().getHigh()));
-
-        int count = 0;
-        while ((m_userAdmin.getRole(userName) == null) && (count++ < 60)) {
-            Thread.sleep(100);
-        }
-        assertTrue("Failed to obtain user from userAdmin!", count != 60);
     }
 }

Modified: ace/trunk/pom/pom.xml
URL: http://svn.apache.org/viewvc/ace/trunk/pom/pom.xml?rev=1329668&r1=1329667&r2=1329668&view=diff
==============================================================================
--- ace/trunk/pom/pom.xml (original)
+++ ace/trunk/pom/pom.xml Tue Apr 24 12:23:47 2012
@@ -134,7 +134,7 @@
         <deployment.providesresourceprocessor />
         <sourceReleaseAssemblyDescriptor>source-release-zip-tar</sourceReleaseAssemblyDescriptor>
         <commons-collections.version>3.2.1</commons-collections.version>
-        <commons-codec.version>1.5</commons-codec.version>
+        <commons-codec.version>1.4</commons-codec.version>
         <commons-lang.version>2.4</commons-lang.version>
         <commons-logging.version>1.1.1</commons-logging.version>
         <commons-io.version>2.0.1</commons-io.version>



Mime
View raw message