Skip to content

Instantly share code, notes, and snippets.

@mguillermin
Created October 22, 2012 07:47
Show Gist options
  • Save mguillermin/3930185 to your computer and use it in GitHub Desktop.
Save mguillermin/3930185 to your computer and use it in GitHub Desktop.
PlayFramework 2.0 Ebean Test with YAML data
package models;
@Entity
public class Company extends Model {
@Id
public Long id;
public String name;
public static Finder<Long, Company> find = new Finder<Long, Company>(Long.class, Company.class);
public static List<Company> all() {
return find.all();
}
}
package models;
public class CompanyTest extends BaseModelTest {
@Test
public void fixtureTest() {
Map data = (Map)Yaml.load("data/testing-data.yml");
Ebean.save((Collection)(data.get("companies")));
assertThat(Company.all().size()).isEqualTo(2);
assertThat(Company.find.query().where().eq("name", "myFirstCompany").findRowCount()).isEqualTo(1);
}
}
companies:
- !!models.Company
name: myFirstCompany
- !!models.Company
name: mySecondCompany
@tavlima
Copy link

tavlima commented Apr 14, 2013

Have you tried to make a bigger YML (30+ entries) and run more than two @test in that CompanyTest of yours? I did and it doesn't work. Somehow Play/Ebeans fails creating the DB INSERTS, replicating IDs and violating PK constraints. Any clue?

@mguillermin
Copy link
Author

No, I didn't tried with bigger YAML files. It was just a little test. Are you sure that the database is cleaned before loading the YAML data (the DDL code should be in a @before annotated method) ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment