views:

96

answers:

2

Hello,
Is it advisable to use the build-test-data plugin to load the bootstrap (seed/initial) data for an application. The plugin tutorial is excellent at http://bitbucket.org/tednaleid/grails-test-data/wiki/Home , but only mention about loading test data. There is a section about TestDataConfig , which allows to set default data. But is it a viable option if the data needs to persist in a larger scale, with complex relations.\ thanks.

+1  A: 

It depends on your data. If you only need a few things like administrator account info, list of categories, etc it should work fine. I'd use it if you’re testing your app with the initial seed data and everything works fine. For large or complex data imports I'd use a gant script to create and save for all the domain objects. For example I'm working on a project that requires me to move data out of a legacy database into a grails application. For this I run a script that uses JDBC calls to get all the old data out of the legacy database. I then create and save new domain objects based off this data. For an example of how to run a script that has access to the entire Grails context including Gorm see this

Jared
thanks you for the help.. the script works great, except I couldn't access service method (as mentioned below).. hope the author helps me.. thanks again
bsreekanth
+1  A: 

Testing data is the primary focus of the plugin, but I use it for all kinds of data loading situations, including bootstrapping data into a new system.

The only thing you need to be aware of is that the plugin, by design, will fill in any holes in required data that you don't supply. This means that you should specify everything that you actually want specific values on (or putting it in the TestDataConfig that you mention). If you don't give build-test-data a value, it'll make something up and that might be something that you don't want.

The newly added functionality around buildLazy makes it even easier to hook into an existing graph of objects that you might have in a BootStrap configuration.

Ted Naleid
Ted.. thank you for the suggestion.. Inevitably, I have to use the plugin as it is probably the best way to do integration test. But, with the suggestion of Jared, I have been building my data using your runscript (http://bitbucket.org/tednaleid/grails-run-script/changeset/14ab603ebf11#chg-scripts/RunScript.groovy).. It work great for the moment, except I can't access the service as you mentioned in your blog. I included the package (part of nimble plugin : import grails.plugins.nimble.core.*) and defined the service like def userService . When I invoke a method of this service, I get an error
bsreekanth
Error executing script Interactive: No such property: userService for class: Script1Application context shutting down...Application context shutdown.can you please help me.. I would eventually migrate to ur plugin for all of these.. thanks a lot..
bsreekanth
@bsreekanth I'm guessing that you aren't instantiating your userService properly, sounds like it isn't defined in your script. You can ask the spring context for a bean like your service with something like this: def userService = grailsApplication.mainContect.getBean("userService").If grailsApplication isn't in scope/defined, you can get one from the ApplicationHolder class. HTH
Ted Naleid
that was indeed the problem... thanks a lot!!!
bsreekanth