diff options
author | Javen O'Neal <onealj@apache.org> | 2017-02-08 07:47:30 +0000 |
---|---|---|
committer | Javen O'Neal <onealj@apache.org> | 2017-02-08 07:47:30 +0000 |
commit | 7b38711979249d1ea6bb3da7974125ef0332c78e (patch) | |
tree | 57321baea500c11f3be2bcbe1345e6b0c75afebd /src/excelant | |
parent | 2a0c4cdde470a9641c0c56f8c7f7e689992e81e8 (diff) | |
download | poi-7b38711979249d1ea6bb3da7974125ef0332c78e.tar.gz poi-7b38711979249d1ea6bb3da7974125ef0332c78e.zip |
Convert all *.java files to use native end of line character(s)
$ dos2unix `find -name *.java`
$ svn propset svn:eol-style native `find -name *.java`
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1782114 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/excelant')
6 files changed, 949 insertions, 949 deletions
diff --git a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntHandlerTask.java b/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntHandlerTask.java index 35f5420f01..c6baee4f24 100644 --- a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntHandlerTask.java +++ b/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntHandlerTask.java @@ -1,76 +1,76 @@ -/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.ss.excelant;
-
-import org.apache.poi.ss.excelant.util.ExcelAntWorkbookUtil;
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.Task;
-
-/**
- * This is the class that backs the <handler> tag in the Ant task.
- * <p>
- * Its purpose is to provide a way to manipulate a workbook in the course
- * of an ExcelAnt task. The idea being to model a way for test writers to
- * simulate the behaviors of the workbook.
- * <p>
- * Suppose, for example, you have a workbook that has a worksheet that
- * reacts to values entered or selected by the user. It's possible in
- * Excel to change other cells based on this but this isn't easily possible
- * in POI. In ExcelAnt we handle this using the Handler, which is a Java
- * class you write to manipulate the workbook.
- * <p>
- * In order to use this tag you must write a class that implements the
- * <code>IExcelAntWorkbookHandler</code> interface. After writing the
- * class you should package it and it's dependencies into a jar file to
- * add as library in your Ant build file.
- *
- * @author Jon Svede ( jon [at] loquatic [dot] com )
- * @author Brian Bush ( brian [dot] bush [at] nrel [dot] gov )
- *
- */
-public class ExcelAntHandlerTask extends Task {
-
- private String className ;
-
- private ExcelAntWorkbookUtil wbUtil ;
-
- public void setClassName( String cName ) {
- className = cName ;
- }
-
- protected void setEAWorkbookUtil( ExcelAntWorkbookUtil wkbkUtil ) {
- wbUtil = wkbkUtil ;
- }
-
- @Override
- public void execute() throws BuildException {
- log( "handling the workbook with class " + className, Project.MSG_INFO ) ;
- try {
- Class<?> clazz = Class.forName( className ) ;
- Object handlerObj = clazz.newInstance() ;
- if( handlerObj instanceof IExcelAntWorkbookHandler ) {
- IExcelAntWorkbookHandler iHandler = (IExcelAntWorkbookHandler)handlerObj ;
- iHandler.setWorkbook( wbUtil.getWorkbook() ) ;
- iHandler.execute() ;
- }
- } catch( Exception e ) {
- throw new BuildException( e.getMessage(), e ) ;
- }
- }
- }
+/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi.ss.excelant; + +import org.apache.poi.ss.excelant.util.ExcelAntWorkbookUtil; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Task; + +/** + * This is the class that backs the <handler> tag in the Ant task. + * <p> + * Its purpose is to provide a way to manipulate a workbook in the course + * of an ExcelAnt task. The idea being to model a way for test writers to + * simulate the behaviors of the workbook. + * <p> + * Suppose, for example, you have a workbook that has a worksheet that + * reacts to values entered or selected by the user. It's possible in + * Excel to change other cells based on this but this isn't easily possible + * in POI. In ExcelAnt we handle this using the Handler, which is a Java + * class you write to manipulate the workbook. + * <p> + * In order to use this tag you must write a class that implements the + * <code>IExcelAntWorkbookHandler</code> interface. After writing the + * class you should package it and it's dependencies into a jar file to + * add as library in your Ant build file. + * + * @author Jon Svede ( jon [at] loquatic [dot] com ) + * @author Brian Bush ( brian [dot] bush [at] nrel [dot] gov ) + * + */ +public class ExcelAntHandlerTask extends Task { + + private String className ; + + private ExcelAntWorkbookUtil wbUtil ; + + public void setClassName( String cName ) { + className = cName ; + } + + protected void setEAWorkbookUtil( ExcelAntWorkbookUtil wkbkUtil ) { + wbUtil = wkbkUtil ; + } + + @Override + public void execute() throws BuildException { + log( "handling the workbook with class " + className, Project.MSG_INFO ) ; + try { + Class<?> clazz = Class.forName( className ) ; + Object handlerObj = clazz.newInstance() ; + if( handlerObj instanceof IExcelAntWorkbookHandler ) { + IExcelAntWorkbookHandler iHandler = (IExcelAntWorkbookHandler)handlerObj ; + iHandler.setWorkbook( wbUtil.getWorkbook() ) ; + iHandler.execute() ; + } + } catch( Exception e ) { + throw new BuildException( e.getMessage(), e ) ; + } + } + } diff --git a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntSet.java b/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntSet.java index 974b1b9e4c..e62f0623d9 100644 --- a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntSet.java +++ b/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntSet.java @@ -1,48 +1,48 @@ -/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.ss.excelant;
-
-import org.apache.poi.ss.excelant.util.ExcelAntWorkbookUtil;
-import org.apache.tools.ant.Task;
-
-/**
- *
- * @author Jon Svede ( jon [at] loquatic [dot] com )
- * @author Brian Bush ( brian [dot] bush [at] nrel [dot] gov )
- *
- */
-public abstract class ExcelAntSet extends Task {
-
- protected String cellStr ;
-
- protected ExcelAntWorkbookUtil wbUtil ;
-
- public void setCell( String cellName ) {
- cellStr = cellName ;
- }
-
- public String getCell() {
- return cellStr ;
- }
-
-
- public void setWorkbookUtil( ExcelAntWorkbookUtil wb ) {
- wbUtil = wb ;
- }
-
-}
+/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi.ss.excelant; + +import org.apache.poi.ss.excelant.util.ExcelAntWorkbookUtil; +import org.apache.tools.ant.Task; + +/** + * + * @author Jon Svede ( jon [at] loquatic [dot] com ) + * @author Brian Bush ( brian [dot] bush [at] nrel [dot] gov ) + * + */ +public abstract class ExcelAntSet extends Task { + + protected String cellStr ; + + protected ExcelAntWorkbookUtil wbUtil ; + + public void setCell( String cellName ) { + cellStr = cellName ; + } + + public String getCell() { + return cellStr ; + } + + + public void setWorkbookUtil( ExcelAntWorkbookUtil wb ) { + wbUtil = wb ; + } + +} diff --git a/src/excelant/java/org/apache/poi/ss/excelant/IExcelAntWorkbookHandler.java b/src/excelant/java/org/apache/poi/ss/excelant/IExcelAntWorkbookHandler.java index 139e34c0d7..c8db7008d6 100644 --- a/src/excelant/java/org/apache/poi/ss/excelant/IExcelAntWorkbookHandler.java +++ b/src/excelant/java/org/apache/poi/ss/excelant/IExcelAntWorkbookHandler.java @@ -1,42 +1,42 @@ -/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.ss.excelant;
-
-import org.apache.poi.ss.usermodel.Workbook;
-
-
-/**
- * In Excel there are many ways to handle manipulating a workbook based
- * on some arbitrary user action (onChange, etc). You use this interface
- * to create classes that will handle the workbook in whatever manner is needed
- * that cannot be handled by POI.
- * <p>
- * For example, suppose that in Excel when you update a cell the workbook
- * does some calculations and updates other cells based on that change. In
- * ExcelAnt you would set the value of the cell then write your own handler
- * then call that from your Ant task after the set task.
- *
- * @author Jon Svede ( jon [at] loquatic [dot] com )
- * @author Brian Bush ( brian [dot] bush [at] nrel [dot] gov )
- *
- */
-public interface IExcelAntWorkbookHandler {
- public void setWorkbook( Workbook workbook ) ;
-
- public void execute() ;
-}
+/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi.ss.excelant; + +import org.apache.poi.ss.usermodel.Workbook; + + +/** + * In Excel there are many ways to handle manipulating a workbook based + * on some arbitrary user action (onChange, etc). You use this interface + * to create classes that will handle the workbook in whatever manner is needed + * that cannot be handled by POI. + * <p> + * For example, suppose that in Excel when you update a cell the workbook + * does some calculations and updates other cells based on that change. In + * ExcelAnt you would set the value of the cell then write your own handler + * then call that from your Ant task after the set task. + * + * @author Jon Svede ( jon [at] loquatic [dot] com ) + * @author Brian Bush ( brian [dot] bush [at] nrel [dot] gov ) + * + */ +public interface IExcelAntWorkbookHandler { + public void setWorkbook( Workbook workbook ) ; + + public void execute() ; +} diff --git a/src/excelant/java/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtilFactory.java b/src/excelant/java/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtilFactory.java index 08e7fb3d98..683ac46368 100644 --- a/src/excelant/java/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtilFactory.java +++ b/src/excelant/java/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtilFactory.java @@ -1,60 +1,60 @@ -/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.ss.excelant.util;
-
-import java.util.HashMap;
-import java.util.Map;
-
-
-/**
- * This is a factory class maps file names to WorkbookUtil instances. This
- * helps ExcelAnt be more efficient when being run many times in an Ant build.
- *
- * @author Jon Svede (jon [at] loquatic [dot] com)
- * @author Brian Bush (brian [dot] bush [at] nrel [dot] gov)
- *
- */
-public final class ExcelAntWorkbookUtilFactory {
-
- private static Map<String, ExcelAntWorkbookUtil> workbookUtilMap;
-
- private ExcelAntWorkbookUtilFactory() {
- }
-
- /**
- * Using the fileName, check the internal map to see if an instance
- * of the WorkbookUtil exists. If not, then add an instance to the map.
- *
- * @param fileName The filename to use as key to look for the ExcelAntWorkbookUtil.
- * @return An instance of ExcelAntWorkbookUtil associated with the filename or
- * a freshly instantiated one if none did exist before.
- */
- public static ExcelAntWorkbookUtil getInstance(String fileName) {
- if(workbookUtilMap == null) {
- workbookUtilMap = new HashMap<String, ExcelAntWorkbookUtil>();
- }
-
- if(workbookUtilMap.containsKey(fileName)) {
- return workbookUtilMap.get(fileName);
- }
-
- ExcelAntWorkbookUtil wbu = new ExcelAntWorkbookUtil(fileName);
- workbookUtilMap.put(fileName, wbu);
- return wbu;
- }
-}
+/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi.ss.excelant.util; + +import java.util.HashMap; +import java.util.Map; + + +/** + * This is a factory class maps file names to WorkbookUtil instances. This + * helps ExcelAnt be more efficient when being run many times in an Ant build. + * + * @author Jon Svede (jon [at] loquatic [dot] com) + * @author Brian Bush (brian [dot] bush [at] nrel [dot] gov) + * + */ +public final class ExcelAntWorkbookUtilFactory { + + private static Map<String, ExcelAntWorkbookUtil> workbookUtilMap; + + private ExcelAntWorkbookUtilFactory() { + } + + /** + * Using the fileName, check the internal map to see if an instance + * of the WorkbookUtil exists. If not, then add an instance to the map. + * + * @param fileName The filename to use as key to look for the ExcelAntWorkbookUtil. + * @return An instance of ExcelAntWorkbookUtil associated with the filename or + * a freshly instantiated one if none did exist before. + */ + public static ExcelAntWorkbookUtil getInstance(String fileName) { + if(workbookUtilMap == null) { + workbookUtilMap = new HashMap<String, ExcelAntWorkbookUtil>(); + } + + if(workbookUtilMap.containsKey(fileName)) { + return workbookUtilMap.get(fileName); + } + + ExcelAntWorkbookUtil wbu = new ExcelAntWorkbookUtil(fileName); + workbookUtilMap.put(fileName, wbu); + return wbu; + } +} 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 55ea777871..ea2bb596cf 100644 --- a/src/excelant/testcases/org/apache/poi/ss/excelant/BuildFileTest.java +++ b/src/excelant/testcases/org/apache/poi/ss/excelant/BuildFileTest.java @@ -1,604 +1,604 @@ -/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.poi.ss.excelant;
-
-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.
- * <p/>
- * This class provides a number of utility methods for particular build file
- * tests which extend this class.
- *
- * @see <a href="http://svn.apache.org/repos/asf/ant/core/trunk/src/tests/junit/org/apache/tools/ant/BuildFileTest.java">
- * http://svn.apache.org/repos/asf/ant/core/trunk/src/tests/junit/org/apache/tools/ant/BuildFileTest.java</a>
- */
-public abstract class BuildFileTest extends TestCase {
-
- protected Project project;
-
- private StringBuffer logBuffer;
- private StringBuffer fullLogBuffer;
- private StringBuffer outBuffer;
- private StringBuffer errBuffer;
- private BuildException buildException;
-
- /**
- * Default constructor for the BuildFileTest object.
- */
- public BuildFileTest() {
- super();
- }
-
- /**
- * Constructor for the BuildFileTest object.
- *
- * @param name string to pass up to TestCase constructor
- */
- public BuildFileTest(String name) {
- super(name);
- }
-
- /**
- * Automatically calls the target called "tearDown"
- * from the build file tested if it exits.
- * <p/>
- * This allows to use Ant tasks directly in the build file
- * to clean up after each test. Note that no "setUp" target
- * is automatically called, since it's trivial to have a
- * test target depend on it.
- */
- @Override
- protected void tearDown() throws Exception {
- if (project == null) {
- /*
- * Maybe the BuildFileTest was subclassed and there is
- * no initialized project. So we could avoid getting a
- * NPE.
- * If there is an initialized project getTargets() does
- * not return null as it is initialized by an empty
- * HashSet.
- */
- return;
- }
- final String tearDown = "tearDown";
- if (project.getTargets().containsKey(tearDown)) {
- project.executeTarget(tearDown);
- }
- }
-
- /**
- * run a target, expect for any build exception
- *
- * @param target target to run
- * @param cause information string to reader of report
- */
- public void expectBuildException(String target, String cause) {
- expectSpecificBuildException(target, cause, null);
- }
-
- /**
- * Assert that only the given message has been logged with a
- * priority <= INFO when running the given target.
- */
- public void expectLog(String target, String log) {
- executeTarget(target);
- String realLog = getLog();
- assertEquals(log, realLog);
- }
-
- /**
- * Assert that the given substring is in the log messages.
- */
- public void assertLogContaining(String substring) {
- String realLog = getLog();
- assertTrue("expecting log to contain \"" + substring + "\" log was \""
- + realLog + "\"",
- realLog.indexOf(substring) >= 0);
- }
-
- /**
- * Assert that the given substring is not in the log messages.
- */
- public void assertLogNotContaining(String substring) {
- String realLog = getLog();
- assertFalse("didn't expect log to contain \"" + substring + "\" log was \""
- + realLog + "\"",
- realLog.indexOf(substring) >= 0);
- }
-
- /**
- * Assert that the given substring is in the output messages.
- *
- * @since Ant1.7
- */
- public void assertOutputContaining(String substring) {
- assertOutputContaining(null, substring);
- }
-
- /**
- * Assert that the given substring is in the output messages.
- *
- * @param message Print this message if the test fails. Defaults to
- * a meaningful text if <tt>null</tt> is passed.
- * @since Ant1.7
- */
- public void assertOutputContaining(String message, String substring) {
- String realOutput = getOutput();
- String realMessage = (message != null)
- ? message
- : "expecting output to contain \"" + substring + "\" output was \"" + realOutput + "\"";
- assertTrue(realMessage, realOutput.indexOf(substring) >= 0);
- }
-
- /**
- * Assert that the given substring is not in the output messages.
- *
- * @param message Print this message if the test fails. Defaults to
- * a meaningful text if <tt>null</tt> is passed.
- * @since Ant1.7
- */
- public void assertOutputNotContaining(String message, String substring) {
- String realOutput = getOutput();
- String realMessage = (message != null)
- ? message
- : "expecting output to not contain \"" + substring + "\" output was \"" + realOutput + "\"";
- assertFalse(realMessage, realOutput.indexOf(substring) >= 0);
- }
-
- /**
- * Assert that the given message has been logged with a priority <= INFO when running the
- * given target.
- */
- public void expectLogContaining(String target, String log) {
- executeTarget(target);
- assertLogContaining(log);
- }
-
- /**
- * Assert that the given message has not been logged with a
- * priority <= INFO when running the given target.
- */
- public void expectLogNotContaining(String target, String log) {
- executeTarget(target);
- assertLogNotContaining(log);
- }
-
- /**
- * Gets the log the BuildFileTest object.
- * Only valid if configureProject() has been called.
- *
- * @return The log value
- * @pre logBuffer!=null
- */
- public String getLog() {
- return logBuffer.toString();
- }
-
- /**
- * Assert that the given message has been logged with a priority
- * >= VERBOSE when running the given target.
- */
- public void expectDebuglog(String target, String log) {
- executeTarget(target);
- String realLog = getFullLog();
- assertEquals(log, realLog);
- }
-
- /**
- * Assert that the given substring is in the log messages.
- */
- public void assertDebuglogContaining(String substring) {
- String realLog = getFullLog();
- assertTrue("expecting debug log to contain \"" + substring
- + "\" log was \""
- + realLog + "\"",
- realLog.indexOf(substring) >= 0);
- }
-
- /**
- * Gets the log the BuildFileTest object.
- * <p/>
- * Only valid if configureProject() has been called.
- *
- * @return The log value
- * @pre fullLogBuffer!=null
- */
- public String getFullLog() {
- return fullLogBuffer.toString();
- }
-
- /**
- * execute the target, verify output matches expectations
- *
- * @param target target to execute
- * @param output output to look for
- */
- public void expectOutput(String target, String output) {
- executeTarget(target);
- String realOutput = getOutput();
- assertEquals(output, realOutput.trim());
- }
-
- /**
- * Executes the target, verify output matches expectations
- * and that we got the named error at the end
- *
- * @param target target to execute
- * @param output output to look for
- * @param error Description of Parameter
- */
- public void expectOutputAndError(String target, String output, String error) {
- executeTarget(target);
- String realOutput = getOutput();
- assertEquals(output, realOutput);
- String realError = getError();
- assertEquals(error, realError);
- }
-
- public String getOutput() {
- return cleanBuffer(outBuffer);
- }
-
- public String getError() {
- return cleanBuffer(errBuffer);
- }
-
- public BuildException getBuildException() {
- return buildException;
- }
-
- private String cleanBuffer(StringBuffer buffer) {
- StringBuffer cleanedBuffer = new StringBuffer();
- for (int i = 0; i < buffer.length(); i++) {
- char ch = buffer.charAt(i);
- if (ch != '\r') {
- cleanedBuffer.append(ch);
- }
- }
- return cleanedBuffer.toString();
- }
-
- /**
- * Sets up to run the named project
- *
- * @param filename name of project file to run
- */
- public void configureProject(String filename) throws BuildException {
- configureProject(filename, Project.MSG_DEBUG);
- }
-
- /**
- * Sets up to run the named project
- *
- * @param filename name of project file to run
- */
- public void configureProject(String filename, int logLevel)
- throws BuildException {
- logBuffer = new StringBuffer();
- 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));
- ProjectHelper.configureProject(project, antFile);
- }
-
- /**
- * Executes a target we have set up
- *
- * @param targetName target to run
- * @pre configureProject has been called
- */
- public void executeTarget(String targetName) {
- PrintStream sysOut = System.out;
- PrintStream sysErr = System.err;
- try {
- sysOut.flush();
- sysErr.flush();
- outBuffer = new StringBuffer();
- PrintStream out = new PrintStream(new AntOutputStream(outBuffer));
- System.setOut(out);
- errBuffer = new StringBuffer();
- PrintStream err = new PrintStream(new AntOutputStream(errBuffer));
- System.setErr(err);
- logBuffer = new StringBuffer();
- fullLogBuffer = new StringBuffer();
- buildException = null;
- project.executeTarget(targetName);
- } finally {
- System.setOut(sysOut);
- System.setErr(sysErr);
- }
-
- }
-
- /**
- * Get the project which has been configured for a test.
- *
- * @return the Project instance for this test.
- */
- public Project getProject() {
- return project;
- }
-
- /**
- * Gets the directory of the project.
- *
- * @return the base dir of the project
- */
- public File getProjectDir() {
- return project.getBaseDir();
- }
-
- /**
- * Runs a target, wait for a build exception.
- *
- * @param target target to run
- * @param cause information string to reader of report
- * @param msg the message value of the build exception we are waiting
- * for set to null for any build exception to be valid
- */
- public void expectSpecificBuildException(String target, String cause, String msg) {
- try {
- executeTarget(target);
- } catch (org.apache.tools.ant.BuildException ex) {
- buildException = ex;
- if ((null != msg) && (!ex.getMessage().equals(msg))) {
- fail("Should throw BuildException because '" + cause
- + "' with message '" + msg
- + "' (actual message '" + ex.getMessage() + "' instead)");
- }
- return;
- }
- fail("Should throw BuildException because: " + cause);
- }
-
- /**
- * run a target, expect an exception string
- * containing the substring we look for (case sensitive match)
- *
- * @param target target to run
- * @param cause information string to reader of report
- * @param contains substring of the build exception to look for
- */
- public void expectBuildExceptionContaining(String target, String cause, String contains) {
- try {
- executeTarget(target);
- } catch (org.apache.tools.ant.BuildException ex) {
- buildException = ex;
- if ((null != contains) && (ex.getMessage().indexOf(contains) == -1)) {
- fail("Should throw BuildException because '" + cause + "' with message containing '" + contains + "' (actual message '" + ex.getMessage() + "' instead)");
- }
- return;
- }
- fail("Should throw BuildException because: " + cause);
- }
-
- /**
- * call a target, verify property is as expected
- *
- * @param target build file target
- * @param property property name
- * @param value expected value
- */
- public void expectPropertySet(String target, String property, String value) {
- executeTarget(target);
- assertPropertyEquals(property, value);
- }
-
- /**
- * assert that a property equals a value; comparison is case sensitive.
- *
- * @param property property name
- * @param value expected value
- */
- public void assertPropertyEquals(String property, String value) {
- String result = project.getProperty(property);
- assertEquals("property " + property, value, result);
- }
-
- /**
- * assert that a property equals "true".
- *
- * @param property property name
- */
- public void assertPropertySet(String property) {
- assertPropertyEquals(property, "true");
- }
-
- /**
- * assert that a property is null.
- *
- * @param property property name
- */
- public void assertPropertyUnset(String property) {
- String result = project.getProperty(property);
- if (result != null) {
- fail("Expected property " + property
- + " to be unset, but it is set to the value: " + result);
- }
- }
-
- /**
- * call a target, verify named property is "true".
- *
- * @param target build file target
- * @param property property name
- */
- public void expectPropertySet(String target, String property) {
- expectPropertySet(target, property, "true");
- }
-
- /**
- * Call a target, verify property is null.
- *
- * @param target build file target
- * @param property property name
- */
- public void expectPropertyUnset(String target, String property) {
- expectPropertySet(target, property, null);
- }
-
- /**
- * Retrieve a resource from the caller classloader to avoid
- * assuming a vm working directory. The resource path must be
- * relative to the package name or absolute from the root path.
- *
- * @param resource the resource to retrieve its url.
- * @throws junit.framework.AssertionFailedError
- * if the resource is not found.
- */
- public URL getResource(String resource) {
- URL url = getClass().getResource(resource);
- 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.
- */
- protected static class AntOutputStream extends java.io.OutputStream {
- private StringBuffer buffer;
-
- public AntOutputStream(StringBuffer buffer) {
- this.buffer = buffer;
- }
-
- @Override
- public void write(int b) {
- buffer.append((char) b);
- }
- }
-
- /**
- * Our own personal build listener.
- */
- private class AntTestListener implements BuildListener {
- private int logLevel;
-
- /**
- * Constructs a test listener which will ignore log events
- * above the given level.
- */
- public AntTestListener(int logLevel) {
- this.logLevel = logLevel;
- }
-
- /**
- * Fired before any targets are started.
- */
- @Override
- public void buildStarted(BuildEvent event) {
- }
-
- /**
- * Fired after the last target has finished. This event
- * will still be thrown if an error occurred during the build.
- *
- * @see BuildEvent#getException()
- */
- @Override
- public void buildFinished(BuildEvent event) {
- }
-
- /**
- * Fired when a target is started.
- *
- * @see BuildEvent#getTarget()
- */
- @Override
- public void targetStarted(BuildEvent event) {
- //System.out.println("targetStarted " + event.getTarget().getName());
- }
-
- /**
- * Fired when a target has finished. This event will
- * still be thrown if an error occurred during the build.
- *
- * @see BuildEvent#getException()
- */
- @Override
- public void targetFinished(BuildEvent event) {
- //System.out.println("targetFinished " + event.getTarget().getName());
- }
-
- /**
- * Fired when a task is started.
- *
- * @see BuildEvent#getTask()
- */
- @Override
- public void taskStarted(BuildEvent event) {
- //System.out.println("taskStarted " + event.getTask().getTaskName());
- }
-
- /**
- * Fired when a task has finished. This event will still
- * be throw if an error occurred during the build.
- *
- * @see BuildEvent#getException()
- */
- @Override
- public void taskFinished(BuildEvent event) {
- //System.out.println("taskFinished " + event.getTask().getTaskName());
- }
-
- /**
- * Fired whenever a message is logged.
- *
- * @see BuildEvent#getMessage()
- * @see BuildEvent#getPriority()
- */
- @Override
- public void messageLogged(BuildEvent event) {
- if (event.getPriority() > logLevel) {
- // ignore event
- return;
- }
-
- if (event.getPriority() == Project.MSG_INFO ||
- event.getPriority() == Project.MSG_WARN ||
- event.getPriority() == Project.MSG_ERR) {
- logBuffer.append(event.getMessage());
- }
- fullLogBuffer.append(event.getMessage());
- }
- }
-
-}
+/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.poi.ss.excelant; + +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. + * <p/> + * This class provides a number of utility methods for particular build file + * tests which extend this class. + * + * @see <a href="http://svn.apache.org/repos/asf/ant/core/trunk/src/tests/junit/org/apache/tools/ant/BuildFileTest.java"> + * http://svn.apache.org/repos/asf/ant/core/trunk/src/tests/junit/org/apache/tools/ant/BuildFileTest.java</a> + */ +public abstract class BuildFileTest extends TestCase { + + protected Project project; + + private StringBuffer logBuffer; + private StringBuffer fullLogBuffer; + private StringBuffer outBuffer; + private StringBuffer errBuffer; + private BuildException buildException; + + /** + * Default constructor for the BuildFileTest object. + */ + public BuildFileTest() { + super(); + } + + /** + * Constructor for the BuildFileTest object. + * + * @param name string to pass up to TestCase constructor + */ + public BuildFileTest(String name) { + super(name); + } + + /** + * Automatically calls the target called "tearDown" + * from the build file tested if it exits. + * <p/> + * This allows to use Ant tasks directly in the build file + * to clean up after each test. Note that no "setUp" target + * is automatically called, since it's trivial to have a + * test target depend on it. + */ + @Override + protected void tearDown() throws Exception { + if (project == null) { + /* + * Maybe the BuildFileTest was subclassed and there is + * no initialized project. So we could avoid getting a + * NPE. + * If there is an initialized project getTargets() does + * not return null as it is initialized by an empty + * HashSet. + */ + return; + } + final String tearDown = "tearDown"; + if (project.getTargets().containsKey(tearDown)) { + project.executeTarget(tearDown); + } + } + + /** + * run a target, expect for any build exception + * + * @param target target to run + * @param cause information string to reader of report + */ + public void expectBuildException(String target, String cause) { + expectSpecificBuildException(target, cause, null); + } + + /** + * Assert that only the given message has been logged with a + * priority <= INFO when running the given target. + */ + public void expectLog(String target, String log) { + executeTarget(target); + String realLog = getLog(); + assertEquals(log, realLog); + } + + /** + * Assert that the given substring is in the log messages. + */ + public void assertLogContaining(String substring) { + String realLog = getLog(); + assertTrue("expecting log to contain \"" + substring + "\" log was \"" + + realLog + "\"", + realLog.indexOf(substring) >= 0); + } + + /** + * Assert that the given substring is not in the log messages. + */ + public void assertLogNotContaining(String substring) { + String realLog = getLog(); + assertFalse("didn't expect log to contain \"" + substring + "\" log was \"" + + realLog + "\"", + realLog.indexOf(substring) >= 0); + } + + /** + * Assert that the given substring is in the output messages. + * + * @since Ant1.7 + */ + public void assertOutputContaining(String substring) { + assertOutputContaining(null, substring); + } + + /** + * Assert that the given substring is in the output messages. + * + * @param message Print this message if the test fails. Defaults to + * a meaningful text if <tt>null</tt> is passed. + * @since Ant1.7 + */ + public void assertOutputContaining(String message, String substring) { + String realOutput = getOutput(); + String realMessage = (message != null) + ? message + : "expecting output to contain \"" + substring + "\" output was \"" + realOutput + "\""; + assertTrue(realMessage, realOutput.indexOf(substring) >= 0); + } + + /** + * Assert that the given substring is not in the output messages. + * + * @param message Print this message if the test fails. Defaults to + * a meaningful text if <tt>null</tt> is passed. + * @since Ant1.7 + */ + public void assertOutputNotContaining(String message, String substring) { + String realOutput = getOutput(); + String realMessage = (message != null) + ? message + : "expecting output to not contain \"" + substring + "\" output was \"" + realOutput + "\""; + assertFalse(realMessage, realOutput.indexOf(substring) >= 0); + } + + /** + * Assert that the given message has been logged with a priority <= INFO when running the + * given target. + */ + public void expectLogContaining(String target, String log) { + executeTarget(target); + assertLogContaining(log); + } + + /** + * Assert that the given message has not been logged with a + * priority <= INFO when running the given target. + */ + public void expectLogNotContaining(String target, String log) { + executeTarget(target); + assertLogNotContaining(log); + } + + /** + * Gets the log the BuildFileTest object. + * Only valid if configureProject() has been called. + * + * @return The log value + * @pre logBuffer!=null + */ + public String getLog() { + return logBuffer.toString(); + } + + /** + * Assert that the given message has been logged with a priority + * >= VERBOSE when running the given target. + */ + public void expectDebuglog(String target, String log) { + executeTarget(target); + String realLog = getFullLog(); + assertEquals(log, realLog); + } + + /** + * Assert that the given substring is in the log messages. + */ + public void assertDebuglogContaining(String substring) { + String realLog = getFullLog(); + assertTrue("expecting debug log to contain \"" + substring + + "\" log was \"" + + realLog + "\"", + realLog.indexOf(substring) >= 0); + } + + /** + * Gets the log the BuildFileTest object. + * <p/> + * Only valid if configureProject() has been called. + * + * @return The log value + * @pre fullLogBuffer!=null + */ + public String getFullLog() { + return fullLogBuffer.toString(); + } + + /** + * execute the target, verify output matches expectations + * + * @param target target to execute + * @param output output to look for + */ + public void expectOutput(String target, String output) { + executeTarget(target); + String realOutput = getOutput(); + assertEquals(output, realOutput.trim()); + } + + /** + * Executes the target, verify output matches expectations + * and that we got the named error at the end + * + * @param target target to execute + * @param output output to look for + * @param error Description of Parameter + */ + public void expectOutputAndError(String target, String output, String error) { + executeTarget(target); + String realOutput = getOutput(); + assertEquals(output, realOutput); + String realError = getError(); + assertEquals(error, realError); + } + + public String getOutput() { + return cleanBuffer(outBuffer); + } + + public String getError() { + return cleanBuffer(errBuffer); + } + + public BuildException getBuildException() { + return buildException; + } + + private String cleanBuffer(StringBuffer buffer) { + StringBuffer cleanedBuffer = new StringBuffer(); + for (int i = 0; i < buffer.length(); i++) { + char ch = buffer.charAt(i); + if (ch != '\r') { + cleanedBuffer.append(ch); + } + } + return cleanedBuffer.toString(); + } + + /** + * Sets up to run the named project + * + * @param filename name of project file to run + */ + public void configureProject(String filename) throws BuildException { + configureProject(filename, Project.MSG_DEBUG); + } + + /** + * Sets up to run the named project + * + * @param filename name of project file to run + */ + public void configureProject(String filename, int logLevel) + throws BuildException { + logBuffer = new StringBuffer(); + 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)); + ProjectHelper.configureProject(project, antFile); + } + + /** + * Executes a target we have set up + * + * @param targetName target to run + * @pre configureProject has been called + */ + public void executeTarget(String targetName) { + PrintStream sysOut = System.out; + PrintStream sysErr = System.err; + try { + sysOut.flush(); + sysErr.flush(); + outBuffer = new StringBuffer(); + PrintStream out = new PrintStream(new AntOutputStream(outBuffer)); + System.setOut(out); + errBuffer = new StringBuffer(); + PrintStream err = new PrintStream(new AntOutputStream(errBuffer)); + System.setErr(err); + logBuffer = new StringBuffer(); + fullLogBuffer = new StringBuffer(); + buildException = null; + project.executeTarget(targetName); + } finally { + System.setOut(sysOut); + System.setErr(sysErr); + } + + } + + /** + * Get the project which has been configured for a test. + * + * @return the Project instance for this test. + */ + public Project getProject() { + return project; + } + + /** + * Gets the directory of the project. + * + * @return the base dir of the project + */ + public File getProjectDir() { + return project.getBaseDir(); + } + + /** + * Runs a target, wait for a build exception. + * + * @param target target to run + * @param cause information string to reader of report + * @param msg the message value of the build exception we are waiting + * for set to null for any build exception to be valid + */ + public void expectSpecificBuildException(String target, String cause, String msg) { + try { + executeTarget(target); + } catch (org.apache.tools.ant.BuildException ex) { + buildException = ex; + if ((null != msg) && (!ex.getMessage().equals(msg))) { + fail("Should throw BuildException because '" + cause + + "' with message '" + msg + + "' (actual message '" + ex.getMessage() + "' instead)"); + } + return; + } + fail("Should throw BuildException because: " + cause); + } + + /** + * run a target, expect an exception string + * containing the substring we look for (case sensitive match) + * + * @param target target to run + * @param cause information string to reader of report + * @param contains substring of the build exception to look for + */ + public void expectBuildExceptionContaining(String target, String cause, String contains) { + try { + executeTarget(target); + } catch (org.apache.tools.ant.BuildException ex) { + buildException = ex; + if ((null != contains) && (ex.getMessage().indexOf(contains) == -1)) { + fail("Should throw BuildException because '" + cause + "' with message containing '" + contains + "' (actual message '" + ex.getMessage() + "' instead)"); + } + return; + } + fail("Should throw BuildException because: " + cause); + } + + /** + * call a target, verify property is as expected + * + * @param target build file target + * @param property property name + * @param value expected value + */ + public void expectPropertySet(String target, String property, String value) { + executeTarget(target); + assertPropertyEquals(property, value); + } + + /** + * assert that a property equals a value; comparison is case sensitive. + * + * @param property property name + * @param value expected value + */ + public void assertPropertyEquals(String property, String value) { + String result = project.getProperty(property); + assertEquals("property " + property, value, result); + } + + /** + * assert that a property equals "true". + * + * @param property property name + */ + public void assertPropertySet(String property) { + assertPropertyEquals(property, "true"); + } + + /** + * assert that a property is null. + * + * @param property property name + */ + public void assertPropertyUnset(String property) { + String result = project.getProperty(property); + if (result != null) { + fail("Expected property " + property + + " to be unset, but it is set to the value: " + result); + } + } + + /** + * call a target, verify named property is "true". + * + * @param target build file target + * @param property property name + */ + public void expectPropertySet(String target, String property) { + expectPropertySet(target, property, "true"); + } + + /** + * Call a target, verify property is null. + * + * @param target build file target + * @param property property name + */ + public void expectPropertyUnset(String target, String property) { + expectPropertySet(target, property, null); + } + + /** + * Retrieve a resource from the caller classloader to avoid + * assuming a vm working directory. The resource path must be + * relative to the package name or absolute from the root path. + * + * @param resource the resource to retrieve its url. + * @throws junit.framework.AssertionFailedError + * if the resource is not found. + */ + public URL getResource(String resource) { + URL url = getClass().getResource(resource); + 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. + */ + protected static class AntOutputStream extends java.io.OutputStream { + private StringBuffer buffer; + + public AntOutputStream(StringBuffer buffer) { + this.buffer = buffer; + } + + @Override + public void write(int b) { + buffer.append((char) b); + } + } + + /** + * Our own personal build listener. + */ + private class AntTestListener implements BuildListener { + private int logLevel; + + /** + * Constructs a test listener which will ignore log events + * above the given level. + */ + public AntTestListener(int logLevel) { + this.logLevel = logLevel; + } + + /** + * Fired before any targets are started. + */ + @Override + public void buildStarted(BuildEvent event) { + } + + /** + * Fired after the last target has finished. This event + * will still be thrown if an error occurred during the build. + * + * @see BuildEvent#getException() + */ + @Override + public void buildFinished(BuildEvent event) { + } + + /** + * Fired when a target is started. + * + * @see BuildEvent#getTarget() + */ + @Override + public void targetStarted(BuildEvent event) { + //System.out.println("targetStarted " + event.getTarget().getName()); + } + + /** + * Fired when a target has finished. This event will + * still be thrown if an error occurred during the build. + * + * @see BuildEvent#getException() + */ + @Override + public void targetFinished(BuildEvent event) { + //System.out.println("targetFinished " + event.getTarget().getName()); + } + + /** + * Fired when a task is started. + * + * @see BuildEvent#getTask() + */ + @Override + public void taskStarted(BuildEvent event) { + //System.out.println("taskStarted " + event.getTask().getTaskName()); + } + + /** + * Fired when a task has finished. This event will still + * be throw if an error occurred during the build. + * + * @see BuildEvent#getException() + */ + @Override + public void taskFinished(BuildEvent event) { + //System.out.println("taskFinished " + event.getTask().getTaskName()); + } + + /** + * Fired whenever a message is logged. + * + * @see BuildEvent#getMessage() + * @see BuildEvent#getPriority() + */ + @Override + public void messageLogged(BuildEvent event) { + if (event.getPriority() > logLevel) { + // ignore event + return; + } + + if (event.getPriority() == Project.MSG_INFO || + event.getPriority() == Project.MSG_WARN || + event.getPriority() == Project.MSG_ERR) { + logBuffer.append(event.getMessage()); + } + fullLogBuffer.append(event.getMessage()); + } + } + +} 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 df1993be0b..7d55c52767 100644 --- a/src/excelant/testcases/org/apache/poi/ss/excelant/TestBuildFile.java +++ b/src/excelant/testcases/org/apache/poi/ss/excelant/TestBuildFile.java @@ -1,119 +1,119 @@ -/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.poi.ss.excelant;
-
-
-/**
- * JUnit test for the ExcelAnt tasks.
- * Leverages Ant's test framework.
- *
- * @see <a href="http://svn.apache.org/repos/asf/ant/core/trunk/src/tests/junit/org/apache/tools/ant/BuildFileTest.java">
- * http://svn.apache.org/repos/asf/ant/core/trunk/src/tests/junit/org/apache/tools/ant/BuildFileTest.java</a>
- */
-public class TestBuildFile extends BuildFileTest {
-
- @Override
- public void setUp() {
- configureProject(BuildFileTest.getDataDir() + "/../src/excelant/testcases/org/apache/poi/ss/excelant/tests.xml");
- }
-
- public void testMissingFilename() {
- expectSpecificBuildException("test-nofile", "required argument not specified",
- "fileName attribute must be set!");
- }
-
- public void testFileNotFound() {
- expectSpecificBuildException("test-filenotfound", "required argument not specified",
- "Cannot load file invalid.xls. Make sure the path and file permissions are correct.");
- }
-
- public void testEvaluate() {
- executeTarget("test-evaluate");
- assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");
- assertLogContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4.");
- }
-
- public void testEvaluateNoDetails() {
- executeTarget("test-evaluate-nodetails");
- assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");
- assertLogNotContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4.");
- }
-
- public void testPrecision() {
- executeTarget("test-precision");
-
- 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. " +
- "It evaluated to 2285.5761494145563 when the value of 2285.576149 with precision of 1.0E-5");
- assertLogContaining("Failed to evaluate cell 'MortgageCalculator'!$B$4. " +
- "It evaluated to 2285.5761494145563 when the value of 2285.576149 with precision of 1.0E-10 was expected.");
- assertLogContaining("2/3 tests passed");
- }
-
- public void testPrecisionFail() {
- expectSpecificBuildException("test-precision-fails", "precision not matched",
- "\tFailed to evaluate cell 'MortgageCalculator'!$B$4. It evaluated to 2285.5761494145563 when the value of 2285.576149 with precision of 1.0E-10 was expected.");
- }
-
- public void testPassOnError() {
- executeTarget("test-passonerror");
- }
-
- public void testFailOnError() {
- expectBuildException("test-failonerror", "fail on error");
- assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");
- assertLogNotContaining("failed because 1 of 0 evaluations failed to evaluate correctly. Failed to evaluate cell 'MortageCalculatorFunction'!$D$3");
- }
-
- public void testFailOnErrorNoDetails() {
- expectBuildException("test-failonerror-nodetails", "fail on error");
- assertLogNotContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");
- assertLogNotContaining("failed because 1 of 0 evaluations failed to evaluate correctly. Failed to evaluate cell 'MortageCalculatorFunction'!$D$3");
- }
-
- public void testUdf() {
- executeTarget("test-udf");
- assertLogContaining("1/1 tests passed");
- }
-
- public void testSetText() {
- executeTarget("test-settext");
- assertLogContaining("1/1 tests passed");
- }
-
- public void testAddHandler() {
- executeTarget("test-addhandler");
- assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");
- assertLogContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4.");
-
- assertNotNull("The workbook should have been passed to the handler", MockExcelAntWorkbookHandler.workbook);
- assertTrue("The handler should have been executed", MockExcelAntWorkbookHandler.executed);
- }
-
- public void testAddHandlerWrongClass() {
- executeTarget("test-addhandler-wrongclass");
- assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");
- assertLogContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4.");
- }
-
- public void testAddHandlerFails() {
- expectSpecificBuildException("test-addhandler-fails", "NullPointException", null);
- }
-}
+/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.poi.ss.excelant; + + +/** + * JUnit test for the ExcelAnt tasks. + * Leverages Ant's test framework. + * + * @see <a href="http://svn.apache.org/repos/asf/ant/core/trunk/src/tests/junit/org/apache/tools/ant/BuildFileTest.java"> + * http://svn.apache.org/repos/asf/ant/core/trunk/src/tests/junit/org/apache/tools/ant/BuildFileTest.java</a> + */ +public class TestBuildFile extends BuildFileTest { + + @Override + public void setUp() { + configureProject(BuildFileTest.getDataDir() + "/../src/excelant/testcases/org/apache/poi/ss/excelant/tests.xml"); + } + + public void testMissingFilename() { + expectSpecificBuildException("test-nofile", "required argument not specified", + "fileName attribute must be set!"); + } + + public void testFileNotFound() { + expectSpecificBuildException("test-filenotfound", "required argument not specified", + "Cannot load file invalid.xls. Make sure the path and file permissions are correct."); + } + + public void testEvaluate() { + executeTarget("test-evaluate"); + assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls"); + assertLogContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4."); + } + + public void testEvaluateNoDetails() { + executeTarget("test-evaluate-nodetails"); + assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls"); + assertLogNotContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4."); + } + + public void testPrecision() { + executeTarget("test-precision"); + + 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. " + + "It evaluated to 2285.5761494145563 when the value of 2285.576149 with precision of 1.0E-5"); + assertLogContaining("Failed to evaluate cell 'MortgageCalculator'!$B$4. " + + "It evaluated to 2285.5761494145563 when the value of 2285.576149 with precision of 1.0E-10 was expected."); + assertLogContaining("2/3 tests passed"); + } + + public void testPrecisionFail() { + expectSpecificBuildException("test-precision-fails", "precision not matched", + "\tFailed to evaluate cell 'MortgageCalculator'!$B$4. It evaluated to 2285.5761494145563 when the value of 2285.576149 with precision of 1.0E-10 was expected."); + } + + public void testPassOnError() { + executeTarget("test-passonerror"); + } + + public void testFailOnError() { + expectBuildException("test-failonerror", "fail on error"); + assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls"); + assertLogNotContaining("failed because 1 of 0 evaluations failed to evaluate correctly. Failed to evaluate cell 'MortageCalculatorFunction'!$D$3"); + } + + public void testFailOnErrorNoDetails() { + expectBuildException("test-failonerror-nodetails", "fail on error"); + assertLogNotContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls"); + assertLogNotContaining("failed because 1 of 0 evaluations failed to evaluate correctly. Failed to evaluate cell 'MortageCalculatorFunction'!$D$3"); + } + + public void testUdf() { + executeTarget("test-udf"); + assertLogContaining("1/1 tests passed"); + } + + public void testSetText() { + executeTarget("test-settext"); + assertLogContaining("1/1 tests passed"); + } + + public void testAddHandler() { + executeTarget("test-addhandler"); + assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls"); + assertLogContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4."); + + assertNotNull("The workbook should have been passed to the handler", MockExcelAntWorkbookHandler.workbook); + assertTrue("The handler should have been executed", MockExcelAntWorkbookHandler.executed); + } + + public void testAddHandlerWrongClass() { + executeTarget("test-addhandler-wrongclass"); + assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls"); + assertLogContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4."); + } + + public void testAddHandlerFails() { + expectSpecificBuildException("test-addhandler-fails", "NullPointException", null); + } +} |