r2467 - in trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck: . it it/generator it/persistence legacy
Author: athimel Date: 2012-05-10 09:25:37 +0200 (Thu, 10 May 2012) New Revision: 2467 Url: http://nuiton.org/repositories/revision/topia/2467 Log: Some tests was using the wrong TopiaDatabase Added: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/generator/ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/generator/CompositeAssociationTest.java trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/persistence/EntityVisitorExportXmlTest.java trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/persistence/ExportXMLVisitor.java trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/persistence/NaturalIdTest.java Removed: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/generator/TopiaTestCase.java trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/generator/ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/persistence/ Modified: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaTckItTestSuite.java trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaTckLegacyTestSuite.java Modified: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaTckItTestSuite.java =================================================================== --- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaTckItTestSuite.java 2012-05-10 06:48:25 UTC (rev 2466) +++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaTckItTestSuite.java 2012-05-10 07:25:37 UTC (rev 2467) @@ -8,11 +8,11 @@ import org.nuiton.topia.tck.legacy.evo1912.EntityDTOTransformerTest; import org.nuiton.topia.tck.legacy.framework.TopiaContextReplicateTest; import org.nuiton.topia.tck.legacy.framework.TopiaUtilTest; -import org.nuiton.topia.tck.legacy.generator.TopiaTestCase; +import org.nuiton.topia.tck.it.generator.CompositeAssociationTest; import org.nuiton.topia.tck.it.EnumTest; import org.nuiton.topia.tck.it.deletetest.DeleteEntityTest; -import org.nuiton.topia.tck.legacy.persistence.EntityVisitorExportXmlTest; -import org.nuiton.topia.tck.legacy.persistence.NaturalIdTest; +import org.nuiton.topia.tck.it.persistence.EntityVisitorExportXmlTest; +import org.nuiton.topia.tck.it.persistence.NaturalIdTest; /** * @author Arnaud Thimel <thimel@codelutin.com> @@ -24,12 +24,12 @@ EntityDTOTransformerTest.class, TopiaContextReplicateTest.class, TopiaUtilTest.class, - TopiaTestCase.class, + CompositeAssociationTest.class, DeleteEntityTest.class, EntityVisitorExportXmlTest.class, NaturalIdTest.class, TopiaContextFactoryTest.class, - EnumTest.class}) // TODO AThimel 09/05/2012 Add all TCK IT tests + EnumTest.class}) public abstract class TopiaTckItTestSuite { } Modified: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaTckLegacyTestSuite.java =================================================================== --- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaTckLegacyTestSuite.java 2012-05-10 06:48:25 UTC (rev 2466) +++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaTckLegacyTestSuite.java 2012-05-10 07:25:37 UTC (rev 2467) @@ -2,14 +2,14 @@ import org.junit.runner.RunWith; import org.junit.runners.Suite; +import org.nuiton.topia.tck.it.generator.CompositeAssociationTest; import org.nuiton.topia.tck.legacy.ano1882.DAOAbstractTransformerTest; import org.nuiton.topia.tck.legacy.ano1991.TopiaQueryTest; import org.nuiton.topia.tck.legacy.evo1912.EntityDTOTransformerTest; import org.nuiton.topia.tck.legacy.framework.TopiaContextReplicateTest; import org.nuiton.topia.tck.legacy.framework.TopiaUtilTest; -import org.nuiton.topia.tck.legacy.generator.TopiaTestCase; -import org.nuiton.topia.tck.legacy.persistence.EntityVisitorExportXmlTest; -import org.nuiton.topia.tck.legacy.persistence.NaturalIdTest; +import org.nuiton.topia.tck.it.persistence.EntityVisitorExportXmlTest; +import org.nuiton.topia.tck.it.persistence.NaturalIdTest; /** * Test suite for {@code mapping} model. @@ -25,10 +25,7 @@ TopiaQueryTest.class, EntityDTOTransformerTest.class, TopiaContextReplicateTest.class, - TopiaUtilTest.class, - TopiaTestCase.class, - EntityVisitorExportXmlTest.class, - NaturalIdTest.class + TopiaUtilTest.class } ) public abstract class TopiaTckLegacyTestSuite { Added: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/generator/CompositeAssociationTest.java =================================================================== --- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/generator/CompositeAssociationTest.java (rev 0) +++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/generator/CompositeAssociationTest.java 2012-05-10 07:25:37 UTC (rev 2467) @@ -0,0 +1,108 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package org.nuiton.topia.tck.it.generator; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.tck.TopiaDatabase; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.tck.it.TopiaDatabaseIt; +import org.nuiton.topia.tck.it.TopiaTckItDAOHelper; +import org.nuiton.topia.tck.it.Company; +import org.nuiton.topia.tck.it.CompanyDAO; +import org.nuiton.topia.tck.it.Department; +import org.nuiton.topia.tck.it.DepartmentDAO; + +/** + * CompositeAssociationTest. + * + * @author chatellier + * @version $Revision$ + * <p/> + * Last update : $Date$ + * By : $Author$ + */ +public class CompositeAssociationTest { + + /** Logger */ + private final static Log log = LogFactory.getLog(CompositeAssociationTest.class); + + @Rule + public final TopiaDatabase db = new TopiaDatabaseIt(); + + @Test + public void testCompositeAssociations() throws TopiaException { + if (log.isDebugEnabled()) { + log.debug("Junit Test testCompositeAssociations"); + } + + TopiaContext newContext = db.beginTransaction(); + + CompanyDAO companyDAO = TopiaTckItDAOHelper.getCompanyDAO(newContext); + DepartmentDAO departmentDAO = TopiaTckItDAOHelper.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 = db.beginTransaction(); + + companyDAO = TopiaTckItDAOHelper.getCompanyDAO(newContext); + + company = companyDAO.findByTopiaId(company.getTopiaId()); + + Assert.assertEquals(company.getName(), "Ma société"); + Assert.assertEquals(company.getDepartment().size(), 4); + + newContext.commitTransaction(); + } +} Property changes on: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/generator/CompositeAssociationTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/generator/TopiaTestCase.java =================================================================== --- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/generator/TopiaTestCase.java 2012-05-10 06:48:25 UTC (rev 2466) +++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/generator/TopiaTestCase.java 2012-05-10 07:25:37 UTC (rev 2467) @@ -1,171 +0,0 @@ -/* - * #%L - * ToPIA :: Persistence - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.topia.tck.legacy.generator; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.tck.TopiaDatabase; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.tck.it.TopiaTckItDAOHelper; -import org.nuiton.topia.tck.it.Company; -import org.nuiton.topia.tck.it.CompanyDAO; -import org.nuiton.topia.tck.it.Department; -import org.nuiton.topia.tck.it.DepartmentDAO; -import org.nuiton.topia.tck.legacy.TopiaDatabaseLegacy; - -/** - * TopiaTestCase. - * - * @author chatellier - * @version $Revision$ - * <p/> - * Last update : $Date$ - * By : $Author$ - */ -public class TopiaTestCase { - - /** Logger */ - private final static Log log = LogFactory.getLog(TopiaTestCase.class); - - @Rule - public final TopiaDatabase db = new TopiaDatabaseLegacy(); - -// /** Proprietes */ -// protected static Properties config; -// -// /** TopiaContext */ -// protected static TopiaContext context; - -// /** -// * Init les proprietes de connection a la base -// * -// * @throws IOException for any IO error while getting configuration. -// */ -// @BeforeClass -// public static void init() throws IOException { -// -// File testBasedir = TestHelper.getTestBasedir(TopiaTestCase.class); -// -// config = TestHelper.initTopiaContextConfiguration( -// testBasedir, -// "/TopiaContextImpl.properties", -// "TopiaTestCaseDb"); -//// config = new Properties(); -//// config.setProperty("topia.persistence.classes", TopiaTckItDAOHelper.getImplementationClassesAsString()); -//// -//// 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:" + testBasedir + "/db/data_" + System.currentTimeMillis()); -// } -// -// @AfterClass -// public static void after() throws TopiaException { -// // destroy database -// context.clear(false); -// } - -// /** Create base with schema created. */ -// @Before -// public void setUp() { -// -// if (log.isDebugEnabled()) { -// log.debug("Junit beforeTest"); -// } -// -// 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() throws TopiaException { - if (log.isDebugEnabled()) { - log.debug("Junit Test testCompositeAssociations"); - } - -// try { - TopiaContext newContext = db.beginTransaction(); - - CompanyDAO companyDAO = TopiaTckItDAOHelper.getCompanyDAO(newContext); - DepartmentDAO departmentDAO = TopiaTckItDAOHelper.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 = db.beginTransaction(); - - companyDAO = TopiaTckItDAOHelper.getCompanyDAO(newContext); - - company = companyDAO.findByTopiaId(company.getTopiaId()); - - Assert.assertEquals(company.getName(), "Ma société"); - Assert.assertEquals(company.getDepartment().size(), 4); - - newContext.commitTransaction(); -// newContext.closeContext(); -// } catch (TopiaException e) { -// log.error("Erreur pendant le test testCompositeAssociations", e); -// } - } -} Copied: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/persistence/EntityVisitorExportXmlTest.java (from rev 2466, trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/persistence/EntityVisitorExportXmlTest.java) =================================================================== --- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/persistence/EntityVisitorExportXmlTest.java (rev 0) +++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/persistence/EntityVisitorExportXmlTest.java 2012-05-10 07:25:37 UTC (rev 2467) @@ -0,0 +1,135 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package org.nuiton.topia.tck.it.persistence; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.persistence.DepthEntityVisitor; +import org.nuiton.topia.persistence.EntityVisitor; +import org.nuiton.topia.tck.TopiaDatabase; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.tck.it.TopiaDatabaseIt; +import org.nuiton.topia.tck.it.TopiaTckItDAOHelper; +import org.nuiton.topia.tck.it.Address; +import org.nuiton.topia.tck.it.AddressDAO; +import org.nuiton.topia.tck.it.Company; +import org.nuiton.topia.tck.it.CompanyDAO; +import org.nuiton.topia.tck.it.Department; +import org.nuiton.topia.tck.it.DepartmentDAO; +import org.nuiton.topia.tck.it.Employe; +import org.nuiton.topia.tck.it.EmployeDAO; + +/** + * Test de visitor. + * + * @author chatellier + * @version $Revision$ + * <p/> + * Last update : $Date$ + * By : $Author$ + */ +public class EntityVisitorExportXmlTest { + + private static final Log log = + LogFactory.getLog(EntityVisitorExportXmlTest.class); + + @Rule + public final TopiaDatabase db = new TopiaDatabaseIt(); + + /** + * Prepare test. + * <p/> + * Add all tests commons data + * + * @throws TopiaException if could not create datas + */ + @Before + public void setUp() throws TopiaException { + + TopiaContext newContext = db.beginTransaction(); + try { + // company + CompanyDAO companyDAO = TopiaTckItDAOHelper.getCompanyDAO(newContext); + Company clCompany = companyDAO.create(Company.PROPERTY_NAME, "CodeLutin"); + + // employe + EmployeDAO employeDAO = TopiaTckItDAOHelper.getEmployeDAO(newContext); + Employe empl1 = employeDAO.create(Employe.PROPERTY_NAME, "boss", Employe.PROPERTY_SALARY, 30000); + + AddressDAO adressDAO = TopiaTckItDAOHelper.getAddressDAO(newContext); + Address addr1 = adressDAO.create(Address.PROPERTY_CITY, "Nantes", Address.PROPERTY_ADRESS, "12 Avenue Jules Vernes"); + empl1.setAddress(addr1); + + Employe empl2 = employeDAO.create(Employe.PROPERTY_NAME, "boss2", Employe.PROPERTY_SALARY, 29000); + Address addr2 = adressDAO.create(Address.PROPERTY_CITY, "Nantes", Address.PROPERTY_ADRESS, "12 Avenue Jules Vernes"); + empl2.setAddress(addr2); + + // departement + DepartmentDAO departmentDAO = TopiaTckItDAOHelper.getDepartmentDAO(newContext); + Department depComm = departmentDAO.create(Department.PROPERTY_NAME, "Commercial"); + depComm.setLeader(empl1); + + Department depDev = departmentDAO.create(Department.PROPERTY_NAME, "Dev"); + depDev.setLeader(empl2); + clCompany.addDepartment(depComm); + clCompany.addDepartment(depDev); + + newContext.commitTransaction(); + } finally { + + newContext.closeContext(); + } + } + + + /** + * Test l'export XML via un visiteur. + * <p/> + * Parcourt en profondeur. + * + * @throws TopiaException + */ + @Test + public void testExportXMLDepth() throws TopiaException { + + TopiaContext context = db.beginTransaction(); + + CompanyDAO companyDAO = TopiaTckItDAOHelper.getCompanyDAO(context); + Company clCompany = companyDAO.findByName("CodeLutin"); + + EntityVisitor delegateVisitor = new ExportXMLVisitor(); + EntityVisitor visitor = new DepthEntityVisitor(delegateVisitor); + clCompany.accept(visitor); + + if (log.isInfoEnabled()) { + log.info("Export XML = \n" + delegateVisitor.toString()); + } + } +} Property changes on: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/persistence/EntityVisitorExportXmlTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/persistence/ExportXMLVisitor.java (from rev 2466, trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/persistence/ExportXMLVisitor.java) =================================================================== --- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/persistence/ExportXMLVisitor.java (rev 0) +++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/persistence/ExportXMLVisitor.java 2012-05-10 07:25:37 UTC (rev 2467) @@ -0,0 +1,109 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package org.nuiton.topia.tck.it.persistence; + + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Ignore; +import org.nuiton.topia.persistence.EntityVisitor; +import org.nuiton.topia.persistence.TopiaEntity; + +/** + * Visitor pour export xml. + * + * @author chatellier + * @version $Revision$ + * <p/> + * Last update : $Date$ + * By : $Author$ + */ +@Ignore +public class ExportXMLVisitor implements EntityVisitor { + + /** log. */ + private static Log log = LogFactory.getLog(ExportXMLVisitor.class); + + protected StringBuffer buffer; + + public ExportXMLVisitor() { + buffer = new StringBuffer(); + } + + @Override + public void start(TopiaEntity e) { + if (log.isDebugEnabled()) { + log.debug("start : " + e); + } + + buffer.append("<").append(e.getClass().getName()); + buffer.append(" topiaId=\"").append(e.getTopiaId()).append("\""); + buffer.append(" topiaCreateDate=\"").append(e.getTopiaCreateDate()).append("\""); + buffer.append(" topiaVersion=\"").append(e.getTopiaVersion()).append("\""); + buffer.append(">\n"); + } + + @Override + public void visit(TopiaEntity e, String name, Class<?> type, Object value) { + if (log.isDebugEnabled()) { + log.debug("visit : " + e); + } + + buffer.append("<").append(type.getName()).append(">").append(value).append("</").append(type.getName()).append(">\n"); + } + + @Override + public void visit(TopiaEntity e, String name, Class<?> collectionType, Class<?> type, + Object value) { + } + + @Override + public void visit(TopiaEntity e, String name, Class<?> collectionType, Class<?> type, int index, Object value) { + visit(e, name, type, value); + } + + @Override + public void end(TopiaEntity e) { + if (log.isDebugEnabled()) { + log.debug("end : " + e); + } + + buffer.append("</").append(e.getClass().getName()).append(">\n"); + } + + @Override + public String toString() { + String content = buffer.toString(); + return content; + } + + @Override + public void clear() { + // do nothing + } + + +} Property changes on: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/persistence/ExportXMLVisitor.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/persistence/NaturalIdTest.java (from rev 2466, trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/legacy/persistence/NaturalIdTest.java) =================================================================== --- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/persistence/NaturalIdTest.java (rev 0) +++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/persistence/NaturalIdTest.java 2012-05-10 07:25:37 UTC (rev 2467) @@ -0,0 +1,180 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package org.nuiton.topia.tck.it.persistence; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.tck.TopiaDatabase; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.tck.it.TopiaDatabaseIt; +import org.nuiton.topia.tck.it.TopiaTckItDAOHelper; +import org.nuiton.topia.tck.it.NaturalizedEntity; +import org.nuiton.topia.tck.it.NaturalizedEntityDAO; + +import javax.persistence.PersistenceException; + +/** + * NaturalIdTest + * <p/> + * Created: 18 févr. 2010 + * + * @author fdesbois + * @version $Revision$ + * <p/> + * Mise a jour: $Date$ + * par : $Author$ + */ +public class NaturalIdTest { + + private static final Log log = LogFactory.getLog(NaturalIdTest.class); + + @Rule + public final TopiaDatabase db = new TopiaDatabaseIt(); + + @Test + public void testCreateSucessfull() throws Exception { + log.debug("Test naturalId : create succesfull"); + TopiaContext transaction = db.beginTransaction(); + + NaturalizedEntityDAO dao = + TopiaTckItDAOHelper.getNaturalizedEntityDAO(transaction); + + // No exception will be thrown with the two properties + dao.createByNaturalId(5, "str"); + transaction.commitTransaction(); + + // No exception will only the need property + dao.createByNotNull(3); + transaction.commitTransaction(); + + // No exception will only the need property + dao.create(NaturalizedEntity.PROPERTY_NATURAL_ID_NOT_NULL, 3); + transaction.commitTransaction(); + } + + @Test + public void testCreateFailed() throws Exception { + log.debug("Test naturalId : create failed"); + TopiaContext transaction = db.beginTransaction(); + + NaturalizedEntityDAO dao = + TopiaTckItDAOHelper.getNaturalizedEntityDAO(transaction); + + // Exception will be throw +// try { + dao.create(); + transaction.commitTransaction(); + + // Note : this is possible to create an empty entity if the type + // is primitive like 'int' which have a default value of '0' +// } catch (PropertyValueException eee) { +// Assert.assertEquals("naturalIdNotNull", eee.getPropertyName()); +// } + } + + @Test + public void testUpdateFailed() throws Exception { + log.debug("Test naturalId : update failed"); + + TopiaContext transaction = db.beginTransaction(); + + NaturalizedEntityDAO dao = + TopiaTckItDAOHelper.getNaturalizedEntityDAO(transaction); + + NaturalizedEntity entity = + dao.createByNaturalId(5, "str"); + transaction.commitTransaction(); + + // Exception will be throw : not allowed to modify a naturalId property + try { + entity.setNaturalIdNotNull(8); + transaction.commitTransaction(); + } catch (TopiaException eee) { + Assert.assertEquals(PersistenceException.class.getName(), + eee.getCause().getClass().getName()); + } + } + + @Test + public void testFindByNaturalId() throws Exception { + log.debug("Test naturalId : findByNaturalId"); + TopiaContext transaction = db.beginTransaction(); + + NaturalizedEntityDAO dao = + TopiaTckItDAOHelper.getNaturalizedEntityDAO(transaction); + + NaturalizedEntity entity = + dao.createByNaturalId(5, "str"); + transaction.commitTransaction(); + + NaturalizedEntity result = dao.findByNaturalId(5, "str"); + + Assert.assertEquals(entity, result); + } + + @Test + public void testExistNaturalId() throws Exception { + log.debug("Test naturalId : existNaturalId"); + TopiaContext transaction = db.beginTransaction(); + + NaturalizedEntityDAO dao = + TopiaTckItDAOHelper.getNaturalizedEntityDAO(transaction); + + dao.createByNaturalId(5, "str"); + transaction.commitTransaction(); + + boolean result = dao.existByNaturalId(5, "str"); + + Assert.assertTrue(result); + + // not find with only one correct property + result = dao.existByNaturalId(8, "str"); + + Assert.assertFalse(result); + } + + @Test + public void testNaturalIdAreGeneralized() throws Exception { + + // test that natural ids are generalized + String[] generalizedNaturalizedNaturalIds = TopiaTckItDAOHelper.TopiaTckItEntityEnum.GeneralizedNaturalizedEntity.getNaturalIds(); + String[] naturalizedNaturalIds = TopiaTckItDAOHelper.TopiaTckItEntityEnum.NaturalizedEntity.getNaturalIds(); + Assert.assertArrayEquals(generalizedNaturalizedNaturalIds, naturalizedNaturalIds); + } + + @Test + public void testNotNullsAreGeneralized() throws Exception { + + // test that not nulls are generalized + String[] generalizedNaturalizedNotNulls = TopiaTckItDAOHelper.TopiaTckItEntityEnum.GeneralizedNaturalizedEntity.getNotNulls(); + String[] naturalizedNotNulls = TopiaTckItDAOHelper.TopiaTckItEntityEnum.NaturalizedEntity.getNotNulls(); + Assert.assertArrayEquals(generalizedNaturalizedNotNulls, naturalizedNotNulls); + } +} Property changes on: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/persistence/NaturalIdTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native
participants (1)
-
athimel@users.nuiton.org