Index: topiatest/src/test/org/codelutin/test2/AppTest.java diff -u topiatest/src/test/org/codelutin/test2/AppTest.java:1.11 topiatest/src/test/org/codelutin/test2/AppTest.java:1.12 --- topiatest/src/test/org/codelutin/test2/AppTest.java:1.11 Wed Sep 21 20:32:15 2005 +++ topiatest/src/test/org/codelutin/test2/AppTest.java Wed Jan 4 13:30:25 2006 @@ -3,36 +3,48 @@ import java.util.Collection; import java.util.Iterator; import java.util.List; +import java.util.Properties; import junit.framework.TestCase; -import org.codelutin.test2Context; -import org.codelutin.test2EntitiesHelper; +import org.codelutin.test2DAOHelper; import org.codelutin.test2.entities.Company; -import org.codelutin.test2.entities.CompanyPersistenceService; +import org.codelutin.test2.entities.CompanyDAO; import org.codelutin.test2.entities.Employee; -import org.codelutin.test2.entities.EmployeePersistenceService; +import org.codelutin.test2.entities.EmployeeDAO; +import org.codelutin.topia.TopiaContext; +import org.codelutin.topia.TopiaContextFactory; import org.codelutin.topia.TopiaException; -import org.codelutin.topia.TopiaId; -import org.codelutin.topia.TopiaUser; -import org.codelutin.topia.persistence.PersistenceStorageJDBC; -import org.codelutin.topia.persistence.TopiaPersistenceObject; -import org.codelutin.topia.persistence.TopiaTransaction; import org.codelutin.util.CallAnalyse; public class AppTest extends TestCase { - protected test2Context topiaContext = null; - protected test2Context child = null; - protected CompanyPersistenceService companyPS = null; - protected TopiaTransaction trans = null; + protected TopiaContext topiaContext = null; + protected TopiaContext child = null; + protected CompanyDAO companyPS = 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"); + 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"); + config.setProperty("hibernate.connection.username", "dbuser"); + config.setProperty("hibernate.connection.password", "xxxxxxxx"); + return config; + } + public void setUp() throws Exception { CallAnalyse.activate(); CallAnalyse.getThreadStatistics().clear(); - topiaContext = test2Context.getContext(); + + topiaContext = TopiaContextFactory.getContext(getConfig()); child = topiaContext.beginTransaction(); - companyPS = child.getCompanyPersistenceService(); + companyPS = test2DAOHelper.getCompanyDAO(child); } public void tearDown() throws Exception { @@ -40,24 +52,6 @@ CallAnalyse.getThreadStatistics().clear(); } - public void testGetParentContext() throws Exception { - try{ - CallAnalyse.enter(AppTest.class.getName() + ".testEventListener"); - test2Context child1 = topiaContext.beginTransaction(); - test2Context child2 = child1.beginTransaction(); - - assertEquals(child1, child2.getParentContext()); - assertEquals(topiaContext, child1.getParentContext()); - assertEquals(null, topiaContext.getParentContext()); - - assertEquals(topiaContext, topiaContext.getRootContext()); - assertEquals(topiaContext, child1.getRootContext()); - assertEquals(topiaContext, child2.getRootContext()); - } finally { - CallAnalyse.exit(AppTest.class.getName() + ".testEventListener"); - } - } - public void testEventListener() throws Exception { try{ CallAnalyse.enter(AppTest.class.getName() + ".testEventListener"); @@ -71,33 +65,33 @@ public void testSousTransaction() throws Exception { try{ CallAnalyse.enter(AppTest.class.getName() + ".testSousTransaction"); - test2Context child1; - test2Context child2; - CompanyPersistenceService companyPS1; - CompanyPersistenceService companyPS2; + TopiaContext child1; + TopiaContext child2; + CompanyDAO companyPS1; + CompanyDAO companyPS2; // 1. On créé une transaction et une sous-transaction, child1 = topiaContext.beginTransaction(); - companyPS1 = child1.getCompanyPersistenceService(); + companyPS1 = test2DAOHelper.getCompanyDAO(child1); child2 = child1.beginTransaction(); - companyPS2 = child2.getCompanyPersistenceService(); + companyPS2 = test2DAOHelper.getCompanyDAO(child2); // - on ajoute un elem dans la 1ere, il existe dans la 2eme, Company comp = companyPS1.create(); comp.setName("thim"); - String id = comp.get_topiaId_(); + String id = comp.getTopiaId(); companyPS1.update(comp); - comp = companyPS1.findBy_TopiaId_(id); + comp = companyPS1.findByTopiaId(id); assertNotSame(null, comp); assertEquals("thim", comp.getName()); - comp = companyPS2.findBy_TopiaId_(id); + comp = companyPS2.findByTopiaId(id); assertNotSame(null, comp); assertEquals("thim", comp.getName()); // - puis on rollback la 1ere, il n'existe plus dans la 2eme child1.rollbackTransaction(); - assertEquals(child1.getTransaction().getId(), child2.getTransaction().getParent().getId()); +// assertEquals(child1.getTransaction().getId(), child2.getTransaction().getParent().getId()); boolean catched = false; try { - companyPS1.findBy_TopiaId_(id); + companyPS1.findByTopiaId(id); }catch(TopiaException eee){ //Doit renvoyer une exception pour dire le l'objet n'a pas été trouvé System.err.println(eee.getMessage()); catched = true; @@ -105,7 +99,7 @@ assertTrue(catched); catched = false; try { - companyPS2.findBy_TopiaId_(id); + companyPS2.findByTopiaId(id); }catch(TopiaException eee){ //idem System.err.println(eee.getMessage()); catched = true; @@ -116,32 +110,32 @@ // 2. Meme schéma child1 = topiaContext.beginTransaction(); - companyPS1 = child1.getCompanyPersistenceService(); + companyPS1 = test2DAOHelper.getCompanyDAO(child1); child2 = child1.beginTransaction(); - companyPS2 = child2.getCompanyPersistenceService(); + companyPS2 = test2DAOHelper.getCompanyDAO(child2); // - on ajoute un elem dans la 1ere, on le modifie dans la 2eme, on recup la valeur pour les deux, la valeur est modifiée slt pr la deuxieme comp = companyPS1.create(); - id = comp.get_topiaId_(); + id = comp.getTopiaId(); comp.setName("thim"); companyPS1.update(comp); - comp = companyPS2.findBy_TopiaId_(id); + comp = companyPS2.findByTopiaId(id); comp.setName("thimel"); companyPS2.update(comp); - comp = companyPS1.findBy_TopiaId_(id); + comp = companyPS1.findByTopiaId(id); assertEquals("thim", comp.getName()); - comp = companyPS2.findBy_TopiaId_(id); + comp = companyPS2.findByTopiaId(id); assertEquals("thimel", comp.getName()); // - on rollback la 2eme, la premiere doit reprendre la valeur avant le debut de la 2eme child2.rollbackTransaction(); - comp = companyPS1.findBy_TopiaId_(id); + comp = companyPS1.findByTopiaId(id); assertEquals("thim", comp.getName()); - comp = companyPS2.findBy_TopiaId_(id); + comp = companyPS2.findByTopiaId(id); assertEquals("thim", comp.getName()); - comp = companyPS2.findBy_TopiaId_(id); + comp = companyPS2.findByTopiaId(id); comp.setName("thimel"); companyPS2.update(comp); @@ -169,37 +163,37 @@ child2.rollbackTransaction(); child1.commitTransaction(); - comp = companyPS1.findBy_TopiaId_(id); + comp = companyPS1.findByTopiaId(id); assertEquals("thim", comp.getName()); - // comp = companyPS2.findBy_TopiaId_(id); //FIXME Le child2 ne peut pas voir les elemes commité par son parent !!! + // comp = companyPS2.findByTopiaId(id); //FIXME Le child2 ne peut pas voir les elemes commité par son parent !!! // assertEquals("thim", comp.getName()); // 3. Même schéma child1 = topiaContext.beginTransaction(); - companyPS1 = child1.getCompanyPersistenceService(); + companyPS1 = test2DAOHelper.getCompanyDAO(child1); child2 = child1.beginTransaction(); - companyPS2 = child2.getCompanyPersistenceService(); + companyPS2 = test2DAOHelper.getCompanyDAO(child2); comp = companyPS2.create(); - id = comp.get_topiaId_(); + id = comp.getTopiaId(); comp.setName("Thimel"); companyPS2.update(comp); try { - companyPS1.findBy_TopiaId_(id); + companyPS1.findByTopiaId(id); }catch(TopiaException eee){ //Doit renvoyer une exception pour dire le l'objet n'a pas été trouvé System.err.println(eee.getMessage()); catched = true; } - comp = companyPS2.findBy_TopiaId_(id); + comp = companyPS2.findByTopiaId(id); assertEquals("Thimel", comp.getName()); child2.commitTransaction(); - comp = companyPS1.findBy_TopiaId_(id); + comp = companyPS1.findByTopiaId(id); assertEquals("Thimel", comp.getName()); - comp = companyPS2.findBy_TopiaId_(id); + comp = companyPS2.findByTopiaId(id); assertEquals("Thimel", comp.getName()); } finally { CallAnalyse.exit(AppTest.class.getName() + ".testSousTransaction"); @@ -244,7 +238,7 @@ System.out.println("-------- makePersistent --------"); company = companyPS.create(); System.out.println("company: " + company); - System.out.println("company: " + test2EntitiesHelper.toString(company)); + System.out.println("company: " + company.toString()); System.out.println("company.getClass()" + company.getClass().getName()); company.setName("Company" + count); company.setEntier(count); @@ -262,7 +256,7 @@ assertEquals(count + 1, companies.size()); System.out.println("-------- find name=? --------"); - companies = companyPS.find(companyPS.newQuery().where("name = ?").addArg("Company" + count)); + companies = companyPS.findAllByName("Company" + count); System.out.println("companies: " + companies); assertEquals(1, companies.size()); Company comp = (Company)companies.iterator().next(); @@ -273,92 +267,92 @@ comp.setReel((float) 0.07); comp = (Company) companyPS.update(comp); - System.out.println("-------- find name like 'Compa%' --------"); - companies = companyPS.find(companyPS.newQuery().where("name like \"Compa%\"")); - System.out.println("size:" + companies.size() + " count:" + count); - assertEquals(count + 1, companies.size()); - - System.out.println("-------- find name like '%'"+count+" --------"); - companies = companyPS.find(companyPS.newQuery().where("name like \"%"+count+"\"")); - assertEquals(1, companies.size()); - - System.out.println("-------- find name not like 'Compa%' --------"); - companies = companyPS.find(companyPS.newQuery().where("name not like \"Compa%\"")); - System.out.println("size:" + companies.size() + " count:" + count); - assertEquals(0, companies.size()); - - System.out.println("-------- find name not like '%'"+count+" --------"); - companies = companyPS.find(companyPS.newQuery().where("name not like \"%"+count+"\"")); - assertEquals(count, companies.size()); +// System.out.println("-------- find name like 'Compa%' --------"); +// companies = companyPS.find(companyPS.newQuery().where("name like \"Compa%\"")); +// System.out.println("size:" + companies.size() + " count:" + count); +// assertEquals(count + 1, companies.size()); +// +// System.out.println("-------- find name like '%'"+count+" --------"); +// companies = companyPS.find(companyPS.newQuery().where("name like \"%"+count+"\"")); +// assertEquals(1, companies.size()); +// +// System.out.println("-------- find name not like 'Compa%' --------"); +// companies = companyPS.find(companyPS.newQuery().where("name not like \"Compa%\"")); +// System.out.println("size:" + companies.size() + " count:" + count); +// assertEquals(0, companies.size()); +// +// System.out.println("-------- find name not like '%'"+count+" --------"); +// companies = companyPS.find(companyPS.newQuery().where("name not like \"%"+count+"\"")); +// assertEquals(count, companies.size()); System.out.println("-------- find entier = "+count+" --------"); - companies = companyPS.find(companyPS.newQuery().where("entier = " + count)); + companies = companyPS.findAllByEntier(count); assertEquals(1, companies.size()); System.out.println("-------- find entier = ? ("+count+") --------"); - companies = companyPS.find(companyPS.newQuery().where("entier = ?").addArg(count)); - assertEquals(1, companies.size()); - - System.out.println("-------- find entier > "+count+" --------"); - companies = companyPS.find(companyPS.newQuery().where("entier > ?").addArg(count)); - assertEquals(0, companies.size()); - - System.out.println("-------- find entier < "+count+" --------"); - companies = companyPS.find(companyPS.newQuery().where("entier < ?").addArg(count)); - assertEquals(count, companies.size()); - - System.out.println("-------- find entier >= "+count+" --------"); - companies = companyPS.find(companyPS.newQuery().where("entier >= ?").addArg(count)); + companies = companyPS.findAllByEntier(count); assertEquals(1, companies.size()); - System.out.println("-------- find entier <= "+count+" --------"); - companies = companyPS.find(companyPS.newQuery().where("entier <= ?").addArg(count)); - assertEquals(count + 1, companies.size()); - - System.out.println("-------- find entier != "+count+" --------"); - companies = companyPS.find(companyPS.newQuery().where("entier != ?").addArg(count)); - assertEquals(count, companies.size()); - - System.out.println("-------- find entier < 3 --------"); - companies = companyPS.find(companyPS.newQuery().where("entier < 3")); - System.out.println("size:" + companies.size() + " count:" + count); - assertEquals(Math.min(3,count+1), companies.size()); +// System.out.println("-------- find entier > "+count+" --------"); +// companies = companyPS.find(companyPS.newQuery().where("entier > ?").addArg(count)); +// assertEquals(0, companies.size()); +// +// System.out.println("-------- find entier < "+count+" --------"); +// companies = companyPS.find(companyPS.newQuery().where("entier < ?").addArg(count)); +// assertEquals(count, companies.size()); +// +// System.out.println("-------- find entier >= "+count+" --------"); +// companies = companyPS.find(companyPS.newQuery().where("entier >= ?").addArg(count)); +// assertEquals(1, companies.size()); +// +// System.out.println("-------- find entier <= "+count+" --------"); +// companies = companyPS.find(companyPS.newQuery().where("entier <= ?").addArg(count)); +// assertEquals(count + 1, companies.size()); +// +// System.out.println("-------- find entier != "+count+" --------"); +// companies = companyPS.find(companyPS.newQuery().where("entier != ?").addArg(count)); +// assertEquals(count, companies.size()); +// +// System.out.println("-------- find entier < 3 --------"); +// companies = companyPS.find(companyPS.newQuery().where("entier < 3")); +// System.out.println("size:" + companies.size() + " count:" + count); +// assertEquals(Math.min(3,count+1), companies.size()); System.out.println("-------- find and1 --------"); - companies = companyPS.find(companyPS.newQuery().where("bool = true and entier <= 0 ")); - assertEquals(1, companies.size()); - - System.out.println("-------- find and2 --------"); - companies = companyPS.find(companyPS.newQuery().where("bool = true and entier <= ? ").addArg(count)); - assertEquals(count/2+1, companies.size()); - - System.out.println("-------- find not and3 --------"); - companies = companyPS.find(companyPS.newQuery().where("not bool = true and entier <= ? ").addArg(count)); - assertEquals((count+1)/2, companies.size()); - - System.out.println("-------- find and4 --------"); - companies = companyPS.find(companyPS.newQuery().where("name like ? and entier = ? ").addArg("Compa%").addArg(0)); + companies = companyPS.findAllByProperties("bool", true, "entier", 0); assertEquals(1, companies.size()); - System.out.println("-------- find and5 --------"); - companies = companyPS.find(companyPS.newQuery().where("name like ? and entier != ? ").addArg("Compa%").addArg(count)); - assertEquals(count, companies.size()); - - System.out.println("-------- find not and6 --------"); - companies = companyPS.find(companyPS.newQuery().where("name like ? and not entier != ? ").addArg("Compa%").addArg(count)); - assertEquals(1, companies.size()); - - System.out.println("-------- find not and7 --------"); - companies = companyPS.find(companyPS.newQuery().where("not (name like ? and entier != ?)").addArg("Compa%").addArg(count)); - assertEquals(1, companies.size()); - - System.out.println("-------- find or --------"); - companies = companyPS.find(companyPS.newQuery().where("bool = true or bool = false")); - assertEquals(count + 1, companies.size()); - - System.out.println("-------- find not (or) --------"); - companies = companyPS.find(companyPS.newQuery().where("not (bool = true or bool = false)")); - assertEquals(0, companies.size()); +// System.out.println("-------- find and2 --------"); +// companies = companyPS.find(companyPS.newQuery().where("bool = true and entier <= ? ".toCharArray()).addArg(count)); +// assertEquals(count/2+1, companies.size()); +// +// System.out.println("-------- find not and3 --------"); +// companies = companyPS.find(companyPS.newQuery().where("not bool = true and entier <= ? ").addArg(count)); +// assertEquals((count+1)/2, companies.size()); +// +// System.out.println("-------- find and4 --------"); +// companies = companyPS.find(companyPS.newQuery().where("name like ? and entier = ? ").addArg("Compa%").addArg(0)); +// assertEquals(1, companies.size()); +// +// System.out.println("-------- find and5 --------"); +// companies = companyPS.find(companyPS.newQuery().where("name like ? and entier != ? ").addArg("Compa%").addArg(count)); +// assertEquals(count, companies.size()); +// +// System.out.println("-------- find not and6 --------"); +// companies = companyPS.find(companyPS.newQuery().where("name like ? and not entier != ? ").addArg("Compa%").addArg(count)); +// assertEquals(1, companies.size()); +// +// System.out.println("-------- find not and7 --------"); +// companies = companyPS.find(companyPS.newQuery().where("not (name like ? and entier != ?)").addArg("Compa%").addArg(count)); +// assertEquals(1, companies.size()); +// +// System.out.println("-------- find or --------"); +// companies = companyPS.find(companyPS.newQuery().where("bool = true or bool = false")); +// assertEquals(count + 1, companies.size()); +// +// System.out.println("-------- find not (or) --------"); +// companies = companyPS.find(companyPS.newQuery().where("not (bool = true or bool = false)")); +// assertEquals(0, companies.size()); // System.out.println("-------- find in --------"); // companies = companyPS.find(companyPS.newQuery().where("entier in (1,2,3)")); @@ -386,6 +380,8 @@ assertEquals(companyPS.size(), 0); child.commitTransaction(); + +// child.rollbackTransaction(); } finally { CallAnalyse.exit(AppTest.class.getName() + ".testApp"); } @@ -432,18 +428,21 @@ } } - @SuppressWarnings("unchecked") +// @SuppressWarnings("unchecked") public void testEmployee() throws Exception { try{ CallAnalyse.enter(AppTest.class.getName() + ".testEmployee"); - test2Context ctx = test2Context.getContext().beginTransaction(); - EmployeePersistenceService empPS = ctx.getEmployeePersistenceService(); - CompanyPersistenceService companyPS = ctx.getCompanyPersistenceService(); + TopiaContext ctx = TopiaContextFactory.getContext(getConfig()).beginTransaction(); + EmployeeDAO empPS = test2DAOHelper.getEmployeeDAO(ctx); + CompanyDAO companyPS = test2DAOHelper.getCompanyDAO(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;