Index: topia2/src/test/org/codelutin/topia/Person.hbm.xml diff -u topia2/src/test/org/codelutin/topia/Person.hbm.xml:1.3 topia2/src/test/org/codelutin/topia/Person.hbm.xml:1.4 --- topia2/src/test/org/codelutin/topia/Person.hbm.xml:1.3 Fri Jul 21 01:00:08 2006 +++ topia2/src/test/org/codelutin/topia/Person.hbm.xml Mon Oct 23 15:01:57 2006 @@ -5,12 +5,12 @@ - + - - - - + + + + Index: topia2/src/test/org/codelutin/topia/PersonAbstract.java diff -u topia2/src/test/org/codelutin/topia/PersonAbstract.java:1.2 topia2/src/test/org/codelutin/topia/PersonAbstract.java:1.3 --- topia2/src/test/org/codelutin/topia/PersonAbstract.java:1.2 Tue Feb 7 19:57:02 2006 +++ topia2/src/test/org/codelutin/topia/PersonAbstract.java Mon Oct 23 15:01:57 2006 @@ -23,14 +23,18 @@ * Created: 29 déc. 2005 00:27:53 * * @author poussin - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ * - * Last update: $Date: 2006/02/07 19:57:02 $ - * by : $Author: thimel $ + * Last update: $Date: 2006/10/23 15:01:57 $ + * by : $Author: ruchaud $ */ package org.codelutin.topia; +import java.util.ArrayList; +import java.util.List; + +import org.codelutin.topia.persistence.TopiaEntity; import org.codelutin.topia.persistence.TopiaEntityAbstract; /** @@ -44,23 +48,39 @@ protected String firstname; public String getFirstname() { - return firstname; + fireOnPreRead("firstname", name); + String result = firstname; + fireOnPreRead("firstname", result); + return result; } public void setFirstname(String firstname) { String _oldValue = this.firstname; + fireOnPreWrite("firstName", _oldValue, firstname); this.firstname = firstname; - fireOnModifyProperty("firstName", _oldValue, firstname); + fireOnPostWrite("firstName", _oldValue, firstname); } public String getName() { - return name; + fireOnPreRead("name", name); + String result = name; + fireOnPreRead("name", result); + return result; } public void setName(String name) { String _oldValue = this.name; + fireOnPreWrite("name", _oldValue, name); this.name = name; - fireOnModifyProperty("name", _oldValue, name); + fireOnPostWrite("name", _oldValue, name); + } + + public List getComposite() throws TopiaException { + return new ArrayList(); + } + + public List getAggregate() throws TopiaException { + return new ArrayList(); } } Index: topia2/src/test/org/codelutin/topia/TopiaContextTest.java diff -u topia2/src/test/org/codelutin/topia/TopiaContextTest.java:1.16 topia2/src/test/org/codelutin/topia/TopiaContextTest.java:1.17 --- topia2/src/test/org/codelutin/topia/TopiaContextTest.java:1.16 Tue Oct 17 13:02:52 2006 +++ topia2/src/test/org/codelutin/topia/TopiaContextTest.java Mon Oct 23 15:01:57 2006 @@ -23,9 +23,9 @@ * * @author poussin * - * @version $Revision: 1.16 $ + * @version $Revision: 1.17 $ * - * Last update: $Date: 2006/10/17 13:02:52 $ by : $Author: bpoussin $ + * Last update: $Date: 2006/10/23 15:01:57 $ by : $Author: ruchaud $ */ package org.codelutin.topia; @@ -41,12 +41,9 @@ import org.apache.commons.logging.LogFactory; import org.codelutin.topia.event.TopiaEntityEvent; import org.codelutin.topia.event.TopiaEntityListener; -import org.codelutin.topia.event.TopiaEntityLoadEvent; -import org.codelutin.topia.event.TopiaEntityLoadListener; -import org.codelutin.topia.event.TopiaVetoableEntityEvent; -import org.codelutin.topia.event.TopiaVetoableEntityListener; -import org.codelutin.topia.event.TopiaVetoableEntityLoadEvent; -import org.codelutin.topia.event.TopiaVetoableEntityLoadListener; +import org.codelutin.topia.event.TopiaEntityVetoable; +import org.codelutin.topia.event.TopiaTransactionEvent; +import org.codelutin.topia.event.TopiaTransactionListener; import org.codelutin.topia.framework.TopiaContextImplementor; import org.codelutin.topia.persistence.TopiaDAO; @@ -201,7 +198,6 @@ Person pp = persons2.findByTopiaId(id); assertEquals("berengere", pp.getFirstname()); - } public void testIsolation() throws Exception { @@ -329,104 +325,109 @@ System.out.println("Debut du test Event"); Properties config = getProperties(); - // FIXME voir pourquoi si on a pas un nouveau context ca ne marche pas - // :( - // On met un propriete qui ne sert a rien pour etre sur qu'il - // recre bien un Context pour ce test - // config.setProperty("test", "testEventHibernate"); - TopiaContext context = TopiaContextFactory.getContext(config); - TopiaContextImplementor childContext = (TopiaContextImplementor) context - .beginTransaction(); + TopiaEntityVetoable entityVetoable = new TopiaEntityVetoable() { + private void print(TopiaEntityEvent event, String _state) { + state += _state; + if(log.isInfoEnabled()) { + log.info(_state + " " + event.getEntity()); + } + } - TopiaVetoableEntityListener v = new TopiaVetoableEntityListener() { - public void createEntity(TopiaVetoableEntityEvent event) { - System.out.println("vetoCreate " + event.getEntityClass() - + " id: " + event.getId()); - state = "vetoCreate"; - } - - public void updateEntity(TopiaVetoableEntityEvent event) { - System.out.println("vetoUpdate " + event.getEntityClass() - + " id: " + event.getId()); - state = "vetoUpdate"; - } - - public void deleteEntity(TopiaVetoableEntityEvent event) { - System.out.println("vetoDelete " + event.getEntityClass() - + " id: " + event.getId()); - state = "vetoDelete"; + public void create(TopiaEntityEvent event) { + print(event, "vetoCreate"); } - }; - TopiaVetoableEntityLoadListener vl = new TopiaVetoableEntityLoadListener() { - public boolean loadEntity(TopiaVetoableEntityLoadEvent event) { - System.out.println("vetoLoad " + event.getEntityClass() - + " id: " + event.getId()); - state = "vetoLoad"; - return true; + public void update(TopiaEntityEvent event) { + print(event, "vetoUpdate"); } - }; - TopiaEntityListener l = new TopiaEntityListener() { - public void entityCreated(TopiaEntityEvent event) { - System.out.println("entityCreated " + event.getTopiaEntities()); - state = "entityCreated"; + public void delete(TopiaEntityEvent event) { + print(event, "vetoDelete"); } + + public void load(TopiaEntityEvent event) { + print(event, "vetoLoad"); + } + }; - public void entityUpdated(TopiaEntityEvent event) { - System.out.println("entityUpdated " + event.getTopiaEntities()); - state = "entityUpdated"; + TopiaEntityListener entityListener = new TopiaEntityListener() { + private void print(TopiaEntityEvent event, String _state) { + state += _state; + if(log.isInfoEnabled()) { + log.info(_state + " " + event.getEntity()); + } + } + + public void create(TopiaEntityEvent event) { + print(event, "entityCreated"); } - public void entityDeleted(TopiaEntityEvent event) { - System.out.println("entityDeleted " + event.getTopiaEntities()); - state = "entityDeleted"; + public void update(TopiaEntityEvent event) { + print(event, "entityUpdated"); } - }; - TopiaEntityLoadListener ll = new TopiaEntityLoadListener() { - public void entityLoaded(TopiaEntityLoadEvent event) { - System.out.println("entityLoaded " + event.getTopiaEntities()); - state = "entityLoaded"; + public void delete(TopiaEntityEvent event) { + print(event, "entityDeleted"); + } + + public void load(TopiaEntityEvent event) { + print(event, "entityLoaded"); } }; - childContext.addVetoableListener(v); - childContext.addVetoableLoadListener(vl); - childContext.addTopiaEntityListener(l); - childContext.addTopiaEntityLoadListener(ll); + TopiaTransactionListener transactionListener = new TopiaTransactionListener() { + public void commit(TopiaTransactionEvent event) { + log.info("commit " + event.getEntities()); + } + public void rollback(TopiaTransactionEvent event) { + log.info("rollback " + event.getEntities()); + } + }; + + TopiaContextImplementor childContext = (TopiaContextImplementor) context + .beginTransaction(); + childContext.addTopiaEntityVetoable(entityVetoable); + childContext.addTopiaEntityListener(entityListener); + childContext.addTopiaTransactionListener(transactionListener); TopiaDAO persons = childContext.getDAO(Person.class); + Person p = persons.create(); - assertEquals("entityCreated", state); p.setName("poussin"); p.setFirstname("benjamin"); persons.update(p); childContext.commitTransaction(); - assertEquals("entityUpdated", state); - + + assertEquals("vetoCreateentityCreatedvetoUpdateentityUpdated", state); + state = ""; + p.setFirstname("toto"); persons.update(p); childContext.commitTransaction(); - assertEquals("entityUpdated", state); - + + assertEquals("vetoUpdateentityUpdated", state); + state = ""; + TopiaContextImplementor childContext2 = (TopiaContextImplementor) context .beginTransaction(); - childContext2.addVetoableListener(v); - childContext2.addVetoableLoadListener(vl); - childContext2.addTopiaEntityListener(l); - childContext2.addTopiaEntityLoadListener(ll); + childContext2.addTopiaEntityVetoable(entityVetoable); + childContext2.addTopiaEntityListener(entityListener); + childContext2.addTopiaTransactionListener(transactionListener); TopiaDAO persons2 = childContext2.getDAO(Person.class); Person pp = persons2.findByTopiaId(p.getTopiaId()); + assertEquals(p.getFirstname(), pp.getFirstname()); - assertEquals("entityLoaded", state); + assertEquals("vetoLoadentityLoaded", state); + state = ""; - persons.delete(pp); - childContext.commitTransaction(); - assertEquals("entityDeleted", state); + persons2.delete(pp); + childContext2.commitTransaction(); + + assertEquals("vetoDeleteentityDeleted", state); + state = ""; } @@ -445,10 +446,15 @@ TopiaDAO personDAO = ctx.getDAO(Person.class); Person p = personDAO.create(); - p.addPropertyListener("firstName", l); - state = null; + p.addPropertyChangeListener("firstName", l); + p.setFirstname("Arno"); assertEquals("entityUpdated", state); + state = ""; + + p.setName("Arno"); + assertEquals("", state); + state = ""; } } //TopiaContextTest