Index: topia/src/test/org/codelutin/topia/persistence/PersistenceStorageJDBCMySQLTest.java diff -u topia/src/test/org/codelutin/topia/persistence/PersistenceStorageJDBCMySQLTest.java:1.2 topia/src/test/org/codelutin/topia/persistence/PersistenceStorageJDBCMySQLTest.java:1.3 --- topia/src/test/org/codelutin/topia/persistence/PersistenceStorageJDBCMySQLTest.java:1.2 Tue Aug 2 15:00:11 2005 +++ topia/src/test/org/codelutin/topia/persistence/PersistenceStorageJDBCMySQLTest.java Wed Aug 3 16:18:20 2005 @@ -23,10 +23,10 @@ * Created: 25 juillet 2005 15:39:19 CEST * * @author Benjamin POUSSIN - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ * - * Last update: $Date: 2005/08/02 15:00:11 $ - * by : $Author: bpoussin $ + * Last update: $Date: 2005/08/03 16:18:20 $ + * by : $Author: thimel $ */ package org.codelutin.topia.persistence; @@ -50,7 +50,7 @@ config.setProperty(TopiaConst.PERSISTENCE_STORAGE_JDBC_URL, "jdbc:mysql:///test"); config.setProperty(TopiaConst.PERSISTENCE_STORAGE_JDBC_LOGIN, "dbuser"); - config.setProperty(TopiaConst.PERSISTENCE_STORAGE_JDBC_PASSWORD, "xxxxxxxx"); + config.setProperty(TopiaConst.PERSISTENCE_STORAGE_JDBC_PASSWORD, ""); return config; } Index: topia/src/test/org/codelutin/topia/persistence/AbstractPersistenceStorageTestCase.java diff -u topia/src/test/org/codelutin/topia/persistence/AbstractPersistenceStorageTestCase.java:1.4 topia/src/test/org/codelutin/topia/persistence/AbstractPersistenceStorageTestCase.java:1.5 --- topia/src/test/org/codelutin/topia/persistence/AbstractPersistenceStorageTestCase.java:1.4 Tue Aug 2 21:03:58 2005 +++ topia/src/test/org/codelutin/topia/persistence/AbstractPersistenceStorageTestCase.java Wed Aug 3 16:18:20 2005 @@ -23,10 +23,10 @@ * Created: 21 juillet 2005 19:57:28 CEST * * @author Benjamin POUSSIN - * @version $Revision: 1.4 $ + * @version $Revision: 1.5 $ * - * Last update: $Date: 2005/08/02 21:03:58 $ - * by : $Author: bpoussin $ + * Last update: $Date: 2005/08/03 16:18:20 $ + * by : $Author: thimel $ */ package org.codelutin.topia.persistence; @@ -50,6 +50,7 @@ static private Logger log = Logger.getLogger("org.codelutin.topia.persistence.TopiaPersistenceStorageTest"); PersistenceStorageJDBC storage = null; + TopiaTestContext testContext = null; TopiaTransactionHelper tth = null; protected int MAX = 10; @@ -58,12 +59,17 @@ public void setUp() throws Exception { Properties config = getConfig(); - tth = new TopiaTransactionHelper(config); + config.put("context.class", "org.codelutin.topia.persistence.TopiaTestContext"); + //Pour éviter les warnings + config.put("context.helper.security", "org.codelutin.topia.security.TopiaSecurityHelper"); + testContext = TopiaTestContext.getContext(config); storage = new PersistenceStorageJDBC(config); + tth = new TopiaTransactionHelper(config); } public void testCommit() throws Exception { - TopiaTransaction tt = tth.newTranstaction(); + TopiaTestContext child1 = testContext.createChild(); + child1.setTransaction(tth.newTranstaction()); String id = TopiaId.create(TopiaUser.class); @@ -71,19 +77,21 @@ TopiaPersistenceObject o2 = new TopiaPersistenceObject(id); o.getData().setField("name", "poussin"); - storage.beginTransaction(tt); - storage.store(tt, o); + storage.beginTransaction(child1); + storage.store(child1, o); - assertTrue(storage.exists(tt, id)); - tt = storage.commitTransaction(tt); + assertTrue(storage.exists(child1, id)); + storage.commitTransaction(child1); - TopiaTransaction tt3 = tth.newTranstaction(); +// TopiaTransaction tt3 = tth.newTranstaction(); + TopiaTestContext child2 = testContext.createChild(); + child2.setTransaction(tth.newTranstaction()); - assertTrue(storage.exists(tt, id)); - assertTrue(storage.exists(tt3, id)); + assertTrue(storage.exists(child1, id)); + assertTrue(storage.exists(child2, id)); o2.getAskedFields().add("name"); - storage.restore(tt3, o2); + storage.restore(child2, o2); assertEquals(o.getData(), o2.getData()); assertEquals("poussin", o.getData().getField("name")); @@ -91,59 +99,63 @@ } public void testRollback() throws Exception { - TopiaTransaction tt = tth.newTranstaction(); + TopiaTestContext child1 = testContext.createChild(); + child1.setTransaction(tth.newTranstaction()); String id = TopiaId.create(TopiaUser.class); TopiaPersistenceObject o = new TopiaPersistenceObject(id); o.getData().setField("name", "poussin"); - storage.beginTransaction(tt); - storage.store(tt, o); + storage.beginTransaction(child1); + storage.store(child1, o); - assertTrue(storage.exists(tt, id)); + assertTrue(storage.exists(child1, id)); - tt = storage.rollbackTransaction(tt); + storage.rollbackTransaction(child1); - assertFalse(storage.exists(tt, id)); + assertFalse(storage.exists(child1, id)); } public void testIsolation() throws Exception { - TopiaTransaction tt = tth.newTranstaction(); - TopiaTransaction tt2 = tth.newTranstaction(); - + TopiaTestContext child1 = testContext.createChild(); + child1.setTransaction(tth.newTranstaction()); + TopiaTestContext child2 = testContext.createChild(); + child2.setTransaction(tth.newTranstaction()); + String id = TopiaId.create(TopiaUser.class); TopiaPersistenceObject o = new TopiaPersistenceObject(id); TopiaPersistenceObject o2 = new TopiaPersistenceObject(id); o.getData().setField("name", "poussin"); - storage.beginTransaction(tt); - storage.store(tt, o); + storage.beginTransaction(child1); + storage.store(child1, o); - assertTrue(storage.exists(tt, id)); - assertFalse(storage.exists(tt2, id)); - tt = storage.commitTransaction(tt); - - TopiaTransaction tt3 = tth.newTranstaction(); - - assertTrue(storage.exists(tt, id)); - assertFalse(storage.exists(tt2, id)); - assertTrue(storage.exists(tt3, id)); + assertTrue(storage.exists(child1, id)); + assertFalse(storage.exists(child2, id)); + storage.commitTransaction(child1); + + TopiaTestContext child3 = testContext.createChild(); + child3.setTransaction(tth.newTranstaction()); + + assertTrue(storage.exists(child1, id)); + assertFalse(storage.exists(child2, id)); + assertTrue(storage.exists(child3, id)); o.getData().setField("name", "repoussin"); - storage.store(tt, o); + storage.store(child1, o); - assertTrue(storage.exists(tt, id)); - assertFalse(storage.exists(tt2, id)); - assertTrue(storage.exists(tt3, id)); + assertTrue(storage.exists(child1, id)); + assertFalse(storage.exists(child2, id)); + assertTrue(storage.exists(child3, id)); - tt = storage.commitTransaction(tt); + storage.commitTransaction(child1); - assertTrue(storage.exists(tt, id)); - assertFalse(storage.exists(tt2, id)); - assertTrue(storage.exists(tt3, id)); + assertTrue(storage.exists(child1, id)); + assertFalse(storage.exists(child2, id)); + assertTrue(storage.exists(child3, id)); o2.getAskedFields().add("name"); - storage.restore(tt3, o2); + storage.restore(child3, o2); assertFalse(o.getData().equals(o2.getData())); assertEquals("repoussin", o.getData().getField("name")); @@ -151,45 +163,49 @@ } public void testDelete() throws Exception { - TopiaTransaction tt = tth.newTranstaction(); + TopiaTestContext child1 = testContext.createChild(); + child1.setTransaction(tth.newTranstaction()); String id = TopiaId.create(TopiaUser.class); TopiaPersistenceObject o = new TopiaPersistenceObject(id); o.getData().setField("name", "poussin"); - storage.beginTransaction(tt); - storage.store(tt, o); + storage.beginTransaction(child1); + storage.store(child1, o); - assertTrue(storage.exists(tt, id)); - tt = storage.commitTransaction(tt); + assertTrue(storage.exists(child1, id)); + storage.commitTransaction(child1); - TopiaTransaction tt3 = tth.newTranstaction(); + TopiaTestContext child2 = testContext.createChild(); + child2.setTransaction(tth.newTranstaction()); - assertTrue(storage.exists(tt, id)); - assertTrue(storage.exists(tt3, id)); + assertTrue(storage.exists(child1, id)); + assertTrue(storage.exists(child2, id)); o.getManagement().setDeleted(true); - storage.store(tt, o); + storage.store(child1, o); - assertFalse(storage.exists(tt, id)); - assertTrue(storage.exists(tt3, id)); + assertFalse(storage.exists(child1, id)); + assertTrue(storage.exists(child2, id)); - tt = storage.commitTransaction(tt); + storage.commitTransaction(child1); - assertFalse(storage.exists(tt, id)); - assertTrue(storage.exists(tt3, id)); + assertFalse(storage.exists(child1, id)); + assertTrue(storage.exists(child2, id)); - TopiaTransaction tt4 = tth.newTranstaction(); + TopiaTestContext child3 = testContext.createChild(); + child3.setTransaction(tth.newTranstaction()); - assertFalse(storage.exists(tt, id)); - assertFalse(storage.exists(tt4, id)); + assertFalse(storage.exists(child1, id)); + assertFalse(storage.exists(child3, id)); } public void testGetAllId() throws Exception { - TopiaTransaction tt = tth.newTranstaction(); + TopiaTestContext child1 = testContext.createChild(); + child1.setTransaction(tth.newTranstaction()); - Collection ids = storage.getAllId(tt); + Collection ids = storage.getAllId(child1); log.info("ids.size: " + ids.size()); Collection os = new ArrayList(ids.size()); for(String id: ids){ @@ -198,25 +214,28 @@ os.add(o); } - storage.beginTransaction(tt); - storage.store(tt, os); + storage.beginTransaction(child1); + storage.store(child1, os); - Collection idsvide = storage.getAllId(tt); + Collection idsvide = storage.getAllId(child1); assertEquals(0, idsvide.size()); - TopiaTransaction tt2 = tth.newTranstaction(); - Collection ids2 = storage.getAllId(tt2); + TopiaTestContext child2 = testContext.createChild(); + child2.setTransaction(tth.newTranstaction()); + Collection ids2 = storage.getAllId(child2); assertEquals(ids, ids2); - storage.commitTransaction(tt); + storage.commitTransaction(child1); - TopiaTransaction tt3 = tth.newTranstaction(); - Collection ids3 = storage.getAllId(tt3); + TopiaTestContext child3 = testContext.createChild(); + child3.setTransaction(tth.newTranstaction()); + Collection ids3 = storage.getAllId(child3); assertEquals(0, ids3.size()); } public void testDataType() throws Exception { - TopiaTransaction tt = tth.newTranstaction(); + TopiaTestContext child1 = testContext.createChild(); + child1.setTransaction(tth.newTranstaction()); String id = TopiaId.create(TopiaUser.class); TopiaPersistenceObject o = new TopiaPersistenceObject(id); TopiaPersistenceObject o2 = new TopiaPersistenceObject(id); @@ -242,11 +261,11 @@ o.getData().setField("object", new ArrayList()); o2.getAskedFields().add("object"); - storage.beginTransaction(tt); - storage.store(tt, o); - tt = storage.commitTransaction(tt); + storage.beginTransaction(child1); + storage.store(child1, o); + storage.commitTransaction(child1); - storage.restore(tt, o2); + storage.restore(child1, o2); System.out.println("o =" + o.getData()); System.out.println("o2=" + o2.getData()); @@ -258,7 +277,8 @@ // en dessous de 10 ca plante lors du calcul du % return; } - TopiaTransaction tt = tth.newTranstaction(); + TopiaTestContext child1 = testContext.createChild(); + child1.setTransaction(tth.newTranstaction()); long time = System.currentTimeMillis(); @@ -281,11 +301,11 @@ long time1 = System.currentTimeMillis(); System.out.println("time to create("+MAX+"): " + (time1 - time)); - storage.beginTransaction(tt); + storage.beginTransaction(child1); int compteur = 0; long timeold = time1; for(TopiaPersistenceObject o: list){ - storage.store(tt, o); + storage.store(child1, o); compteur++; if(compteur%(MAX/10) == 0){ long timenew = System.currentTimeMillis(); @@ -298,7 +318,7 @@ long time2 = System.currentTimeMillis(); System.out.println("time to store: " + (time2 - time1)); - tt = storage.commitTransaction(tt); + storage.commitTransaction(child1); long time3 = System.currentTimeMillis(); System.out.println("time to commit: " + (time3 - time2)); System.out.println("-- Total time: " + (time3 - time)); Index: topia/src/test/org/codelutin/topia/persistence/TopiaTestContext.java diff -u /dev/null topia/src/test/org/codelutin/topia/persistence/TopiaTestContext.java:1.1 --- /dev/null Wed Aug 3 16:18:25 2005 +++ topia/src/test/org/codelutin/topia/persistence/TopiaTestContext.java Wed Aug 3 16:18:20 2005 @@ -0,0 +1,130 @@ +/* *##% + * Copyright (C) 2002, 2003 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. + *##%*/ + +/* * + * TopiaTestContext.java + * + * Created: 3 août 2005 + * + * @author Arnaud Thimel + * Copyright Code Lutin + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2005/08/03 16:18:20 $ + * par : $Author: thimel $ + */ + +package org.codelutin.topia.persistence; + +import org.codelutin.topia.TopiaContext; +import org.codelutin.topia.TopiaContextFactory; +import org.codelutin.topia.TopiaException; +import org.codelutin.topia.security.TopiaSecurityException; +import org.codelutin.topia.security.TopiaPrincipal; +import java.util.Properties; +import java.util.List; +import java.util.logging.Logger; + +public class TopiaTestContext extends TopiaContext { + + /** to use log facility, just put in your code: log.info("..."); */ + static private Logger log = Logger.getLogger("org.codelutin.TopiaTestContext"); + + /** + */ + protected TopiaTestContext(Properties properties) { + super(properties); + } + + /** + * Constructeur utilisé pour l'ouverture de transaction + */ + protected TopiaTestContext(TopiaTestContext parentContext) { + super(parentContext); + } + + public String getContextName() { + return "TopiaTest"; + } + + /** + * Donne le nom du fichier de propriété lu par defaut. + */ + static public String getContextPropertiesFilename(){ + String propName = "TopiaTestContext.properties"; + return propName; + } + + /** + * Donne le nom du fichier de propriété client lu par defaut. + */ + static public String getClientContextPropertiesFilename(){ + String propName = "TopiaTestContext-client.properties"; + return propName; + } + + @Override + protected TopiaTestContext createChild() { + return new TopiaTestContext(this); + } + + /** + * Methode qui permet de recuperer un context pour l'application. + * Cette methode est en fait un appel a la factory de context. + * L'avantage d'utiliser cette methode est qu'elle vous evite un cast + */ + public static TopiaTestContext getContext() throws TopiaException { + String propName = getContextPropertiesFilename(); + return (TopiaTestContext)TopiaContextFactory.getContext(propName); + } + + /** + * Methode qui permet de recuperer un context client pour l'application. + * Cette methode est en fait un appel a la factory de context. + * L'avantage d'utiliser cette methode est qu'elle vous evite un cast + */ + public static TopiaTestContext getClientContext() throws TopiaException { + String propName = getClientContextPropertiesFilename(); + return (TopiaTestContext)TopiaContextFactory.getClientContext(propName); + } + + /** + * Method qui permet de recuperer un context pour l'application. + * Cette methode est en fait un appel a la factory de context. + * L'avantage d'utiliser cette methode est qu'elle vous evite un cast + */ + public static TopiaTestContext getContext(Properties prop) throws TopiaException { + return (TopiaTestContext)TopiaContextFactory.getContext(prop); + } + + /** + * Method qui permet de recuperer un context client pour l'application. + * Cette methode est en fait un appel a la factory de context. + * L'avantage d'utiliser cette methode est qu'elle vous evite un cast + */ + public static TopiaTestContext getClientContext(Properties prop) throws TopiaException { + return (TopiaTestContext)TopiaContextFactory.getClientContext(prop); + } + + + // TODO Controls + + protected List xmiAuthentication(String login, String password) throws TopiaSecurityException { + throw new TopiaSecurityException("xmiAuthentication not supported"); } + +} Index: topia/src/test/org/codelutin/topia/persistence/TopiaJDBCQueryBuilderTest.java diff -u /dev/null topia/src/test/org/codelutin/topia/persistence/TopiaJDBCQueryBuilderTest.java:1.1 --- /dev/null Wed Aug 3 16:18:25 2005 +++ topia/src/test/org/codelutin/topia/persistence/TopiaJDBCQueryBuilderTest.java Wed Aug 3 16:18:20 2005 @@ -0,0 +1,101 @@ +/* *##% + * Copyright (C) 2002, 2003 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. + *##%*/ + +/* * + * TopiaJDBCQueryBuilderTest.java + * + * Created: 28 juil. 2005 + * + * @author Arnaud Thimel + * Copyright Code Lutin + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2005/08/03 16:18:20 $ + * par : $Author: thimel $ + */ +package org.codelutin.topia.persistence; + +import org.codelutin.util.RecursiveProperties; + +import junit.framework.TestCase; + + +public class TopiaJDBCQueryBuilderTest extends TestCase { + + public void testParseQuery() throws Exception { + TopiaTransactionHelper tth = new TopiaTransactionHelper(new RecursiveProperties()); + TopiaTransaction t = tth.newTranstaction(); + + TopiaJDBCQueryHelper qHelper = new TopiaJDBCQueryHelper(); + qHelper.setQuery("select * from A"); + System.out.println(qHelper.getPreparedQuery(t)); + System.out.println(qHelper.getArgs()); + + qHelper = new TopiaJDBCQueryHelper(); + qHelper.setQuery("select * from A where (age='24' or age='25') and nom='Thimel'"); + System.out.println(qHelper.getPreparedQuery(t)); + System.out.println(qHelper.getArgs()); + + qHelper = new TopiaJDBCQueryHelper(); + qHelper.setQuery("select * from A where age!='24' and nom='Thimel'"); + System.out.println(qHelper.getPreparedQuery(t)); + System.out.println(qHelper.getArgs()); + + qHelper = new TopiaJDBCQueryHelper(); + qHelper.setQuery("select * from A where nom='Thimel' and (age='24' or age='25')"); + System.out.println(qHelper.getPreparedQuery(t)); + System.out.println(qHelper.getArgs()); + + qHelper = new TopiaJDBCQueryHelper(); + qHelper.setQuery("select * from A where nom='Thimel'"); + System.out.println(qHelper.getPreparedQuery(t)); + System.out.println(qHelper.getArgs()); + + qHelper = new TopiaJDBCQueryHelper(); + qHelper.setQuery("select * from A where nom=?"); + qHelper.addArg("Thimel"); + System.out.println(qHelper.getPreparedQuery(t)); + System.out.println(qHelper.getArgs()); + + qHelper = new TopiaJDBCQueryHelper(); + qHelper.setQuery("select * from A where nom like '%mel'"); + System.out.println(qHelper.getPreparedQuery(t)); + System.out.println(qHelper.getArgs()); + + qHelper = new TopiaJDBCQueryHelper(); + qHelper.setQuery("SELECT * FROM A WHERE nom NOT LIKE '%mel'"); + System.out.println(qHelper.getPreparedQuery(t)); + System.out.println(qHelper.getArgs()); + + qHelper = new TopiaJDBCQueryHelper(); + qHelper.setQuery("SELECT * FROM A WHERE NOT nom='Thimel'"); + System.out.println(qHelper.getPreparedQuery(t)); + System.out.println(qHelper.getArgs()); + + qHelper = new TopiaJDBCQueryHelper(); + qHelper.setQuery("select * from A where NOT (age='24' or age='25') and NOT (NOT (nom='Thimel'))"); + System.out.println(qHelper.getPreparedQuery(t)); + System.out.println(qHelper.getArgs()); + + qHelper = new TopiaJDBCQueryHelper(); + qHelper.setQuery("select * from A where NOT (age!='24' and nom='Thimel')"); + System.out.println(qHelper.getPreparedQuery(t)); + System.out.println(qHelper.getArgs()); + } + +}