[154000] Enhanced common oda consumer behavior to find and set trace logging configuration
diff --git a/plugins/org.eclipse.datatools.connectivity.oda.consumer/META-INF/MANIFEST.MF b/plugins/org.eclipse.datatools.connectivity.oda.consumer/META-INF/MANIFEST.MF
index 801a7f0..760f3f5 100644
--- a/plugins/org.eclipse.datatools.connectivity.oda.consumer/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.datatools.connectivity.oda.consumer/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
Bundle-ManifestVersion: 2
Bundle-Name: DTP ODA Consumer Helper Component Plug-in
Bundle-SymbolicName: org.eclipse.datatools.connectivity.oda.consumer;singleton:=true
-Bundle-Version: 3.0.3.200610131
+Bundle-Version: 3.0.3.200610231
Bundle-Localization: plugin
Bundle-Vendor: Eclipse.org
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
diff --git a/plugins/org.eclipse.datatools.connectivity.oda.consumer/src/org/eclipse/datatools/connectivity/oda/consumer/helper/OdaDriver.java b/plugins/org.eclipse.datatools.connectivity.oda.consumer/src/org/eclipse/datatools/connectivity/oda/consumer/helper/OdaDriver.java
index 8293610..929941c 100644
--- a/plugins/org.eclipse.datatools.connectivity.oda.consumer/src/org/eclipse/datatools/connectivity/oda/consumer/helper/OdaDriver.java
+++ b/plugins/org.eclipse.datatools.connectivity.oda.consumer/src/org/eclipse/datatools/connectivity/oda/consumer/helper/OdaDriver.java
@@ -22,6 +22,7 @@
import org.eclipse.datatools.connectivity.oda.IDriver;
import org.eclipse.datatools.connectivity.oda.LogConfiguration;
import org.eclipse.datatools.connectivity.oda.OdaException;
+import org.eclipse.datatools.connectivity.oda.consumer.internal.impl.LogConfigHelper;
import org.eclipse.datatools.connectivity.oda.consumer.internal.impl.LogPathHelper;
import org.eclipse.datatools.connectivity.oda.consumer.nls.Messages;
import org.eclipse.datatools.connectivity.oda.consumer.util.manifest.DriverExtensionManifest;
@@ -178,6 +179,9 @@
// store the underlying driver instance within this OdaDriver
setObject( wrappedDriver );
+ // initialize log configuration for this helper and its underlying ODA driver
+ setLogConfiguration( driverConfig );
+
logMethodExitWithReturn( context, this );
}
@@ -462,6 +466,20 @@
{
m_logDirectory = logDirectory;
}
+
+ /**
+ * Initialize and set the trace logging configuration for this
+ * oda consumer helper instance and its underlying ODA runtime driver.
+ * Uses the default trace logging configuration specified for
+ * the underlying ODA runtime driver.
+ * @throws OdaException
+ */
+ private void setLogConfiguration( ExtensionManifest driverManifest )
+ throws OdaException
+ {
+ LogConfigHelper configHelper = new LogConfigHelper( driverManifest );
+ setLogConfiguration( configHelper.getDriverLogConfiguration() );
+ }
/* (non-Javadoc)
* @see org.eclipse.datatools.connectivity.oda.IDriver#setLogConfiguration(org.eclipse.datatools.connectivity.oda.LogConfiguration)
@@ -471,6 +489,13 @@
final String context = "OdaDriver.setLogConfiguration( " + //$NON-NLS-1$
logConfig + " )\t"; //$NON-NLS-1$
logMethodCalled( context );
+
+ if( logConfig == null )
+ {
+ // nothing to set, done
+ logMethodExit( context );
+ return;
+ }
// set log configuration for the oda consumer helper
try
@@ -481,15 +506,18 @@
if( LogManager.getLogger( getLoggerName() ) == null &&
m_logDirectory == null )
{
- m_logDirectory =
- LogPathHelper.getConsumerLogParent(
- logConfig.getDataSourceId() ).getPath();
+ // use underlying oda data source id as the logs' relative sub-directory
+ m_logDirectory = logConfig.getDataSourceId();
}
// set log configuration values in the ODA consumer helper of the driver,
// whose logging requires a log directory
if( m_logDirectory != null && m_logDirectory.length() > 0 )
{
+ // ensure that either user-defined or default log directory
+ // has an absolute path
+ m_logDirectory = LogPathHelper.getAbsoluteLogDirName( m_logDirectory );
+
LogManager.getLogger( getLoggerName(), logConfig.getLogLevel(),
m_logDirectory, "OdaHelperLog", null ); //$NON-NLS-1$
}
@@ -683,5 +711,5 @@
logMethodExit( methodName );
}
-
+
}
diff --git a/plugins/org.eclipse.datatools.connectivity.oda.consumer/src/org/eclipse/datatools/connectivity/oda/consumer/internal/impl/LogConfigHelper.java b/plugins/org.eclipse.datatools.connectivity.oda.consumer/src/org/eclipse/datatools/connectivity/oda/consumer/internal/impl/LogConfigHelper.java
new file mode 100644
index 0000000..f1f1fc6
--- /dev/null
+++ b/plugins/org.eclipse.datatools.connectivity.oda.consumer/src/org/eclipse/datatools/connectivity/oda/consumer/internal/impl/LogConfigHelper.java
@@ -0,0 +1,184 @@
+/*
+ *************************************************************************
+ * Copyright (c) 2006 Actuate Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Actuate Corporation - initial API and implementation
+ *
+ *************************************************************************
+ */
+
+package org.eclipse.datatools.connectivity.oda.consumer.internal.impl;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.datatools.connectivity.oda.LogConfiguration;
+import org.eclipse.datatools.connectivity.oda.OdaException;
+import org.eclipse.datatools.connectivity.oda.util.manifest.ExtensionManifest;
+import org.eclipse.datatools.connectivity.oda.util.manifest.TraceLogging;
+
+/**
+ * Internal helper of the oda consumer component for handling
+ * trace log configuration.
+ */
+public class LogConfigHelper
+{
+ private ExtensionManifest m_driverManifest;
+
+ /**
+ * Constructor of a helper for the specified ODA driver's manifest.
+ * @param driverManifest an ODA runtime extension's manifest
+ */
+ public LogConfigHelper( ExtensionManifest driverManifest )
+ throws OdaException
+ {
+ if( driverManifest == null )
+ throw new OdaException( new IllegalArgumentException() );
+
+ m_driverManifest = driverManifest;
+ }
+
+ /**
+ * Returns the plug-in trace logging configuration from
+ * the .options file if set to debugging; otherwise,
+ * from the driver's traceLogging element defined in its ODA extension.
+ * @return the driver's log configuration, or null if none is found
+ */
+ public LogConfiguration getDriverLogConfiguration()
+ {
+ // get log configuration specified in plug-in .options file
+ LogConfiguration logOptions = createLogConfigFromTraceOptions();
+ if( logOptions != null )
+ return logOptions; // done
+
+ // no trace options are set for ODA driver;
+ // get log configuration specified in the
+ // driver's trace logging element in plug-in manifest
+ return createLogConfigFromTraceLogging();
+ }
+
+ /*
+ * Gets the plug-in trace logging configuration
+ * from the PDE .options file
+ */
+ private LogConfiguration createLogConfigFromTraceOptions()
+ {
+ String pluginId = getDriverPluginId();
+
+ String debugOption = pluginId + "/debug"; //$NON-NLS-1$
+ String debugOptionValue = Platform.getDebugOption( debugOption );
+ Boolean isDebug = Boolean.valueOf( debugOptionValue );
+ if( isDebug == Boolean.FALSE )
+ return null; // not found or not debugging
+
+ String logLevelOption = pluginId + "/traceLogging/logLevel"; //$NON-NLS-1$
+ int logLevel = TraceLogging.toLogLevelNumber(
+ Platform.getDebugOption( logLevelOption ) );
+
+ String logFormatterOption = pluginId + "/traceLogging/logFormatterClass"; //$NON-NLS-1$
+ String logFilePrefixOption = pluginId + "/traceLogging/logFileNamePrefix"; //$NON-NLS-1$
+ String logDirOption = pluginId + "/traceLogging/logDirectory"; //$NON-NLS-1$
+
+ // set default configuration values if not specified
+ String logFilenamePrefix = Platform.getDebugOption( logFilePrefixOption );
+ String logDest = Platform.getDebugOption( logDirOption );
+
+ // if either log file attribute has value, ensure
+ // both attributes have values, using default value as needed
+ if( isNotEmpty( logFilenamePrefix ) || isNotEmpty( logDest ) )
+ {
+ logFilenamePrefix = getDefaultLogFilenamePrefix( logFilenamePrefix );
+
+ // ensure that either user-defined or default log directory
+ // has an absolute path
+ logDest = LogPathHelper.getAbsoluteLogDirName(
+ getDefaultLogDirectory( logDest ) );
+ }
+
+
+ // instantiate object with log configuration values
+ return new LogConfiguration( pluginId,
+ logLevel,
+ logDest,
+ logFilenamePrefix,
+ Platform.getDebugOption( logFormatterOption ) );
+ }
+
+ /*
+ * Gets the plug-in trace logging configuration settings
+ * from the plugin.xml traceLogging element
+ */
+ private LogConfiguration createLogConfigFromTraceLogging()
+ {
+ ExtensionManifest manifest = m_driverManifest;
+ assert( manifest != null );
+ TraceLogging loggingElement = manifest.getTraceLogging();
+ if( loggingElement == null )
+ return null; // none found
+
+ // set default configuration values if not specified
+ String logFilenamePrefix = loggingElement.getLogFileNamePrefix();
+ String logDest = loggingElement.getLogDirectory();
+
+ // if either log file attribute has value, ensure
+ // both attributes have values, using default value as needed
+ if( isNotEmpty( logFilenamePrefix ) || isNotEmpty( logDest ) )
+ {
+ logFilenamePrefix = getDefaultLogFilenamePrefix( logFilenamePrefix );
+
+ // ensure that either user-defined or default log directory
+ // has an absolute path
+ logDest = LogPathHelper.getAbsoluteLogDirName(
+ getDefaultLogDirectory( logDest ) );
+ }
+
+ // instantiate object with log configuration values
+ return new LogConfiguration( getDriverPluginId(),
+ loggingElement.getLogLevel(),
+ logDest,
+ logFilenamePrefix,
+ loggingElement.getLogFormatterClass() );
+ }
+
+ /*
+ * Returns the default configuration value if
+ * the given log filename prefix is not specified
+ */
+ private String getDefaultLogFilenamePrefix( String prefix )
+ {
+ if( isNotEmpty( prefix ) )
+ return prefix; // already specified, use as is
+ return getDriverPluginId();
+ }
+
+ /*
+ * Returns the driver name as the default relative folder name if
+ * the given log directory is not specified
+ */
+ private String getDefaultLogDirectory( String logDir )
+ {
+ if( isNotEmpty( logDir ) )
+ return logDir; // already specified, use as is
+ return getDriverPluginId();
+ }
+
+ private String getDriverPluginId()
+ {
+ assert( m_driverManifest != null );
+ return m_driverManifest.getNamespace();
+ }
+
+ private boolean isNullOrEmpty( String value )
+ {
+ return ( value == null || value.length() == 0 );
+ }
+
+ private boolean isNotEmpty( String value )
+ {
+ return ! isNullOrEmpty( value );
+ }
+
+}
diff --git a/plugins/org.eclipse.datatools.connectivity.oda.consumer/src/org/eclipse/datatools/connectivity/oda/consumer/internal/impl/LogPathHelper.java b/plugins/org.eclipse.datatools.connectivity.oda.consumer/src/org/eclipse/datatools/connectivity/oda/consumer/internal/impl/LogPathHelper.java
index c68f969..5e154cb 100644
--- a/plugins/org.eclipse.datatools.connectivity.oda.consumer/src/org/eclipse/datatools/connectivity/oda/consumer/internal/impl/LogPathHelper.java
+++ b/plugins/org.eclipse.datatools.connectivity.oda.consumer/src/org/eclipse/datatools/connectivity/oda/consumer/internal/impl/LogPathHelper.java
@@ -34,7 +34,7 @@
* @throws IllegalStateException when the plugin activator
* is not instantiated yet
*/
- public static IPath getPluginLogPath() throws IllegalStateException
+ static IPath getPluginLogPath() throws IllegalStateException
{
// try to use plugin's default state location's log folder as its parent
OdaConsumerPlugin thePlugin = OdaConsumerPlugin.getDefault();
@@ -53,7 +53,7 @@
* or empty for no sub-directory
* @return
*/
- public static File getConsumerLogParent( String subdirName )
+ static File getConsumerLogParent( String subdirName )
{
IPath pluginLogPath = getPluginLogPath();
@@ -61,5 +61,29 @@
return pluginLogPath.toFile();
return pluginLogPath.append( subdirName ).toFile();
}
+
+ /**
+ * Returns the specified logDirectory as an absolute path name.
+ * If specified logDirectory is already absolute, use as is.
+ * Otherwise, use the odaconsumer plugin's default logs folder
+ * as the parent directory.
+ * @param logDirectory non-empty log directory which may be a
+ * relative or absolute path
+ * @return an absolute directory path for the log files;
+ * or null if specified argument is null or empty
+ */
+ public static String getAbsoluteLogDirName( String logDirectory )
+ {
+ if( logDirectory == null || logDirectory.length() == 0 )
+ return null;
+ File logParent = new File( logDirectory );
+ if( logParent.isAbsolute() )
+ return logDirectory; // use as is
+
+ // the specified logDirectory is relative,
+ // set its parent to the odaconsumer plugin's default logs folder
+ return LogPathHelper.getConsumerLogParent(
+ logDirectory ).getPath();
+ }
}
diff --git a/tests/org.eclipse.datatools.connectivity.oda.consumer.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.datatools.connectivity.oda.consumer.tests/META-INF/MANIFEST.MF
index 59c798f..8babe8a 100644
--- a/tests/org.eclipse.datatools.connectivity.oda.consumer.tests/META-INF/MANIFEST.MF
+++ b/tests/org.eclipse.datatools.connectivity.oda.consumer.tests/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
Bundle-ManifestVersion: 2
Bundle-Name: DTP ODA Consumer Helper Tests Suite
Bundle-SymbolicName: org.eclipse.datatools.connectivity.oda.consumer.tests;singleton:=true
-Bundle-Version: 3.0.2.200608301
+Bundle-Version: 3.0.3.200610231
Bundle-Localization: plugin
Bundle-Vendor: Eclipse.org
Require-Bundle: org.junit;bundle-version="[3.8.1,4.0.0)",
diff --git a/tests/org.eclipse.datatools.connectivity.oda.consumer.tests/src/org/eclipse/datatools/connectivity/oda/consumer/tests/TraceLogConfigTest.java b/tests/org.eclipse.datatools.connectivity.oda.consumer.tests/src/org/eclipse/datatools/connectivity/oda/consumer/tests/TraceLogConfigTest.java
new file mode 100644
index 0000000..33ea25d
--- /dev/null
+++ b/tests/org.eclipse.datatools.connectivity.oda.consumer.tests/src/org/eclipse/datatools/connectivity/oda/consumer/tests/TraceLogConfigTest.java
@@ -0,0 +1,169 @@
+/*
+ *************************************************************************
+ * Copyright (c) 2006 Actuate Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Actuate Corporation - initial API and implementation
+ *
+ *************************************************************************
+ */
+
+package org.eclipse.datatools.connectivity.oda.consumer.tests;
+
+import java.io.File;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.eclipse.datatools.connectivity.oda.IDriver;
+import org.eclipse.datatools.connectivity.oda.LogConfiguration;
+import org.eclipse.datatools.connectivity.oda.consumer.helper.OdaConsumerPlugin;
+import org.eclipse.datatools.connectivity.oda.consumer.helper.OdaDriver;
+import org.eclipse.datatools.connectivity.oda.util.logging.Level;
+
+/**
+ *
+ */
+public class TraceLogConfigTest extends TestCase
+{
+ static final String TEST_DRIVER_ID =
+ "org.eclipse.datatools.connectivity.oda.consumer.testdriver"; //$NON-NLS-1$
+
+ private static IDriver sm_odaDriver;
+ private static File sm_consumerLogDir;
+ private String m_driverLogRelativeDirName;
+ private File m_driverLogAbsoluteDir;
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ if( sm_odaDriver == null )
+ sm_odaDriver = new OdaDriver( TEST_DRIVER_ID );
+
+ if( sm_consumerLogDir == null )
+ {
+ sm_consumerLogDir =
+ OdaConsumerPlugin.getDefault().getStateLocation()
+ .append( "logs" )
+ .append( TEST_DRIVER_ID ).toFile();
+ }
+
+ m_driverLogRelativeDirName = TraceLogTestUtil.getOptionsLogDir( TEST_DRIVER_ID );
+ // change driver log dir in explicit setLogConfig
+ if( getName() == "testDriverTraceOptionsAndSetLogConfig" )
+ m_driverLogRelativeDirName = "testSetLogDir";
+
+ if( m_driverLogRelativeDirName != null )
+ {
+ m_driverLogAbsoluteDir =
+ OdaConsumerPlugin.getDefault().getStateLocation()
+ .append( "logs" )
+ .append( m_driverLogRelativeDirName ).toFile();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ // turn off OdaDriver's logging before log files can be deleted
+ String logDir = m_driverLogAbsoluteDir != null ?
+ m_driverLogAbsoluteDir.getPath() :
+ m_driverLogRelativeDirName;
+ LogConfiguration offLogConfig =
+ new LogConfiguration(
+ TEST_DRIVER_ID,
+ Level.OFF,
+ logDir,
+ TraceLogTestUtil.CONSUMER_LOG_PREFIX,
+ null );
+ sm_odaDriver.setLogConfiguration( offLogConfig );
+
+ cleanupTestLogFiles( sm_consumerLogDir ); // reset for new test case
+ if( sm_consumerLogDir != null )
+ sm_consumerLogDir.delete();
+
+ try
+ {
+ cleanupTestLogFiles( m_driverLogAbsoluteDir );
+ if( m_driverLogAbsoluteDir != null )
+ m_driverLogAbsoluteDir.delete();
+ }
+ catch( IOException e )
+ {
+ // ignore
+ e.printStackTrace();
+ }
+ }
+
+ public void testDriverTraceOptions() throws Exception
+ {
+ // use the default one set by trace options or traceLogging element
+ // change driver log dir in explicit setLogConfig
+ String logFilePrefix = "testTraceOptions";
+ String logDir = m_driverLogAbsoluteDir != null ?
+ m_driverLogAbsoluteDir.getPath() :
+ m_driverLogRelativeDirName;
+ LogConfiguration logConfig = new LogConfiguration( TEST_DRIVER_ID,
+ Level.FINE,
+ logDir,
+ logFilePrefix,
+ "throwsException" ); // triggers test driver to throw exception
+ sm_odaDriver.setLogConfiguration( logConfig );
+
+ // expects driver has thrown exception, so no log is written
+ assertFalse( hasTestLogFiles( m_driverLogAbsoluteDir, logFilePrefix ) );
+
+ // expected to use odaconsumer's logs/driver directory
+ // to log driver's unsupported operation exception
+ assertTrue( hasTestLogFiles( sm_consumerLogDir, TraceLogTestUtil.CONSUMER_LOG_PREFIX ) );
+ }
+
+ public void testDriverTraceOptionsAndSetLogConfig() throws Exception
+ {
+ // change driver log dir in explicit setLogConfig
+ String logFilePrefix = "testTraceOptionsAndSetLogConfig";
+ LogConfiguration logConfig = new LogConfiguration( TEST_DRIVER_ID,
+ Level.FINE, // triggers test driver to log
+ m_driverLogAbsoluteDir.getPath(),
+ logFilePrefix,
+ null );
+ sm_odaDriver.setLogConfiguration( logConfig );
+
+ // expects driver log gets written to explicit logConfig's logDir
+ assertTrue( hasTestLogFiles( m_driverLogAbsoluteDir, logFilePrefix ) );
+
+ // expects default log dir is not used
+ String optionsLogDir = TraceLogTestUtil.getOptionsLogDir( TEST_DRIVER_ID );
+ if( optionsLogDir != null )
+ {
+ File defaultLogDir =
+ OdaConsumerPlugin.getDefault().getStateLocation()
+ .append( "logs" )
+ .append( optionsLogDir ).toFile();
+ assertFalse( defaultLogDir.exists() );
+ assertFalse( hasTestLogFiles( defaultLogDir, logFilePrefix ) );
+ }
+ }
+
+ private void cleanupTestLogFiles( File logDir ) throws IOException
+ {
+ TraceLogTestUtil.cleanupTestLogFiles( logDir );
+ }
+
+ private boolean hasTestLogFiles( File logDir, String logFilePrefix )
+ {
+ return TraceLogTestUtil.hasTestLogFiles( logDir, logFilePrefix );
+ }
+
+}
diff --git a/tests/org.eclipse.datatools.connectivity.oda.consumer.tests/src/org/eclipse/datatools/connectivity/oda/consumer/tests/TraceLogTest.java b/tests/org.eclipse.datatools.connectivity.oda.consumer.tests/src/org/eclipse/datatools/connectivity/oda/consumer/tests/TraceLogTest.java
index d1cb646..030b52e 100644
--- a/tests/org.eclipse.datatools.connectivity.oda.consumer.tests/src/org/eclipse/datatools/connectivity/oda/consumer/tests/TraceLogTest.java
+++ b/tests/org.eclipse.datatools.connectivity.oda.consumer.tests/src/org/eclipse/datatools/connectivity/oda/consumer/tests/TraceLogTest.java
@@ -20,26 +20,39 @@
import org.eclipse.datatools.connectivity.oda.LogConfiguration;
import org.eclipse.datatools.connectivity.oda.consumer.helper.OdaConsumerPlugin;
import org.eclipse.datatools.connectivity.oda.consumer.helper.OdaDriver;
-import org.eclipse.datatools.connectivity.oda.util.OdaPlugin;
import org.eclipse.datatools.connectivity.oda.util.logging.Level;
public class TraceLogTest extends FlatFileTestCase
{
- private static final String TEST_LOG_PREFIX = "OdaHelperLog"; //$NON-NLS-1$
- private static File sm_testLogDir;
-
+ private static final String CONSUMER_LOG_PREFIX = TraceLogTestUtil.CONSUMER_LOG_PREFIX;
+ private static File sm_consumerLogDir;
+ private String m_driverLogRelativeDirName;
+ private File m_driverLogAbsoluteDir;
+
protected void setUp() throws Exception
{
super.setUp();
-
- if( sm_testLogDir == null )
+
+ if( sm_consumerLogDir == null )
{
- sm_testLogDir =
+ sm_consumerLogDir =
OdaConsumerPlugin.getDefault().getStateLocation()
.append( "logs" )
.append( TEST_FLATFILE_ID ).toFile();
}
- cleanupTestLogFiles( sm_testLogDir );
+ cleanupTestLogFiles( sm_consumerLogDir );
+
+ if( getName() == "testDefaultLogDir" )
+ m_driverLogRelativeDirName = "./OdaLogs";
+ else if( getName() == "testSetLogDir" )
+ m_driverLogRelativeDirName = "testSetLogDir";
+
+ if( m_driverLogRelativeDirName != null )
+ m_driverLogAbsoluteDir =
+ OdaConsumerPlugin.getDefault().getStateLocation()
+ .append( "logs" )
+ .append( m_driverLogRelativeDirName ).toFile();
+ cleanupTestLogFiles( m_driverLogAbsoluteDir );
}
/*
@@ -57,96 +70,69 @@
new LogConfiguration(
TEST_FLATFILE_ID,
Level.OFF,
- "./OdaLogs",
- TEST_LOG_PREFIX,
- "java.util.logging.SimpleFormatter" );
+ m_driverLogRelativeDirName,
+ CONSUMER_LOG_PREFIX,
+ null );
getOdaDriver().setLogConfiguration( offLogConfig );
- cleanupTestLogFiles( sm_testLogDir );
+ cleanupTestLogFiles( sm_consumerLogDir );
+ cleanupTestLogFiles( m_driverLogAbsoluteDir );
}
private void cleanupTestLogFiles( File logDir ) throws IOException
- {
- if( logDir == null || ! logDir.exists() )
- return; // nothing to clear
- File[] filesInDir = logDir.listFiles();
- if( filesInDir == null )
- return; // nothing to clear
-
- for ( int i = 0; i < filesInDir.length; i += 1 )
- {
- boolean deleted = filesInDir[i].delete();
- if ( ! deleted )
- throw new IOException( "Cannot delete file: " + filesInDir[i].getName() );
- }
+ {
+ TraceLogTestUtil.cleanupTestLogFiles( logDir );
}
public void testDefaultLogDir() throws Exception
{
LogConfiguration logConfig = new LogConfiguration( TEST_FLATFILE_ID,
Level.FINE,
- "./OdaLogs",
- TEST_LOG_PREFIX,
- "java.util.logging.SimpleFormatter" );
+ m_driverLogRelativeDirName,
+ CONSUMER_LOG_PREFIX,
+ null );
- assertFalse( hasTestLogFiles( sm_testLogDir ) );
+ assertFalse( hasTestLogFiles( sm_consumerLogDir ) );
+ if( getOdaDriver() instanceof OdaDriver )
+ {
+ // reset to use default odaconsumer log dir
+ ((OdaDriver) getOdaDriver()).setLogDirectory( sm_consumerLogDir.getPath() );
+ }
getOdaDriver().setLogConfiguration( logConfig );
- assertTrue( sm_testLogDir.exists() );
- assertTrue( hasTestLogFiles( sm_testLogDir ) );
+ assertTrue( hasTestLogFiles( sm_consumerLogDir ) );
}
public void testSetLogDir() throws Exception
{
LogConfiguration logConfig = new LogConfiguration( TEST_FLATFILE_ID,
Level.FINE,
- "./OdaLogs",
- TEST_LOG_PREFIX,
- "java.util.logging.SimpleFormatter" );
+ m_driverLogRelativeDirName,
+ CONSUMER_LOG_PREFIX,
+ null );
- assertFalse( hasTestLogFiles( sm_testLogDir ) );
+ assertFalse( hasTestLogFiles( sm_consumerLogDir ) );
- String ownLogDir = "testSetLogDir";
+ String ownLogDir = m_driverLogRelativeDirName;
if( getOdaDriver() instanceof OdaDriver )
{
// overrides the default log dir
((OdaDriver) getOdaDriver()).setLogDirectory( ownLogDir );
}
+ // this is expected to use odaconsumer's logs/$m_logRelativeDirName
+ // to log driver's unsupported operation exception
getOdaDriver().setLogConfiguration( logConfig );
// default log dir still should not exist
- assertFalse( hasTestLogFiles( sm_testLogDir ) );
-
- // expects to find log file relative to the oda LogManager base dir
- File relativeBaseDir =
- OdaPlugin.getDefault().getStateLocation()
- .append( "logs" )
- .append( ownLogDir ).toFile();
- assertTrue( hasTestLogFiles( relativeBaseDir ) );
-
- // cleanup
- LogConfiguration offLogConfig = new LogConfiguration(
- logConfig.getDataSourceId(),
- Level.OFF,
- logConfig.getLogDirectory(),
- logConfig.getLogPrefix(),
- logConfig.getFormatterClassName() );
- getOdaDriver().setLogConfiguration( offLogConfig );
- cleanupTestLogFiles( relativeBaseDir );
+ assertFalse( hasTestLogFiles( sm_consumerLogDir ) );
+
+ // expects to find log file relative to the odaconsumer logs base dir
+ assertTrue( hasTestLogFiles( m_driverLogAbsoluteDir ) );
}
private boolean hasTestLogFiles( File logDir )
{
- String[] filesInDir = logDir.list();
- if( filesInDir == null )
- return false;
-
- for( int i = 0; i < filesInDir.length; i++ )
- {
- if( filesInDir[i].startsWith( TEST_LOG_PREFIX ) )
- return true;
- }
- return false;
+ return TraceLogTestUtil.hasTestLogFiles( logDir, CONSUMER_LOG_PREFIX );
}
}
diff --git a/tests/org.eclipse.datatools.connectivity.oda.consumer.tests/src/org/eclipse/datatools/connectivity/oda/consumer/tests/TraceLogTestUtil.java b/tests/org.eclipse.datatools.connectivity.oda.consumer.tests/src/org/eclipse/datatools/connectivity/oda/consumer/tests/TraceLogTestUtil.java
new file mode 100644
index 0000000..7add205
--- /dev/null
+++ b/tests/org.eclipse.datatools.connectivity.oda.consumer.tests/src/org/eclipse/datatools/connectivity/oda/consumer/tests/TraceLogTestUtil.java
@@ -0,0 +1,64 @@
+/*
+ *************************************************************************
+ * Copyright (c) 2006 Actuate Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Actuate Corporation - initial API and implementation
+ *
+ *************************************************************************
+ */
+
+package org.eclipse.datatools.connectivity.oda.consumer.tests;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.eclipse.core.runtime.Platform;
+
+public class TraceLogTestUtil
+{
+ static final String CONSUMER_LOG_PREFIX = "OdaHelperLog"; //$NON-NLS-1$
+
+ static String getOptionsLogDir( String pluginId )
+ {
+ String logDirOption = pluginId + "/traceLogging/logDirectory";
+ return Platform.getDebugOption( logDirOption );
+ }
+
+ static void cleanupTestLogFiles( File logDir ) throws IOException
+ {
+ if( logDir == null || ! logDir.exists() )
+ return; // nothing to clear
+ File[] filesInDir = logDir.listFiles();
+ if( filesInDir == null )
+ return; // nothing to clear
+
+ for ( int i = 0; i < filesInDir.length; i += 1 )
+ {
+ boolean deleted = filesInDir[i].delete();
+ if ( ! deleted )
+ throw new IOException( "Cannot delete file: " + filesInDir[i].getName() );
+ }
+ }
+
+ static boolean hasTestLogFiles( File logDir, String logFilePrefix )
+ {
+ if( logDir == null )
+ return false;
+ String[] filesInDir = logDir.list();
+ if( filesInDir == null )
+ return false;
+
+ for( int i = 0; i < filesInDir.length; i++ )
+ {
+ if( filesInDir[i].startsWith( logFilePrefix ) )
+ return true;
+ }
+ return false;
+ }
+
+}