prickett 2002/10/24 12:29:30
Modified:
periodicity/src/plugins-build/database/src/test/org/apache/commons/periodicity/database
DatabaseMDNameNullTest.java
periodicity/src/plugins-build/database/src/test/org/apache/commons/periodicity/junit
TestWithMavenLogging.java
Log:
Changed the DatabaseMDNameNullTest to inherit rom TestWithMavenLogging
Changed the key from maven test report directory key to maven base
directory key because maven does not pass the test reports directory
information into the system properties. I hard coded the relative path
to the test directory using java constants.
Added a tearDown method to TestWithMavenLogging
Changed the setLogger method to allow for a null logger.
Revision Changes Path
1.4 +9 -5
jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/test/org/apache/commons/periodicity/database/DatabaseMDNameNullTest.java
Index: DatabaseMDNameNullTest.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/test/org/apache/commons/periodicity/database/DatabaseMDNameNullTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DatabaseMDNameNullTest.java 23 Oct 2002 15:56:59 -0000 1.3
+++ DatabaseMDNameNullTest.java 24 Oct 2002 19:29:30 -0000 1.4
@@ -63,9 +63,9 @@
import junit.framework.Test;
-import junit.framework.TestCase;
+import org.apache.commons.periodicity.junit.TestWithMavenLogging;
-public class DatabaseMDNameNullTest extends TestCase
+public class DatabaseMDNameNullTest extends TestWithMavenLogging
{
public static final String TEST_NAME =
@@ -89,6 +89,10 @@
}
catch(Exception e)
{
+ if(getLogger() != null)
+ {
+ getLogger().info("Expected Exception", e);
+ }
}
}
1.3 +46 -34
jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/test/org/apache/commons/periodicity/junit/TestWithMavenLogging.java
Index: TestWithMavenLogging.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/test/org/apache/commons/periodicity/junit/TestWithMavenLogging.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestWithMavenLogging.java 24 Oct 2002 05:03:14 -0000 1.2
+++ TestWithMavenLogging.java 24 Oct 2002 19:29:30 -0000 1.3
@@ -68,12 +68,18 @@
import org.apache.log4j.FileAppender;
import org.apache.log4j.SimpleLayout;
import org.apache.log4j.Logger;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.BasicConfigurator;
public class TestWithMavenLogging extends TestCase
{
- public static final String MAVEN_TEST_REPORT_DIR_KEY =
- "maven.test.reportsDirectory";
+ public static final String MAVEN_BASE_DIR_KEY =
+ "basedir";
+
+ public static final String TARGET_DIR = "target";
+
+ public static final String TEST_REPORTS_DIR = "test-reports";
public static final String FILE_SEPARATOR = "file.separator";
@@ -88,31 +94,35 @@
super(name);
}
- protected void setup() throws Exception
+ protected void setUp() throws Exception
{
- String mavenTestReport = System.getProperty(MAVEN_TEST_REPORT_DIR_KEY);
- if(mavenTestReport != null)
+ String mavenBase = System.getProperty(MAVEN_BASE_DIR_KEY);
+ if(mavenBase != null)
{
- File mavenTestReportDir = new File(mavenTestReport);
- if(mavenTestReportDir.exists() && mavenTestReportDir.isDirectory()
- && mavenTestReportDir.canWrite() && getClass() != null)
+ File mavenBaseDir = new File(mavenBase);
+ if(mavenBaseDir.exists() && mavenBaseDir.isDirectory()
+ && mavenBaseDir.canWrite() && getClass() != null)
{
- String refinedTestReportDir =
- mavenTestReportDir.getAbsolutePath();
+ String refinedBaseDir =
+ mavenBaseDir.getAbsolutePath();
String fileSeparator = System.getProperty(FILE_SEPARATOR);
String className = getClass().getName();
- if(refinedTestReportDir != null && fileSeparator != null &&
+ if(refinedBaseDir != null && fileSeparator != null &&
className != null)
{
StringBuffer buffy = new StringBuffer();
- buffy.append(refinedTestReportDir);
+ buffy.append(refinedBaseDir);
+ buffy.append(fileSeparator);
+ buffy.append(TARGET_DIR);
+ buffy.append(fileSeparator);
+ buffy.append(TEST_REPORTS_DIR);
buffy.append(fileSeparator);
buffy.append(TEST_LOG_PREFIX);
buffy.append(className);
buffy.append(TEST_LOG_EXTENSION);
setLogger(buffy.toString());
}
- else if(refinedTestReportDir == null)
+ else if(refinedBaseDir == null)
{
throw new Exception("refinedTestReportDir == null");
}
@@ -129,25 +139,25 @@
throw new Exception("UNEXPECTED EXCEPTION");
}
}
- else if(!mavenTestReportDir.exists())
+ else if(!mavenBaseDir.exists())
{
throw new Exception(
"The maven test report directory, \"" +
- mavenTestReportDir.getAbsolutePath() + "\", does not "
+ mavenBaseDir.getAbsolutePath() + "\", does not "
+ "exist.");
}
- else if(!mavenTestReportDir.isDirectory())
+ else if(!mavenBaseDir.isDirectory())
{
throw new Exception(
"The maven test report directory, \"" +
- mavenTestReportDir.getAbsolutePath() + "\", is not a " +
+ mavenBaseDir.getAbsolutePath() + "\", is not a " +
"directory.");
}
- else if(!mavenTestReportDir.canWrite())
+ else if(!mavenBaseDir.canWrite())
{
throw new Exception(
"The maven test report directory, \"" +
- mavenTestReportDir.getAbsolutePath() + "\", is not " +
+ mavenBaseDir.getAbsolutePath() + "\", is not " +
"writable.");
}
else if(getClass() != null)
@@ -159,8 +169,20 @@
throw new Exception("UNEXPECTED EXCEPTION");
}
}
+ else
+ {
+ throw new Exception("basedir == null");
+ }
}
+ protected void tearDown() throws Exception
+ {
+ if(getLogger() != null)
+ {
+ LogManager.shutdown();
+ }
+ }
+
protected Logger getLogger()
{
return logger;
@@ -172,15 +194,8 @@
{
FileAppender logFileAppender =
new FileAppender(new SimpleLayout(), logFileName, false);
- if(Logger.getRootLogger() != null)
- {
- logger = Logger.getRootLogger();
- logger.addAppender(logFileAppender);
- }
- else
- {
- throw new Exception("logger == null");
- }
+ BasicConfigurator.configure(logFileAppender);
+ logger = LogManager.getRootLogger();
}
else if(logFileName == null)
{
@@ -192,6 +207,3 @@
}
}
}
-
-
-
--
To unsubscribe, e-mail: <mailto:commons-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@;jakarta.apache.org>