Skip to content
gunnarmorling edited this page Sep 13, 2010 · 2 revisions

An implementation of a DBUnit IDataSet, that allows the use of script expressions in its fields. In order to use a certain scripting language in a scriptable data set, a JSR 223 ("Scripting for the JavaTM Platform") compatible script engine has to exist for that language.

Using the JRuby engine e.g., a scriptable data set file could look like this:

<dataset>
<location num="jruby:12/2" addr="jruby:‘Webster Street’.reverse" date="jruby:DateTime::now() – 14"/>
</dataset>
A ScriptableDataSet can be created as follows:
IDataSet wrapped = …;

List<ScriptInvocationHandler> handlers = new ArrayList<Class<? extends ScriptInvocationHandler>>();
handlers.add(new JRubyImportAddingInvocationHandler());

IDataSet scriptableDS = new ScriptableDataSet(
wrapped, new ScriptableDataSetConfig("jruby", "jruby:", handlers));
where
  • jruby is the name of a scripting language as understood by javax.script.ScriptEngineManager
  • jruby: is a prefix, that shall precede fields in that scripting language
  • handlers is an optional list of ScriptInvocationHandlers, that can be used to pre-process scripts (e.g. to add common imports) and post-process scripts (e.g. to convert results into data types understood by DBUnit).
Clone this wiki locally