\r
package org.apache.poi.ss.excelant;\r
\r
-import junit.framework.TestCase;\r
-import org.apache.tools.ant.*;\r
-\r
import java.io.File;\r
import java.io.PrintStream;\r
import java.net.URL;\r
\r
+import junit.framework.TestCase;\r
+\r
+import org.apache.poi.POIDataSamples;\r
+import org.apache.tools.ant.BuildEvent;\r
+import org.apache.tools.ant.BuildException;\r
+import org.apache.tools.ant.BuildListener;\r
+import org.apache.tools.ant.Project;\r
+import org.apache.tools.ant.ProjectHelper;\r
+\r
/**\r
* A BuildFileTest is a TestCase which executes targets from an Ant buildfile\r
* for testing.\r
* is automatically called, since it's trivial to have a\r
* test target depend on it.\r
*/\r
+ @Override\r
protected void tearDown() throws Exception {\r
if (project == null) {\r
/*\r
fullLogBuffer = new StringBuffer();\r
project = new Project();\r
project.init();\r
+ project.setNewProperty("data.dir.name", getDataDir());\r
File antFile = new File(System.getProperty("root"), filename);\r
project.setUserProperty("ant.file", antFile.getAbsolutePath());\r
project.addBuildListener(new AntTestListener(logLevel));\r
assertNotNull("Could not find resource :" + resource, url);\r
return url;\r
}\r
+ \r
+ public static String getDataDir() {\r
+ String dataDirName = System.getProperty(POIDataSamples.TEST_PROPERTY);\r
+ return dataDirName == null ? "test-data" : dataDirName;\r
+ }\r
\r
/**\r
* an output stream which saves stuff to our buffer.\r
*/\r
package org.apache.poi.ss.excelant;\r
\r
+\r
/**\r
* JUnit test for the ExcelAnt tasks.\r
* Leverages Ant's test framework.\r
*/\r
public class TestBuildFile extends BuildFileTest {\r
\r
+ @Override\r
public void setUp() {\r
- configureProject("src/excelant/testcases/org/apache/poi/ss/excelant/tests.xml");\r
+ configureProject(BuildFileTest.getDataDir() + "/../src/excelant/testcases/org/apache/poi/ss/excelant/tests.xml");\r
}\r
\r
public void testMissingFilename() {\r
\r
public void testEvaluate() {\r
executeTarget("test-evaluate");\r
- assertLogContaining("Using input file: test-data/spreadsheet/excelant.xls");\r
+ assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");\r
assertLogContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4.");\r
}\r
\r
public void testPrecision() {\r
executeTarget("test-precision");\r
\r
- assertLogContaining("Using input file: test-data/spreadsheet/excelant.xls");\r
+ assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");\r
assertLogContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4. " +\r
"It evaluated to 2285.5761494145563 when the value of 2285.576149 with precision of 1.0E-4");\r
assertLogContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4. " +\r
// 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() ;
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() ;
<!-- 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"/>
</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">
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"/>
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"/>
<!-- 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>
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;
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 ;
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 ) ;
}
import junit.framework.TestCase;
+import org.apache.poi.ss.excelant.BuildFileTest;
+
/**
* Tests for the ExcelAntWorbookUtilFactory.
*/
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" ;
/**
* 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 ) ;
import java.util.ArrayList;
import java.util.List;
+import org.apache.poi.POIDataSamples;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.junit.Test;
@Test
public void testMain() throws Exception {
- int count = runWithDir("test-data/spreadsheet");
- count += runWithDir("test-data/hpsf");
+ String dataDirName = System.getProperty(POIDataSamples.TEST_PROPERTY);
+ if(dataDirName == null) {
+ dataDirName = "test-data";
+ }
+
+ int count = runWithDir(dataDirName + "/spreadsheet");
+ count += runWithDir(dataDirName + "/hpsf");
System.out.println("Had " + count + " files");
}
}
});
+ assertNotNull("Did not find any xls files in directory " + dir, files);
+
runWithArrayOfFiles(files, dir, failed);
assertTrue("Expected to have no failed except the ones excluded, but had: " + failed,
SILENT_EXCLUDED.add("XRefCalc.xls");
SILENT_EXCLUDED.add("password.xls");
SILENT_EXCLUDED.add("51832.xls"); // password
+ SILENT_EXCLUDED.add("xor-encryption-abc.xls"); // password, ty again later!
SILENT_EXCLUDED.add("43493.xls"); // HSSFWorkbook cannot open it as well
+ SILENT_EXCLUDED.add("46904.xls"); // Exception, too old
};
@Override
import java.util.ArrayList;
import java.util.List;
+import org.apache.poi.POIDataSamples;
import org.junit.Test;
public class TestReSave extends BaseXLSIteratingTest {
@Test
public void testOneFile() throws Exception {
+ String dataDirName = System.getProperty(POIDataSamples.TEST_PROPERTY);
+ if(dataDirName == null) {
+ dataDirName = "test-data";
+ }
+
List<String> failed = new ArrayList<String>();
- runOneFile("test-data/spreadsheet", "49219.xls", failed);
+ runOneFile(dataDirName + "/spreadsheet", "49219.xls", failed);
assertTrue("Expected to have no failed except the ones excluded, but had: " + failed,
failed.isEmpty());