directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 20436 - in incubator/directory/rms/trunk/jdbc: . src/java/org/apache/rms/jdbc/utils src/test/org/apache/rms/jdbc src/test/org/apache/rms/jdbc/testutils
Date Tue, 25 May 2004 17:53:02 GMT
Author: akarasulu
Date: Tue May 25 10:53:01 2004
New Revision: 20436

Added:
   incubator/directory/rms/trunk/jdbc/src/test/org/apache/rms/jdbc/testutils/
   incubator/directory/rms/trunk/jdbc/src/test/org/apache/rms/jdbc/testutils/TestCaseProperties.java
  (contents, props changed)
Modified:
   incubator/directory/rms/trunk/jdbc/project.properties
   incubator/directory/rms/trunk/jdbc/src/java/org/apache/rms/jdbc/utils/PropertiesDataSource.java
   incubator/directory/rms/trunk/jdbc/src/test/org/apache/rms/jdbc/JdbcApplicationFactoryTest.java
   incubator/directory/rms/trunk/jdbc/src/test/org/apache/rms/jdbc/JdbcPermFactoryTest.java
   incubator/directory/rms/trunk/jdbc/src/test/org/apache/rms/jdbc/JdbcRoleFactoryTest.java
Log:
Commit changes ...
 
 o created test case base class that loads first the build.properties file 
   from the user's home directory then merges (possibly overriding) values
   from the project.properties in the basedir
 o all test cases now derive from this test case with properties
 o all test cases check for the fail.without.db property, if defined
   and set to true then the tests fail, otherwise if undefined or set
   to anything other than 'true', '1', 'yes' or 'on' the tests pass
   when the DB is not found with a warning to the console
 o added warning about using the PropertiesDataDource for only toy apps or tests



Modified: incubator/directory/rms/trunk/jdbc/project.properties
==============================================================================
--- incubator/directory/rms/trunk/jdbc/project.properties	(original)
+++ incubator/directory/rms/trunk/jdbc/project.properties	Tue May 25 10:53:01 2004
@@ -6,3 +6,6 @@
 maven.repo.central.directory=/www/cvs.apache.org/repository
 maven.remote.group=apcvs
 
+# Uncomment this line to make the tests fail when a db is not present
+# this is suppressed by defualt to allow the compile to succeed.
+#fail.without.db=true

Modified: incubator/directory/rms/trunk/jdbc/src/java/org/apache/rms/jdbc/utils/PropertiesDataSource.java
==============================================================================
--- incubator/directory/rms/trunk/jdbc/src/java/org/apache/rms/jdbc/utils/PropertiesDataSource.java
(original)
+++ incubator/directory/rms/trunk/jdbc/src/java/org/apache/rms/jdbc/utils/PropertiesDataSource.java
Tue May 25 10:53:01 2004
@@ -69,8 +69,12 @@
      */
     public PropertiesDataSource()
     {
-        this( new File( System.getProperty( "user.home" ), 
+        this( new File( System.getProperty( "user.home" ),
                         "build.properties" ) ) ;
+
+        System.err.println( "+-----------------------------+" ) ;
+        System.err.println( "|  FOR PROTOTYPING USE ONLY!  |" ) ;
+        System.err.println( "+-----------------------------+" ) ;
     }
     
 

Modified: incubator/directory/rms/trunk/jdbc/src/test/org/apache/rms/jdbc/JdbcApplicationFactoryTest.java
==============================================================================
--- incubator/directory/rms/trunk/jdbc/src/test/org/apache/rms/jdbc/JdbcApplicationFactoryTest.java
(original)
+++ incubator/directory/rms/trunk/jdbc/src/test/org/apache/rms/jdbc/JdbcApplicationFactoryTest.java
Tue May 25 10:53:01 2004
@@ -17,14 +17,13 @@
 package org.apache.rms.jdbc ;
 
 
-import junit.framework.TestCase ;
-
-
 import java.util.Iterator ;
+import java.sql.Connection ;
 import javax.sql.DataSource ;
 
 import org.apache.rms.Application ;
 import org.apache.rms.jdbc.utils.PropertiesDataSource ;
+import org.apache.rms.jdbc.testutils.TestCaseProperties;
 
 
 /**
@@ -33,11 +32,11 @@
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class JdbcApplicationFactoryTest extends TestCase
+public class JdbcApplicationFactoryTest extends TestCaseProperties
 {
     private DataSource m_ds ;
 
-    
+
     public static void main( String[] args )
     {
         junit.textui.TestRunner.run( JdbcApplicationFactoryTest.class ) ;
@@ -50,6 +49,8 @@
     protected void setUp() throws Exception
     {
         super.setUp() ;
+
+        getProperty( "fail.without.db" ) ;
     }
 
     
@@ -66,15 +67,53 @@
      * Constructor for JdbcApplicationFactoryTest.
      * @param arg0
      */
-    public JdbcApplicationFactoryTest( String arg0 )
+    public JdbcApplicationFactoryTest( String arg0 ) throws Exception
     {
         super( arg0 ) ;
-        m_ds = new PropertiesDataSource() ;
+
+        try
+        {
+            m_ds = new PropertiesDataSource() ;
+            Connection conn = m_ds.getConnection() ;
+            if ( conn == null )
+            {
+                m_ds = null ;
+            }
+        }
+        catch( Exception e )
+        {
+            m_ds = null ;
+
+            String prop = getProperty( "fail.without.db", "false" ) ;
+            if ( prop.equalsIgnoreCase( "true" ) ||
+                    prop.equalsIgnoreCase( "on" ) ||
+                    prop.equalsIgnoreCase( "yes" ) ||
+                    prop.equalsIgnoreCase( "1" ) )
+            {
+                System.err.println( "+-----------------------------+" ) ;
+                System.err.println( "|   TEST FAILED WITHOUT DB!   |" ) ;
+                System.err.println( "+-----------------------------+" ) ;
+                throw e ;
+            }
+            else
+            {
+                System.err.println( "+-----------------------------+" ) ;
+                System.err.println( "| DB NOT FOUND! TEST ABORTED! |" ) ;
+                System.err.println( "+-----------------------------+" ) ;
+            }
+        }
     }
-    
+
+
 
     public void testJdbcApplicationFactory() throws Exception
     {
+        if ( m_ds == null )
+        {
+            System.err.println( "Aborted test due to non-existant test DB" ) ;
+            return ;
+        }
+
         JdbcApplicationFactory l_factory = new JdbcApplicationFactory( m_ds ) ;
         assertNotNull( l_factory ) ;
     }
@@ -82,6 +121,12 @@
     
     public void testGetApplication() throws Exception
     {
+        if ( m_ds == null )
+        {
+            System.err.println( "Aborted test due to non-existant test DB" ) ;
+            return ;
+        }
+
         JdbcApplicationFactory l_factory = new JdbcApplicationFactory( m_ds ) ;
         Application l_app = l_factory.getApplication( "app1" ) ;
         System.out.println( l_app ) ;
@@ -92,6 +137,12 @@
     
     public void testGetApplicationNames() throws Exception
     {
+        if ( m_ds == null )
+        {
+            System.err.println( "Aborted test due to non-existant test DB" ) ;
+            return ;
+        }
+
         JdbcApplicationFactory l_factory = new JdbcApplicationFactory( m_ds ) ;
         Iterator l_list = l_factory.getApplicationNames() ;
         

Modified: incubator/directory/rms/trunk/jdbc/src/test/org/apache/rms/jdbc/JdbcPermFactoryTest.java
==============================================================================
--- incubator/directory/rms/trunk/jdbc/src/test/org/apache/rms/jdbc/JdbcPermFactoryTest.java
(original)
+++ incubator/directory/rms/trunk/jdbc/src/test/org/apache/rms/jdbc/JdbcPermFactoryTest.java
Tue May 25 10:53:01 2004
@@ -18,14 +18,13 @@
 
 
 import java.util.List;
+import java.sql.Connection;
 
 import javax.sql.DataSource ;
 
-
-import junit.framework.TestCase ;
-
 import org.apache.rms.BitPermission ;
 import org.apache.rms.jdbc.utils.PropertiesDataSource ;
+import org.apache.rms.jdbc.testutils.TestCaseProperties;
 
 
 /**
@@ -34,15 +33,46 @@
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class JdbcPermFactoryTest extends TestCase
+public class JdbcPermFactoryTest extends TestCaseProperties
 {
     private DataSource m_ds = null ;
 
     
-    public JdbcPermFactoryTest( String name )
+    public JdbcPermFactoryTest( String name ) throws Exception
     {
         super( name ) ;
-        m_ds = new PropertiesDataSource() ;
+        try
+        {
+            m_ds = new PropertiesDataSource() ;
+            Connection conn = m_ds.getConnection() ;
+            if ( conn == null )
+            {
+                m_ds = null ;
+            }
+        }
+        catch( Exception e )
+        {
+            m_ds = null ;
+            m_ds = null ;
+
+            String prop = getProperty( "fail.without.db", "false" ) ;
+            if ( prop.equalsIgnoreCase( "true" ) ||
+                    prop.equalsIgnoreCase( "on" ) ||
+                    prop.equalsIgnoreCase( "yes" ) ||
+                    prop.equalsIgnoreCase( "1" ) )
+            {
+                System.err.println( "+-----------------------------+" ) ;
+                System.err.println( "|   TEST FAILED WITHOUT DB!   |" ) ;
+                System.err.println( "+-----------------------------+" ) ;
+                throw e ;
+            }
+            else
+            {
+                System.err.println( "+-----------------------------+" ) ;
+                System.err.println( "| DB NOT FOUND! TEST ABORTED! |" ) ;
+                System.err.println( "+-----------------------------+" ) ;
+            }
+        }
     }
     
     
@@ -72,6 +102,12 @@
     
     public void testJdbcPermFactory()
     {
+        if ( m_ds == null )
+        {
+            System.err.println( "Aborted test due to non-existant test DB" ) ;
+            return ;
+        }
+
         JdbcPermFactory l_factory = new JdbcPermFactory( m_ds ) ;
         assertNotNull( l_factory ) ;
     }
@@ -79,6 +115,12 @@
     
     public void testGetPermissionsMap() throws Exception
     {
+        if ( m_ds == null )
+        {
+            System.err.println( "Aborted test due to non-existant test DB" ) ;
+            return ;
+        }
+
         JdbcPermFactory l_factory = new JdbcPermFactory( m_ds ) ;
         List l_mapping = l_factory.getPermissionsMap( "app1" ) ;
         assertNotNull( l_mapping ) ;
@@ -95,6 +137,12 @@
     
     public void testCreateDelete() throws Exception
     {
+        if ( m_ds == null )
+        {
+            System.err.println( "Aborted test due to non-existant test DB" ) ;
+            return ;
+        }
+
         JdbcPermFactory l_factory = new JdbcPermFactory( m_ds ) ;
         for( int ii = 0; ii < 16; ii++ )
         {

Modified: incubator/directory/rms/trunk/jdbc/src/test/org/apache/rms/jdbc/JdbcRoleFactoryTest.java
==============================================================================
--- incubator/directory/rms/trunk/jdbc/src/test/org/apache/rms/jdbc/JdbcRoleFactoryTest.java
(original)
+++ incubator/directory/rms/trunk/jdbc/src/test/org/apache/rms/jdbc/JdbcRoleFactoryTest.java
Tue May 25 10:53:01 2004
@@ -17,15 +17,14 @@
 package org.apache.rms.jdbc ;
 
 import java.util.Iterator ;
+import java.sql.Connection;
 
 import javax.sql.DataSource ;
 
-
-import junit.framework.TestCase ;
-
 import org.apache.rms.Role ;
 import org.apache.rms.Application ;
 import org.apache.rms.jdbc.utils.PropertiesDataSource ;
+import org.apache.rms.jdbc.testutils.TestCaseProperties;
 
 
 /**
@@ -34,7 +33,7 @@
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class JdbcRoleFactoryTest extends TestCase
+public class JdbcRoleFactoryTest extends TestCaseProperties
 {
     private DataSource m_ds = null ;
 
@@ -67,15 +66,55 @@
      * Constructor for JdbcRoleFactoryTest.
      * @param arg0
      */
-    public JdbcRoleFactoryTest(String arg0)
+    public JdbcRoleFactoryTest(String arg0) throws Exception
     {
         super( arg0 ) ;
-        m_ds = new PropertiesDataSource() ;
+
+        try
+        {
+            m_ds = new PropertiesDataSource() ;
+            Connection conn = m_ds.getConnection() ;
+            if ( conn == null )
+            {
+                m_ds = null ;
+                throw new Exception( "Datasource returns null connections." ) ;
+            }
+        }
+        catch( Exception e )
+        {
+            m_ds = null ;
+
+            m_ds = null ;
+
+            String prop = getProperty( "fail.without.db", "false" ) ;
+            if ( prop.equalsIgnoreCase( "true" ) ||
+                    prop.equalsIgnoreCase( "on" ) ||
+                    prop.equalsIgnoreCase( "yes" ) ||
+                    prop.equalsIgnoreCase( "1" ) )
+            {
+                System.err.println( "+-----------------------------+" ) ;
+                System.err.println( "|   TEST FAILED WITHOUT DB!   |" ) ;
+                System.err.println( "+-----------------------------+" ) ;
+                throw e ;
+            }
+            else
+            {
+                System.err.println( "+-----------------------------+" ) ;
+                System.err.println( "| DB NOT FOUND! TEST ABORTED! |" ) ;
+                System.err.println( "+-----------------------------+" ) ;
+            }
+        }
     }
 
     
     public void testJdbcRoleFactory() throws Exception
     {
+        if ( m_ds == null )
+        {
+            System.err.println( "Aborted test due to non-existant test DB" ) ;
+            return ;
+        }
+
         JdbcRoleFactory l_factory = new JdbcRoleFactory( m_ds ) ;
         assertNotNull( l_factory ) ;
     }
@@ -83,6 +122,12 @@
     
     public void testGetRole() throws Exception
     {
+        if ( m_ds == null )
+        {
+            System.err.println( "Aborted test due to non-existant test DB" ) ;
+            return ;
+        }
+
         JdbcRoleFactory l_factory = new JdbcRoleFactory( m_ds ) ;
         JdbcApplicationFactory l_factory2 = new JdbcApplicationFactory( m_ds ) ;
         Application l_app = l_factory2.getApplication( "app1" ) ;
@@ -93,6 +138,12 @@
     
     public void testGetRoleNames() throws Exception
     {
+        if ( m_ds == null )
+        {
+            System.err.println( "Aborted test due to non-existant test DB" ) ;
+            return ;
+        }
+
         JdbcRoleFactory l_factory = new JdbcRoleFactory( m_ds ) ;
         Iterator l_list = l_factory.getRoleNames( "app1" ) ;
         
@@ -106,6 +157,12 @@
     
     public void testGetRoles() throws Exception
     {
+        if ( m_ds == null )
+        {
+            System.err.println( "Aborted test due to non-existant test DB" ) ;
+            return ;
+        }
+
         JdbcRoleFactory l_factory = new JdbcRoleFactory( m_ds ) ;
         JdbcApplicationFactory l_factory2 = new JdbcApplicationFactory( m_ds ) ;
         Application l_app = l_factory2.getApplication( "app1" ) ;

Added: incubator/directory/rms/trunk/jdbc/src/test/org/apache/rms/jdbc/testutils/TestCaseProperties.java
==============================================================================
--- (empty file)
+++ incubator/directory/rms/trunk/jdbc/src/test/org/apache/rms/jdbc/testutils/TestCaseProperties.java
Tue May 25 10:53:01 2004
@@ -0,0 +1,113 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.rms.jdbc.testutils ;
+
+
+import junit.framework.TestCase ;
+
+import java.util.Properties ;
+
+import java.io.File ;
+import java.io.FileInputStream ;
+
+
+/**
+ * A base test class used to load settings for the jdbc provider tests.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class TestCaseProperties extends TestCase
+{
+    /** test properties pulled in from various resources */
+    private Properties testprops = new Properties() ;
+
+
+    public TestCaseProperties() throws Exception
+    {
+        super() ;
+        loadProperties() ;
+    }
+
+
+    public TestCaseProperties( String s ) throws Exception
+    {
+        super( s ) ;
+        loadProperties() ;
+    }
+
+
+    void loadProperties() throws Exception
+    {
+        File propfile = null ;
+        String basedir = null ;
+        String userhome = null ;
+        FileInputStream in = null ;
+
+        // load the user's build.properties first in their home directory
+        userhome = System.getProperty( "user.home" ) ;
+        propfile = new File( userhome, "build.properties" ) ;
+
+        if ( propfile.exists() && propfile.canRead() )
+        {
+            in = new FileInputStream( propfile ) ;
+            testprops.load( in ) ;
+        }
+
+        // Load the project.properties file
+        basedir = System.getProperty( "basedir", "." ) ;
+
+        // ugly hardcoded fix for running inside an IDE with rms at toplevel
+        if ( ( new File( basedir, "jdbc" ) ).exists() )
+        {
+            basedir = System.getProperty( "basedir", "jdbc" ) ;
+        }
+        propfile = new File( basedir, "project.properties" ) ;
+        if ( propfile.exists() && propfile.canRead() )
+        {
+            in = new FileInputStream( propfile ) ;
+            testprops.load( in ) ;
+        }
+    }
+
+
+    /**
+     * Gets a property key for this test case.
+     *
+     * @return the test cases property value
+     */
+    public String getProperty( String key )
+    {
+        return testprops.getProperty( key ) ;
+    }
+
+
+    /**
+     * Gets a property key for this test case or the default.
+     *
+     * @return the test cases property value or the default value if null
+     */
+    public String getProperty( String key, String defaultValue )
+    {
+        if ( testprops.getProperty( key ) != null )
+        {
+            return testprops.getProperty( key ) ;
+        }
+
+        return defaultValue ;
+    }
+}

Mime
View raw message