Author: centic
Date: Sat Feb 15 00:20:24 2014
New Revision: 1568557

URL: http://svn.apache.org/r1568557
Log:
Adjust some tests to not hardcode the 'test-data' directory. This breaks the 
Sonar-maven build that I am working on locally

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

Modified: 
poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/BuildFileTest.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/BuildFileTest.java?rev=1568557&r1=1568556&r2=1568557&view=diff
==============================================================================
--- 
poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/BuildFileTest.java 
(original)
+++ 
poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/BuildFileTest.java 
Sat Feb 15 00:20:24 2014
@@ -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 exte
      * 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 exte
         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 exte
         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.

Modified: 
poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/TestBuildFile.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/TestBuildFile.java?rev=1568557&r1=1568556&r2=1568557&view=diff
==============================================================================
--- 
poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/TestBuildFile.java 
(original)
+++ 
poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/TestBuildFile.java 
Sat Feb 15 00:20:24 2014
@@ -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 Build
 
     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.  " +

Modified: 
poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSet.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSet.java?rev=1568557&r1=1568556&r2=1568557&view=diff
==============================================================================
--- 
poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSet.java
 (original)
+++ 
poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSet.java
 Sat Feb 15 00:20:24 2014
@@ -28,10 +28,9 @@ public class TestExcelAntSet extends Tes
        // 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() ;

Modified: 
poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSetDoubleCell.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSetDoubleCell.java?rev=1568557&r1=1568556&r2=1568557&view=diff
==============================================================================
--- 
poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSetDoubleCell.java
 (original)
+++ 
poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/TestExcelAntSetDoubleCell.java
 Sat Feb 15 00:20:24 2014
@@ -25,11 +25,11 @@ public class TestExcelAntSetDoubleCell e
        
        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() ;

Modified: poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/tests.xml
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/tests.xml?rev=1568557&r1=1568556&r2=1568557&view=diff
==============================================================================
--- poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/tests.xml 
(original)
+++ poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/tests.xml Sat 
Feb 15 00:20:24 2014
@@ -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>

Modified: 
poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtil.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtil.java?rev=1568557&r1=1568556&r2=1568557&view=diff
==============================================================================
--- 
poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtil.java
 (original)
+++ 
poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtil.java
 Sat Feb 15 00:20:24 2014
@@ -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.BuildExcepti
 
 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 ex
 
        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 ) ;
        }

Modified: 
poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtilFactory.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtilFactory.java?rev=1568557&r1=1568556&r2=1568557&view=diff
==============================================================================
--- 
poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtilFactory.java
 (original)
+++ 
poi/trunk/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtilFactory.java
 Sat Feb 15 00:20:24 2014
@@ -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 TestExcelAntWorkbookUtilFac
         * 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 ) ;

Modified: 
poi/trunk/src/testcases/org/apache/poi/hssf/dev/BaseXLSIteratingTest.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/dev/BaseXLSIteratingTest.java?rev=1568557&r1=1568556&r2=1568557&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/dev/BaseXLSIteratingTest.java 
(original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/dev/BaseXLSIteratingTest.java 
Sat Feb 15 00:20:24 2014
@@ -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 BaseXLSIteratingTe
 
        @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 BaseXLSIteratingTe
                        }
                });
                
+               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, 

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestEFBiffViewer.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestEFBiffViewer.java?rev=1568557&r1=1568556&r2=1568557&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestEFBiffViewer.java 
(original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestEFBiffViewer.java Sat 
Feb 15 00:20:24 2014
@@ -30,7 +30,9 @@ public class TestEFBiffViewer extends Ba
                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

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestReSave.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestReSave.java?rev=1568557&r1=1568556&r2=1568557&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestReSave.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestReSave.java Sat Feb 15 
00:20:24 2014
@@ -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 BaseXLSI
 
        @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());



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@poi.apache.org
For additional commands, e-mail: commits-h...@poi.apache.org

Reply via email to