S2EJB3Unit(S2Unit)を使ったエンティティの一括登録の検証について
カスケードの複数登録ではないですけど、一括登録の検証はこんなかんじ?
insertEmployeePrepare.xlsはAddressテーブルとDepartmentテーブルのデータを含めてます。
insertEmployeeResult.xlsにはEmployeeテーブルのシートだけを含めてます。列にはプライマリキーを含めてません。ただプライマリキーで昇順になるように並べてあります。
@Rollback public void testInsertEmployee() { readXlsReplaceDb("insertEmployeePrepare.xls"); DataSet expected = readXls("insertEmployeeResult.xls"); EntityManager em = getEntityManager(); Address address1 = em.find(Address.class, new Long(1)); Address address2 = em.find(Address.class, new Long(2)); Address address3 = em.find(Address.class, new Long(3)); Department dept1 = em.find(Department.class, new Long(1)); Department dept2 = em.find(Department.class, new Long(2)); Employee emp1 = new Employee("A", 1000, address1, dept1); Employee emp2 = new Employee("B", 2000, address2, dept2); Employee emp3 = new Employee("C", 3000, address3, dept2); em.persist(emp1); em.persist(emp2); em.persist(emp3); em.flush(); assertEquals("0", expected.getTable(0), readDbBySql("select * from Employee order by id", "Employee")); }
EntityManagerをflushした後、readDbBySqlでEmployeeのデータをプライマリキー昇順で取得して比較してます。
どうでしょうか、id:da-yoshiさん。SQL書くのがちょっと面倒くさい感じはしますが...。これだとうまくいかないとことかあります?