Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load test data (fixtures) in Play2?

How to load test data (fixtures) in Play2?

I've noticed that for Play1 people would use .yaml files and the Fixtures class, but couldn't find the equivalent for Play2 (Java).

like image 868
Lucas Pottersky Avatar asked Jul 18 '12 17:07

Lucas Pottersky


1 Answers

I've been successful with this script:

Map<String, List<Object>> tableMap = (Map<String, List<Object>>) Yaml.load(fixtureFile);//yaml must be in conf folder?

for (Map.Entry<String, List<Object>> tableEntry : tableMap.entrySet()) {
    Ebean.save(tableEntry.getValue());
    Logger.info("loaded " + tableEntry.getValue().size() + " " + tableEntry.getKey() + " from '" + fixtureFile + "' into the database");
}

Hope this could help.

like image 182
Duc Tran Avatar answered Nov 20 '22 01:11

Duc Tran