Base File Format
<?xml version="1.0" encoding="iso-8859-1"?> |
Hello World
Descriptor:
<import defaults="true"/> |
Output:
message[text=Hello World]
message[text=Hi World]
message[text=Hello Planet]
message[text=Hello Planet]
message[text=Howdy Earth]
Simple-Type Data Generation
Regular-Expression-based
<attribute name="wecomeMessage" type="string" pattern="(Hello|Hi|Howdy) (World|Earth|Planet)"/> |
List-based
<attribute name="rank" type="string" pattern="A,B,C"/> |
Script-based
<variable name="block" pattern="[A-Z]" /> |
Decisions in FreeMarker
A common requirement is to have alternative ways to render some data, depending on context or necessary data conversion, e.g. for entities with multifield constraints or mapping of null values or booleans. The simplest way
The simplest way to configure this is a FreeMarker condition expression in the general form:
<attribute name="test" script="ftl:[#ftl][#if condition]expression[#else]expression[/#if]" /> |
An example that mixes data of two alternatives alt1 and alt2 (possibly taken from two different data sets) is:
<attribute name="test" script="ftl:[#ftl][#if random < percentage]${alt1}[#else]${alt2}[/#if]" /> |
Please note, that random and percentage can be variables or properties defined before and may not be wrapped with ${}!
Exporting entities in different formats
Writing entities to a CSV file
<generate name="Person" count="5"> |
creates a file 'users.csv' in UTF-8 encoding with the columns id and name:
id,name |
Database related
Defining a database
<database id="db" url="jdbc:hsqldb:hsql://localhost" driver="org.hsqldb.jdbcDriver" user="sa" password="" schema="public" batch="false"/> |
Executing DDL
from a file
<execute uri="create-tables.sql" target="db" onError="fatal"/> |
inline
<execute target="db" type="sql" onError="warn"> |
Importing data from a from a DbUnit XML file
<iterate source="shop.dbunit.xml" consumer="db"/> |
Exporting generated data to a SQL file
You need to configure the SQLEntityExporter to usse a database dialect for SQL file generation:
<database id="db" ... /> |
Available dialects are
| dialect | database system |
| db2 | DB2 |
| derby | Derby |
| firebird | Firebird |
| hsql | HSQL |
| h2 | H2 |
| oracle | Oracle |
| postgres | PostgreSQL |
| sql_server | SQL Server |


