Created
October 22, 2012 07:47
-
-
Save mguillermin/3930185 to your computer and use it in GitHub Desktop.
PlayFramework 2.0 Ebean Test with YAML data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
companies: | |
- !!models.Company | |
name: myFirstCompany | |
- !!models.Company | |
name: mySecondCompany |
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
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?