Index: topia-security/src/test/org/codelutin/topia/index/IndexTest.java diff -u /dev/null topia-security/src/test/org/codelutin/topia/index/IndexTest.java:1.1 --- /dev/null Tue Oct 17 13:51:29 2006 +++ topia-security/src/test/org/codelutin/topia/index/IndexTest.java Tue Oct 17 13:51:24 2006 @@ -0,0 +1,124 @@ +/* *##% + * 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. + *##%*/ + +/* * + * IndexTest.java + * + * Created: 16 oct. 06 20:03:22 + * + * @author poussin + * @version $Revision: 1.1 $ + * + * Last update: $Date: 2006/10/17 13:51:24 $ + * by : $Author: bpoussin $ + */ + +package org.codelutin.topia.index; + +import java.io.File; +import java.util.Properties; +import java.util.SortedSet; + +import org.codelutin.topia.Person; +import org.codelutin.topia.TopiaContext; +import org.codelutin.topia.TopiaContextFactory; +import org.codelutin.topia.framework.TopiaContextImplementor; +import org.codelutin.topia.persistence.TopiaDAO; + +import junit.framework.TestCase; + + +/** + * @author poussin + * + */ + +public class IndexTest extends TestCase { + + protected String entitiesList = Person.class.getName(); + + protected Properties getH2Properties() { + Properties config = new Properties(); + config.setProperty("hibernate.show_sql", "true"); + config.setProperty("hibernate.hbm2ddl.auto", "create"); + + new File("/tmp/topiadb/").mkdirs(); + config.setProperty("topia.dao.flatfile.directory", "/tmp/topiadb/h2"); + 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:/tmp/topiaderby;create=true"); + config.setProperty("hibernate.connection.username", "sa"); + config.setProperty("hibernate.connection.password", ""); + + return config; + } + + protected Properties getProperties() { + return getH2Properties(); + } + + protected Properties getIndexProperties() { + Properties result = getProperties(); + result.setProperty("topia.index.engin", "org.codelutin.topia.index.LuceneIndexer"); + result.setProperty("topia.index.lucene.directory", "/tmp/topia-test-index"); + return result; + } + + + public void testIndex() throws Exception { + System.out.println("Debut du test index"); + + Properties config = getIndexProperties(); + + TopiaContext context = TopiaContextFactory.getContext(config); + + TopiaContextImplementor childContext = (TopiaContextImplementor) context + .beginTransaction(); + TopiaDAO persons = childContext.getDAO(Person.class); + Person p = persons.create(); + p.setName("poussin de la chapelle"); + p.setFirstname("benjamin"); + + p = persons.create(); + p.setName("poussin"); + p.setFirstname("benjamin"); + + p = persons.create(); + p.setName("poussin informaticien"); + p.setFirstname("benjamin"); + + childContext.commitTransaction(); + childContext.closeContext(); + + TopiaIndexService ie = TopiaIndexHelper.get(context); + SortedSet results = ie.search("poussin"); + + System.out.println("Index result: " + results.size()); + for (IndexEntry result : results) { + System.out.println("Index result: " + result.getScore()+ " topiaId: " + result.getTopiaId()); + } + } + +} + +