CheckIn:Fix a unit test problem in flat file driver.
diff --git a/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/META-INF/MANIFEST.MF
index 499c556..088ec61 100644
--- a/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/META-INF/MANIFEST.MF
+++ b/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
Bundle-ManifestVersion: 2
Bundle-Name: DTP ODA Flatfile Tests Suite
Bundle-SymbolicName: org.eclipse.datatools.connectivity.oda.flatfile.tests
-Bundle-Version: 3.0.3.200610251
+Bundle-Version: 3.0.3.200610261
Bundle-Activator: org.eclipse.datatools.connectivity.oda.flatfile.tests.plugin.Activator
Bundle-Localization: plugin
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
diff --git a/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/src/org/eclipse/datatools/connectivity/oda/flatfile/tests/ConnectionTestBase.java b/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/src/org/eclipse/datatools/connectivity/oda/flatfile/tests/ConnectionTestBase.java
index f2014af..93a01be 100644
--- a/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/src/org/eclipse/datatools/connectivity/oda/flatfile/tests/ConnectionTestBase.java
+++ b/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/src/org/eclipse/datatools/connectivity/oda/flatfile/tests/ConnectionTestBase.java
@@ -109,7 +109,7 @@
protected Properties setUpDefaultProperties( )
{
Properties prop = new Properties( );
- prop.setProperty( CommonConstants.CONN_HOME_DIR_PROP, "testdatabase" );
+ prop.setProperty( CommonConstants.CONN_HOME_DIR_PROP, TestUtil.getHomeDir( ) );
prop.setProperty( CommonConstants.CONN_CHARSET_PROP, "UTF-16LE" );
return prop;
}
diff --git a/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/src/org/eclipse/datatools/connectivity/oda/flatfile/tests/QueryTestBase.java b/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/src/org/eclipse/datatools/connectivity/oda/flatfile/tests/QueryTestBase.java
index e0d870a..74f4adf 100644
--- a/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/src/org/eclipse/datatools/connectivity/oda/flatfile/tests/QueryTestBase.java
+++ b/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/src/org/eclipse/datatools/connectivity/oda/flatfile/tests/QueryTestBase.java
@@ -312,7 +312,7 @@
{
connection = new Connection( );
prop = new Properties( );
- prop.setProperty( CommonConstants.CONN_HOME_DIR_PROP, "testdatabase" );
+ prop.setProperty( CommonConstants.CONN_HOME_DIR_PROP, TestUtil.getHomeDir( ) );
prop.setProperty( CommonConstants.CONN_CHARSET_PROP, TestUtil.DATASET );
prop.setProperty( CommonConstants.CONN_DELIMITER_TYPE,
getDelimiterName( ) );
diff --git a/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/src/org/eclipse/datatools/connectivity/oda/flatfile/tests/ResultSetMetaDataTestBase.java b/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/src/org/eclipse/datatools/connectivity/oda/flatfile/tests/ResultSetMetaDataTestBase.java
index ac08f20..1b532c1 100644
--- a/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/src/org/eclipse/datatools/connectivity/oda/flatfile/tests/ResultSetMetaDataTestBase.java
+++ b/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/src/org/eclipse/datatools/connectivity/oda/flatfile/tests/ResultSetMetaDataTestBase.java
@@ -40,7 +40,7 @@
super.setUp( );
Connection connection = new Connection( );
Properties prop = new Properties( );
- prop.setProperty( CommonConstants.CONN_HOME_DIR_PROP, "testdatabase" );
+ prop.setProperty( CommonConstants.CONN_HOME_DIR_PROP, TestUtil.getHomeDir( ) );
prop.setProperty( CommonConstants.CONN_CHARSET_PROP, TestUtil.DATASET );
prop.setProperty( CommonConstants.CONN_DELIMITER_TYPE,
getDelimiterName( ) );
diff --git a/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/src/org/eclipse/datatools/connectivity/oda/flatfile/tests/ResultSetTestBase.java b/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/src/org/eclipse/datatools/connectivity/oda/flatfile/tests/ResultSetTestBase.java
index 47a15cf..8506bc8 100644
--- a/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/src/org/eclipse/datatools/connectivity/oda/flatfile/tests/ResultSetTestBase.java
+++ b/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/src/org/eclipse/datatools/connectivity/oda/flatfile/tests/ResultSetTestBase.java
@@ -42,7 +42,7 @@
super.setUp( );
Connection connection = new Connection( );
Properties prop = new Properties( );
- prop.setProperty( CommonConstants.CONN_HOME_DIR_PROP, "testdatabase" );
+ prop.setProperty( CommonConstants.CONN_HOME_DIR_PROP, TestUtil.getHomeDir( ) );
prop.setProperty( CommonConstants.CONN_CHARSET_PROP, TestUtil.DATASET );
prop.setProperty( CommonConstants.CONN_DELIMITER_TYPE,
getDelimiterName( ) );
diff --git a/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/src/org/eclipse/datatools/connectivity/oda/flatfile/tests/TestUtil.java b/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/src/org/eclipse/datatools/connectivity/oda/flatfile/tests/TestUtil.java
index 0d00bcf..aa07305 100644
--- a/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/src/org/eclipse/datatools/connectivity/oda/flatfile/tests/TestUtil.java
+++ b/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/src/org/eclipse/datatools/connectivity/oda/flatfile/tests/TestUtil.java
@@ -16,6 +16,9 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Random;
@@ -48,7 +51,7 @@
*/
public static void createTestFile( String delimiter ) throws OdaException
{
- createTestFileDirectory( );
+ String path = createTestFileDirectory( );
if ( delimiter.equals( CommonConstants.DELIMITER_COMMA_VALUE ) )
fileExtension = CSV_EXTENSION;
@@ -59,45 +62,85 @@
else if ( delimiter.equals( CommonConstants.DELIMITER_PIPE_VALUE ) )
fileExtension = PSV_EXTENSION;
- createTestFile_test1( delimiter );
- createTestFile_test2( delimiter );
- createTestFile_test3( delimiter );
- createTestFile_test4( delimiter );
- createTestFile_test5( delimiter );
- createTestFile_test6( delimiter );
- createTestFile_test7( delimiter );
- createTestFile_test8( delimiter );
+ createTestFile_test1( path, delimiter );
+ createTestFile_test2( path, delimiter );
+ createTestFile_test3( path, delimiter );
+ createTestFile_test4( path, delimiter );
+ createTestFile_test5( path, delimiter );
+ createTestFile_test6( path, delimiter );
+ createTestFile_test7( path, delimiter );
+ createTestFile_test8( path, delimiter );
}
+
+ /**
+ *
+ * @return
+ */
+ public static String getHomeDir( )
+ {
+ URL url = TestUtil.class.getProtectionDomain( ).getCodeSource( ).getLocation( );
+ String pathBase = url.toString( );
+
+ if( !pathBase.matches( ".*\\Q \\E.*" ))
+ try
+ {
+ pathBase = new URI( pathBase ).getPath( );
+ }
+ catch ( URISyntaxException e1 )
+ {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ if ( pathBase.endsWith( "bin/" ) ) //$NON-NLS-1$
+ pathBase = pathBase.substring( 0,
+ pathBase.length( ) - 4 );
+ if ( pathBase.endsWith( "bin" ) ) //$NON-NLS-1$
+ pathBase = pathBase.substring( 0,
+ pathBase.length( ) - 3 );
+
+ return pathBase + "testdatabase";
+ }
/**
*
* @throws OdaException
+ * @throws URISyntaxException
*/
- private static void createTestFileDirectory( ) throws OdaException
+ private static String createTestFileDirectory( ) throws OdaException
{
- File file = new File( "testdatabase" );
+
+ String path = getHomeDir();
+ File file = new File( path );
if ( file.exists( ) )
- return;
+ {
+ file.deleteOnExit( );
+ return path;
+ }
try
{
file.mkdirs( );
+ file.deleteOnExit( );
}
catch ( SecurityException e )
{
throw new OdaException( e.getMessage( ) );
}
+ return path;
}
- private static void createTestFile_test1( String delimiter )
+ private static void createTestFile_test1( String path, String delimiter )
throws OdaException
{
File file = null;
- file = new File( "testdatabase"
+ file = new File( path
+ File.separator + "table1" + getSuffix( delimiter )
+ fileExtension );
if ( file.exists( ) )
+ {
+ file.deleteOnExit( );
return;
+ }
try
{
FileOutputStream fos = new FileOutputStream( file );
@@ -167,18 +210,22 @@
{
throw new OdaException( e.getMessage( ) );
}
+ file.deleteOnExit( );
}
- private static void createTestFile_test2( String delimiter )
+ private static void createTestFile_test2( String path, String delimiter )
throws OdaException
{
File file = null;
- file = new File( "testdatabase"
+ file = new File( path
+ File.separator + "table2" + getSuffix( delimiter )
+ fileExtension );
if ( file.exists( ) )
+ {
+ file.deleteOnExit( );
return;
+ }
try
{
FileOutputStream fos = new FileOutputStream( file );
@@ -241,17 +288,21 @@
{
throw new OdaException( e.getMessage( ) );
}
+ file.deleteOnExit( );
}
- private static void createTestFile_test3( String delimiter )
+ private static void createTestFile_test3( String path, String delimiter )
throws OdaException
{
File file = null;
- file = new File( "testdatabase"
+ file = new File( path
+ File.separator + "table3" + getSuffix( delimiter )
+ fileExtension );
if ( file.exists( ) )
+ {
+ file.deleteOnExit( );
return;
+ }
try
{
FileOutputStream fos = new FileOutputStream( file );
@@ -304,17 +355,21 @@
{
throw new OdaException( e.getMessage( ) );
}
+ file.deleteOnExit( );
}
- private static void createTestFile_test4( String delimiter )
+ private static void createTestFile_test4( String path, String delimiter )
throws OdaException
{
File file = null;
- file = new File( "testdatabase"
+ file = new File( path
+ File.separator + "table4" + getSuffix( delimiter )
+ fileExtension );
if ( file.exists( ) )
+ {
+ file.deleteOnExit( );
return;
+ }
try
{
FileOutputStream fos = new FileOutputStream( file );
@@ -379,17 +434,21 @@
{
throw new OdaException( e.getMessage( ) );
}
+ file.deleteOnExit( );
}
- private static void createTestFile_test5( String delimiter )
+ private static void createTestFile_test5( String path, String delimiter )
throws OdaException
{
File file = null;
- file = new File( "testdatabase"
+ file = new File( path
+ File.separator + "table5" + getSuffix( delimiter )
+ fileExtension );
if ( file.exists( ) )
+ {
+ file.deleteOnExit( );
return;
+ }
try
{
FileOutputStream fos = new FileOutputStream( file );
@@ -434,17 +493,21 @@
{
throw new OdaException( e.getMessage( ) );
}
+ file.deleteOnExit( );
}
- private static void createTestFile_test6( String delimiter )
+ private static void createTestFile_test6( String path, String delimiter )
throws OdaException
{
File file = null;
- file = new File( "testdatabase"
+ file = new File( path
+ File.separator + "table6" + getSuffix( delimiter )
+ fileExtension );
if ( file.exists( ) )
+ {
+ file.deleteOnExit( );
return;
+ }
try
{
FileOutputStream fos = new FileOutputStream( file );
@@ -487,17 +550,21 @@
{
throw new OdaException( e.getMessage( ) );
}
+ file.deleteOnExit( );
}
- private static void createTestFile_test7( String delimiter )
+ private static void createTestFile_test7( String path, String delimiter )
throws OdaException
{
File file = null;
- file = new File( "testdatabase"
+ file = new File( path
+ File.separator + "table7" + getSuffix( delimiter )
+ fileExtension );
if ( file.exists( ) )
+ {
+ file.deleteOnExit( );
return;
+ }
try
{
FileOutputStream fos = new FileOutputStream( file );
@@ -530,17 +597,21 @@
{
throw new OdaException( e.getMessage( ) );
}
+ file.deleteOnExit( );
}
- private static void createTestFile_test8( String delimiter )
+ private static void createTestFile_test8( String path, String delimiter )
throws OdaException
{
File file = null;
- file = new File( "testdatabase"
+ file = new File( path
+ File.separator + "table8" + getSuffix( delimiter )
+ fileExtension );
if ( file.exists( ) )
+ {
+ file.deleteOnExit( );
return;
+ }
try
{
FileOutputStream fos = new FileOutputStream( file );
@@ -568,6 +639,7 @@
{
throw new OdaException( e.getMessage( ) );
}
+ file.deleteOnExit( );
}
private static String getSuffix( String delimiter )