db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpendle...@apache.org
Subject svn commit: r468605 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/lang/XMLMissingClassesTest.java functionTests/tests/lang/XMLTypeAndOpsTest.java junit/JDBC.java junit/XML.java
Date Sat, 28 Oct 2006 01:00:45 GMT
Author: bpendleton
Date: Fri Oct 27 18:00:44 2006
New Revision: 468605

URL: http://svn.apache.org/viewvc?view=rev&rev=468605
Log:
DERBY-1758: Enable xmlSuite to run as part of derbyall for qualified JVMs

This patch was contributed by A B (qozinx@gmail.com)

I'm attaching another patch, d1758_followup_v1.patch, that moves the XML
utility methods out of junit.JDBC and into a new class, junit.XML, per Dan's
suggestion (thanks Dan).

Note that I changed the "haveClass()" method in JDBC.java from private to
protected so that it can be called from the junit.XML class.  That was the
easiest thing to do. 

Since checking the classpath is not a JDBC-specific operation, the other
option is to move "haveClass()" to some other class in the junit package.  If
anyone indicates a preference for doing so and also indicates the class to
which the method should be moved, I can do it this way.  Otherwise I'll just
leave it as it is (i.e. keep it in JDBC.java and make it protected).

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/XML.java   (with props)
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XMLMissingClassesTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XMLTypeAndOpsTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XMLMissingClassesTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XMLMissingClassesTest.java?view=diff&rev=468605&r1=468604&r2=468605
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XMLMissingClassesTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XMLMissingClassesTest.java
Fri Oct 27 18:00:44 2006
@@ -23,6 +23,7 @@
 import junit.framework.TestSuite;
 
 import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.XML;
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import org.apache.derbyTesting.junit.TestConfiguration;
 
@@ -82,7 +83,7 @@
     public static Test suite()
     {
         TestSuite suite = new TestSuite("XML Missing Classes Suite");
-        if (!JDBC.classpathHasXalanAndJAXP())
+        if (!XML.classpathHasXalanAndJAXP())
         {
             // Run this test in embedded and client modes.
             suite.addTest(TestConfiguration.defaultSuite(

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XMLTypeAndOpsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XMLTypeAndOpsTest.java?view=diff&rev=468605&r1=468604&r2=468605
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XMLTypeAndOpsTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XMLTypeAndOpsTest.java
Fri Oct 27 18:00:44 2006
@@ -23,6 +23,7 @@
 import junit.framework.TestSuite;
 
 import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.XML;
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import org.apache.derbyTesting.junit.BaseJDBCTestSetup;
 import org.apache.derbyTesting.junit.TestConfiguration;
@@ -78,7 +79,7 @@
     public static Test suite()
     {
         TestSuite suite = new TestSuite("XML Type and Operators Suite\n");
-        if (!JDBC.classpathMeetsXMLReqs())
+        if (!XML.classpathMeetsXMLReqs())
             return suite;
 
         // First wrap the tests in a TestSetup that sets up / tears down

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java?view=diff&rev=468605&r1=468604&r2=468605
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java Fri Oct 27 18:00:44
2006
@@ -25,15 +25,6 @@
 import java.util.List;
 import java.util.ListIterator;
 
-import java.io.PrintWriter;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-
-import java.lang.reflect.Method;
-
-import java.util.StringTokenizer;
-import java.util.Properties;
-
 import junit.framework.Assert;
 
 /**
@@ -43,15 +34,6 @@
 public class JDBC {
 	
     /**
-     * Minimum version of Xalan required to run XML tests under
-     * Security Manager. In this case, we're saying that the
-     * minimum version is Xalan 2.5.0 (because there's a bug
-     * in earlier versions that causes problems with security
-     * manager).
-     */
-    private static int [] MIN_XALAN_VERSION = new int [] { 2, 5, 0 };
-
-    /**
      * Tell if we are allowed to use DriverManager to create database
      * connections.
      */
@@ -70,45 +52,13 @@
      */
     private static final boolean HAVE_SQLXML
                            = haveClass("java.sql.SQLXML");
-    
-    /**
-     * Determine whether or not the classpath with which we're
-     * running has the JAXP API classes required for use of
-     * the Derby XML operators.
-     */
-    private static final boolean HAVE_JAXP
-                           = haveClass("org.w3c.dom.Document");
-
-
-    /**
-     * Determine whether or not the classpath with which we're
-     * running has a version of Xalan in it.  Xalan is required
-     * for use of the Derby XML operators.  In particular we
-     * check for:
-     *
-     *  1. Xalan classes (version doesn't matter here)
-     *  2. The Xalan "EnvironmentCheck" class, which is included
-     *     as part of Xalan.  This allows us to check the specific
-     *     version of Xalan in use so that we can determine if
-     *     if we satisfy the minimum requirement.
-     */
-    private static final boolean HAVE_XALAN =
-            haveClass("org.apache.xpath.XPath") &&
-            haveClass("org.apache.xalan.xslt.EnvironmentCheck");
-
-    /**
-     * Determine if we have the minimum required version of Xalan
-     * for successful use of the XML operators.
-     */
-    private static final boolean HAVE_MIN_XALAN
-            = HAVE_XALAN && checkXalanVersion();
 
     /**
      * Can we load a specific class, use this to determine JDBC level.
      * @param className Class to attempt load on.
      * @return true if class can be loaded, false otherwise.
      */
-    private static boolean haveClass(String className)
+    protected static boolean haveClass(String className)
     {
         try {
             Class.forName(className);
@@ -164,31 +114,6 @@
 	}	
 	
 	/**
- 	 * <p>
-	 * Return true if the classpath contains JAXP and
-	 * Xalan classes (this method doesn't care about
-	 * the particular version of Xalan).
-	 * </p>
-	 */
-	public static boolean classpathHasXalanAndJAXP()
-	{
-		return HAVE_JAXP && HAVE_XALAN;
-	}
-
-	/**
-	 * <p>
-	 * Return true if the classpath meets all of the requirements
-	 * for use of the SQL/XML operators.  This means that all
-	 * required classes exist in the classpath AND the version
-	 * of Xalan that we found is at least MIN_XALAN_VERSION.
-	 * </p>
-	 */
-	public static boolean classpathMeetsXMLReqs()
-	{
-		return HAVE_JAXP && HAVE_MIN_XALAN;
-	}
-
-	/**
 	 * Rollback and close a connection for cleanup.
 	 * Test code that is expecting Connection.close to succeed
 	 * normally should just call conn.close().
@@ -716,137 +641,5 @@
 	{
 		return "\"" + schema + "\".\"" + name + "\"";
 	}
-
-    /**
-     * Determine whether or not the classpath with which we're
-     * running has a version of Xalan that meets the minimum
-     * Xalan version requirement.  We do that by using a Java
-     * utility that ships with Xalan--namely, "EnvironmentCheck"--
-     * and by parsing the info gathered by that method to find
-     * the Xalan version.  We use reflection when doing this
-     * so that this file will compile/execute even if XML classes
-     * are missing.
-     *
-     * Assumption is that we only get to this method if we already
-     * know that there *is* a version of Xalan in the classpath
-     * and that version includes the "EnvironmentCheck" class.
-     *
-     * Note that this method returns false if the call to Xalan's
-     * EnvironmentCheck.checkEnvironment() returns false for any
-     * reason.  As a specific example, that method will always
-     * return false when running with ibm131 because it cannot
-     * find the required methods on the SAX 2 classes (apparently
-     * the classes in ibm131 jdk don't have all of the methods
-     * required by Xalan).  Thus this method will always return
-     * "false" for ibm131.
-     */
-    private static boolean checkXalanVersion()
-    {
-        boolean haveMinXalanVersion = false;
-        try {
-
-            // These io objects allow us to retrieve information generated
-            // by the call to EnvironmenCheck.checkEnvironment()
-            ByteArrayOutputStream bos = new ByteArrayOutputStream();
-            PrintWriter pW = new PrintWriter(bos);
-
-            // Call the method using reflection.
-
-            Class cl = Class.forName("org.apache.xalan.xslt.EnvironmentCheck");
-            Method meth = cl.getMethod("checkEnvironment",
-                new Class[] { PrintWriter.class });
-
-            Boolean boolObj = (Boolean)meth.invoke(
-                cl.newInstance(), new Object [] { pW });
-
-            pW.flush();
-            bos.flush();
-
-            cl = null;
-            meth = null;
-            pW = null;
-
-            /* At this point 'bos' holds a list of properties with
-             * a bunch of environment information.  The specific
-             * property we're looking for is "version.xalan2_2",
-             * so get that property, parse the value, and see
-             * if the version is at least the minimum required.
-             */
-            if (boolObj.booleanValue())
-            {
-                // Load the properties gathered from checkEnvironment().
-                Properties props = new Properties();
-                props.load(new ByteArrayInputStream(bos.toByteArray()));
-                bos.close();
-
-                // Now pull out the one we need.
-                String ver = props.getProperty("version.xalan2_2");
-                haveMinXalanVersion = (ver != null);
-                if (haveMinXalanVersion)
-                {
-                    /* We found the property, so parse out the necessary
-                     * piece.  The value is of the form:
-                     *
-                     *   <productName> Major.minor.x
-                     *
-                     * Ex:
-                     *
-                     *   version.xalan2_2=Xalan Java 2.5.1 
-                     *   version.xalan2_2=XSLT4J Java 2.6.6
-                     */
-                    int i = 0;
-                    StringTokenizer tok = new StringTokenizer(ver, ". ");
-                    while (tok.hasMoreTokens())
-                    {
-                        String str = tok.nextToken().trim();
-                        if (Character.isDigit(str.charAt(0)))
-                        {
-                            int val = Integer.valueOf(str).intValue();
-                            if (val < MIN_XALAN_VERSION[i])
-                            {
-                                haveMinXalanVersion = false;
-                                break;
-                            }
-                            i++;
-                        }
-
-                        /* If we've checked all parts of the min version,
-                         * then we assume we're okay. Ex. "2.5.0.2"
-                         * is considered greater than "2.5.0".
-                         */
-                        if (i >= MIN_XALAN_VERSION.length)
-                            break;
-                    }
-
-                    /* If the value had fewer parts than the
-                     * mininum version, then it doesn't meet
-                     * the requirement.  Ex. "2.5" is considered
-                     * to be a lower version than "2.5.0".
-                     */
-                    if (i < MIN_XALAN_VERSION.length)
-                        haveMinXalanVersion = false;
-                }
-            }
-
-            /* Else the call to checkEnvironment() returned "false",
-             * which means it couldn't find all of the classes/methods
-             * required for Xalan to function.  So in that case we'll
-             * fall through and just return false, as well.
-             */
-
-        } catch (Throwable t) {
-
-            System.out.println("Unexpected exception while " +
-                "trying to find Xalan version:");
-            t.printStackTrace(System.err);
-
-            // If something went wrong, assume we don't have the
-            // necessary classes.
-            haveMinXalanVersion = false;
-
-        }
-
-        return haveMinXalanVersion;
-    }
 
 }

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/XML.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/XML.java?view=auto&rev=468605
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/XML.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/XML.java Fri Oct 27 18:00:44
2006
@@ -0,0 +1,231 @@
+/*
+ *
+ * Derby - Class org.apache.derbyTesting.functionTests.util.XML
+ *
+ * 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.derbyTesting.junit;
+
+import java.io.PrintWriter;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import java.lang.reflect.Method;
+
+import java.util.StringTokenizer;
+import java.util.Properties;
+
+import junit.framework.Assert;
+
+/**
+ * XML utility methods for the JUnit tests.
+ *
+ */
+public class XML {
+    
+    /**
+     * Minimum version of Xalan required to run XML tests under
+     * Security Manager. In this case, we're saying that the
+     * minimum version is Xalan 2.5.0 (because there's a bug
+     * in earlier versions that causes problems with security
+     * manager).
+     */
+    private static int [] MIN_XALAN_VERSION = new int [] { 2, 5, 0 };
+
+    /**
+     * Determine whether or not the classpath with which we're
+     * running has the JAXP API classes required for use of
+     * the Derby XML operators.
+     */
+    private static final boolean HAVE_JAXP =
+        JDBC.haveClass("org.w3c.dom.Document");
+
+    /**
+     * Determine whether or not the classpath with which we're
+     * running has a version of Xalan in it.  Xalan is required
+     * for use of the Derby XML operators.  In particular we
+     * check for:
+     *
+     *  1. Xalan classes (version doesn't matter here)
+     *  2. The Xalan "EnvironmentCheck" class, which is included
+     *     as part of Xalan.  This allows us to check the specific
+     *     version of Xalan in use so that we can determine if
+     *     if we satisfy the minimum requirement.
+     */
+    private static final boolean HAVE_XALAN =
+            JDBC.haveClass("org.apache.xpath.XPath") &&
+            JDBC.haveClass("org.apache.xalan.xslt.EnvironmentCheck");
+
+    /**
+     * Determine if we have the minimum required version of Xalan
+     * for successful use of the XML operators.
+     */
+    private static final boolean HAVE_MIN_XALAN
+            = HAVE_XALAN && checkXalanVersion();
+
+    /**
+     * Return true if the classpath contains JAXP and
+     * Xalan classes (this method doesn't care about
+     * the particular version of Xalan).
+     */
+    public static boolean classpathHasXalanAndJAXP()
+    {
+        return HAVE_JAXP && HAVE_XALAN;
+    }
+
+    /**
+     * Return true if the classpath meets all of the requirements
+     * for use of the SQL/XML operators.  This means that all
+     * required classes exist in the classpath AND the version
+     * of Xalan that we found is at least MIN_XALAN_VERSION.
+     */
+    public static boolean classpathMeetsXMLReqs()
+    {
+        return HAVE_JAXP && HAVE_MIN_XALAN;
+    }
+
+    /**
+     * Determine whether or not the classpath with which we're
+     * running has a version of Xalan that meets the minimum
+     * Xalan version requirement.  We do that by using a Java
+     * utility that ships with Xalan--namely, "EnvironmentCheck"--
+     * and by parsing the info gathered by that method to find
+     * the Xalan version.  We use reflection when doing this
+     * so that this file will compile/execute even if XML classes
+     * are missing.
+     *
+     * Assumption is that we only get to this method if we already
+     * know that there *is* a version of Xalan in the classpath
+     * and that version includes the "EnvironmentCheck" class.
+     *
+     * Note that this method returns false if the call to Xalan's
+     * EnvironmentCheck.checkEnvironment() returns false for any
+     * reason.  As a specific example, that method will always
+     * return false when running with ibm131 because it cannot
+     * find the required methods on the SAX 2 classes (apparently
+     * the classes in ibm131 jdk don't have all of the methods
+     * required by Xalan).  Thus this method will always return
+     * "false" for ibm131.
+     */
+    private static boolean checkXalanVersion()
+    {
+        boolean haveMinXalanVersion = false;
+        try {
+
+            // These io objects allow us to retrieve information generated
+            // by the call to EnvironmenCheck.checkEnvironment()
+            ByteArrayOutputStream bos = new ByteArrayOutputStream();
+            PrintWriter pW = new PrintWriter(bos);
+
+            // Call the method using reflection.
+
+            Class cl = Class.forName("org.apache.xalan.xslt.EnvironmentCheck");
+            Method meth = cl.getMethod("checkEnvironment",
+                new Class[] { PrintWriter.class });
+
+            Boolean boolObj = (Boolean)meth.invoke(
+                cl.newInstance(), new Object [] { pW });
+
+            pW.flush();
+            bos.flush();
+
+            cl = null;
+            meth = null;
+            pW = null;
+
+            /* At this point 'bos' holds a list of properties with
+             * a bunch of environment information.  The specific
+             * property we're looking for is "version.xalan2_2",
+             * so get that property, parse the value, and see
+             * if the version is at least the minimum required.
+             */
+            if (boolObj.booleanValue())
+            {
+                // Load the properties gathered from checkEnvironment().
+                Properties props = new Properties();
+                props.load(new ByteArrayInputStream(bos.toByteArray()));
+                bos.close();
+
+                // Now pull out the one we need.
+                String ver = props.getProperty("version.xalan2_2");
+                haveMinXalanVersion = (ver != null);
+                if (haveMinXalanVersion)
+                {
+                    /* We found the property, so parse out the necessary
+                     * piece.  The value is of the form:
+                     *
+                     *   <productName> Major.minor.x
+                     *
+                     * Ex:
+                     *
+                     *   version.xalan2_2=Xalan Java 2.5.1 
+                     *   version.xalan2_2=XSLT4J Java 2.6.6
+                     */
+                    int i = 0;
+                    StringTokenizer tok = new StringTokenizer(ver, ". ");
+                    while (tok.hasMoreTokens())
+                    {
+                        String str = tok.nextToken().trim();
+                        if (Character.isDigit(str.charAt(0)))
+                        {
+                            int val = Integer.valueOf(str).intValue();
+                            if (val < MIN_XALAN_VERSION[i])
+                            {
+                                haveMinXalanVersion = false;
+                                break;
+                            }
+                            i++;
+                        }
+
+                        /* If we've checked all parts of the min version,
+                         * then we assume we're okay. Ex. "2.5.0.2"
+                         * is considered greater than "2.5.0".
+                         */
+                        if (i >= MIN_XALAN_VERSION.length)
+                            break;
+                    }
+
+                    /* If the value had fewer parts than the
+                     * mininum version, then it doesn't meet
+                     * the requirement.  Ex. "2.5" is considered
+                     * to be a lower version than "2.5.0".
+                     */
+                    if (i < MIN_XALAN_VERSION.length)
+                        haveMinXalanVersion = false;
+                }
+            }
+
+            /* Else the call to checkEnvironment() returned "false",
+             * which means it couldn't find all of the classes/methods
+             * required for Xalan to function.  So in that case we'll
+             * fall through and just return false, as well.
+             */
+
+        } catch (Throwable t) {
+
+            System.out.println("Unexpected exception while " +
+                "trying to find Xalan version:");
+            t.printStackTrace(System.err);
+
+            // If something went wrong, assume we don't have the
+            // necessary classes.
+            haveMinXalanVersion = false;
+
+        }
+
+        return haveMinXalanVersion;
+    }
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/XML.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message