You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by dj...@apache.org on 2007/01/05 01:04:06 UTC
svn commit: r492822 - in
/db/derby/code/trunk/java/testing/org/apache/derbyTesting:
functionTests/tests/derbynet/ functionTests/util/ junit/
Author: djd
Date: Thu Jan 4 16:04:05 2007
New Revision: 492822
URL: http://svn.apache.org/viewvc?view=rev&rev=492822
Log:
DERBY-2213 (partial) Add a set of utilities in junit.Derby that allows
test code to determine which Derby functionality is available,
so that tests can exclude themselves if they require tools, engine, client
and/or server. Allows the junit tests to be setup so that they be run
with different classpaths that are a subset of the full set of jars.
Added:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Derby.java (with props)
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/_Suite.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ScriptTestCase.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SecurityManagerSetup.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/_Suite.java?view=diff&rev=492822&r1=492821&r2=492822
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/_Suite.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/_Suite.java Thu Jan 4 16:04:05 2007
@@ -22,6 +22,7 @@
package org.apache.derbyTesting.functionTests.tests.derbynet;
import org.apache.derbyTesting.junit.BaseTestCase;
+import org.apache.derbyTesting.junit.Derby;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -43,13 +44,19 @@
public static Test suite() {
TestSuite suite = new TestSuite("derbynet");
-
- suite.addTest(ByteArrayCombinerStreamTest.suite());
+
suite.addTest(PrepareStatementTest.suite());
suite.addTest(ShutDownDBWhenNSShutsDownTest.suite());
- suite.addTest(SqlExceptionTest.suite());
suite.addTest(SuicideOfStreamingTest.suite());
suite.addTest(DRDAProtocolTest.suite());
+
+ // These tests references a client class directly
+ // thus causing class not found exceptions if the
+ // client code is not in the classpath.
+ if (Derby.hasClient()) {
+ suite.addTest(ByteArrayCombinerStreamTest.suite());
+ suite.addTest(SqlExceptionTest.suite());
+ }
return suite;
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ScriptTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ScriptTestCase.java?view=diff&rev=492822&r1=492821&r2=492822
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ScriptTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ScriptTestCase.java Thu Jan 4 16:04:05 2007
@@ -23,7 +23,10 @@
import java.net.URL;
import java.sql.Connection;
+import org.apache.derbyTesting.junit.Derby;
+
import junit.framework.Test;
+import junit.framework.TestSuite;
/**
* Run a .sql script as a test comparing it to
@@ -71,6 +74,11 @@
*/
public static Test getIJConfig(Test test)
{
+ // Need the tools to run the scripts as this
+ // test uses ij as the script runner.
+ if (!Derby.hasTools())
+ return new TestSuite("empty: no tools support");
+
// No decorator needed currently.
return test;
}
Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Derby.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Derby.java?view=auto&rev=492822
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Derby.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Derby.java Thu Jan 4 16:04:05 2007
@@ -0,0 +1,104 @@
+/*
+ *
+ * Derby - Class org.apache.derbyTesting.functionTests.util.Derby
+ *
+ * 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.net.URL;
+import java.sql.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+
+import junit.framework.Assert;
+
+/**
+ * Derby related utility methods for the JUnit tests.
+ * The class assumes the tests are either being run
+ * from the build classes folder or from the standard
+ * jar files (or a subset of the standard jars).
+ * <BR>
+ * If the tests are being run from the classes then
+ * it is assumed all the functionality is available,
+ * otherwise the functionality will be driven from which
+ * jar files are on the classpath. E.g. if only
+ * derby.jar is on the classpath then the hasXXX() methods
+ * will return false except hasEmbedded().
+ */
+public class Derby {
+
+ /**
+ * Returns true if the embedded engine is available to the tests.
+ */
+ public static boolean hasEmbedded()
+ {
+ // classes folder - assume all is available.
+ if (!SecurityManagerSetup.isJars)
+ return true;
+
+ return hasCorrectJar("/derby.jar",
+ "org.apache.derby.authentication.UserAuthenticator");
+ }
+ /**
+ * Returns true if the network server is available to the tests.
+ */
+ public static boolean hasServer()
+ {
+ // classes folder - assume all is available.
+ if (!SecurityManagerSetup.isJars)
+ return true;
+
+ return hasCorrectJar("/derbynet.jar",
+ "org.apache.derby.drda.NetworkServerControl");
+ }
+ /**
+ * Returns true if the tools are available to the tests.
+ */
+ public static boolean hasTools()
+ {
+ // classes folder - assume all is available.
+ if (!SecurityManagerSetup.isJars)
+ return true;
+
+ return hasCorrectJar("/derbytools.jar",
+ "org.apache.derby.tools.ij");
+ }
+ /**
+ * Returns true if the derby client is available to the tests.
+ */
+ public static boolean hasClient()
+ {
+ // classes folder - assume all is available.
+ if (!SecurityManagerSetup.isJars)
+ return true;
+
+ return hasCorrectJar("/derbyclient.jar",
+ "org.apache.derby.jdbc.ClientDataSource");
+ }
+
+ private static boolean hasCorrectJar(String jarName, String className)
+ {
+ URL url = SecurityManagerSetup.getURL(className);
+ if (url == null)
+ return false;
+
+ return url.toExternalForm().endsWith(jarName);
+ }
+}
Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Derby.java
------------------------------------------------------------------------------
svn:eol-style = native
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=492822&r1=492821&r2=492822
==============================================================================
--- 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 Thu Jan 4 16:04:05 2007
@@ -59,7 +59,7 @@
* @param className Class to attempt load on.
* @return true if class can be loaded, false otherwise.
*/
- protected static boolean haveClass(String className)
+ static boolean haveClass(String className)
{
try {
Class.forName(className);
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SecurityManagerSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SecurityManagerSetup.java?view=diff&rev=492822&r1=492821&r2=492822
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SecurityManagerSetup.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SecurityManagerSetup.java Thu Jan 4 16:04:05 2007
@@ -236,21 +236,15 @@
//We need the junit classes to instantiate this class, so the
//following should not cause runtime errors.
- URL junit = null;
- junit = getURL(junit.framework.Test.class);
- classPathSet.setProperty("derbyTesting.junit", junit == null ? "" : junit.toString());
+ URL junit = getURL(junit.framework.Test.class);
+ if (junit != null)
+ classPathSet.setProperty("derbyTesting.junit", junit.toExternalForm());
- URL antjunit = null;
- Class antjunitclass = null;
- try {
- // Load indirectly so we don't need ant-junit.jar at compile time.
- antjunitclass = Class.forName("org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner");
- antjunit = getURL(antjunitclass);
- classPathSet.setProperty("derbyTesting.antjunit", antjunit == null ? "" : antjunit.toString());
- } catch (java.lang.ClassNotFoundException e) {
- // Not running in Ant, do nothing.
- antjunit = null;
- }
+ // Load indirectly so we don't need ant-junit.jar at compile time.
+ URL antjunit = getURL("org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner");
+ if (antjunit != null)
+ classPathSet.setProperty("derbyTesting.antjunit", antjunit.toExternalForm());
+
/* When inserting XML values that use external DTD's, the JAXP
* parser needs permission to read the DTD files. So here we set
@@ -279,22 +273,13 @@
}
isJars = true;
- URL derby = null;
- try {
- derby = getURL(org.apache.derby.jdbc.EmbeddedSimpleDataSource.class);
- } catch (java.lang.NoClassDefFoundError e) {
- derby = testing;
- }
- classPathSet.setProperty("derbyTesting.codejar", stripJar(derby));
+ URL derby = getURL("org.apache.derby.jdbc.EmbeddedSimpleDataSource");
+ if (derby != null)
+ classPathSet.setProperty("derbyTesting.codejar", stripJar(derby));
- URL client = null;
- try {
- client = getURL(org.apache.derby.jdbc.ClientDataSource.class);
- } catch (java.lang.NoClassDefFoundError e) {
- client = derby;
- }
-
- classPathSet.setProperty("derbyTesting.clientjar", stripJar(client));
+ URL client = getURL("org.apache.derby.jdbc.ClientDataSource");
+ if (client != null)
+ classPathSet.setProperty("derbyTesting.clientjar", stripJar(client));
return false;
}
@@ -323,11 +308,23 @@
String ef = url.toExternalForm();
return ef.substring(0, ef.lastIndexOf('/') + 1);
}
+
+ /**
+ * Get the URL of the code base from a class name.
+ * If the class cannot be loaded, null is returned.
+ */
+ static URL getURL(String className) {
+ try {
+ return getURL(Class.forName(className));
+ } catch (ClassNotFoundException e) {
+ return null;
+ }
+ }
/**
* Get the URL of the code base from a class.
*/
- protected static URL getURL(final Class cl)
+ static URL getURL(final Class cl)
{
return (URL)
AccessController.doPrivileged(new java.security.PrivilegedAction() {
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java?view=diff&rev=492822&r1=492821&r2=492822
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java Thu Jan 4 16:04:05 2007
@@ -250,8 +250,11 @@
*/
public static Test clientServerDecorator(Test suite)
{
- if (JDBC.vmSupportsJSR169())
- return new TestSuite();
+ // Need to have network server and client and not
+ // running in J2ME (JSR169).
+ if (!(Derby.hasClient() && Derby.hasServer())
+ || JDBC.vmSupportsJSR169())
+ return new TestSuite("empty: no network server support");
TestConfiguration config = TestConfiguration.getCurrent();