Author: chatellier Date: 2009-01-29 16:15:38 +0000 (Thu, 29 Jan 2009) New Revision: 1335 Removed: topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/Person.hbm.xml topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/Person.java topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/PersonAbstract.java topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/PersonImpl.java topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/TopiaContextTest.java Modified: topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/framework/EntityStateTest.java topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/framework/TopiaUtilTest.java topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/generator/TopiaTestCase.java topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/persistence/ExportXMLVisitor.java Log: Mise ?\195?\160 jour des test, utilisation des entit?\195?\169s du modeles de test Deleted: topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/Person.hbm.xml =================================================================== --- topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/Person.hbm.xml 2009-01-29 15:47:42 UTC (rev 1334) +++ topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/Person.hbm.xml 2009-01-29 16:15:38 UTC (rev 1335) @@ -1,16 +0,0 @@ -<?xml version="1.0"?> -<!DOCTYPE hibernate-mapping PUBLIC - "-//Hibernate/Hibernate Mapping DTD 3.0//EN" - "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> - -<hibernate-mapping> - <class name="org.codelutin.topia.PersonImpl" table="person" node="org.codelutin.topia.Person" proxy="org.codelutin.topia.Person"> - <id name="topiaId" length="255" node="@topiaId" access="field"> - <!-- on utilise des TopiaId maintenant <generator class="uuid.hex"/> --> - </id> - <version name="topiaVersion" type="long" node="@topiaVersion" access="field"/> - <property name="topiaCreateDate" type="date" node="@topiaCreateDate" access="field"/> - <property name="name" type="string" node="@name" access="field"/> - <property name="firstname" type="string" node="@firstname" access="field"/> - </class> -</hibernate-mapping> Deleted: topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/Person.java =================================================================== --- topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/Person.java 2009-01-29 15:47:42 UTC (rev 1334) +++ topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/Person.java 2009-01-29 16:15:38 UTC (rev 1335) @@ -1,59 +0,0 @@ -/* *##% ToPIA - Tools for Portable and Independent Architecture - * Copyright (C) 2004 - 2008 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ - -/* * - * Person.java - * - * Created: 29 déc. 2005 00:27:53 - * - * @author poussin - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ - -package org.codelutin.topia; - -import org.codelutin.topia.persistence.TopiaEntity; - -/** - * @author poussin - */ -public interface Person extends TopiaEntity { - - /** - * @return Returns the firstname. - */ - public abstract String getFirstname(); - - /** - * @param firstname The firstname to set. - */ - public abstract void setFirstname(String firstname); - - /** - * @return Returns the name. - */ - public abstract String getName(); - - /** - * @param name The name to set. - */ - public abstract void setName(String name); - -} Deleted: topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/PersonAbstract.java =================================================================== --- topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/PersonAbstract.java 2009-01-29 15:47:42 UTC (rev 1334) +++ topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/PersonAbstract.java 2009-01-29 16:15:38 UTC (rev 1335) @@ -1,86 +0,0 @@ -/* *##% ToPIA - Tools for Portable and Independent Architecture - * Copyright (C) 2004 - 2008 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ - -/* * - * PersonAbstract.java - * - * Created: 29 déc. 2005 00:27:53 - * - * @author poussin - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ - -package org.codelutin.topia; - -import java.util.ArrayList; -import java.util.List; - -import org.codelutin.topia.TopiaException; -import org.codelutin.topia.persistence.TopiaEntity; -import org.codelutin.topia.persistence.TopiaEntityAbstract; - -/** - * @author poussin - * - */ -public abstract class PersonAbstract extends TopiaEntityAbstract implements - Person { - - protected String name; - - protected String firstname; - - public String getFirstname() { - 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; - fireOnPostWrite("firstName", _oldValue, firstname); - } - - public String getName() { - 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; - fireOnPostWrite("name", _oldValue, name); - } - - public List<TopiaEntity> getComposite() throws TopiaException { - return new ArrayList<TopiaEntity>(); - } - - public List<TopiaEntity> getAggregate() throws TopiaException { - return new ArrayList<TopiaEntity>(); - } - -} Deleted: topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/PersonImpl.java =================================================================== --- topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/PersonImpl.java 2009-01-29 15:47:42 UTC (rev 1334) +++ topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/PersonImpl.java 2009-01-29 16:15:38 UTC (rev 1335) @@ -1,38 +0,0 @@ -/* *##% ToPIA - Tools for Portable and Independent Architecture - * Copyright (C) 2004 - 2008 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ - -/******************************************************************************* - * PersonImpl.java - * - * Created: 28 déc. 2005 16:14:04 - * - * @author poussin - * - * @version $Revision$ - * - * Last update: $Date$ by : $Author$ - */ - -package org.codelutin.topia; - -/** - * @author poussin - * - */ -public class PersonImpl extends PersonAbstract implements Person { - -} Deleted: topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/TopiaContextTest.java =================================================================== --- topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/TopiaContextTest.java 2009-01-29 15:47:42 UTC (rev 1334) +++ topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/TopiaContextTest.java 2009-01-29 16:15:38 UTC (rev 1335) @@ -1,504 +0,0 @@ -/* *##% ToPIA - Tools for Portable and Independent Architecture - * Copyright (C) 2004 - 2008 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ - -/******************************************************************************* - * TopiaContextTest.java - * - * Created: 28 d?c. 2005 16:26:24 - * - * @author poussin - * - * @version $Revision$ - * - * Last update: $Date$ by : $Author$ - */ - -package org.codelutin.topia; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.codelutin.topia.event.TopiaEntityEvent; -import org.codelutin.topia.event.TopiaEntityListener; -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; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.BeforeClass; -import org.junit.Ignore; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.io.File; -import java.util.Properties; - -/** @author poussin */ -public class TopiaContextTest extends Assert { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - static private Log log = LogFactory.getLog(TopiaContextTest.class); - - protected String entitiesList = Person.class.getName(); - - protected String timeStamp; - - protected TopiaContext context; - - protected static File testDir; - - @BeforeClass - public static void beforeClass() { - String basedir = System.getProperty("basedir"); - if (basedir==null) { - basedir = new File("").getAbsolutePath(); - } - testDir = new File(basedir, "target" + File.separator + "tests" + File.separator + TopiaContextTest.class.getSimpleName()); - } - - @Before - public void before() { - timeStamp = System.nanoTime() + ""; - } - - @After - public void after() throws TopiaException { - if (context != null && !context.isClosed()) { - context.closeContext(); - } - } - - protected Properties getPostgreSQLProperties() { - Properties config = new Properties(); - config.setProperty("hibernate.show_sql", "true"); - config.setProperty("hibernate.hbm2ddl.auto", "create"); - - config.setProperty("topia.dao.flatfile.directory", new File(testDir, "topiadb_" + timeStamp).getAbsolutePath()); - config.setProperty("topia.dao.flatfile.mapping.key", "firstname"); - - config.setProperty("topia.persistence.classes", 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:database"); - config.setProperty("hibernate.connection.username", "dbuser"); - config.setProperty("hibernate.connection.password", "xxxxxxxx"); - - return config; - } - - protected Properties getDerbyProperties() { - Properties config = new Properties(); - config.setProperty("hibernate.show_sql", "true"); - config.setProperty("hibernate.hbm2ddl.auto", "create"); - - config.setProperty("topia.dao.flatfile.directory", new File(testDir, "topiadb_" + timeStamp).getAbsolutePath()); - config.setProperty("topia.dao.flatfile.mapping.key", "firstname"); - - config.setProperty("topia.persistence.classes", entitiesList); - config.setProperty("hibernate.dialect", - "org.hibernate.dialect.DerbyDialect"); - config.setProperty("hibernate.connection.driver_class", - "org.apache.derby.jdbc.EmbeddedDriver"); - config.setProperty("hibernate.connection.url", - "jdbc:derby:/tmp/topiaderby;create=true"); - config.setProperty("hibernate.connection.username", "dbuser"); - config.setProperty("hibernate.connection.password", "xxxxxxxx"); - - return config; - } - - protected Properties getH2Properties() { - Properties config = new Properties(); - config.setProperty("hibernate.show_sql", "true"); - config.setProperty("hibernate.hbm2ddl.auto", "create"); - - File dbFile = new File(testDir, "topiadb"); - if (!dbFile.exists() && !dbFile.mkdirs()) { - throw new RuntimeException("could not create directory " + dbFile); - } - //new File("/tmp/topiadb/").mkdirs(); - config.setProperty("topia.dao.flatfile.directory", new File(dbFile,"topiadb2_" + timeStamp + "/h2").getAbsolutePath()); - config.setProperty("topia.dao.flatfile.mapping.key", "firstname"); - - config.setProperty("topia.persistence.classes", entitiesList); - config.setProperty("hibernate.dialect", - "org.hibernate.dialect.HSQLDialect"); - config - .setProperty("hibernate.connection.driver_class", - "org.h2.Driver"); - config.setProperty("hibernate.connection.url", - "jdbc:h2:file:"+new File(testDir,"topiadb_" + timeStamp).getAbsolutePath() + "/h2;create=true;LOCK_MODE=0"); - config.setProperty("hibernate.connection.username", "sa"); - config.setProperty("hibernate.connection.password", ""); - - return config; - } - - protected Properties getProperties() { - return getH2Properties(); - } - - /* - * #hibernate.dialect org.hibernate.dialect.DerbyDialect - * #hibernate.connection.driver_class org.apache.derby.jdbc.EmbeddedDriver - * #hibernate.connection.url jdbc:derby:/test;create=true - * #hibernate.connection.username #hibernate.connection.password - */ - @Test - public void testGetParentContext() throws Exception { - Properties config = getProperties(); - - context = TopiaContextFactory - .getContext(config); - - TopiaContextImplementor child1 = (TopiaContextImplementor) context - .beginTransaction(); - TopiaContextImplementor child2 = (TopiaContextImplementor) child1 - .beginTransaction(); - - assertEquals(child1, child2.getParentContext()); - assertEquals(context, child1.getParentContext()); - assertEquals(null, ((TopiaContextImplementor) context).getParentContext()); - - assertEquals(context, ((TopiaContextImplementor) context).getRootContext()); - assertEquals(context, child1.getRootContext()); - assertEquals(context, child2.getRootContext()); - } - - @Test - public void testHibernate() throws Exception { - System.out.println("Debut du test Hibernate"); - - Properties config = getProperties(); - - context = TopiaContextFactory.getContext(config); - - TopiaContextImplementor childContext = (TopiaContextImplementor) context - .beginTransaction(); - TopiaDAO<Person> persons = childContext.getDAO(Person.class); - Person p = persons.create(); - p.setName("poussin"); - p.setFirstname("benjamin"); - persons.update(p); - childContext.commitTransaction(); - - String id = p.getTopiaId(); - - 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(); - - p.setFirstname("toto"); - persons.update(p); - assertEquals("toto", p.getFirstname()); - childContext.rollbackTransaction(); - - p = persons.findByTopiaId(id); - assertEquals("berengere", p.getFirstname()); - - TopiaContextImplementor childContext2 = (TopiaContextImplementor) context - .beginTransaction(); - TopiaDAO<Person> persons2 = childContext2.getDAO(Person.class); - - Person pp = persons2.findByTopiaId(id); - assertEquals("berengere", pp.getFirstname()); - } - - @Ignore - //FIXME : - public void testIsolation() throws Exception { - System.out.println("Debut du test Isolation"); - - Properties config = getProperties(); - - context = TopiaContextFactory.getContext(config); - - TopiaContextImplementor c1 = (TopiaContextImplementor) context - .beginTransaction(); - TopiaContextImplementor c2 = (TopiaContextImplementor) context - .beginTransaction(); - - TopiaDAO<Person> ps1 = c1.getDAO(Person.class); - TopiaDAO<Person> ps2 = c2.getDAO(Person.class); - - assertEquals(0, ps1.findAll().size()); - assertEquals(0, ps2.findAll().size()); - - Person p = ps1.create(); - p.setName("poussin"); - p.setFirstname("benjamin"); - ps1.update(p); - - c1.rollbackTransaction(); - - assertEquals(0, ps1.findAll().size()); - assertEquals(0, ps2.findAll().size()); - - p = ps1.create(); - p.setName("poussin"); - p.setFirstname("benjamin"); - ps1.update(p); - - assertEquals(1, ps1.findAll().size()); - //FIXME this test does not work (anylonger?), this is a bit scaring... - assertEquals(0, ps2.findAll().size()); - - c1.commitTransaction(); - - assertEquals(1, ps1.findAll().size()); - assertEquals(0, ps2.findAll().size()); - - ps1.delete(p); - - assertEquals(0, ps1.findAll().size()); - assertEquals(0, ps2.findAll().size()); - - c1.commitTransaction(); - - assertEquals(0, ps1.findAll().size()); - assertEquals(0, ps2.findAll().size()); - - } - - @Test - public void testFlatFile() throws Exception { - System.out.println("Debut du test FlatFile"); - - Properties config = getProperties(); - config.setProperty("topia.dao.default.class", "flatfile"); - - context = TopiaContextFactory.getContext(config); - - TopiaContextImplementor childContext = (TopiaContextImplementor) context - .beginTransaction(); - TopiaDAO<Person> persons = childContext.getDAO(Person.class); - Person p = persons.create(); - p.setName("poussin"); - p.setFirstname("benjamin"); - 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(); - - } - - @Test - public void testConstructor() throws Exception { - System.out.println("Debut du test constructor"); - - Properties config = getProperties(); - - context = TopiaContextFactory.getContext(config); - - TopiaContextImplementor childContext = (TopiaContextImplementor) context - .beginTransaction(); - - TopiaDAO<Person> persons = childContext.getDAO(Person.class); - Person p = persons.create("name", "poussin", "firstname", "toto"); - assertEquals("poussin", p.getName()); - assertEquals("toto", p.getFirstname()); - - persons.update(p); - childContext.commitTransaction(); - - p.setFirstname("titi"); - assertEquals("titi", p.getFirstname()); - - persons.update(p); - childContext.commitTransaction(); - - p.setFirstname("benjamin"); - assertEquals("benjamin", p.getFirstname()); - - persons.update(p); - childContext.commitTransaction(); - - persons.delete(p); - childContext.commitTransaction(); - } - - String state = ""; - - @Test - public void testEventHibernate() throws Exception { - System.out.println("Debut du test Event"); - - Properties config = getProperties(); - context = TopiaContextFactory.getContext(config); - - TopiaEntityVetoable entityVetoable = new TopiaEntityVetoable() { - private void print(TopiaEntityEvent event, String _state) { - state += _state; - if (log.isInfoEnabled()) { - log.info(_state + " " + event.getEntity()); - } - } - - public void create(TopiaEntityEvent event) { - print(event, "vetoCreate"); - } - - public void update(TopiaEntityEvent event) { - print(event, "vetoUpdate"); - } - - public void delete(TopiaEntityEvent event) { - print(event, "vetoDelete"); - } - - public void load(TopiaEntityEvent event) { - print(event, "vetoLoad"); - } - }; - - 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 update(TopiaEntityEvent event) { - print(event, "entityUpdated"); - } - - public void delete(TopiaEntityEvent event) { - print(event, "entityDeleted"); - } - - public void load(TopiaEntityEvent event) { - print(event, "entityLoaded"); - } - }; - - 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<Person> persons = childContext.getDAO(Person.class); - - Person p = persons.create(); - p.setName("poussin"); - p.setFirstname("benjamin"); - persons.update(p); - childContext.commitTransaction(); - - assertEquals("vetoCreateentityCreatedvetoUpdateentityUpdated", state); - state = ""; - - p.setFirstname("toto"); - persons.update(p); - childContext.commitTransaction(); - - assertEquals("vetoUpdateentityUpdated", state); - state = ""; - - TopiaContextImplementor childContext2 = (TopiaContextImplementor) context - .beginTransaction(); - childContext2.addTopiaEntityVetoable(entityVetoable); - childContext2.addTopiaEntityListener(entityListener); - childContext2.addTopiaTransactionListener(transactionListener); - TopiaDAO<Person> persons2 = childContext2.getDAO(Person.class); - - Person pp = persons2.findByTopiaId(p.getTopiaId()); - - assertEquals(p.getFirstname(), pp.getFirstname()); - assertEquals("vetoLoadentityLoaded", state); - state = ""; - - persons2.delete(pp); - childContext2.commitTransaction(); - - assertEquals("vetoDeleteentityDeleted", state); - state = ""; - - } - - @Test - public void testPropertyEvent() throws Exception { - PropertyChangeListener l = new PropertyChangeListener() { - public void propertyChange(PropertyChangeEvent evt) { - System.out.println("entityUpdated " + evt.getSource()); - state = "entityUpdated"; - } - }; - - Properties config = getProperties(); - - context = TopiaContextFactory.getContext(config).beginTransaction(); - - TopiaDAO<Person> personDAO = ((TopiaContextImplementor) context).getDAO(Person.class); - Person p = personDAO.create(); - p.addPropertyChangeListener("firstName", l); - - p.setFirstname("Arno"); - assertEquals("entityUpdated", state); - state = ""; - - p.setName("Arno"); - assertEquals("", state); - state = ""; - } - -} //TopiaContextTest Modified: topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/framework/EntityStateTest.java =================================================================== --- topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/framework/EntityStateTest.java 2009-01-29 15:47:42 UTC (rev 1334) +++ topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/framework/EntityStateTest.java 2009-01-29 16:15:38 UTC (rev 1335) @@ -1,5 +1,5 @@ /* *##% ToPIA - Tools for Portable and Independent Architecture - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -15,7 +15,14 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * + + +package org.codelutin.topia.framework; + +import org.junit.Assert; +import org.junit.Test; + +/** * EntityStateTest.java * * Created: 22 nov. 06 12:15:11 @@ -26,61 +33,58 @@ * Last update: $Date$ * by : $Author$ */ +public class EntityStateTest { -package org.codelutin.topia.framework; - -import org.junit.Assert; -import org.junit.Test; - -/** @author poussin */ - -public class EntityStateTest extends Assert { - + /** + * Test les changements d'etat de {@link EntityState}. + * + * @throws Exception + */ @Test public void testState() throws Exception { EntityState state = new EntityState(); state.addLoad(); - assertTrue(state.isLoad()); - assertFalse(state.isRead()); - assertFalse(state.isCreate()); - assertFalse(state.isUpdate()); - assertFalse(state.isDelete()); + Assert.assertTrue(state.isLoad()); + Assert.assertFalse(state.isRead()); + Assert.assertFalse(state.isCreate()); + Assert.assertFalse(state.isUpdate()); + Assert.assertFalse(state.isDelete()); state.addRead(); - assertTrue(state.isLoad()); - assertTrue(state.isRead()); - assertFalse(state.isCreate()); - assertFalse(state.isUpdate()); - assertFalse(state.isDelete()); + Assert.assertTrue(state.isLoad()); + Assert.assertTrue(state.isRead()); + Assert.assertFalse(state.isCreate()); + Assert.assertFalse(state.isUpdate()); + Assert.assertFalse(state.isDelete()); //state.addRead(); state.addCreate(); - assertTrue(state.isLoad()); - assertTrue(state.isRead()); - assertTrue(state.isCreate()); - assertFalse(state.isUpdate()); - assertFalse(state.isDelete()); + Assert.assertTrue(state.isLoad()); + Assert.assertTrue(state.isRead()); + Assert.assertTrue(state.isCreate()); + Assert.assertFalse(state.isUpdate()); + Assert.assertFalse(state.isDelete()); state.addUpdate(); - assertTrue(state.isLoad()); - assertTrue(state.isRead()); - assertTrue(state.isCreate()); - assertTrue(state.isUpdate()); - assertFalse(state.isDelete()); + Assert.assertTrue(state.isLoad()); + Assert.assertTrue(state.isRead()); + Assert.assertTrue(state.isCreate()); + Assert.assertTrue(state.isUpdate()); + Assert.assertFalse(state.isDelete()); state.addDelete(); - assertTrue(state.isLoad()); - assertTrue(state.isRead()); - assertTrue(state.isCreate()); - assertTrue(state.isUpdate()); - assertTrue(state.isDelete()); + Assert.assertTrue(state.isLoad()); + Assert.assertTrue(state.isRead()); + Assert.assertTrue(state.isCreate()); + Assert.assertTrue(state.isUpdate()); + Assert.assertTrue(state.isDelete()); state = new EntityState(); state.addDelete(); - assertFalse(state.isRead()); - assertFalse(state.isCreate()); - assertFalse(state.isUpdate()); - assertTrue(state.isDelete()); + Assert.assertFalse(state.isRead()); + Assert.assertFalse(state.isCreate()); + Assert.assertFalse(state.isUpdate()); + Assert.assertTrue(state.isDelete()); } } Modified: topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/framework/TopiaUtilTest.java =================================================================== --- topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/framework/TopiaUtilTest.java 2009-01-29 15:47:42 UTC (rev 1334) +++ topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/framework/TopiaUtilTest.java 2009-01-29 16:15:38 UTC (rev 1335) @@ -1,36 +1,64 @@ +/* *##% + * Copyright (C) 2009 Code Lutin + * + * 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. + *##%*/ + package org.codelutin.topia.framework; -import org.codelutin.topia.Person; -import org.junit.Assert; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.util.regex.Matcher; import java.util.regex.Pattern; -/** @author chemit */ +import org.codelutin.topiatest.Personne; +import org.junit.Assert; +import org.junit.Test; + +/** + * Test pour les methodes de {@link TopiaUtil}. + * + * @author chemit + * @version $Revision: 1242 $ + * + * Last update: $Date: 2008-12-05 00:33:31 +0100 (ven 05 déc 2008) $ + * by : $Author: tchemit $ + */ public class TopiaUtilTest { - protected static final String PERSON_ID = "org.codelutin.topia.Person#1226701039001#0.6502325993664224"; - protected static final String PERSON_ID2 = "org.codelutin.topia.Person#1226701039001#0.6502325993664999"; + protected static final String PERSON_ID = "org.codelutin.topiatest.Personne#1226701039001#0.6502325993664224"; + protected static final String PERSON_ID2 = "org.codelutin.topiatest.Personne#1226701039001#0.6502325993664999"; - @org.junit.Test + @Test public void testGetTopiaIdPattern() throws Exception { String expected; String actual; - expected = "org\\.codelutin\\.topia\\.Person#(?:\\d+?)#(?:\\d+)\\.(?:\\d+)"; - actual = TopiaUtil.getTopiaIdPattern(Person.class); + expected = "org\\.codelutin\\.topiatest\\.Personne#(?:\\d+?)#(?:\\d+)\\.(?:\\d+)"; + actual = TopiaUtil.getTopiaIdPattern(Personne.class); assertEquals(expected, actual); } - @org.junit.Test + @Test public void testGetTopiaPattern() throws Exception { String expected; Pattern pattern; - expected = "(\\d+)-(org\\.codelutin\\.topia\\.Person#(?:\\d+?)#(?:\\d+)\\.(?:\\d+))-(org\\.codelutin\\.topia\\.Person#(?:\\d+?)#(?:\\d+)\\.(?:\\d+))(.*)"; - pattern = TopiaUtil.getTopiaPattern("(\\d+)-%1$s-%1$s(.*)", Person.class); + expected = "(\\d+)-(org\\.codelutin\\.topiatest\\.Personne#(?:\\d+?)#(?:\\d+)\\.(?:\\d+))-(org\\.codelutin\\.topiatest\\.Personne#(?:\\d+?)#(?:\\d+)\\.(?:\\d+))(.*)"; + pattern = TopiaUtil.getTopiaPattern("(\\d+)-%1$s-%1$s(.*)", Personne.class); assertEquals(expected, pattern.toString()); String expression = 123 + "-" + PERSON_ID + "-" + PERSON_ID2 + "-afterall"; @@ -46,6 +74,4 @@ assertEquals(PERSON_ID2, matcher.group(3)); assertEquals("-afterall", matcher.group(4)); } - - } Modified: topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/generator/TopiaTestCase.java =================================================================== --- topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/generator/TopiaTestCase.java 2009-01-29 15:47:42 UTC (rev 1334) +++ topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/generator/TopiaTestCase.java 2009-01-29 16:15:38 UTC (rev 1335) @@ -1,5 +1,5 @@ /* *##% ToPIA Testing - * Copyright (C) 2007 - 2008 CodeLutin + * Copyright (C) 2007 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -26,17 +26,18 @@ import org.codelutin.topia.TopiaException; import org.codelutin.topia.TopiaNotFoundException; import org.codelutin.topia.TopiaTestDAOHelper; -import org.codelutin.topiatest.CompanyDAO; -import org.codelutin.topiatest.DepartmentDAO; import org.codelutin.topiatest.Company; +import org.codelutin.topiatest.CompanyDAO; import org.codelutin.topiatest.Department; +import org.codelutin.topiatest.DepartmentDAO; import org.hibernate.cfg.Environment; -import org.junit.After; +import org.junit.Assert; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; /** - * TopiaTestCase + * TopiaTestCase. * * @author chatellier * @version $Revision: 1186 $ @@ -50,18 +51,17 @@ private final static Log log = LogFactory.getLog(TopiaTestCase.class); /** Proprietes */ - protected Properties config = null; + protected static Properties config = null; /** TopiaContext */ protected TopiaContext context = null; /** - * Retourne les proprietes de connection a la base - * @return la config + * Init les proprietes de connection a la base */ - protected Properties getProperties() { - - Properties config = new Properties(); + @BeforeClass + protected static void init() { + config = new Properties(); config.setProperty("topia.persistence.classes",TopiaTestDAOHelper.entitiesList); config.setProperty(Environment.USER, "sa"); @@ -70,27 +70,18 @@ config.setProperty(Environment.DIALECT,"org.hibernate.dialect.H2Dialect"); config.setProperty(Environment.DRIVER,"org.h2.Driver"); config.setProperty(Environment.URL,"jdbc:h2:file:/tmp/db/data"); - - return config; } /** - * Init + * Create base with schema created. */ - protected void init() { - if(config == null) { - config = getProperties(); - } - } - @Before public void setUp() { + if(log.isInfoEnabled()) { log.info("Junit beforeTest"); } - init(); - try { context = TopiaContextFactory.getContext(config); @@ -148,8 +139,8 @@ company = companyDAO.findByTopiaId(company.getTopiaId()); - org.junit.Assert.assertEquals(company.getName(),"Ma société"); - org.junit.Assert.assertEquals(company.getDepartment().size(),4); + Assert.assertEquals(company.getName(),"Ma société"); + Assert.assertEquals(company.getDepartment().size(),4); newContext.commitTransaction(); newContext.closeContext(); @@ -157,18 +148,4 @@ log.error("Erreur pendant le test testCompositeAssociations",e); } } - - /*@Test - public void testOther() { - if(log.isInfoEnabled()) { - log.info("Junit Test testOther"); - } - }*/ - - @After - public void tearDown() { - if(log.isInfoEnabled()) { - log.info("Junit afterTest"); - } - } } \ No newline at end of file Modified: topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/persistence/ExportXMLVisitor.java =================================================================== --- topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/persistence/ExportXMLVisitor.java 2009-01-29 15:47:42 UTC (rev 1334) +++ topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/persistence/ExportXMLVisitor.java 2009-01-29 16:15:38 UTC (rev 1335) @@ -84,17 +84,20 @@ log.debug("visit collection : " + e); } + Collection cValue = (Collection)value; - buffer.append("<" + collectionType.getName() + ">"); - Iterator itOnValues = cValue.iterator(); - while(itOnValues.hasNext()) { - TopiaEntityAbstract entity = (TopiaEntityAbstract)itOnValues.next(); - - buffer.append("<" + type.getName() + ">\n"); - buffer.append("TODO sublist visit\n"); - buffer.append("</" + type.getName() + ">\n"); + if(cValue != null && !cValue.isEmpty()) { + buffer.append("<" + collectionType.getName() + ">\n"); + Iterator itOnValues = cValue.iterator(); + while(itOnValues.hasNext()) { + TopiaEntityAbstract entity = (TopiaEntityAbstract)itOnValues.next(); + + buffer.append("<" + type.getName() + ">\n"); + buffer.append("TODO sublist visit\n"); + buffer.append("</" + type.getName() + ">\n"); + } + buffer.append("</" + collectionType.getName() + ">\n"); } - buffer.append("</" + collectionType.getName() + ">"); } /*