You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by ja...@apache.org on 2009/10/27 21:09:45 UTC

svn commit: r830324 - in /incubator/jspwiki/trunk: ./ src/java/org/apache/wiki/ tests/java/org/apache/wiki/ tests/java/org/apache/wiki/auth/authorize/ tests/java/org/apache/wiki/auth/user/

Author: jalkanen
Date: Tue Oct 27 20:09:44 2009
New Revision: 830324

URL: http://svn.apache.org/viewvc?rev=830324&view=rev
Log:
Added new test base class and NotExecutableException.
Added code to Ldap*Test to throw a NotExecutableException if it can't find an LDAP server.

Added:
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/JSPWikiTestBase.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/JSPWikiTestResult.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/NotExecutableException.java
Modified:
    incubator/jspwiki/trunk/ChangeLog
    incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/auth/authorize/LdapAuthorizerTest.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/auth/user/LdapUserDatabaseTest.java

Modified: incubator/jspwiki/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ChangeLog?rev=830324&r1=830323&r2=830324&view=diff
==============================================================================
--- incubator/jspwiki/trunk/ChangeLog (original)
+++ incubator/jspwiki/trunk/ChangeLog Tue Oct 27 20:09:44 2009
@@ -1,3 +1,13 @@
+2009-10-26 Janne Jalkanen <ja...@apache.org>
+
+        * 3.0.0-svn-174
+
+        * Added code to test harness to check for existence of LDAP server
+        before trying to execute tests.
+        
+        * Introduced JSPWikiTestBase which testcases should extend if
+        they wish to throw NotExecutableExceptions.
+        
 2009-10-26 Andrew Jaquith <ajaquith AT apache DOT org>
 
         * 3.0.0-svn-173

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java?rev=830324&r1=830323&r2=830324&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java Tue Oct 27 20:09:44 2009
@@ -77,7 +77,7 @@
      *  <p>
      *  If the build identifier is empty, it is not added.
      */
-    public static final String     BUILD         = "173";
+    public static final String     BUILD         = "174";
 
     /**
      *  This is the generic version string you should use

Added: incubator/jspwiki/trunk/tests/java/org/apache/wiki/JSPWikiTestBase.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/JSPWikiTestBase.java?rev=830324&view=auto
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/JSPWikiTestBase.java (added)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/JSPWikiTestBase.java Tue Oct 27 20:09:44 2009
@@ -0,0 +1,20 @@
+package org.apache.wiki;
+
+import junit.framework.TestCase;
+import junit.framework.TestResult;
+
+/**
+ *  Provides a base class for all JSPWiki tests.  Any tests which want to throw a NotExecutableException
+ *  should extend from this class.
+ *  <p>
+ *  Technique for ignoring non-executable tests picked from Apache Jackrabbit - thanks heaps guys!
+ */
+public class JSPWikiTestBase extends TestCase
+{
+    public void run(TestResult testResult) 
+    {
+        super.run(new JSPWikiTestResult(testResult));
+    }
+    
+    
+}

Added: incubator/jspwiki/trunk/tests/java/org/apache/wiki/JSPWikiTestResult.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/JSPWikiTestResult.java?rev=830324&view=auto
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/JSPWikiTestResult.java (added)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/JSPWikiTestResult.java Tue Oct 27 20:09:44 2009
@@ -0,0 +1,106 @@
+package org.apache.wiki;
+
+import java.util.Enumeration;
+
+import junit.framework.*;
+
+/**
+ *  Provides a facade for TestResult which ignores all NotExecutableExceptions.
+ */
+public class JSPWikiTestResult extends TestResult
+{
+    private TestResult m_result;
+    
+    public JSPWikiTestResult( TestResult testResult )
+    {
+        m_result = testResult;
+    }
+
+    @Override
+    public synchronized void addError( Test arg0, Throwable arg1 )
+    {
+        if( arg1 instanceof NotExecutableException )
+            return;
+        
+        m_result.addError( arg0, arg1 );
+    }
+
+    @Override
+    public synchronized void addFailure( Test arg0, AssertionFailedError arg1 )
+    {
+        m_result.addFailure( arg0, arg1 );
+    }
+
+    @Override
+    public synchronized void addListener( TestListener listener )
+    {
+        m_result.addListener( listener );
+    }
+
+    @Override
+    public void endTest( Test arg0 )
+    {
+        m_result.endTest( arg0 );
+    }
+
+    @Override
+    public synchronized int errorCount()
+    {
+        return m_result.errorCount();
+    }
+
+    @Override
+    public synchronized Enumeration errors()
+    {
+        return m_result.errors();
+    }
+
+    @Override
+    public synchronized int failureCount()
+    {
+        return m_result.failureCount();
+    }
+
+    @Override
+    public synchronized Enumeration failures()
+    {
+        return m_result.failures();
+    }
+
+    @Override
+    public synchronized void removeListener( TestListener listener )
+    {
+        m_result.removeListener( listener );
+    }
+
+    @Override
+    public synchronized int runCount()
+    {
+        return m_result.runCount();
+    }
+
+    @Override
+    public synchronized boolean shouldStop()
+    {
+        return m_result.shouldStop();
+    }
+
+    @Override
+    public void startTest( Test arg0 )
+    {
+        m_result.startTest( arg0 );
+    }
+
+    @Override
+    public synchronized void stop()
+    {
+        m_result.stop();
+    }
+
+    @Override
+    public synchronized boolean wasSuccessful()
+    {
+        return m_result.wasSuccessful();
+    }
+
+}

Added: incubator/jspwiki/trunk/tests/java/org/apache/wiki/NotExecutableException.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/NotExecutableException.java?rev=830324&view=auto
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/NotExecutableException.java (added)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/NotExecutableException.java Tue Oct 27 20:09:44 2009
@@ -0,0 +1,9 @@
+package org.apache.wiki;
+
+/**
+ *  Throws this exception when your test should not be executed.
+ */
+public class NotExecutableException extends Exception
+{
+  
+}

Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/auth/authorize/LdapAuthorizerTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/auth/authorize/LdapAuthorizerTest.java?rev=830324&r1=830323&r2=830324&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/auth/authorize/LdapAuthorizerTest.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/auth/authorize/LdapAuthorizerTest.java Tue Oct 27 20:09:44 2009
@@ -20,7 +20,12 @@
  */
 package org.apache.wiki.auth.authorize;
 
-import java.io.*;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.net.ConnectException;
+import java.net.InetSocketAddress;
+import java.net.Socket;
 import java.security.Principal;
 import java.util.HashMap;
 import java.util.Map;
@@ -28,8 +33,8 @@
 
 import javax.security.auth.login.LoginException;
 
-import junit.framework.TestCase;
-
+import org.apache.wiki.JSPWikiTestBase;
+import org.apache.wiki.NotExecutableException;
 import org.apache.wiki.TestEngine;
 import org.apache.wiki.WikiSession;
 import org.apache.wiki.auth.*;
@@ -39,12 +44,31 @@
 
 /**
  */
-public class LdapAuthorizerTest extends TestCase
+public class LdapAuthorizerTest extends JSPWikiTestBase
 {
     private TestEngine m_engine;
 
+    private static final String LDAP_HOST = "127.0.0.1";
+    private static final int    LDAP_PORT = 4890;
+    
     protected void setUp() throws Exception
     {
+        //
+        //  First check if the LDAP server exists.
+        //
+        
+        try
+        {
+            Socket socket = new Socket( LDAP_HOST, LDAP_PORT );
+            socket.connect( new InetSocketAddress(0) );
+            socket.close();
+        }
+        catch( ConnectException e )
+        {
+            // OK, so there is no LDAP server existing.
+            throw new NotExecutableException();
+        }
+        
         // Create the TestEngine properties
         Properties props = new Properties();
         props.load( TestEngine.findTestProperties() );
@@ -52,7 +76,7 @@
         // Set the LoginModule options
         props.put( UserManager.PROP_READ_ONLY_PROFILES, "true" );
         props.put( AuthenticationManager.PROP_LOGIN_MODULE, UserDatabaseLoginModule.class.getCanonicalName() );
-        props.put( LdapConfig.PROPERTY_CONNECTION_URL, "ldap://127.0.0.1:4890" );
+        props.put( LdapConfig.PROPERTY_CONNECTION_URL, "ldap://"+LDAP_HOST+":"+LDAP_PORT );
         props.put( LdapConfig.PROPERTY_LOGIN_ID_PATTERN, "uid={0},ou=people,dc=jspwiki,dc=org" );
         props.put( LdapConfig.PROPERTY_USER_BASE, "dc=jspwiki,dc=org" );
         props.put( LdapConfig.PROPERTY_USER_FILTER, "(&(objectClass=inetOrgPerson)(uid={0}))" );

Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/auth/user/LdapUserDatabaseTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/auth/user/LdapUserDatabaseTest.java?rev=830324&r1=830323&r2=830324&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/auth/user/LdapUserDatabaseTest.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/auth/user/LdapUserDatabaseTest.java Tue Oct 27 20:09:44 2009
@@ -20,20 +20,25 @@
  */
 package org.apache.wiki.auth.user;
 
+import java.net.ConnectException;
+import java.net.InetSocketAddress;
+import java.net.Socket;
 import java.security.Principal;
 import java.util.Properties;
 
-import junit.framework.TestCase;
-
 import org.apache.commons.lang.ArrayUtils;
+import org.apache.wiki.JSPWikiTestBase;
+import org.apache.wiki.NotExecutableException;
 import org.apache.wiki.TestEngine;
 import org.apache.wiki.auth.*;
 
 /**
  */
-public class LdapUserDatabaseTest extends TestCase
+public class LdapUserDatabaseTest extends JSPWikiTestBase
 {
-
+    private static final String LDAP_HOST = "127.0.0.1";
+    private static final int    LDAP_PORT = 4890;
+    
     private LdapUserDatabase m_db;
 
     private TestEngine m_engine = null;
@@ -44,10 +49,27 @@
     protected void setUp() throws Exception
     {
         super.setUp();
+        
+        //
+        //  First check if the LDAP server exists.
+        //
+        
+        try
+        {
+            Socket socket = new Socket( LDAP_HOST, LDAP_PORT );
+            socket.connect( new InetSocketAddress(0) );
+            socket.close();
+        }
+        catch( ConnectException e )
+        {
+            // OK, so there is no LDAP server existing.
+            throw new NotExecutableException();
+        }
+
         Properties props = new Properties();
         props.load( TestEngine.findTestProperties() );
         props.put( UserManager.PROP_DATABASE, "org.apache.wiki.auth.user.LdapUserDatabase" );
-        props.put( LdapConfig.PROPERTY_CONNECTION_URL, "ldap://127.0.0.1:4890/" );
+        props.put( LdapConfig.PROPERTY_CONNECTION_URL, "ldap://"+LDAP_HOST+":"+LDAP_PORT );
         props.put( LdapConfig.PROPERTY_USER_BASE, "ou=people,dc=jspwiki,dc=org" );
         props.put( LdapConfig.PROPERTY_AUTHENTICATION, "simple" );
         props.put( LdapConfig.PROPERTY_LOGIN_ID_PATTERN, "uid={0},ou=people,dc=jspwiki,dc=org" );