I've got an existing Grails/MongoDB application that I am adding some automated tests to. I want those tests to be executed against a specific set of data in a Mongo collection. I want the tests to be able to mangle the data (with predictable results, if I'm lucky) and then be able to quickly drop and recreate/reload the database so that I can run the test again.
Since I'm going to base this seed test data on real data from our production system, I'd like to be able to perhaps load the data from a JSON/BSON format that I could retrieve from a query in the Mongo shell or something similar.
Basically I don't want to have to write a hundred lines of code like the following: new Record(name: 'John Doe', age: '25', favoriteColor: 'blue').save()
Except with 30 properties each, all the while ensuring that constraints are met and that the data is realistic. That's why I want to use production data.
I also don't want to have to resort to spawning execs that run mongorestore to load and reload real data, since that would require additional software to be running on the tester's machine.
Is there a better way? Perhaps somehow unmarshalling raw JSON into something that I can then execute with the Grails MongoDB GORM or GMongo or a direct call to the Java MongoDB driver?