-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HOWTO: How can one re-use Generator definitions? #46
Comments
In general copy paste would be always an option when it comes to xml part, but in your case you can create a custom generator as already suggested by taking for example the PersonGenerator as example check out how the return object looks like , the Persongenerator is returning a Person object, create a bean for example
or you can access the propertis like this
or you can somehow use the already existing xml properties like |
What is the equivalent of
to be used in the custom generator? There's quite a lot of functionality tied up in |
actually the person generator is doing excatly what you need, it is also loading csv files in background and using distribution funtions to pick data from a list. |
maybe something important i should add, some generators are structured in datasets and these datasets are reflected in csv files like the GivenNameGenerator and these classes are child of WeightedDatasetCSVGenerator, related and loaded datasets you can find here https://github.com/rapiddweller/rapiddweller-benerator-ce/tree/development/src/main/resources/com/rapiddweller/domain/person hope this helps to make things more clear |
i would probably build a simple generator class, handle the distribution stuff in this class by using java random utils and when it come to using this generator inside my specs (.ben.xml) i would go for this approach
|
Thanks - although, PersonGeneratar (and AddressGenerator and friends) are all weighted CSV Generators : they have just one data column, and a weight column. My example is actually an entity CSV source (see name bank.ent.csv) - I need multiple columns, not just a single one (Sorry, not trying to be deliberately obtuse!) |
The PersonGenerator actually ist generating a Person object , thats why you can say
you are getting a Person object with related attributes you can access with person.familyName for example. My understanding is , this is the datastructure you want to generate with custom generator
and access via
please tell me when i have the wrong understanding of what you want to archive ? |
My apologies, I probably am not being entirely clear! I want to have a Company generator - generating a bank account, and a company name, and an address. The CompanyGenerator - if it is to be a Java Generator, which it sounds like it needs to be - would be like PersonGenerator, and delegate to lots of other Generators (adress generators, company name generators, Regex generators). That would lead to something like the following. I am not wildly happy with the repeated and duplicated
In summary : I think the "difficulty" I am having is that the In this particular case, I think I want to be able to know how to select/genereate a random entity from a CSVfile, and use it in a custom generator And finally, it would be good if you could reuse some template generator in the xml, and then override individual attributes. Don't want much, do i? :-) |
Thank you for your input ! i am going to thing about how to realize such kind of template generator. I can also recommend to use javascript in benerator context , you can interact with benerator object through polyglot for example using the database connection to query data more dynamic
or generating data by using javascript functions
|
How can one define a "basic" generator template in a ben.xml and re-use it in multiple scenarios in the same .ben.xml ?
As an example, I am generating data for 3 different classes of organisation, where address and bank account generation are the same, but other attributes are overriden (and new attributes are added).
Currently, I can only see cut-and-paste reuse as an option, or define a Generator class in Java - which is doable, of course, but it's not terribly clear how to map the XML elements/attributes to the constituent generator classes...
Ideally, one would be able to define a basic generator and reuse them as a source for a variable, e.g.
The text was updated successfully, but these errors were encountered: