Author: athimel Date: 2012-05-09 17:07:53 +0200 (Wed, 09 May 2012) New Revision: 2452 Url: http://nuiton.org/repositories/revision/topia/2452 Log: Database dependent tests now in src/main/java of t-p-tck Added: trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck/ trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck/it/ trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck/it/TopiaTckItHibernateTestSuite.java trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/TopiaContextFactoryTest.java trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/ano1882/ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/ano1991/ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/evo1912/ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/framework/ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/framework/TopiaContextReplicateTest.java trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/framework/TopiaUtilTest.java trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/generator/ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/generator/TopiaTestCase.java trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/TopiaTckItTestSuite.java trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/persistence/ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/persistence/EntityVisitorExportXmlTest.java trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/persistence/ExportXMLVisitor.java trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/persistence/NaturalIdTest.java Removed: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/TopiaContextFactoryTest.java trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaUtilTest.java trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/generator/ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/persistence/EntityVisitorExportXmlTest.java trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/persistence/ExportXMLVisitor.java trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/test/ano1882/ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/test/ano1991/ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/test/evo1912/ Modified: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/ano1882/DAOAbstractTransformerTest.java trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/ano1991/TopiaQueryTest.java trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/evo1912/EntityDTOTransformerTest.java trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaQueryTest.java Added: trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck/it/TopiaTckItHibernateTestSuite.java =================================================================== --- trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck/it/TopiaTckItHibernateTestSuite.java (rev 0) +++ trunk/topia-persistence-hibernate/src/test/java/org/nuiton/topia/tck/it/TopiaTckItHibernateTestSuite.java 2012-05-09 15:07:53 UTC (rev 2452) @@ -0,0 +1,10 @@ +package org.nuiton.topia.tck.it; + +/** + * Do not remove event if empty : this class represents the TCK IT tests + * for topia-persistence-hibernate module + * + * @author Arnaud Thimel <thimel@codelutin.com> + */ +public class TopiaTckItHibernateTestSuite extends TopiaTckItTestSuite { +} Copied: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/TopiaContextFactoryTest.java (from rev 2450, trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/TopiaContextFactoryTest.java) =================================================================== --- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/TopiaContextFactoryTest.java (rev 0) +++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/TopiaContextFactoryTest.java 2012-05-09 15:07:53 UTC (rev 2452) @@ -0,0 +1,190 @@ +/* + * #%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; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.nuiton.topia.framework.TopiaContextImpl; +import org.nuiton.topia.tck.TopiaDatabase; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.Properties; + +/** + * Created: 8 mai 2010 + * + * @author fdesbois <fdesbois@codelutin.com> + * @version $Id$ + */ +public class TopiaContextFactoryTest { + + private static final Log log = + LogFactory.getLog(TopiaContextFactoryTest.class); + + protected static File testBasedir; + + protected Properties properties; + + @BeforeClass + public static void init() throws IOException { + + testBasedir = TopiaDatabase.getTestSpecificDirectory(TopiaContextFactoryTest.class, "dummy"); + + } + + @Before + public void setUp() throws Exception { + properties = new Properties(); + properties.setProperty("prop1", "value1"); + properties.setProperty("prop2", "value2"); + TopiaContextFactory.contextCache.clear(); + } + + @Test + public void testGetContextOpened() throws Exception { + log.debug("## testGetContextOpened"); + + /** PREPARE DATA **/ + String databaseName = "h2data-testGetContextByPropertie"; + File dbDirectory = new File(testBasedir, databaseName); + String url = "jdbc:h2:file:" + dbDirectory; + properties.setProperty("hibernate.connection.url", url); + + TopiaContextImpl test = new TopiaContextImpl(properties); + TopiaContextFactory.contextCache.put(properties, test); + + /** EXEC METHOD **/ + List<String> result = TopiaContextFactory.getContextOpened(); + Assert.assertEquals(1, result.size()); + Assert.assertEquals(url, result.get(0)); + } + + @Test + public void testRemoveContext() throws Exception { + log.debug("## testRemoveContext"); + + /** PREPARE DATA **/ + TopiaContextImpl test = new TopiaContextImpl(properties); + TopiaContextFactory.contextCache.put(properties, test); + + /** EXEC METHOD **/ + TopiaContextFactory.removeContext(test); + Assert.assertEquals(0, TopiaContextFactory.contextCache.size()); + } + + //@Test + + public void testGetContext() throws Exception { + // TODO-fdesbois-20100508 : only used TopiaUtil.getProperties, need tests for this method + } + + @Test + public void testGetContextByProperties() throws Exception { + log.debug("## testGetContextByProperties"); + + /** PREPARE DATA **/ + Properties propertiesParent = new Properties(properties); + propertiesParent.setProperty("prop3", "value3"); + + Properties propertiesAll = new Properties(); + propertiesAll.setProperty("prop1", "value1"); + propertiesAll.setProperty("prop2", "value2"); + propertiesAll.setProperty("prop3", "value3"); + + /** EXEC METHOD **/ + + log.info("test 0 : add null properties"); + try { + TopiaContextFactory.getContext(null); + } catch (Exception eee) { + Assert.assertEquals(NullPointerException.class, eee.getClass()); + } + + log.info("test 1 : add new properties, will instantiate a new" + + " TopiaContext"); + TopiaContext test1 = TopiaContextFactory.getContext(propertiesParent); + Assert.assertNotNull(test1); + Assert.assertEquals(1, TopiaContextFactory.contextCache.size()); + + log.info("test 2 : with same properties, will retrieve existing" + + " TopiaContext"); + TopiaContext test2 = TopiaContextFactory.getContext(propertiesParent); + Assert.assertEquals(test1, test2); + Assert.assertEquals(1, TopiaContextFactory.contextCache.size()); + + log.info("test 3 : use other properties, will instantiate a different" + + "TopiaContext"); + TopiaContext test3 = TopiaContextFactory.getContext(properties); + log.debug("cache size : " + TopiaContextFactory.contextCache.size()); + log.debug("result : " + test1); + log.debug("result3 : " + test3); + Assert.assertNotSame(test1, test3); + Assert.assertEquals(2, TopiaContextFactory.contextCache.size()); + + log.info("test 4 : use other properties but equivalent to existing " + + "TopiaContext"); + // Test flating of properties + TopiaContext test4 = TopiaContextFactory.getContext(propertiesAll); + Assert.assertEquals(test1, test4); + Assert.assertEquals(2, TopiaContextFactory.contextCache.size()); + + log.info("test5a : reinstantiate new TopiaContext after one is closed."); + // TEST + // Strange behavior the closed flag of context stay true if + // hibernateFactory is not loaded from real properties +// test1.closeContext(); +// Assert.assertTrue(test1.isClosed()); + + // Add properties for Hibernate to have real opened topiaContext + String databaseName = "h2data-testGetContextByPropertie"; + File f = new File(testBasedir, databaseName); + + properties.setProperty("hibernate.connection.username", "sa"); + properties.setProperty("hibernate.connection.password", ""); + properties.setProperty("hibernate.connection.driver_class", "org.h2.Driver"); + properties.setProperty("hibernate.connection.url", + "jdbc:h2:file:" + f.getAbsolutePath()); + + + TopiaContext test5 = TopiaContextFactory.getContext(properties); + Assert.assertNotSame(test1, test5); + Assert.assertEquals(3, TopiaContextFactory.contextCache.size()); + + log.info("test5b : beginTransaction to properly close the context"); + test5.beginTransaction(); + + test5.closeContext(); + + TopiaContext result = TopiaContextFactory.getContext(properties); + Assert.assertNotSame(test5, result); + Assert.assertEquals(3, TopiaContextFactory.contextCache.size()); + } +} Property changes on: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/TopiaContextFactoryTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/ano1882/DAOAbstractTransformerTest.java =================================================================== --- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/test/ano1882/DAOAbstractTransformerTest.java 2012-05-09 14:32:00 UTC (rev 2450) +++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/ano1882/DAOAbstractTransformerTest.java 2012-05-09 15:07:53 UTC (rev 2452) @@ -22,13 +22,17 @@ * <http://www.gnu.org/licenses/lgpl-3.0.html>. * #L% */ -package org.nuiton.topia.test.ano1882; +package org.nuiton.topia.tck.ano1882; import org.junit.Rule; import org.junit.Test; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.tck.TopiaDatabase; import org.nuiton.topia.TopiaTckItDAOHelper; +import org.nuiton.topia.test.ano1882.FrenchCompany; +import org.nuiton.topia.test.ano1882.FrenchCompanyDAO; +import org.nuiton.topia.test.ano1882.SIRET; +import org.nuiton.topia.test.ano1882.SIRETDAO; import java.util.Arrays; Modified: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/ano1991/TopiaQueryTest.java =================================================================== --- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/test/ano1991/TopiaQueryTest.java 2012-05-09 14:32:00 UTC (rev 2450) +++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/ano1991/TopiaQueryTest.java 2012-05-09 15:07:53 UTC (rev 2452) @@ -22,7 +22,7 @@ * <http://www.gnu.org/licenses/lgpl-3.0.html>. * #L% */ -package org.nuiton.topia.test.ano1991; +package org.nuiton.topia.tck.ano1991; import org.junit.Assert; import org.junit.Rule; Modified: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/evo1912/EntityDTOTransformerTest.java =================================================================== --- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/test/evo1912/EntityDTOTransformerTest.java 2012-05-09 14:32:00 UTC (rev 2450) +++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/evo1912/EntityDTOTransformerTest.java 2012-05-09 15:07:53 UTC (rev 2452) @@ -22,7 +22,7 @@ * <http://www.gnu.org/licenses/lgpl-3.0.html>. * #L% */ -package org.nuiton.topia.test.evo1912; +package org.nuiton.topia.tck.evo1912; import org.junit.Assert; import org.junit.Test; Copied: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/framework/TopiaContextReplicateTest.java (from rev 2450, trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java) =================================================================== --- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/framework/TopiaContextReplicateTest.java (rev 0) +++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/framework/TopiaContextReplicateTest.java 2012-05-09 15:07:53 UTC (rev 2452) @@ -0,0 +1,157 @@ +/* + * #%L + * ToPIA :: Persistence + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2012 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.framework; + +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaContextFactory; +import org.nuiton.topia.tck.TopiaDatabase; +import org.nuiton.topia.TopiaTckItDAOHelper; +import org.nuiton.topia.test.entities.Person; +import org.nuiton.topia.test.entities.PersonDAO; +import org.nuiton.topia.test.entities.Pet; +import org.nuiton.topia.test.entities.PetDAO; + +import java.io.File; +import java.util.Properties; + +/** + * To test replication sugin TopiaContext. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.6.8 + */ +public class TopiaContextReplicateTest { + + @Rule + public final TopiaDatabase dbSource = + new TopiaDatabase() { + + @Override + protected void onDbConfigurationCreate(Properties configuration, File testDir, String dbPath) { + configuration.setProperty( + TopiaContextFactory.CONFIG_URL, "jdbc:h2:file:" + dbPath + "-source"); + + } + }; + + @Rule + public final TopiaDatabase dbTarget = + new TopiaDatabase() { + + @Override + protected void onDbConfigurationCreate(Properties configuration, File testDir, String dbPath) { + configuration.setProperty( + TopiaContextFactory.CONFIG_URL, "jdbc:h2:file:" + dbPath + "-target"); + + } + }; + + @Test + public void replicateEntity() throws Exception { +// +// Properties configSource = TestHelper.initTopiaContextConfiguration( +// testBasedir, +// "/TopiaContextImpl.properties", +// "replicateSource"); +// +// Properties configTarget = TestHelper.initTopiaContextConfiguration( +// testBasedir, +// "/TopiaContextImpl.properties", +// "replicateTarget"); +// + + TopiaContext contextSource = dbSource.getRootCtxt(); + TopiaContext contextTarget = dbTarget.getRootCtxt(); + +// try { +// contextSource = TopiaContextFactory.getContext(configSource); +// contextTarget = TopiaContextFactory.getContext(configTarget); + + TopiaContext txSource; + TopiaContext txTarget; + PersonDAO daoSource, daoTarget; + PetDAO petDAOSource, petDAOTarget; + Person personSource, personTarget; + Pet petSource, petTarget; + + txSource = contextSource.beginTransaction(); + daoSource = TopiaTckItDAOHelper.getPersonDAO(txSource); + petDAOSource = TopiaTckItDAOHelper.getPetDAO(txSource); + + personSource = daoSource.create(Person.PROPERTY_FIRSTNAME, " firstName", + Person.PROPERTY_NAME, " name" + ); + + petSource = petDAOSource.create(Pet.PROPERTY_NAME, "name", + Pet.PROPERTY_TYPE, "type", + Pet.PROPERTY_PERSON, personSource + ); + + personSource.addPet(petSource); + + txSource.commitTransaction(); + + daoSource = TopiaTckItDAOHelper.getPersonDAO(txSource); + + personSource = daoSource.findByTopiaId(personSource.getTopiaId()); + Assert.assertNotNull(personSource); + + petSource = petDAOSource.findByTopiaId(petSource.getTopiaId()); + Assert.assertNotNull(petSource); + Assert.assertEquals(1, personSource.sizePet()); + Assert.assertEquals(petSource, personSource.getPet().iterator().next()); + + txTarget = contextTarget.beginTransaction(); + + txSource.replicateEntity(txTarget, petSource); + txSource.replicateEntity(txTarget, personSource); + + txTarget.commitTransaction(); + + daoTarget = TopiaTckItDAOHelper.getPersonDAO(txTarget); + petDAOTarget = TopiaTckItDAOHelper.getPetDAO(txTarget); + + personTarget = daoTarget.findByTopiaId(personSource.getTopiaId()); + Assert.assertNotNull(personTarget); + Assert.assertEquals(personSource, personTarget); + Assert.assertEquals(1, personTarget.sizePet()); + + petTarget = petDAOTarget.findByTopiaId(petSource.getTopiaId()); + Assert.assertNotNull(petTarget); + Assert.assertEquals(petSource, petTarget); + + Assert.assertEquals(petTarget, personTarget.getPet().iterator().next()); + + +// } finally { +// closeDb(contextSource); +// closeDb(contextTarget); +// } + + } +} Property changes on: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/framework/TopiaContextReplicateTest.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/framework/TopiaUtilTest.java (from rev 2450, trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaUtilTest.java) =================================================================== --- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/framework/TopiaUtilTest.java (rev 0) +++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/framework/TopiaUtilTest.java 2012-05-09 15:07:53 UTC (rev 2452) @@ -0,0 +1,114 @@ +/* + * #%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.framework; + +import org.junit.Rule; +import org.junit.Test; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.framework.TopiaUtil; +import org.nuiton.topia.tck.TopiaDatabase; +import org.nuiton.topia.tck.it.Personne; +import org.nuiton.topia.test.entities.PersonImpl; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Test pour les methodes de {@link org.nuiton.topia.framework.TopiaUtil}. + * + * @author tchemit <chemit@codelutin.com> + * @version $Revision$ + * <p/> + * Last update: $Date$ + * by : $Author$ + */ +public class TopiaUtilTest { + + protected static final String PERSON_ID = "org.nuiton.topiatest.Personne#1226701039001#0.6502325993664224"; + + protected static final String PERSON_ID2 = "org.nuiton.topiatest.Personne#1226701039001#0.6502325993664999"; + + @Rule + public final TopiaDatabase db = new TopiaDatabase(); + + @Test + public void testGetTopiaIdPattern() throws Exception { + String expected; + String actual; + + expected = "org\\.nuiton\\.topiatest\\.Personne#(?:\\d+?)#(?:\\d+)\\.(?:\\d+)"; + actual = TopiaUtil.getTopiaIdPattern(Personne.class); + assertEquals(expected, actual); + } + + @Test + public void testGetTopiaPattern() throws Exception { + String expected; + Pattern pattern; + + expected = "(\\d+)-(org\\.nuiton\\.topiatest\\.Personne#(?:\\d+?)#(?:\\d+)\\.(?:\\d+))-(org\\.nuiton\\.topiatest\\.Personne#(?:\\d+?)#(?:\\d+)\\.(?:\\d+))(.*)"; + pattern = TopiaUtil.getTopiaPattern("(\\d+)-%1$s-%1$s(.*)", Personne.class); + assertEquals(expected, pattern.toString()); + + String expression = 123 + "-" + PERSON_ID + "-" + PERSON_ID2 + "-afterall"; + + Matcher matcher = pattern.matcher(expression); + + assertTrue(matcher.matches()); + + assertTrue(matcher.matches()); + assertEquals(4, matcher.groupCount()); + assertEquals("123", matcher.group(1)); + assertEquals(PERSON_ID, matcher.group(2)); + assertEquals(PERSON_ID2, matcher.group(3)); + assertEquals("-afterall", matcher.group(4)); + } + + @Test(expected = IllegalArgumentException.class) + public void testIsSchemaExistFailed() throws Exception { + TopiaUtil.isSchemaExist(db.getRootCtxt(), "fake"); + } + + @Test + public void testIsSchemaExist() throws Exception { + TopiaContext rootContext = db.getRootCtxt(); + boolean actual = TopiaUtil.isSchemaExist(rootContext, + PersonImpl.class.getName()); + + assertFalse(actual); + TopiaContext tx = rootContext.beginTransaction(); + + tx.createSchema(); + actual = TopiaUtil.isSchemaExist(rootContext, PersonImpl.class.getName()); + + assertTrue(actual); + + } +} Property changes on: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/framework/TopiaUtilTest.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/generator/TopiaTestCase.java (from rev 2450, trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/generator/TopiaTestCase.java) =================================================================== --- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/generator/TopiaTestCase.java (rev 0) +++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/generator/TopiaTestCase.java 2012-05-09 15:07:53 UTC (rev 2452) @@ -0,0 +1,170 @@ +/* + * #%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.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.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; + +/** + * 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 TopiaDatabase(); + +// /** 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); +// } + } +} Property changes on: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/generator/TopiaTestCase.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/TopiaTckItTestSuite.java =================================================================== --- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/TopiaTckItTestSuite.java (rev 0) +++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/it/TopiaTckItTestSuite.java 2012-05-09 15:07:53 UTC (rev 2452) @@ -0,0 +1,13 @@ +package org.nuiton.topia.tck.it; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +/** + * @author Arnaud Thimel <thimel@codelutin.com> + */ +@RunWith(Suite.class) +@Suite.SuiteClasses({EnumTest.class}) // TODO AThimel 09/05/2012 Add all TCK IT tests +public abstract class TopiaTckItTestSuite { + +} Copied: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/persistence/EntityVisitorExportXmlTest.java (from rev 2450, trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/persistence/EntityVisitorExportXmlTest.java) =================================================================== --- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/persistence/EntityVisitorExportXmlTest.java (rev 0) +++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/persistence/EntityVisitorExportXmlTest.java 2012-05-09 15:07:53 UTC (rev 2452) @@ -0,0 +1,134 @@ +/* + * #%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.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.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 TopiaDatabase(); + + /** + * 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/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/persistence/ExportXMLVisitor.java (from rev 2450, trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/persistence/ExportXMLVisitor.java) =================================================================== --- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/persistence/ExportXMLVisitor.java (rev 0) +++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/persistence/ExportXMLVisitor.java 2012-05-09 15:07:53 UTC (rev 2452) @@ -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.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/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/persistence/NaturalIdTest.java (from rev 2450, trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java) =================================================================== --- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/persistence/NaturalIdTest.java (rev 0) +++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/persistence/NaturalIdTest.java 2012-05-09 15:07:53 UTC (rev 2452) @@ -0,0 +1,177 @@ +/* + * #%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.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.TopiaTckItDAOHelper; +import org.nuiton.topia.tck.it.NaturalizedEntity; +import org.nuiton.topia.tck.it.NaturalizedEntityDAO; + +/** + * 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 TopiaDatabase(); + + @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("org.hibernate.HibernateException", + 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/persistence/NaturalIdTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/TopiaContextFactoryTest.java =================================================================== --- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/TopiaContextFactoryTest.java 2012-05-09 14:37:49 UTC (rev 2451) +++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/TopiaContextFactoryTest.java 2012-05-09 15:07:53 UTC (rev 2452) @@ -1,190 +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; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.nuiton.topia.framework.TopiaContextImpl; -import org.nuiton.topia.tck.TopiaDatabase; - -import java.io.File; -import java.io.IOException; -import java.util.List; -import java.util.Properties; - -/** - * Created: 8 mai 2010 - * - * @author fdesbois <fdesbois@codelutin.com> - * @version $Id$ - */ -public class TopiaContextFactoryTest { - - private static final Log log = - LogFactory.getLog(TopiaContextFactoryTest.class); - - protected static File testBasedir; - - protected Properties properties; - - @BeforeClass - public static void init() throws IOException { - - testBasedir = TopiaDatabase.getTestSpecificDirectory(TopiaContextFactoryTest.class, "dummy"); - - } - - @Before - public void setUp() throws Exception { - properties = new Properties(); - properties.setProperty("prop1", "value1"); - properties.setProperty("prop2", "value2"); - TopiaContextFactory.contextCache.clear(); - } - - @Test - public void testGetContextOpened() throws Exception { - log.debug("## testGetContextOpened"); - - /** PREPARE DATA **/ - String databaseName = "h2data-testGetContextByPropertie"; - File dbDirectory = new File(testBasedir, databaseName); - String url = "jdbc:h2:file:" + dbDirectory; - properties.setProperty("hibernate.connection.url", url); - - TopiaContextImpl test = new TopiaContextImpl(properties); - TopiaContextFactory.contextCache.put(properties, test); - - /** EXEC METHOD **/ - List<String> result = TopiaContextFactory.getContextOpened(); - Assert.assertEquals(1, result.size()); - Assert.assertEquals(url, result.get(0)); - } - - @Test - public void testRemoveContext() throws Exception { - log.debug("## testRemoveContext"); - - /** PREPARE DATA **/ - TopiaContextImpl test = new TopiaContextImpl(properties); - TopiaContextFactory.contextCache.put(properties, test); - - /** EXEC METHOD **/ - TopiaContextFactory.removeContext(test); - Assert.assertEquals(0, TopiaContextFactory.contextCache.size()); - } - - //@Test - - public void testGetContext() throws Exception { - // TODO-fdesbois-20100508 : only used TopiaUtil.getProperties, need tests for this method - } - - @Test - public void testGetContextByProperties() throws Exception { - log.debug("## testGetContextByProperties"); - - /** PREPARE DATA **/ - Properties propertiesParent = new Properties(properties); - propertiesParent.setProperty("prop3", "value3"); - - Properties propertiesAll = new Properties(); - propertiesAll.setProperty("prop1", "value1"); - propertiesAll.setProperty("prop2", "value2"); - propertiesAll.setProperty("prop3", "value3"); - - /** EXEC METHOD **/ - - log.info("test 0 : add null properties"); - try { - TopiaContextFactory.getContext(null); - } catch (Exception eee) { - Assert.assertEquals(NullPointerException.class, eee.getClass()); - } - - log.info("test 1 : add new properties, will instantiate a new" + - " TopiaContext"); - TopiaContext test1 = TopiaContextFactory.getContext(propertiesParent); - Assert.assertNotNull(test1); - Assert.assertEquals(1, TopiaContextFactory.contextCache.size()); - - log.info("test 2 : with same properties, will retrieve existing" + - " TopiaContext"); - TopiaContext test2 = TopiaContextFactory.getContext(propertiesParent); - Assert.assertEquals(test1, test2); - Assert.assertEquals(1, TopiaContextFactory.contextCache.size()); - - log.info("test 3 : use other properties, will instantiate a different" + - "TopiaContext"); - TopiaContext test3 = TopiaContextFactory.getContext(properties); - log.debug("cache size : " + TopiaContextFactory.contextCache.size()); - log.debug("result : " + test1); - log.debug("result3 : " + test3); - Assert.assertNotSame(test1, test3); - Assert.assertEquals(2, TopiaContextFactory.contextCache.size()); - - log.info("test 4 : use other properties but equivalent to existing " + - "TopiaContext"); - // Test flating of properties - TopiaContext test4 = TopiaContextFactory.getContext(propertiesAll); - Assert.assertEquals(test1, test4); - Assert.assertEquals(2, TopiaContextFactory.contextCache.size()); - - log.info("test5a : reinstantiate new TopiaContext after one is closed."); - // TEST - // Strange behavior the closed flag of context stay true if - // hibernateFactory is not loaded from real properties -// test1.closeContext(); -// Assert.assertTrue(test1.isClosed()); - - // Add properties for Hibernate to have real opened topiaContext - String databaseName = "h2data-testGetContextByPropertie"; - File f = new File(testBasedir, databaseName); - - properties.setProperty("hibernate.connection.username", "sa"); - properties.setProperty("hibernate.connection.password", ""); - properties.setProperty("hibernate.connection.driver_class", "org.h2.Driver"); - properties.setProperty("hibernate.connection.url", - "jdbc:h2:file:" + f.getAbsolutePath()); - - - TopiaContext test5 = TopiaContextFactory.getContext(properties); - Assert.assertNotSame(test1, test5); - Assert.assertEquals(3, TopiaContextFactory.contextCache.size()); - - log.info("test5b : beginTransaction to properly close the context"); - test5.beginTransaction(); - - test5.closeContext(); - - TopiaContext result = TopiaContextFactory.getContext(properties); - Assert.assertNotSame(test5, result); - Assert.assertEquals(3, TopiaContextFactory.contextCache.size()); - } -} Deleted: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java =================================================================== --- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java 2012-05-09 14:37:49 UTC (rev 2451) +++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java 2012-05-09 15:07:53 UTC (rev 2452) @@ -1,157 +0,0 @@ -/* - * #%L - * ToPIA :: Persistence - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2012 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.framework; - -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaContextFactory; -import org.nuiton.topia.tck.TopiaDatabase; -import org.nuiton.topia.TopiaTckItDAOHelper; -import org.nuiton.topia.test.entities.Person; -import org.nuiton.topia.test.entities.PersonDAO; -import org.nuiton.topia.test.entities.Pet; -import org.nuiton.topia.test.entities.PetDAO; - -import java.io.File; -import java.util.Properties; - -/** - * To test replication sugin TopiaContext. - * - * @author tchemit <chemit@codelutin.com> - * @since 2.6.8 - */ -public class TopiaContextReplicateTest { - - @Rule - public final TopiaDatabase dbSource = - new TopiaDatabase() { - - @Override - protected void onDbConfigurationCreate(Properties configuration, File testDir, String dbPath) { - configuration.setProperty( - TopiaContextFactory.CONFIG_URL, "jdbc:h2:file:" + dbPath + "-source"); - - } - }; - - @Rule - public final TopiaDatabase dbTarget = - new TopiaDatabase() { - - @Override - protected void onDbConfigurationCreate(Properties configuration, File testDir, String dbPath) { - configuration.setProperty( - TopiaContextFactory.CONFIG_URL, "jdbc:h2:file:" + dbPath + "-target"); - - } - }; - - @Test - public void replicateEntity() throws Exception { -// -// Properties configSource = TestHelper.initTopiaContextConfiguration( -// testBasedir, -// "/TopiaContextImpl.properties", -// "replicateSource"); -// -// Properties configTarget = TestHelper.initTopiaContextConfiguration( -// testBasedir, -// "/TopiaContextImpl.properties", -// "replicateTarget"); -// - - TopiaContext contextSource = dbSource.getRootCtxt(); - TopiaContext contextTarget = dbTarget.getRootCtxt(); - -// try { -// contextSource = TopiaContextFactory.getContext(configSource); -// contextTarget = TopiaContextFactory.getContext(configTarget); - - TopiaContext txSource; - TopiaContext txTarget; - PersonDAO daoSource, daoTarget; - PetDAO petDAOSource, petDAOTarget; - Person personSource, personTarget; - Pet petSource, petTarget; - - txSource = contextSource.beginTransaction(); - daoSource = TopiaTckItDAOHelper.getPersonDAO(txSource); - petDAOSource = TopiaTckItDAOHelper.getPetDAO(txSource); - - personSource = daoSource.create(Person.PROPERTY_FIRSTNAME, " firstName", - Person.PROPERTY_NAME, " name" - ); - - petSource = petDAOSource.create(Pet.PROPERTY_NAME, "name", - Pet.PROPERTY_TYPE, "type", - Pet.PROPERTY_PERSON, personSource - ); - - personSource.addPet(petSource); - - txSource.commitTransaction(); - - daoSource = TopiaTckItDAOHelper.getPersonDAO(txSource); - - personSource = daoSource.findByTopiaId(personSource.getTopiaId()); - Assert.assertNotNull(personSource); - - petSource = petDAOSource.findByTopiaId(petSource.getTopiaId()); - Assert.assertNotNull(petSource); - Assert.assertEquals(1, personSource.sizePet()); - Assert.assertEquals(petSource, personSource.getPet().iterator().next()); - - txTarget = contextTarget.beginTransaction(); - - txSource.replicateEntity(txTarget, petSource); - txSource.replicateEntity(txTarget, personSource); - - txTarget.commitTransaction(); - - daoTarget = TopiaTckItDAOHelper.getPersonDAO(txTarget); - petDAOTarget = TopiaTckItDAOHelper.getPetDAO(txTarget); - - personTarget = daoTarget.findByTopiaId(personSource.getTopiaId()); - Assert.assertNotNull(personTarget); - Assert.assertEquals(personSource, personTarget); - Assert.assertEquals(1, personTarget.sizePet()); - - petTarget = petDAOTarget.findByTopiaId(petSource.getTopiaId()); - Assert.assertNotNull(petTarget); - Assert.assertEquals(petSource, petTarget); - - Assert.assertEquals(petTarget, personTarget.getPet().iterator().next()); - - -// } finally { -// closeDb(contextSource); -// closeDb(contextTarget); -// } - - } -} Modified: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaQueryTest.java =================================================================== --- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaQueryTest.java 2012-05-09 14:37:49 UTC (rev 2451) +++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaQueryTest.java 2012-05-09 15:07:53 UTC (rev 2452) @@ -45,7 +45,7 @@ TopiaQuery query = new TopiaQuery(QueriedEntity.class); query.addEquals(QueriedEntity.PROPERTY_TEST_ADD, value); Assert.assertEquals( - "FROM org.nuiton.topiatest.QueriedEntity " + + "FROM org.nuiton.topia.tck.it.QueriedEntity " + "WHERE testAdd = :testAdd", query.fullQuery()); @@ -54,7 +54,7 @@ query = new TopiaQuery(QueriedEntity.class); query.addEquals(QueriedEntity.PROPERTY_TEST_ADD, new Object[]{null}); Assert.assertEquals( - "FROM org.nuiton.topiatest.QueriedEntity " + + "FROM org.nuiton.topia.tck.it.QueriedEntity " + "WHERE testAdd IS NULL", query.fullQuery()); @@ -63,7 +63,7 @@ query = new TopiaQuery(QueriedEntity.class); query.addEquals(QueriedEntity.PROPERTY_TEST_ADD, value, value2); Assert.assertEquals( - "FROM org.nuiton.topiatest.QueriedEntity " + + "FROM org.nuiton.topia.tck.it.QueriedEntity " + "WHERE testAdd IN (:testAdd1, :testAdd2)", query.fullQuery()); @@ -71,7 +71,7 @@ query = new TopiaQuery(QueriedEntity.class); query.addEquals(QueriedEntity.PROPERTY_TEST_ADD, value, value2, null); Assert.assertEquals( - "FROM org.nuiton.topiatest.QueriedEntity " + + "FROM org.nuiton.topia.tck.it.QueriedEntity " + "WHERE testAdd IN (:testAdd1, :testAdd2) OR testAdd IS NULL", query.fullQuery()); } Deleted: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaUtilTest.java =================================================================== --- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaUtilTest.java 2012-05-09 14:37:49 UTC (rev 2451) +++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/framework/TopiaUtilTest.java 2012-05-09 15:07:53 UTC (rev 2452) @@ -1,113 +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.framework; - -import org.junit.Rule; -import org.junit.Test; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.tck.TopiaDatabase; -import org.nuiton.topia.tck.it.Personne; -import org.nuiton.topia.test.entities.PersonImpl; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -/** - * Test pour les methodes de {@link TopiaUtil}. - * - * @author tchemit <chemit@codelutin.com> - * @version $Revision$ - * <p/> - * Last update: $Date$ - * by : $Author$ - */ -public class TopiaUtilTest { - - protected static final String PERSON_ID = "org.nuiton.topiatest.Personne#1226701039001#0.6502325993664224"; - - protected static final String PERSON_ID2 = "org.nuiton.topiatest.Personne#1226701039001#0.6502325993664999"; - - @Rule - public final TopiaDatabase db = new TopiaDatabase(); - - @Test - public void testGetTopiaIdPattern() throws Exception { - String expected; - String actual; - - expected = "org\\.nuiton\\.topiatest\\.Personne#(?:\\d+?)#(?:\\d+)\\.(?:\\d+)"; - actual = TopiaUtil.getTopiaIdPattern(Personne.class); - assertEquals(expected, actual); - } - - @Test - public void testGetTopiaPattern() throws Exception { - String expected; - Pattern pattern; - - expected = "(\\d+)-(org\\.nuiton\\.topiatest\\.Personne#(?:\\d+?)#(?:\\d+)\\.(?:\\d+))-(org\\.nuiton\\.topiatest\\.Personne#(?:\\d+?)#(?:\\d+)\\.(?:\\d+))(.*)"; - pattern = TopiaUtil.getTopiaPattern("(\\d+)-%1$s-%1$s(.*)", Personne.class); - assertEquals(expected, pattern.toString()); - - String expression = 123 + "-" + PERSON_ID + "-" + PERSON_ID2 + "-afterall"; - - Matcher matcher = pattern.matcher(expression); - - assertTrue(matcher.matches()); - - assertTrue(matcher.matches()); - assertEquals(4, matcher.groupCount()); - assertEquals("123", matcher.group(1)); - assertEquals(PERSON_ID, matcher.group(2)); - assertEquals(PERSON_ID2, matcher.group(3)); - assertEquals("-afterall", matcher.group(4)); - } - - @Test(expected = IllegalArgumentException.class) - public void testIsSchemaExistFailed() throws Exception { - TopiaUtil.isSchemaExist(db.getRootCtxt(), "fake"); - } - - @Test - public void testIsSchemaExist() throws Exception { - TopiaContext rootContext = db.getRootCtxt(); - boolean actual = TopiaUtil.isSchemaExist(rootContext, - PersonImpl.class.getName()); - - assertFalse(actual); - TopiaContext tx = rootContext.beginTransaction(); - - tx.createSchema(); - actual = TopiaUtil.isSchemaExist(rootContext, PersonImpl.class.getName()); - - assertTrue(actual); - - } -} Deleted: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/persistence/EntityVisitorExportXmlTest.java =================================================================== --- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/persistence/EntityVisitorExportXmlTest.java 2012-05-09 14:37:49 UTC (rev 2451) +++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/persistence/EntityVisitorExportXmlTest.java 2012-05-09 15:07:53 UTC (rev 2452) @@ -1,132 +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.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.tck.TopiaDatabase; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.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 TopiaDatabase(); - - /** - * 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()); - } - } -} Deleted: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/persistence/ExportXMLVisitor.java =================================================================== --- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/persistence/ExportXMLVisitor.java 2012-05-09 14:37:49 UTC (rev 2451) +++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/persistence/ExportXMLVisitor.java 2012-05-09 15:07:53 UTC (rev 2452) @@ -1,107 +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.persistence; - - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.Ignore; - -/** - * 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 - } - - -} Deleted: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java =================================================================== --- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java 2012-05-09 14:37:49 UTC (rev 2451) +++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java 2012-05-09 15:07:53 UTC (rev 2452) @@ -1,177 +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.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.TopiaTckItDAOHelper; -import org.nuiton.topia.tck.it.NaturalizedEntity; -import org.nuiton.topia.tck.it.NaturalizedEntityDAO; - -/** - * 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 TopiaDatabase(); - - @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("org.hibernate.HibernateException", - 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); - } -}