]> source.dussan.org Git - poi.git/commitdiff
Adjust some tests to not hardcode the 'test-data' directory. This breaks the Sonar...
authorDominik Stadler <centic@apache.org>
Sat, 15 Feb 2014 00:20:24 +0000 (00:20 +0000)
committerDominik Stadler <centic@apache.org>
Sat, 15 Feb 2014 00:20:24 +0000 (00:20 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1568557 13f79535-47bb-0310-9956-ffa450edef68

src/excelant/testcases/org/apache/poi/ss/excelant/BuildFileTest.java
src/excelant/testcases/org/apache/poi/ss/excelant/TestBuildFile.java
src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSet.java
src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSetDoubleCell.java
src/excelant/testcases/org/apache/poi/ss/excelant/tests.xml
src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtil.java
src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtilFactory.java
src/testcases/org/apache/poi/hssf/dev/BaseXLSIteratingTest.java
src/testcases/org/apache/poi/hssf/dev/TestEFBiffViewer.java
src/testcases/org/apache/poi/hssf/dev/TestReSave.java

index 5a30744cd0c956f97098ec15c79aedc18c95dec1..41b3b04fdcc46bbcc56b88c75349cedd0349426e 100644 (file)
 \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
@@ -70,6 +76,7 @@ public abstract class BuildFileTest extends TestCase {
      * 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
@@ -300,6 +307,7 @@ public abstract class BuildFileTest extends TestCase {
         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
@@ -476,6 +484,11 @@ public abstract class BuildFileTest extends TestCase {
         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
index 4d8f0d5a81d54fc01053892992e049ad8b86cdbf..651a2319d524858612eaae36687f0e317306b915 100644 (file)
@@ -17,6 +17,7 @@
  */\r
 package org.apache.poi.ss.excelant;\r
 \r
+\r
 /**\r
  *  JUnit test for the ExcelAnt tasks.\r
  *  Leverages Ant's test framework.\r
@@ -26,8 +27,9 @@ package org.apache.poi.ss.excelant;
  */\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
@@ -42,14 +44,14 @@ public class TestBuildFile extends BuildFileTest {
 \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
index cfba01b585a9b5353dd435b81b680e02c2c5b977..b59c886ae9bdab7e7765e0113890b71eda415dcc 100644 (file)
@@ -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() ;
index 1b9e527e07d2ff500862159cfde12aafe1b4f9be..3d5b11ef49c654cb80db49f53c9a374881e138ef 100644 (file)
@@ -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() ;
index 78ed1311e93ac748222f5d0e8c06a1ec669f3976..de0e616aecc8c755c2d38f56cfb0b632a0a909d6 100644 (file)
@@ -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>
index eebf8bec1369b53afaef652c5de74911bc3749b2..7e5b1e4534e7470a63427004bb35707b0def9507 100644 (file)
@@ -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 ) ;
        }
index 79c898a034954ddac35e2f1992030d13094f2acd..0d4e7c31123c55cc190fea551071bb69a1772c8c 100644 (file)
@@ -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 ) ;
index eb6b5a9d3079afd44dd613a78284778e2b632ced..8c700b5620e858f4350245ced0f9049adc12d5a9 100644 (file)
@@ -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, 
index 174beca38a0dfc1879bf43b9f24f3247c1627aea..a1c70bde9096826dd46c9803bd0e340a3c879dd1 100644 (file)
@@ -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
index 3e0773ee516f49eafb687e44c096a04d2e565ab8..36a6de4eb9c15038e95ca4d25441e6ff22b74b46 100644 (file)
@@ -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());