Index: topia-security/src/test/org/codelutin/topia/history/HistoryTest.java diff -u /dev/null topia-security/src/test/org/codelutin/topia/history/HistoryTest.java:1.1 --- /dev/null Tue Oct 17 13:51:29 2006 +++ topia-security/src/test/org/codelutin/topia/history/HistoryTest.java Tue Oct 17 13:51:24 2006 @@ -0,0 +1,129 @@ +/* *##% + * Copyright (C) 2006 + * 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. + *##%*/ + +/* * + * HistoryTest.java + * + * Created: 16 oct. 06 18:27:54 + * + * @author poussin + * @version $Revision: 1.1 $ + * + * Last update: $Date: 2006/10/17 13:51:24 $ + * by : $Author: bpoussin $ + */ + +package org.codelutin.topia.history; + +import java.io.File; +import java.util.List; +import java.util.Properties; + +import org.codelutin.topia.TopiaContext; +import org.codelutin.topia.TopiaContextFactory; +import org.codelutin.topia.TopiaServiceDAOHelper; +import org.codelutin.topia.security.test.entities.Person; +import org.codelutin.topia.security.test.entities.PersonDAO; +import org.codelutin.topia.security.util.TopiaSecurityUtil; +import org.codelutin.util.FileUtil; + +import junit.framework.TestCase; + + +/** + * @author poussin + * + */ + +public class HistoryTest extends TestCase { + + protected static String entitiesList = + "org.codelutin.topia.security.test.entities.PersonImpl," + + "org.codelutin.topia.security.test.entities.PetImpl"; + + protected static Properties getProperties() throws Exception { + Properties config = new Properties(); + //config.setProperty("hibernate.hbm2ddl.auto", "create"); + config.setProperty("hibernate.show_sql", "true"); + + config.setProperty("topia.persistence.classes", entitiesList); + + config.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect"); + config.setProperty("hibernate.connection.username", "sa"); + config.setProperty("hibernate.connection.password", ""); + config.setProperty("hibernate.connection.driver_class", "org.h2.Driver"); + + File tmp = FileUtil.createTempDirectory("topia-test-service", "history"); + config.setProperty("hibernate.connection.url", + "jdbc:h2:" + tmp.getCanonicalPath() + "/data;LOCK_METHOD=NO"); + + config.setProperty("topia.history", + "org.codelutin.topia.history.TopiaHistoryServiceImpl"); + + return config; + } + + public void testHistory() throws Exception { + Properties config = getProperties(); + TopiaContext context = TopiaContextFactory.getContext(config); + + /* Tests */ + TopiaContext childContext = context.beginTransaction(); + + /* Personnes */ + PersonDAO personDAO = TopiaServiceDAOHelper.getPersonDAO(childContext); + Person p = personDAO.create(); + + p.setName("poussin"); + p.setFirstname("benjamin"); + + childContext.commitTransaction(); + + p.delete(); + + childContext.commitTransaction(); + + List all = personDAO.findAll(); + for (Person pp : all) { + pp.getName(); + } + + childContext.closeContext(); + + TopiaHistoryService ths = TopiaHistoryHelper.get(context); + System.out.println("Created: " + ths.findLastAction(-1, null, null, + TopiaSecurityUtil.CREATE)); + System.out.println("Delete: " + ths.findLastAction(-1, null, null, + TopiaSecurityUtil.DELETE)); + System.out.println("Load: " + ths.findLastAction(-1, null, null, + TopiaSecurityUtil.LOAD)); + System.out.println("Update: " + ths.findLastAction(-1, null, null, + TopiaSecurityUtil.UPDATE)); + + System.out.println("All: " + ths.findLastAction(-1, null, null, + TopiaSecurityUtil.CREATE, + TopiaSecurityUtil.DELETE, + TopiaSecurityUtil.LOAD, + TopiaSecurityUtil.UPDATE)); + + } + +} + +