Index: topia2/src/test/org/codelutin/topia/TopiaContextTest.java diff -u topia2/src/test/org/codelutin/topia/TopiaContextTest.java:1.1.1.1 topia2/src/test/org/codelutin/topia/TopiaContextTest.java:1.2 --- topia2/src/test/org/codelutin/topia/TopiaContextTest.java:1.1.1.1 Mon Jan 2 13:54:35 2006 +++ topia2/src/test/org/codelutin/topia/TopiaContextTest.java Wed Jan 4 13:21:51 2006 @@ -1,32 +1,31 @@ -/* *##% - * Copyright (C) 2005 - * Code Lutin, Cédric Pineau, Benjamin Poussin - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ +/* + * *##% Copyright (C) 2005 Code Lutin, Cédric Pineau, Benjamin Poussin + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place - Suite 330, Boston, MA 02111-1307, USA. ##% + */ -/* * +/******************************************************************************* * TopiaContextTest.java - * + * * Created: 28 déc. 2005 16:26:24 - * + * * @author poussin - * @version $Revision: 1.1.1.1 $ - * - * Last update: $Date: 2006/01/02 13:54:35 $ - * by : $Author: bpoussin $ + * + * @version $Revision: 1.2 $ + * + * Last update: $Date: 2006/01/04 13:21:51 $ by : $Author: bpoussin $ */ package org.codelutin.topia; @@ -37,75 +36,114 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.codelutin.topia.TopiaContext; +import org.codelutin.topia.framework.TopiaContextImplementor; import org.codelutin.topia.persistence.TopiaDAO; /** * @author poussin - * + * */ public class TopiaContextTest extends TestCase { /** to use log facility, just put in your code: log.info(\"...\"); */ static private Log log = LogFactory.getLog(TopiaContextTest.class); + public void testGetParentContext() throws Exception { + Properties config = new Properties(); + config.setProperty("hibernate.show_sql", "true"); + config.setProperty("hibernate.hbm2ddl.auto", "create"); + + config.setProperty("topia.persistence.classes", + "org.codelutin.topia.Person"); + 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"); + + TopiaContextImplementor topiaContext = (TopiaContextImplementor) TopiaContextFactory + .getContext(config); + + TopiaContextImplementor child1 = (TopiaContextImplementor) topiaContext + .beginTransaction(); + TopiaContextImplementor child2 = (TopiaContextImplementor) 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()); + } + public void testHibernate() throws Exception { log.info("Debut du test"); log.debug("(debug mode)"); - + Properties config = new Properties(); config.setProperty("hibernate.show_sql", "true"); config.setProperty("hibernate.hbm2ddl.auto", "create"); - - config.setProperty("topia.persistence.classes", "org.codelutin.topia.Person"); - 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("topia.persistence.classes", + "org.codelutin.topia.Person"); + 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"); - + /* - #hibernate.dialect org.hibernate.dialect.DerbyDialect - #hibernate.connection.driver_class org.apache.derby.jdbc.EmbeddedDriver - #hibernate.connection.username - #hibernate.connection.password - #hibernate.connection.url jdbc:derby:/test;create=true - */ - - TopiaContext context = TopiaContext.getContext(config); + * #hibernate.dialect org.hibernate.dialect.DerbyDialect + * #hibernate.connection.driver_class + * org.apache.derby.jdbc.EmbeddedDriver #hibernate.connection.username + * #hibernate.connection.password #hibernate.connection.url + * jdbc:derby:/test;create=true + */ + + TopiaContext context = TopiaContextFactory.getContext(config); - TopiaContext childContext = context.beginTransaction(); + TopiaContextImplementor childContext = (TopiaContextImplementor) context + .beginTransaction(); TopiaDAO persons = childContext.getDAO(Person.class); Person p = persons.create(); p.setName("poussin"); p.setFirstname("benjamin"); - persons.update(p); + persons.update(p); childContext.commitTransaction(); - + Person p1 = persons.create(); p1.setName("poussin"); p1.setFirstname("jacques"); persons.update(p1); childContext.commitTransaction(); - + Person p2 = persons.create(); p2.setName("poussin"); p2.setFirstname("mylene"); persons.update(p2); childContext.rollbackTransaction(); - + p.setFirstname("berengere"); persons.update(p); childContext.commitTransaction(); - - } + + } public void testFlatFile() throws Exception { log.info("Debut du test"); log.debug("(debug mode)"); - + Properties config = new Properties(); - config.setProperty("topia.persistence.classes", "org.codelutin.topia.Person"); + config.setProperty("topia.persistence.classes", + "org.codelutin.topia.Person"); config.setProperty("topia.dao.default.class", "flatfile"); config.setProperty("topia.dao.flatfile.directory", "/tmp/topiadb"); @@ -113,42 +151,43 @@ config.setProperty("hibernate.show_sql", "true"); config.setProperty("hibernate.hbm2ddl.auto", "create"); - - 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.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"); - - TopiaContext context = TopiaContext.getContext(config); - TopiaContext childContext = context.beginTransaction(); + TopiaContext context = TopiaContextFactory.getContext(config); + + TopiaContextImplementor childContext = (TopiaContextImplementor) context + .beginTransaction(); TopiaDAO persons = childContext.getDAO(Person.class); Person p = persons.create(); p.setName("poussin"); p.setFirstname("benjamin"); - persons.update(p); + persons.update(p); childContext.commitTransaction(); - + Person p1 = persons.create(); p1.setName("poussin"); p1.setFirstname("jacques"); persons.update(p1); childContext.commitTransaction(); - + Person p2 = persons.create(); p2.setName("poussin"); p2.setFirstname("mylene"); persons.update(p2); childContext.rollbackTransaction(); - + p.setFirstname("berengere"); persons.update(p); childContext.commitTransaction(); - - } - -} - + } +}