databene

 
  • Increase font size
  • Default font size
  • Decrease font size

Hello World Tutorial

 

1. Create a descriptor file

After installing benerator, create a file benerator.xml with the following content:

<?xml version="1.0" encoding="iso-8859-1"?>
<setup>
    <generate type="message" count="5" consumer="ConsoleExporter" >
        <attribute name="text" type="string" pattern="(Hello|Hi|Howdy) (World|Earth|Planet)"/>
    </generate>
</setup>  



That's a benerator descriptor file! It contains data descriptions and commands for benerator. It has some similarities with an ant file.
 

2. Check the descriptor file

Look at the code: After importing some default classes and packages, you see that 5 entities of type 'message' shall be created and consumed by a 'ConsoleExporter'. Each entity shall contain an attribute 'text' of type 'string' which complies to the regular expression '(Hello|Hi|Howdy) (World|Earth|Planet)'.

 
3. Run benerator

Open a shell in the directory that contains the descriptor file and if you are using Windows, type

benerator

otherwise

benerator.sh

Now benerator will run the descriptor file and generate messages similar to these:

message[text=Hi World]
message[text=Hello World]
message[text=Hello Planet]
message[text=Hello Planet]
message[text=Hello Earth]