Index: topiatest/src/test/org/codelutin/test2/AppTest.java diff -u topiatest/src/test/org/codelutin/test2/AppTest.java:1.13 topiatest/src/test/org/codelutin/test2/AppTest.java:1.14 --- topiatest/src/test/org/codelutin/test2/AppTest.java:1.13 Fri Jan 6 18:43:49 2006 +++ topiatest/src/test/org/codelutin/test2/AppTest.java Tue Jan 10 19:56:13 2006 @@ -11,14 +11,17 @@ import org.codelutin.test2DAOHelper; import org.codelutin.test2.entities.Company; import org.codelutin.test2.entities.CompanyDAO; -//import org.codelutin.test2.entities.Contract; -//import org.codelutin.test2.entities.ContractDAO; import org.codelutin.test2.entities.Employee; import org.codelutin.test2.entities.EmployeeDAO; +import org.codelutin.test2.entities.Idea; +import org.codelutin.test2.entities.IdeaDAO; +import org.codelutin.test2.entities.Vote; +import org.codelutin.test2.entities.VoteDAO; import org.codelutin.topia.TopiaContext; import org.codelutin.topia.TopiaContextFactory; import org.codelutin.topia.TopiaException; import org.codelutin.util.CallAnalyse; +import org.hibernate.ObjectDeletedException; public class AppTest extends TestCase { @@ -31,7 +34,7 @@ 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.Contract + 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("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect"); config.setProperty("hibernate.connection.driver_class", "org.postgresql.Driver"); config.setProperty("hibernate.connection.url", "jdbc:postgresql:database"); @@ -470,50 +473,83 @@ } } -// -//// @SuppressWarnings("unchecked") -// public void testEmployeeWithContract() 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); -// ContractDAO contractPS = test2DAOHelper.getContractDAO(ctx); -// // for(Employee emp : empPS.findAll()){ -// // empPS.delete(emp); -// // } -// // assertEquals(0, empPS.findAll().size()); -// -// // bsh.Interpreter.DEBUG = true; -// // bsh.Interpreter.TRACE = true; -// -// Company comp = companyPS.create(); -// comp.setName("Code Lutin"); -// 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); -// assertEquals(nbEmployees, employees.size()); -// } finally { -// CallAnalyse.exit(AppTest.class.getName() + ".testEmployee"); -// } -// } +// @SuppressWarnings("unchecked") + 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(); + String ideaText = "Finis les haricots a la cantine" + System.currentTimeMillis(); + idea.setText(ideaText); + ideaDAO.update(idea); + + Employee emp = empDAO.create(); + String name = "Zim" + System.currentTimeMillis(); + emp.setName(name); + empDAO.update(emp); + + Vote vote = voteDAO.create(); + vote.setVote(true); + vote.setEmployee(emp); + voteDAO.update(vote); + + idea.addEmployeeVote(vote); + ideaDAO.update(idea); + + List votesTrue = voteDAO.findAllByVote(true); + assertEquals(1, votesTrue.size()); + assertEquals(name, votesTrue.get(0).getEmployee().getName()); + assertEquals(ideaText, votesTrue.get(0).getIdea().getText()); + + } finally { + CallAnalyse.exit(AppTest.class.getName() + ".testAssociationClass"); + } + } + + 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(); + comp.setName("Code Lutin"); + + Employee emp = empDAO.create(); + String empName = "toi " + System.currentTimeMillis(); + emp.setName(empName); + empDAO.update(emp); + + comp.addEmployee(emp); + compDAO.update(comp); + + Serializable empId = emp.getTopiaId(); + + emp = empDAO.findByTopiaId(empId); + assertEquals(empName, emp.getName()); + assertEquals(emp.getCompany().getTopiaId(), comp.getTopiaId()); + + compDAO.delete(comp); + + boolean deletedException = false; + try { + emp = empDAO.findByTopiaId(empId); + } catch (TopiaException te) { + deletedException = true; + } + assertTrue(deletedException || emp == null); + + } finally { + CallAnalyse.exit(AppTest.class.getName() + ".testComposite"); + } + } + static public void main(String [] args) throws Exception { MAX = Integer.parseInt(args[0]); AppTest test = new AppTest();