Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Show comment
Hide comment
@tavlima

tavlima 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?

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

This comment has been minimized.

Show comment
Hide comment
@mguillermin

mguillermin Apr 15, 2013

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) ?

Owner

mguillermin commented Apr 15, 2013

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