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 rh...@apache.org on 2006/08/25 22:36:28 UTC
svn commit: r436933 - in
/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting:
functionTests/util/CanonTestCase.java
functionTests/util/ScriptTestCase.java junit/BaseTestCase.java
junit/TestConfiguration.java
Author: rhillegas
Date: Fri Aug 25 13:36:26 2006
New Revision: 436933
URL: http://svn.apache.org/viewvc?rev=436933&view=rev
Log:
DERBY-1725: Merge 434562 (no JIRA) from trunk to 10.2 branch.
Added:
db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/util/CanonTestCase.java
- copied unchanged from r434563, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/CanonTestCase.java
Modified:
db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/util/ScriptTestCase.java
db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java
db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
Modified: db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/util/ScriptTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/util/ScriptTestCase.java?rev=436933&r1=436932&r2=436933&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/util/ScriptTestCase.java (original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/util/ScriptTestCase.java Fri Aug 25 13:36:26 2006
@@ -19,18 +19,10 @@
*/
package org.apache.derbyTesting.functionTests.util;
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.FileOutputStream;
import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.PrintStream;
import java.net.URL;
import java.sql.Connection;
-import org.apache.derbyTesting.junit.BaseJDBCTestCase;
-
import junit.framework.Test;
/**
@@ -38,10 +30,9 @@
* a master output file.
*
*/
-public abstract class ScriptTestCase extends BaseJDBCTestCase {
+public abstract class ScriptTestCase extends CanonTestCase {
private final String inputEncoding;
- private final String outputEncoding = "US-ASCII";
/**
* Create a ScriptTestCase to run a single test
@@ -109,74 +100,20 @@
assertNotNull("SQL script missing: " + resource, sql);
InputStream sqlIn = openTestResource(sql);
-
- ByteArrayOutputStream rawBytes =
- new ByteArrayOutputStream(20 * 1024);
-
+
Connection conn = getConnection();
org.apache.derby.tools.ij.runScript(
conn,
sqlIn,
inputEncoding,
- rawBytes,
+ getOutputStream(),
outputEncoding);
if (!conn.isClosed() && !conn.getAutoCommit())
conn.commit();
- rawBytes.flush();
- rawBytes.close();
sqlIn.close();
-
-
- byte[] testRawBytes = rawBytes.toByteArray();
-
- try {
- URL canonURL = getTestResource(canon);
- assertNotNull("No master file " + canon, canonURL);
-
- InputStream canonStream = getTestResource(canon).openStream();
-
- BufferedReader cannonReader = new BufferedReader(
- new InputStreamReader(canonStream, outputEncoding));
-
- BufferedReader testOutput = new BufferedReader(
- new InputStreamReader(
- new ByteArrayInputStream(testRawBytes),
- outputEncoding));
-
- for (int lineNumber = 1; ; lineNumber++)
- {
- String testLine = testOutput.readLine();
-
- // Skip blank lines.
- if ("".equals(testLine))
- continue;
-
- String canonLine = cannonReader.readLine();
-
- if (canonLine == null && testLine == null)
- break;
-
- if (canonLine == null)
- fail("More output from test than expected");
-
- if (testLine == null)
- fail("Less output from test than expected, stoped at line"
- + lineNumber);
-
- assertEquals("Output at line " + lineNumber,
- canonLine, testLine);
- }
-
- cannonReader.close();
- testOutput.close();
- } catch (Throwable t) {
- FileOutputStream outFile = new FileOutputStream(getName() + ".out");
- outFile.write(testRawBytes);
- outFile.flush();
- outFile.close();
- throw t;
- }
+
+ this.compareCanon(canon);
}
}
Modified: db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java?rev=436933&r1=436932&r2=436933&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java (original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java Fri Aug 25 13:36:26 2006
@@ -21,6 +21,7 @@
import junit.framework.TestCase;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
@@ -65,15 +66,15 @@
* <BR>
* Method is final to ensure security manager is
* enabled by default. Tests should not need to
- * ovveride runTest, instead use test methods
+ * override runTest, instead use test methods
* setUp, tearDown methods and decorators.
*/
public final void runBare() throws Throwable {
// still not ready for prime time
//if (getTestConfiguration().defaultSecurityManagerSetup())
// assertSecurityManager();
-
- super.runBare();
+
+ super.runBare();
}
/**
@@ -82,6 +83,16 @@
public final TestConfiguration getTestConfiguration()
{
return TestConfiguration.getCurrent();
+ }
+
+ /**
+ * Get the folder where a test leaves any information
+ * about its failure.
+ * @return Folder to use.
+ * @see TestConfiguration#getFailureFolder(TestCase)
+ */
+ public final File getFailureFolder() {
+ return getTestConfiguration().getFailureFolder(this);
}
/**
Modified: db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java?rev=436933&r1=436932&r2=436933&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java (original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java Fri Aug 25 13:36:26 2006
@@ -19,12 +19,16 @@
*/
package org.apache.derbyTesting.junit;
+import java.io.File;
import java.security.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
+import junit.framework.Test;
+import junit.framework.TestCase;
+
import org.apache.derbyTesting.functionTests.util.TestDataSourceFactory;
/**
@@ -59,6 +63,7 @@
}
/**
+ * WORK IN PROGRESS
* Set this Thread's current configuration for running tests.
* @param config Configuration to set it to.
*/
@@ -66,7 +71,34 @@
{
CURRENT_CONFIG.set(config);
}
-
+ /**
+ * WORK IN PROGRESS
+ * Return a decorator for the passed in tests that sets the
+ * configuration for the client to be Derby's JDBC client
+ * and to start the network server at setUp and shut it
+ * down at tearDown.
+ * <BR>
+ * The database configuration (name etc.) is based upon
+ * the previous configuration.
+ * <BR>
+ * The previous TestConfiguration is restored at tearDown.
+ * @param tests
+ * @return
+ */
+ public static Test derbyClientServerDecorator(Test tests)
+ {
+ TestConfiguration config = TestConfiguration.getCurrent();
+
+ // Already in the correct configuration, do nothing.
+ if (config.getJDBCClient().isDerbyNetClient())
+ return tests;
+
+ TestConfiguration derbyClientConfig = null;
+ // new TestConfiguration(config, JDBCClient.DERBYNETCLIENT);
+
+ return null;
+ }
+
/**
* This constructor creates a TestConfiguration from a Properties object.
*
@@ -111,7 +143,7 @@
/**
* Get the given system property as specified at startup.
*/
- public String getSystemStartupProperty( String key )
+ private String getSystemStartupProperty( String key )
{
return systemStartupProperties.getProperty( key );
}
@@ -292,6 +324,7 @@
//
// jvm.java sets this property to the build jar directory
// if we are using derbyTesting.jar.
+ //
//
return ( !UNUSED.equals( getSystemStartupProperty( "derbyTesting.codejar" ) ) );
@@ -303,6 +336,61 @@
*/
public boolean isSingleLegXA () {
return singleLegXA;
+ }
+
+ /**
+ * Get a folder already created where a test can
+ * write its failure information. The name of the folder,
+ * relative to ${user.dir} is:
+ * <BR>
+ * <code>
+ * fail/client/testclass/testname
+ * <code>
+ * <UL>
+ * <LI> client - value of JDBCClient.getName() for the test's configuration
+ * <LI> testclass - last element of the class name
+ * <LI> testname - value of test.getName()
+ * </UL>
+ */
+ File getFailureFolder(TestCase test){
+
+ StringBuffer sb = new StringBuffer();
+
+ sb.append("fail");
+ sb.append(File.separatorChar);
+ sb.append(getJDBCClient().getName());
+ sb.append(File.separatorChar);
+
+ String className = test.getClass().getName();
+ int lastDot = className.lastIndexOf('.');
+ if (lastDot != -1)
+ className = className.substring(lastDot+1, className.length());
+
+ sb.append(className);
+ sb.append(File.separatorChar);
+ sb.append(test.getName());
+
+ String base = sb.toString().intern();
+ final File folder = new File(base);
+
+ // Create the folder
+ // TODO: Dump this configuration in some human readable format
+ synchronized (base) {
+
+ AccessController.doPrivileged
+ (new java.security.PrivilegedAction(){
+ public Object run(){
+ if (folder.exists()) {
+ // do something
+ }
+ return new Boolean(folder.mkdirs());
+ }
+ }
+ );
+ }
+
+ return folder;
+
}
/**