Index: topiatest/src/test/org/codelutin/topiatest/TopiaTestCase.java diff -u /dev/null topiatest/src/test/org/codelutin/topiatest/TopiaTestCase.java:1.1 --- /dev/null Thu Nov 22 18:01:42 2007 +++ topiatest/src/test/org/codelutin/topiatest/TopiaTestCase.java Thu Nov 22 18:01:37 2007 @@ -0,0 +1,174 @@ +/* *##% + * Copyright (C) 2007 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.topiatest; + +import java.util.Properties; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.topia.TopiaContext; +import org.codelutin.topia.TopiaContextFactory; +import org.codelutin.topia.TopiaException; +import org.codelutin.topia.TopiaNotFoundException; +import org.codelutin.topia.TopiaTestDAOHelper; +import org.hibernate.cfg.Environment; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.assertEquals; + +/** + * TopiaTestCase + * + * @author chatellier + * @version $Revision: 1.1 $ + * + * Last update : $Date: 2007-11-22 18:01:37 $ + * By : $Author: chatellier $ + */ +public class TopiaTestCase { + + /** Logger */ + private final static Log log = LogFactory.getLog(TopiaTestCase.class); + + /** Proprietes */ + protected Properties config = null; + + /** TopiaContext */ + protected TopiaContext context = null; + + /** + * Retourne les proprietes de connection a la base + * @return la config + */ + protected Properties getProperties() { + + // javassist pour les out of memery error de cglib + System.setProperty("hibernate.bytecode.provider", "javassist"); + + Properties config = new Properties(); + config.setProperty("topia.persistence.classes",TopiaTestDAOHelper.entitiesList); + + config.setProperty(Environment.USER, "sa"); + config.setProperty(Environment.PASS, ""); + config.setProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread"); + 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 + */ + 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); + + try { + context.createSchema(); + } catch (TopiaException e) { + log.error("Erreur à la creation du schema",e); + } + } catch (TopiaNotFoundException e) { + log.error("Erreur à la creation du topia context",e); + } + } + + @Test + public void testCompositeAssociations() { + if(log.isInfoEnabled()) { + log.info("Junit Test testCompositeAssociations"); + } + + try { + TopiaContext newContext = context.beginTransaction(); + + CompanyDAO companyDAO = TopiaTestDAOHelper.getCompanyDAO(newContext); + DepartmentDAO departmentDAO = TopiaTestDAOHelper.getDepartmentDAO(newContext); + + Company company = companyDAO.create(); + company.setName("Ma société"); + + + Department dep1 = departmentDAO.create(); + dep1.setName("Departement 1"); + Department dep2 = departmentDAO.create(); + dep2.setName("Departement 2"); + Department dep3 = departmentDAO.create(); + dep3.setName("Departement 3"); + Department dep4 = departmentDAO.create(); + dep4.setName("Departement 7"); + + departmentDAO.update(dep1); + departmentDAO.update(dep2); + departmentDAO.update(dep3); + departmentDAO.update(dep4); + + company.addDepartment(dep1); + company.addDepartment(dep2); + company.addDepartment(dep3); + company.addDepartment(dep4); + + companyDAO.update(company); + newContext.commitTransaction(); + + newContext = context.beginTransaction(); + + companyDAO = TopiaTestDAOHelper.getCompanyDAO(newContext); + + company = companyDAO.findByTopiaId(company.getTopiaId()); + + assertEquals(company.getName(),"Ma société"); + assertEquals(company.getDepartment().size(),4); + + newContext.commitTransaction(); + } catch (TopiaException e) { + 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"); + } + } +}