Index: topiatest/src/test/org/codelutin/test2/AppTest.java diff -u topiatest/src/test/org/codelutin/test2/AppTest.java:1.15 topiatest/src/test/org/codelutin/test2/AppTest.java:1.16 --- topiatest/src/test/org/codelutin/test2/AppTest.java:1.15 Wed Jan 11 18:33:39 2006 +++ topiatest/src/test/org/codelutin/test2/AppTest.java Mon Jan 16 14:33:02 2006 @@ -26,15 +26,18 @@ public class AppTest extends TestCase { protected TopiaContext topiaContext = null; - protected TopiaContext child = null; + protected TopiaContext ctx = null; protected CompanyDAO companyPS = null; + protected EmployeeDAO employeePS = null; + protected IdeaDAO ideaPS = null; + protected VoteDAO votePS = null; protected Properties getConfig() { Properties config = new Properties(); config.setProperty("hibernate.show_sql", "true"); config.setProperty("hibernate.hbm2ddl.auto", "create"); - config.setProperty("topia.persistence.classes", "org.codelutin.test2.entities.Company,org.codelutin.test2.entities.Employee,org.codelutin.test2.entities.Vote,org.codelutin.test2.entities.Idea"); + config.setProperty("topia.persistence.classes", test2DAOHelper.entitiesList); config.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect"); config.setProperty("hibernate.connection.driver_class", "org.postgresql.Driver"); config.setProperty("hibernate.connection.url", "jdbc:postgresql:topiatest"); @@ -49,13 +52,30 @@ CallAnalyse.getThreadStatistics().clear(); topiaContext = TopiaContextFactory.getContext(getConfig()); - child = topiaContext.beginTransaction(); - companyPS = test2DAOHelper.getCompanyDAO(child); + ctx = topiaContext.beginTransaction(); + companyPS = test2DAOHelper.getCompanyDAO(ctx); + employeePS = test2DAOHelper.getEmployeeDAO(ctx); + ideaPS = test2DAOHelper.getIdeaDAO(ctx); + votePS = test2DAOHelper.getVoteDAO(ctx); + + for (Employee employee : employeePS.findAll()) { + employeePS.delete(employee); + } + for (Company company : companyPS.findAll()) { + companyPS.delete(company); + } + for (Vote vote : votePS.findAll()) { + votePS.delete(vote); + } + for (Idea idea: ideaPS.findAll()) { + ideaPS.delete(idea); + } } public void tearDown() throws Exception { System.out.println(CallAnalyse.getThreadStatistics()); CallAnalyse.getThreadStatistics().clear(); +// ctx.commitTransaction(); } public void testEventListener() throws Exception { @@ -84,7 +104,7 @@ // - on ajoute un elem dans la 1ere, il existe dans la 2eme, Company comp = companyPS1.create(); comp.setName("thim"); - Serializable id = comp.getTopiaId(); + String id = comp.getTopiaId(); companyPS1.update(comp); comp = companyPS1.findByTopiaId(id); assertNotSame(null, comp); @@ -385,7 +405,7 @@ assertEquals(companyPS.size(), 0); - child.commitTransaction(); + ctx.commitTransaction(); // child.rollbackTransaction(); } finally { @@ -428,7 +448,7 @@ long time4 = System.currentTimeMillis(); System.out.println("delete en : " + (time4-time3)); - child.commitTransaction(); + ctx.commitTransaction(); } finally { CallAnalyse.exit(AppTest.class.getName() + ".testPerf"); } @@ -438,9 +458,6 @@ public void testEmployee() throws Exception { try{ CallAnalyse.enter(AppTest.class.getName() + ".testEmployee"); - TopiaContext ctx = TopiaContextFactory.getContext(getConfig()).beginTransaction(); - EmployeeDAO empPS = test2DAOHelper.getEmployeeDAO(ctx); - CompanyDAO companyPS = test2DAOHelper.getCompanyDAO(ctx); // for(Employee emp : empPS.findAll()){ // empPS.delete(emp); // } @@ -451,22 +468,23 @@ Company comp = companyPS.create(); comp.setName("Code Lutin"); + companyPS.update(comp); Employee emp; int nbEmployees = 12; for(int i=0; i employees; employees = comp.getEmployee(); assertEquals(nbEmployees, employees.size()); for(Employee e: employees){ assertEquals(comp, e.getCompany()); } - employees = empPS.findAllByCompany(comp); + ctx.commitTransaction(); + employees = employeePS.findAllByCompany(comp); assertEquals(nbEmployees, employees.size()); } finally { CallAnalyse.exit(AppTest.class.getName() + ".testEmployee"); @@ -478,28 +496,24 @@ public void testAssociationClass() throws Exception { try{ CallAnalyse.enter(AppTest.class.getName() + ".testAssociationClass"); - TopiaContext ctx = TopiaContextFactory.getContext(getConfig()).beginTransaction(); - EmployeeDAO empDAO = test2DAOHelper.getEmployeeDAO(ctx); - IdeaDAO ideaDAO = test2DAOHelper.getIdeaDAO(ctx); - VoteDAO voteDAO = test2DAOHelper.getVoteDAO(ctx); - Idea idea = ideaDAO.create(); + Idea idea = ideaPS.create(); String ideaText = "Finis les haricots a la cantine" + System.currentTimeMillis(); idea.setText(ideaText); - ideaDAO.update(idea); + ideaPS.update(idea); - Employee emp = empDAO.create(); + Employee emp = employeePS.create(); String name = "Zim" + System.currentTimeMillis(); emp.setName(name); - empDAO.update(emp); + employeePS.update(emp); - Vote vote = voteDAO.create(); + Vote vote = votePS.create(); vote.setVote(true); vote.setEmployee(emp); vote.setIdea(idea); - voteDAO.update(vote); + votePS.update(vote); - List votesTrue = voteDAO.findAllByVote(true); + List votesTrue = votePS.findAllByVote(true); assertEquals(1, votesTrue.size()); assertEquals(name, votesTrue.get(0).getEmployee().getName()); assertEquals(ideaText, votesTrue.get(0).getIdea().getText()); @@ -512,32 +526,29 @@ public void testComposite() throws Exception { try{ CallAnalyse.enter(AppTest.class.getName() + ".testComposite"); - TopiaContext ctx = TopiaContextFactory.getContext(getConfig()).beginTransaction(); - EmployeeDAO empDAO = test2DAOHelper.getEmployeeDAO(ctx); - CompanyDAO compDAO = test2DAOHelper.getCompanyDAO(ctx); - Company comp = compDAO.create(); + Company comp = companyPS.create(); comp.setName("Code Lutin"); - Employee emp = empDAO.create(); + Employee emp = employeePS.create(); String empName = "toi " + System.currentTimeMillis(); emp.setName(empName); - empDAO.update(emp); + employeePS.update(emp); comp.addEmployee(emp); - compDAO.update(comp); + companyPS.update(comp); - Serializable empId = emp.getTopiaId(); + String empId = emp.getTopiaId(); - emp = empDAO.findByTopiaId(empId); + emp = employeePS.findByTopiaId(empId); assertEquals(empName, emp.getName()); assertEquals(emp.getCompany().getTopiaId(), comp.getTopiaId()); - compDAO.delete(comp); + companyPS.delete(comp); boolean deletedException = false; try { - emp = empDAO.findByTopiaId(empId); + emp = employeePS.findByTopiaId(empId); } catch (TopiaException te) { deletedException = true; }