db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r373382 - /db/ddlutils/trunk/src/test/org/apache/ddlutils/TestDatabaseWriterBase.java
Date Sun, 29 Jan 2006 23:05:11 GMT
Author: tomdz
Date: Sun Jan 29 15:05:03 2006
New Revision: 373382

URL: http://svn.apache.org/viewcvs?rev=373382&view=rev
Log:
Added facilities to specify catalog/schema for running the unit tests

Modified:
    db/ddlutils/trunk/src/test/org/apache/ddlutils/TestDatabaseWriterBase.java

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/TestDatabaseWriterBase.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/TestDatabaseWriterBase.java?rev=373382&r1=373381&r2=373382&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/TestDatabaseWriterBase.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/TestDatabaseWriterBase.java Sun Jan 29
15:05:03 2006
@@ -45,9 +45,13 @@
     public static final String JDBC_PROPERTIES_PROPERTY = "jdbc.properties.file";
     /** The prefix for properties of the datasource. */
     public static final String DATASOURCE_PROPERTY_PREFIX = "datasource.";
+    /** The prefix for properties for ddlutils. */
+    public static final String DDLUTILS_PROPERTY_PREFIX = "ddlutils.";
     /** The property for specifying the platform. */
-    public static final String PLATFORM_PROPERTY = "ddlutils.platform";
+    public static final String PLATFORM_PROPERTY = DDLUTILS_PROPERTY_PREFIX + "platform";
 
+    /** The test properties as defined by an external properties file. */
+    private static Properties _testProps;
     /** The data source to test against. */
     private static DataSource _dataSource;
     /** The database name. */
@@ -65,6 +69,42 @@
     }
 
     /**
+     * Returns the test properties.
+     * 
+     * @return The properties
+     */
+    protected Properties getTestProperties()
+    {
+    	if (_testProps == null)
+    	{
+    		String propFile = System.getProperty(JDBC_PROPERTIES_PROPERTY);
+	
+	        if (propFile == null)
+	        {
+	        	throw new RuntimeException("Please specify the properties file via the jdbc.properties.file
environment variable");
+	        }
+	        try
+	        {
+	            InputStream propStream = getClass().getResourceAsStream(propFile);
+	
+	            if (propStream == null)
+	            {
+	                propStream = new FileInputStream(propFile);
+	            }
+	            Properties props = new Properties();
+
+	            props.load(propStream);
+	            _testProps = props;
+	        }
+	        catch (Exception ex)
+	        {
+	        	throw new RuntimeException(ex);
+	        }
+    	}
+    	return _testProps;
+    }
+    
+    /**
      * Initializes the test datasource and the platform.
      */
     private void init()
@@ -76,19 +116,10 @@
             return;
         }
 
-        Properties props    = new Properties();
-        String     propFile = System.getProperty(JDBC_PROPERTIES_PROPERTY);
+        Properties props = getTestProperties();
 
         try
         {
-            InputStream propStream = getClass().getResourceAsStream(propFile);
-
-            if (propStream == null)
-            {
-                propStream = new FileInputStream(propFile);
-            }
-            props.load(propStream);
-
             String dataSourceClass = props.getProperty(DATASOURCE_PROPERTY_PREFIX + "class",
BasicDataSource.class.getName());
 
             _dataSource = (DataSource)Class.forName(dataSourceClass).newInstance();
@@ -238,6 +269,20 @@
         }
     }
 
+    /**
+     * Reads the database model from the database.
+     * 
+     * @return The model
+     */
+    protected Database readModelFromDatabase(String databaseName)
+    {
+    	Properties props   = getTestProperties();
+        String     catalog = props.getProperty(DDLUTILS_PROPERTY_PREFIX + "catalog");
+        String     schema  = props.getProperty(DDLUTILS_PROPERTY_PREFIX + "schema");
+
+    	return getPlatform().readModelFromDatabase(databaseName, catalog, schema, null);
+    }
+    
     /**
      * Determines the value of the bean's property that has the given name. Depending on
the
      * case-setting of the current builder, the case of teh name is considered or not. 



Mime
View raw message