Databene benerator: use an already generated date, to be the min value of another date in the same entity

StackOverflow https://stackoverflow.com/questions/15598645

  •  29-03-2022
  •  | 
  •  

Question

I have this RESERVATION entity with a start date and end date. I'm generating test data using benerator. What I want is to use the the start date + 1 day as the min value for the end date. how to achieve this is proving difficult. Here is part of the generate tag which makes benerator complain.

<attribute name="START_DATE" type="date" min="2013-03-24" max="2013-03-30"    
     nullable="false"/>
<attribute name="END_DATE" type = "date" min="this.START_DATE + 1" max="2013-04-13" 
     nullable="false"/>

So how do I use the start date generated as the min value for the end date to be generated?

Was it helpful?

Solution

Databene benerator's writer Volker bergmann gave me an answer when I emailed him the problem. Just use the TimeUtil class and some variables like this...

<attribute name="START_DATE" type="date" script="TimeUtil.today()" nullable="false"/>
<variable name="for_endDate" type="int" min="1" max="10" />
<attribute name="END_DATE" type = "date" script="TimeUtil.addDays(this.START_DATE,   
      for_endDate)"  nullable="false"/>

And you have to import the TimeUtil class at the beginning of the xml just after the setup tag

<import class="org.databene.commons.TimeUtil"/>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top