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
This commit is contained in:
parent
d5e69ccbb5
commit
8bc8ac9bef
@ -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.
|
||||
|
@ -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. " +
|
||||
|
@ -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() ;
|
||||
|
@ -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() ;
|
||||
|
@ -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>
|
||||
|
@ -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 ) ;
|
||||
}
|
||||
|
@ -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 ) ;
|
||||
|
@ -27,6 +27,7 @@ import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.POIDataSamples;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -42,8 +43,13 @@ public abstract class BaseXLSIteratingTest {
|
||||
|
||||
@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");
|
||||
}
|
||||
@ -57,6 +63,8 @@ public abstract class BaseXLSIteratingTest {
|
||||
}
|
||||
});
|
||||
|
||||
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,
|
||||
|
@ -30,7 +30,9 @@ public class TestEFBiffViewer extends BaseXLSIteratingTest {
|
||||
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
|
||||
|
@ -23,6 +23,7 @@ import java.io.PrintStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.POIDataSamples;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestReSave extends BaseXLSIteratingTest {
|
||||
@ -75,8 +76,13 @@ 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());
|
||||
|
Loading…
Reference in New Issue
Block a user