r1322 - in topia/trunk: . topia-persistence/src/main/java/org/codelutin/topia/generator topia-persistence/src/main/java/org/codelutin/topia/persistence topia-persistence/src/test/java/org/codelutin/topia topia-persistence/src/test/java/org/codelutin/topia/generator topia-persistence/src/test/java/org/codelutin/topia/persistence topia-persistence/src/test/resources topia-persistence/src/test/xmi
Author: chatellier Date: 2009-01-29 10:11:31 +0000 (Thu, 29 Jan 2009) New Revision: 1322 Added: topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/persistence/ topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/persistence/EntityVisitorExportXmlTest.java topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/persistence/ExportXMLVisitor.java Removed: topia/trunk/topia-persistence/src/test/resources/log4j.properties Modified: topia/trunk/pom.xml topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityAbstractGenerator.java topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/EntityVisitor.java topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/generator/TopiaTestCase.java topia/trunk/topia-persistence/src/test/xmi/topiatest.zargo Log: Ajout des tests pour les visiteurs Modified: topia/trunk/pom.xml =================================================================== --- topia/trunk/pom.xml 2009-01-28 19:26:20 UTC (rev 1321) +++ topia/trunk/pom.xml 2009-01-29 10:11:31 UTC (rev 1322) @@ -129,7 +129,7 @@ <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> - <version>1.1.104</version> + <version>1.1.107</version> <scope>test</scope> </dependency> Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityAbstractGenerator.java =================================================================== --- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityAbstractGenerator.java 2009-01-28 19:26:20 UTC (rev 1321) +++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityAbstractGenerator.java 2009-01-29 10:11:31 UTC (rev 1322) @@ -253,24 +253,24 @@ if (!Util.isNMultiplicity(attr)) { if (!attr.hasAssociationClass()) { // FIXME il faut encapsuler getType() pour retourner la version objet des types simples -/*{ visitor.accept(this, <%=attr.getType()%>.class, <%=attr.getName()%>); +/*{ visitor.visit(this, <%=attr.getType()%>.class, <%=attr.getName()%>); }*/ } else { String assocAttrName = GeneratorUtil.getAssocAttrName(attr); -/*{ visitor.accept(this, <%=attr.getAssociationClass().getQualifiedName()%>.class, <%=Util.toLowerCaseFirstLetter(assocAttrName)%>); +/*{ visitor.visit(this, <%=attr.getAssociationClass().getQualifiedName()%>.class, <%=Util.toLowerCaseFirstLetter(assocAttrName)%>); }*/ } } else { String collectionType = GeneratorUtil.getNMultiplicityInterfaceType(attr); if (!attr.hasAssociationClass()) { -/*{ visitor.accept(this, <%=collectionType%>.class, <%=attr.getType()%>.class, <%=attr.getName()%>); +/*{ visitor.visit(this, <%=collectionType%>.class, <%=attr.getType()%>.class, <%=attr.getName()%>); }*/ } else { String assocAttrName = GeneratorUtil.getAssocAttrName(attr); -/*{ visitor.accept(this, <%=collectionType%>.class, <%=attr.getAssociationClass().getQualifiedName()%>.class, <%=Util.toLowerCaseFirstLetter(assocAttrName)%>); +/*{ visitor.visit(this, <%=collectionType%>.class, <%=attr.getAssociationClass().getQualifiedName()%>.class, <%=Util.toLowerCaseFirstLetter(assocAttrName)%>); }*/ } @@ -282,7 +282,7 @@ ObjectModelAssociationClass assoc = (ObjectModelAssociationClass) clazz; for (ObjectModelAttribute attr : assoc.getParticipantsAttributes()) { if (attr != null) { -/*{ visitor.accept(this, <%=attr.getType()%>.class, <%=Util.toLowerCaseFirstLetter(attr.getName())%>); +/*{ visitor.visit(this, <%=attr.getType()%>.class, <%=Util.toLowerCaseFirstLetter(attr.getName())%>); }*/ } Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/EntityVisitor.java =================================================================== --- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/EntityVisitor.java 2009-01-28 19:26:20 UTC (rev 1321) +++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/EntityVisitor.java 2009-01-29 10:11:31 UTC (rev 1322) @@ -31,6 +31,6 @@ public void start(TopiaEntity e); public void end(TopiaEntity e); - public void accept(TopiaEntity e, Class type, Object value); - public void accept(TopiaEntity e, Class collectionType, Class type, Object value); + public void visit(TopiaEntity e, Class type, Object value); + public void visit(TopiaEntity e, Class collectionType, Class type, Object value); } 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-28 19:26:20 UTC (rev 1321) +++ topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/generator/TopiaTestCase.java 2009-01-29 10:11:31 UTC (rev 1322) @@ -61,9 +61,6 @@ */ 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); Added: topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/persistence/EntityVisitorExportXmlTest.java =================================================================== --- topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/persistence/EntityVisitorExportXmlTest.java (rev 0) +++ topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/persistence/EntityVisitorExportXmlTest.java 2009-01-29 10:11:31 UTC (rev 1322) @@ -0,0 +1,184 @@ +/* *##% + * 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.persistence; + +import java.io.File; +import java.io.IOException; +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.TopiaTestDAOHelper; +import org.codelutin.topiatest.Address; +import org.codelutin.topiatest.AddressDAO; +import org.codelutin.topiatest.Company; +import org.codelutin.topiatest.CompanyAbstract; +import org.codelutin.topiatest.CompanyDAO; +import org.codelutin.topiatest.Department; +import org.codelutin.topiatest.DepartmentDAO; +import org.codelutin.topiatest.Employe; +import org.codelutin.topiatest.EmployeDAO; +import org.codelutin.util.FileUtil; +import org.hibernate.cfg.Environment; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Test de visitor. + * + * @author chatellier + * @version $Revision: 1.0 $ + * + * Last update : $Date: 28 janv. 2009 $ + * By : $Author: chatellier $ + */ +public class EntityVisitorExportXmlTest { + + private static Log log = LogFactory.getLog(EntityVisitorExportXmlTest.class); + + protected static File tempDir; + + protected static Properties config; + + /** + * Init les données de tous les tests. + * @throws IOException + */ + @BeforeClass + public static void init() throws IOException { + + tempDir = FileUtil.createTempDirectory("h2", "-exportxml"); + + // init dburl + String dburl = "file:" + tempDir.getAbsolutePath() + File.separator + "data"; + + // init config + + 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:" + dburl); + } + + /** + * Prepare test. + * + * Add all tests commons data + * @throws TopiaException + */ + @Before + public void setUp() throws TopiaException { + TopiaContext context = TopiaContextFactory.getContext(config); + context.createSchema(); + + addData(context); + } + + /** + * Add tests data. + * @throws TopiaException + */ + protected void addData(TopiaContext context) throws TopiaException { + + TopiaContext newContext = context.beginTransaction(); + + // company + CompanyDAO companyDAO = TopiaTestDAOHelper.getCompanyDAO(newContext); + Company clCompany = companyDAO.create(); + clCompany.setName("CodeLutin"); + + // employe + EmployeDAO employeDAO = TopiaTestDAOHelper.getEmployeDAO(newContext); + Employe empl1 = employeDAO.create(); + empl1.setName("boss"); + empl1.setSalary(30000); + + AddressDAO adressDAO = TopiaTestDAOHelper.getAddressDAO(newContext); + Address addr1 = adressDAO.create(); + addr1.setCity("nantes"); + addr1.setAdress("bd des pas enchantés"); + empl1.setAddress(addr1); + + Employe empl2 = employeDAO.create(); + empl2.setName("boss2"); + empl2.setSalary(29000); + Address addr2 = adressDAO.create(); + addr2.setCity("nantes"); + addr2.setAdress("bd des pas enchantés"); + empl2.setAddress(addr2); + + // departement + DepartmentDAO departmentDAO = TopiaTestDAOHelper.getDepartmentDAO(newContext); + Department depComm = departmentDAO.create(); + depComm.setName("Commercial"); + depComm.setLeader(empl1); + + Department depDev = departmentDAO.create(); + depDev.setName("Dev"); + depDev.setLeader(empl2); + clCompany.addDepartment(depComm); + clCompany.addDepartment(depDev); + + newContext.commitTransaction(); + newContext.closeContext(); + } + + /** + * Clean tests. + */ + @After + public void tearDown() { + if(tempDir.exists()) { + tempDir.delete(); + } + } + + /** + * Test l'export XML via un visiteur. + * @throws TopiaException + */ + @Test + public void testExportXML() throws TopiaException { + TopiaContext rootContext = TopiaContextFactory.getContext(config); + + TopiaContext context = rootContext.beginTransaction(); + + CompanyDAO companyDAO = TopiaTestDAOHelper.getCompanyDAO(context); + Company clCompany = companyDAO.findByName("CodeLutin"); + + ExportXMLVisitor visitor = new ExportXMLVisitor(); + // FIXME voir pour l'abstract + ((CompanyAbstract)clCompany).accept(visitor); + context.closeContext(); + + if(log.isInfoEnabled()) { + log.info("Export XML = \n" + visitor.toString()); + } + } +} Added: 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 (rev 0) +++ topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/persistence/ExportXMLVisitor.java 2009-01-29 10:11:31 UTC (rev 1322) @@ -0,0 +1,117 @@ +/* *##% + * 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.persistence; + +import java.util.Collection; +import java.util.Iterator; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Ignore; + +/** + * Visitor pour export xml. + * + * @author chatellier + * @version $Revision: 1.0 $ + * + * Last update : $Date: 29 janv. 2009 $ + * By : $Author: chatellier $ + */ +@Ignore +public class ExportXMLVisitor implements EntityVisitor { + + /** log. */ + private static Log log = LogFactory.getLog(ExportXMLVisitor.class); + + protected StringBuffer buffer; + + public ExportXMLVisitor() { + buffer = new StringBuffer(); + } + + /* + * @see org.codelutin.topia.persistence.EntityVisitor#start(org.codelutin.topia.persistence.TopiaEntity) + */ + @Override + public void start(TopiaEntity e) { + if(log.isDebugEnabled()) { + log.debug("start : " + e); + } + + buffer.append("<" + e.getClass().getName()); + buffer.append(" topiaId=\"" + e.getTopiaId() + "\""); + buffer.append(" topiaCreateDate=\"" + e.getTopiaCreateDate() + "\""); + buffer.append(" topiaVersion=\"" + e.getTopiaVersion() + "\""); + buffer.append(">\n"); + } + + /* + * @see org.codelutin.topia.persistence.EntityVisitor#visit(org.codelutin.topia.persistence.TopiaEntity, java.lang.Class, java.lang.Object) + */ + @Override + public void visit(TopiaEntity e, Class type, Object value) { + if(log.isDebugEnabled()) { + log.debug("visit : " + e); + } + + buffer.append("<" + type.getName() + ">" + value + "</" + type.getName() + ">\n"); + } + + /* + * @see org.codelutin.topia.persistence.EntityVisitor#visit(org.codelutin.topia.persistence.TopiaEntity, java.lang.Class, java.lang.Class, java.lang.Object) + */ + @Override + public void visit(TopiaEntity e, Class collectionType, Class type, + Object value) { + if(log.isDebugEnabled()) { + 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"); + } + buffer.append("</" + collectionType.getName() + ">"); + } + + /* + * @see org.codelutin.topia.persistence.EntityVisitor#end(org.codelutin.topia.persistence.TopiaEntity) + */ + @Override + public void end(TopiaEntity e) { + if(log.isDebugEnabled()) { + log.debug("end : " + e); + } + + buffer.append("</" + e.getClass().getName() + ">\n"); + } + + @Override + public String toString() { + String content = buffer.toString(); + return content; + } +} Deleted: topia/trunk/topia-persistence/src/test/resources/log4j.properties =================================================================== --- topia/trunk/topia-persistence/src/test/resources/log4j.properties 2009-01-28 19:26:20 UTC (rev 1321) +++ topia/trunk/topia-persistence/src/test/resources/log4j.properties 2009-01-29 10:11:31 UTC (rev 1322) @@ -1,9 +0,0 @@ -# Global logging configuration -log4j.rootLogger=INFO, stdout -# Console output... -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n -# package level -log4j.logger.org.codelutin.topia=INFO -log4j.logger.org.hibernate=INFO Modified: topia/trunk/topia-persistence/src/test/xmi/topiatest.zargo =================================================================== (Binary files differ)
participants (1)
-
chatellier@users.labs.libre-entreprise.org