The importer used a property file in which it relates to the file with the data to import. So for every test-case I had to create a test-file and a configuration file. I named them like:
- test001_configuration.properties
- test001_medewlist.txt
- test002_configuration.properties
- test002_medewlist.txt
For the importer a working ant build file was created with a run target. So I thought it would be nice to have a seperate testBuild.xml file that does the job.
So I created this file with first a simple copy-target that copies a backupped original configuration file back to the conf directory. I want to leave the project as it is committed to subversion after my test.
Then I created a macro-definition that gets the test-configuration-file as an attribute.
It copies this test configuration file over the actual configuration file. Then it tries to call the run-target of the main build file. And then it copies the original one back.
I found that the run-target of the original file could fail and in that case it should also restore the original configuration file, in stead of failing my test-script. With ant-contrib you can use a try-catch-finally the same way as in Java.
Here's my resulting testBuild.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project name="TestDirectoryServiceSynchronizer" basedir=".">
<!-- Task Definition for ant-contrib.jar -->
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="c:/repository/generic/support/common/lib/ant-contrib.jar"/>
</classpath>
</taskdef>
<target name="copyOrgConfig">
<echo>Copy Original Config-file Back</echo>
<copy toFile="conf/configuration.properties" overwrite="true">
<fileset file="test/configuration.properties.org" />
</copy>
</target>
<target name="001-AddOneEmployee">
<test-case configFile="test001_configuration.properties" />
</target>
<target name="002-RemoveOneEmployee">
<test-case configFile="test002_configuration.properties" />
</target>
<macrodef name="test-case">
<attribute name="configFile" default="attribute configFile not set" />
<sequential>
<echo>Copy Config-file @{configFile}</echo>
<copy toFile="conf/configuration.properties" overwrite="true">
<fileset file="test/@{configFile}" />
</copy>
<!-- call run -->
<echo>Run DirectorySynchronizer</echo>
<trycatch>
<try>
<ant antfile="${basedir}/build.xml" target="run" />
</try>
<catch>
<echo>Investigate exceptions in the run!</echo>
</catch>
<finally>
<antcall target="copyOrgConfig" />
</finally>
</trycatch>
</sequential>
</macrodef>
</project>