aboutsummaryrefslogtreecommitdiffstats
path: root/src/excelant
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2014-02-15 00:20:24 +0000
committerDominik Stadler <centic@apache.org>2014-02-15 00:20:24 +0000
commit7dc649c648d01347d55377018441c0b9b0972b88 (patch)
treec3efaa1ee036ff746d327d63dc29f331b06f089f /src/excelant
parenta4cb9a5826d3766c9514a6eb410ac0126e2cce24 (diff)
downloadpoi-7dc649c648d01347d55377018441c0b9b0972b88.tar.gz
poi-7dc649c648d01347d55377018441c0b9b0972b88.zip
Adjust some tests to not hardcode the 'test-data' directory. This breaks the Sonar-maven build that I am working on locally
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1568557 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/excelant')
-rw-r--r--src/excelant/testcases/org/apache/poi/ss/excelant/BuildFileTest.java19
-rw-r--r--src/excelant/testcases/org/apache/poi/ss/excelant/TestBuildFile.java8
-rw-r--r--src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSet.java7
-rw-r--r--src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSetDoubleCell.java6
-rw-r--r--src/excelant/testcases/org/apache/poi/ss/excelant/tests.xml10
-rw-r--r--src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtil.java10
-rw-r--r--src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtilFactory.java8
7 files changed, 43 insertions, 25 deletions
diff --git a/src/excelant/testcases/org/apache/poi/ss/excelant/BuildFileTest.java b/src/excelant/testcases/org/apache/poi/ss/excelant/BuildFileTest.java
index 5a30744cd0..41b3b04fdc 100644
--- a/src/excelant/testcases/org/apache/poi/ss/excelant/BuildFileTest.java
+++ b/src/excelant/testcases/org/apache/poi/ss/excelant/BuildFileTest.java
@@ -18,13 +18,19 @@
package org.apache.poi.ss.excelant;
-import junit.framework.TestCase;
-import org.apache.tools.ant.*;
-
import java.io.File;
import java.io.PrintStream;
import java.net.URL;
+import junit.framework.TestCase;
+
+import org.apache.poi.POIDataSamples;
+import org.apache.tools.ant.BuildEvent;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildListener;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.ProjectHelper;
+
/**
* A BuildFileTest is a TestCase which executes targets from an Ant buildfile
* for testing.
@@ -70,6 +76,7 @@ public abstract class BuildFileTest extends TestCase {
* is automatically called, since it's trivial to have a
* test target depend on it.
*/
+ @Override
protected void tearDown() throws Exception {
if (project == null) {
/*
@@ -300,6 +307,7 @@ public abstract class BuildFileTest extends TestCase {
fullLogBuffer = new StringBuffer();
project = new Project();
project.init();
+ project.setNewProperty("data.dir.name", getDataDir());
File antFile = new File(System.getProperty("root"), filename);
project.setUserProperty("ant.file", antFile.getAbsolutePath());
project.addBuildListener(new AntTestListener(logLevel));
@@ -476,6 +484,11 @@ public abstract class BuildFileTest extends TestCase {
assertNotNull("Could not find resource :" + resource, url);
return url;
}
+
+ public static String getDataDir() {
+ String dataDirName = System.getProperty(POIDataSamples.TEST_PROPERTY);
+ return dataDirName == null ? "test-data" : dataDirName;
+ }
/**
* an output stream which saves stuff to our buffer.
diff --git a/src/excelant/testcases/org/apache/poi/ss/excelant/TestBuildFile.java b/src/excelant/testcases/org/apache/poi/ss/excelant/TestBuildFile.java
index 4d8f0d5a81..651a2319d5 100644
--- a/src/excelant/testcases/org/apache/poi/ss/excelant/TestBuildFile.java
+++ b/src/excelant/testcases/org/apache/poi/ss/excelant/TestBuildFile.java
@@ -17,6 +17,7 @@
*/
package org.apache.poi.ss.excelant;
+
/**
* JUnit test for the ExcelAnt tasks.
* Leverages Ant's test framework.
@@ -26,8 +27,9 @@ package org.apache.poi.ss.excelant;
*/
public class TestBuildFile extends BuildFileTest {
+ @Override
public void setUp() {
- configureProject("src/excelant/testcases/org/apache/poi/ss/excelant/tests.xml");
+ configureProject(BuildFileTest.getDataDir() + "/../src/excelant/testcases/org/apache/poi/ss/excelant/tests.xml");
}
public void testMissingFilename() {
@@ -42,14 +44,14 @@ public class TestBuildFile extends BuildFileTest {
public void testEvaluate() {
executeTarget("test-evaluate");
- assertLogContaining("Using input file: test-data/spreadsheet/excelant.xls");
+ assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");
assertLogContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4.");
}
public void testPrecision() {
executeTarget("test-precision");
- assertLogContaining("Using input file: test-data/spreadsheet/excelant.xls");
+ assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");
assertLogContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4. " +
"It evaluated to 2285.5761494145563 when the value of 2285.576149 with precision of 1.0E-4");
assertLogContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4. " +
diff --git a/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSet.java b/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSet.java
index cfba01b585..b59c886ae9 100644
--- a/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSet.java
+++ b/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSet.java
@@ -28,10 +28,9 @@ public class TestExcelAntSet extends TestCase {
// concrete instance to test the set methods.
private ExcelAntSet fixture ;
- private final String mortgageCalculatorFileName =
- "test-data/spreadsheet/mortgage-calculation.xls" ;
-
-
+ private static final String mortgageCalculatorFileName =
+ BuildFileTest.getDataDir() + "/spreadsheet/mortgage-calculation.xls" ;
+
@Override
public void setUp() {
fixture = new ExcelAntSetDoubleCell() ;
diff --git a/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSetDoubleCell.java b/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSetDoubleCell.java
index 1b9e527e07..3d5b11ef49 100644
--- a/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSetDoubleCell.java
+++ b/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSetDoubleCell.java
@@ -25,11 +25,11 @@ public class TestExcelAntSetDoubleCell extends TestCase {
private ExcelAntSetDoubleCell fixture ;
- private final String mortgageCalculatorFileName =
- "test-data/spreadsheet/mortgage-calculation.xls" ;
-
private ExcelAntWorkbookUtil util ;
+ private static final String mortgageCalculatorFileName =
+ BuildFileTest.getDataDir() + "/spreadsheet/mortgage-calculation.xls" ;
+
@Override
public void setUp() {
fixture = new ExcelAntSetDoubleCell() ;
diff --git a/src/excelant/testcases/org/apache/poi/ss/excelant/tests.xml b/src/excelant/testcases/org/apache/poi/ss/excelant/tests.xml
index 78ed1311e9..de0e616aec 100644
--- a/src/excelant/testcases/org/apache/poi/ss/excelant/tests.xml
+++ b/src/excelant/testcases/org/apache/poi/ss/excelant/tests.xml
@@ -46,7 +46,7 @@ under the License.
<!-- basic evaluation test -->
<target name="test-evaluate">
- <poi:excelant fileName="test-data/spreadsheet/excelant.xls">
+ <poi:excelant fileName="${data.dir.name}/spreadsheet/excelant.xls">
<poi:test showSuccessDetails="true">
<poi:setDouble cell="'MortgageCalculator'!$B$1" value="240000"/>
<poi:setDouble cell="'MortgageCalculator'!$B$2" value ="0.11"/>
@@ -58,7 +58,7 @@ under the License.
</target>
<target name="test-precision">
- <poi:excelant fileName="test-data/spreadsheet/excelant.xls">
+ <poi:excelant fileName="${data.dir.name}/spreadsheet/excelant.xls">
<poi:precision value="1.0E-4"/>
<poi:test name="global-precision" showFailureDetail="true" showSuccessDetails="true">
@@ -92,7 +92,7 @@ under the License.
By default ExcelAnt does not terminate execution if an error occurs
-->
<target name="test-passonerror">
- <poi:excelant fileName="test-data/spreadsheet/excelant.xls">
+ <poi:excelant fileName="${data.dir.name}/spreadsheet/excelant.xls">
<poi:test name="failonerror" showFailureDetail="true" showSuccessDetails="true">
<poi:setDouble cell="'MortageCalculatorFunction'!$D$1" value="1"/>
@@ -108,7 +108,7 @@ under the License.
failOnError="true" forces ExcelAnt tot terminate execution if an error occurs
-->
<target name="test-failonerror">
- <poi:excelant fileName="test-data/spreadsheet/excelant.xls" failOnError="true">
+ <poi:excelant fileName="${data.dir.name}/spreadsheet/excelant.xls" failOnError="true">
<poi:test name="failonerror" showFailureDetail="true" showSuccessDetails="true">
<poi:setDouble cell="'MortageCalculatorFunction'!$D$1" value="1"/>
@@ -122,7 +122,7 @@ under the License.
<!-- Evaluation of user-defined functions -->
<target name="test-udf">
- <poi:excelant fileName="test-data/spreadsheet/excelant.xls">
+ <poi:excelant fileName="${data.dir.name}/spreadsheet/excelant.xls">
<poi:udf functionAlias="calculatePayment"
className="org.apache.poi.ss.examples.formula.CalculateMortgageFunction"/>
<poi:test>
diff --git a/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtil.java b/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtil.java
index eebf8bec13..7e5b1e4534 100644
--- a/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtil.java
+++ b/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtil.java
@@ -26,6 +26,7 @@ import junit.framework.TestCase;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.examples.formula.CalculateMortgageFunction;
+import org.apache.poi.ss.excelant.BuildFileTest;
import org.apache.poi.ss.formula.udf.UDFFinder;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
@@ -35,8 +36,9 @@ import org.apache.tools.ant.BuildException;
public class TestExcelAntWorkbookUtil extends TestCase {
- private final String mortgageCalculatorFileName =
- "test-data/spreadsheet/excelant.xls" ;
+ private static final String mortgageCalculatorFileName =
+ BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls" ;
+
private ExcelAntWorkbookUtilTestHelper fixture ;
@@ -125,10 +127,10 @@ public class TestExcelAntWorkbookUtil extends TestCase {
public void testGetEvaluatorXLSX() {
fixture = new ExcelAntWorkbookUtilTestHelper(
- "test-data/spreadsheet/sample.xlsx") ;
+ BuildFileTest.getDataDir() + "/spreadsheet/sample.xlsx") ;
FormulaEvaluator evaluator = fixture.getEvaluator(
- "test-data/spreadsheet/sample.xlsx" ) ;
+ BuildFileTest.getDataDir() + "/spreadsheet/sample.xlsx" ) ;
assertNotNull( evaluator ) ;
}
diff --git a/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtilFactory.java b/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtilFactory.java
index 79c898a034..0d4e7c3112 100644
--- a/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtilFactory.java
+++ b/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtilFactory.java
@@ -18,6 +18,8 @@ package org.apache.poi.ss.excelant.util;
import junit.framework.TestCase;
+import org.apache.poi.ss.excelant.BuildFileTest;
+
/**
* Tests for the ExcelAntWorbookUtilFactory.
@@ -28,8 +30,8 @@ import junit.framework.TestCase;
*/
public class TestExcelAntWorkbookUtilFactory extends TestCase{
- private final String mortgageCalculatorWorkbookFile =
- "test-data/spreadsheet/mortgage-calculation.xls" ;
+ private static final String mortgageCalculatorWorkbookFile =
+ BuildFileTest.getDataDir() + "/spreadsheet/mortgage-calculation.xls" ;
/**
@@ -52,7 +54,7 @@ public class TestExcelAntWorkbookUtilFactory extends TestCase{
* the same resource, are passed in.
*/
public void testVerifyEquivalence() {
- String sameFileName = "test-data/spreadsheet/mortgage-calculation.xls" ;
+ String sameFileName = BuildFileTest.getDataDir() + "/spreadsheet/mortgage-calculation.xls" ;
ExcelAntWorkbookUtil util = ExcelAntWorkbookUtilFactory.getInstance(
mortgageCalculatorWorkbookFile ) ;