r2416 - in trunk/topia-persistence/src/test/java/org/nuiton: topia topia/framework topia/generator topia/persistence topia/persistence/util topia/test/ano1882 topia/test/evo1912 topiatest topiatest/deletetest
Author: tchemit Date: 2012-03-02 11:08:59 +0100 (Fri, 02 Mar 2012) New Revision: 2416 Url: http://nuiton.org/repositories/revision/topia/2416 Log: Evolution #1992: Clean tests in topia-persistence Added: trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaDatabase.java trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaContextFactoryTest.java trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/EntityStateTest.java trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaConnectionProviderTest.java trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaQueryTest.java trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaUtilTest.java trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaGeneratorUtilTest.java trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaTestCase.java trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/EntityVisitorExportXmlTest.java trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/TopiaDAOTest.java trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/TopiaEntityRefTester.java trunk/topia-persistence/src/test/java/org/nuiton/topia/test/ano1882/DAOAbstractTransformerTest.java trunk/topia-persistence/src/test/java/org/nuiton/topia/test/evo1912/EntityDTOTransformerTest.java trunk/topia-persistence/src/test/java/org/nuiton/topiatest/EnumTest.java trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaContextFactoryTest.java =================================================================== --- trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaContextFactoryTest.java 2012-03-02 10:08:45 UTC (rev 2415) +++ trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaContextFactoryTest.java 2012-03-02 10:08:59 UTC (rev 2416) @@ -55,7 +55,7 @@ @BeforeClass public static void init() throws IOException { - testBasedir = TestHelper.getTestBasedir(TopiaContextFactoryTest.class); + testBasedir = TopiaDatabase.getTestSpecificDirectory(TopiaContextFactoryTest.class, "dummy"); } Added: trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaDatabase.java =================================================================== --- trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaDatabase.java (rev 0) +++ trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaDatabase.java 2012-03-02 10:08:59 UTC (rev 2416) @@ -0,0 +1,192 @@ +/* + * #%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; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; + +import java.io.File; +import java.io.InputStream; +import java.util.Properties; + +/** + * Put this class as a Rule in test to obtain a new isolated db for each test. + * <p/> + * Here is a simple example of usage : + * <pre> + * public class MyTest { + * + * \@Rule + * public final TopiaDatabase db = new TopiaDatabase(); + * + * \@Test + * public void testMethod() throws TopiaException { + * + * TopiaContext tx = db.beginTransaction(); + * ... + * } + * </pre> + * The db created will be unique for each test method (and for each build also). + * <p/> + * You don't need to close any transaction, it will be done for you and the end + * of each method test. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.6.8 + */ +public class TopiaDatabase extends TestWatcher { + + /** Logger. */ + private static final Log log = LogFactory.getLog(TopiaDatabase.class); + + /** A time-stamp, allow to make multiple build and keep the tests data. */ + public static final String TIMESTAMP = String.valueOf(System.nanoTime()); + + private File testBasedir; + + private Properties dbConfiguration; + + private TopiaContext rootCtxt; + + private final String configurationPath; + + public TopiaDatabase() { + this(TestHelper.DEFAULT_CONFIGURATION_LOCATION); + } + + public TopiaDatabase(String configurationPath) { + this.configurationPath = configurationPath; + } + + @Override + protected void starting(Description description) { + + // get test directory + testBasedir = getTestSpecificDirectory( + description.getTestClass(), + description.getMethodName()); + + if (log.isDebugEnabled()) { + log.debug("testBasedir = " + testBasedir); + } + + // create the root context + try { + + dbConfiguration = new Properties(); + InputStream stream = + getClass().getResourceAsStream(configurationPath); + + try { + dbConfiguration.load(stream); + } finally { + stream.close(); + } + dbConfiguration.setProperty( + TopiaContextFactory.CONFIG_PERSISTENCE_CLASSES, + TopiaTestDAOHelper.getImplementationClassesAsString()); + + // make sure we always use a different directory + + String dbPath = new File(testBasedir, "db").getAbsolutePath(); + + if (log.isDebugEnabled()) { + log.debug("dbPath = " + dbPath); + } + dbConfiguration.setProperty( + TopiaContextFactory.CONFIG_URL, "jdbc:h2:file:" + dbPath); + + onDbConfigurationCreate(dbConfiguration, testBasedir, dbPath); + + rootCtxt = TopiaContextFactory.getContext(dbConfiguration); + } catch (Exception e) { + throw new IllegalStateException( + "Could not start db at " + testBasedir, e); + } + } + + @Override + public void finished(Description description) { + + if (rootCtxt != null && !rootCtxt.isClosed()) { + try { + rootCtxt.closeContext(); + } catch (TopiaException e) { + if (log.isErrorEnabled()) { + log.error("Could not close topia root context", e); + } + } + } + rootCtxt = null; + dbConfiguration = null; + } + + public File getTestBasedir() { + return testBasedir; + } + + public TopiaContext getRootCtxt() { + return rootCtxt; + } + + public Properties getDbConfiguration() { + return dbConfiguration; + } + + public TopiaContext beginTransaction() throws TopiaException { + return rootCtxt.beginTransaction(); + } + + protected void onDbConfigurationCreate(Properties configuration, + File testDir, + String dbPath) { + + } + + public static File getTestSpecificDirectory(Class<?> testClassName, String methodName) { + // Trying to look for the temporary folder to store data for the test + String tempDirPath = System.getProperty("java.io.tmpdir"); + if (tempDirPath == null) { + // can this really occur ? + tempDirPath = ""; + if (log.isWarnEnabled()) { + log.warn("'\"java.io.tmpdir\" not defined"); + } + } + File tempDirFile = new File(tempDirPath); + + // create the directory to store database data + String dataBasePath = testClassName.getName() + + File.separator // a directory with the test class name + + methodName// a sub-directory with the method name + + '_' + + TIMESTAMP; // and a timestamp + File databaseFile = new File(tempDirFile, dataBasePath); + return databaseFile; + } +} + Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topia/TopiaDatabase.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/EntityStateTest.java =================================================================== --- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/EntityStateTest.java 2012-03-02 10:08:45 UTC (rev 2415) +++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/EntityStateTest.java 2012-03-02 10:08:59 UTC (rev 2416) @@ -30,20 +30,20 @@ /** * EntityStateTest.java - * + * <p/> * Created: 22 nov. 06 12:15:11 * * @author poussin <poussin@codelutin.com> * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ + * <p/> + * Last update: $Date$ + * by : $Author$ */ public class EntityStateTest { /** * Test les changements d'etat de {@link EntityState}. - * + * * @throws Exception */ @Test Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaConnectionProviderTest.java =================================================================== --- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaConnectionProviderTest.java 2012-03-02 10:08:45 UTC (rev 2415) +++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaConnectionProviderTest.java 2012-03-02 10:08:59 UTC (rev 2416) @@ -24,16 +24,12 @@ */ package org.nuiton.topia.framework; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.cfg.Environment; -import org.junit.After; import org.junit.Assert; -import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; -import org.nuiton.topia.TestHelper; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaContextFactory; +import org.nuiton.topia.TopiaDatabase; import org.nuiton.topia.TopiaException; import org.nuiton.topia.TopiaTestDAOHelper; import org.nuiton.topia.test.entities.Person; @@ -55,54 +51,67 @@ */ public class TopiaConnectionProviderTest { +// private static final Log log = +// LogFactory.getLog(TopiaConnectionProviderTest.class); - private static final Log log = - LogFactory.getLog(TopiaConnectionProviderTest.class); + public static final String TEST_URL = "testURL"; - protected static File testBasedir; + @Rule + public final TopiaDatabase db = + new TopiaDatabase("/TopiaConnectionProviderHardcoded.properties") { - public static final String TEST_URL = "testURL"; + @Override + protected void onDbConfigurationCreate(Properties configuration, + File testdir, + String dbPath) { - protected TopiaContext root; + Assert.assertFalse(testdir.exists()); - @BeforeClass - public static void setUpClass() throws Exception { + String dbPathFake = new File(testdir, "fake" + File.separator + "db").getAbsolutePath(); - testBasedir = TestHelper.getTestBasedir(TopiaConnectionProviderTest.class); - } + Assert.assertFalse(new File(dbPathFake).getParentFile().exists()); - @After - public void tearDown() throws TopiaException { - if (root != null && !root.isClosed()) { - root.closeContext(); - } - } + configuration.setProperty("dbPath", dbPath); + configuration.setProperty("dbPathFake", dbPathFake); + // give the path where connection provider will create db + configuration.setProperty(TEST_URL, + "jdbc:h2:file:" + dbPath); + + // give a fake db path (we will make sure it is never create after hibernate usage). + configuration.setProperty(TopiaContextFactory.CONFIG_URL, + "jdbc:h2:file:" + dbPathFake); + } + }; + @Test public void testWithHardcoded() throws Exception { - Properties dbProperties = TestHelper.loadHibernateConfiguration( - "/TopiaConnectionProviderHardcoded.properties"); +// Properties dbProperties = TestHelper.loadHibernateConfiguration( +// "/TopiaConnectionProviderHardcoded.properties"); +// +// File directory = new File(TestHelper.getDbName(testBasedir, "testWithHardcoded")); - File directory = new File(TestHelper.getDbName(testBasedir, "testWithHardcoded")); + String dbPath = (String) db.getDbConfiguration().get("dbPath"); + String dbPathFake = (String) db.getDbConfiguration().get("dbPathFake"); - String dbPath = new File(directory, "real" + File.separator + "db").getAbsolutePath(); - Assert.assertFalse(new File(dbPath).getParentFile().exists()); +// new File(directory, "real" + File.separator + "db").getAbsolutePath(); +// Assert.assertFalse(new File(dbPath).getParentFile().exists()); - String dbPathFake = new File(directory, "fake" + File.separator + "db").getAbsolutePath(); +// String dbPathFake = new File(directory, "fake" + File.separator + "db").getAbsolutePath(); - Assert.assertFalse(new File(dbPathFake).getParentFile().exists()); +// Assert.assertFalse(new File(dbPathFake).getParentFile().exists()); - // give the path where connection provider will create db - dbProperties.setProperty(TEST_URL, "jdbc:h2:file:" + dbPath); +// // give the path where connection provider will create db +// dbProperties.setProperty(TEST_URL, "jdbc:h2:file:" + dbPath); +// +// // give a fake db path (we will make sure it is never create after hibernate usage). +// dbProperties.setProperty(Environment.URL, "jdbc:h2:file:" + dbPathFake); +// +// root = TopiaContextFactory.getContext(dbProperties); - // give a fake db path (we will make sure it is never create after hibernate usage). - dbProperties.setProperty(Environment.URL, "jdbc:h2:file:" + dbPathFake); + Locale.setDefault(Locale.FRANCE); - root = TopiaContextFactory.getContext(dbProperties); - - Locale.setDefault(Locale.FRANCE); - doStuffOnDb(); // the db file must have been created @@ -113,7 +122,7 @@ } private void doStuffOnDb() throws TopiaException { - TopiaContext transaction = root.beginTransaction(); + TopiaContext transaction = db.beginTransaction(); try { PersonDAO dao = TopiaTestDAOHelper.getPersonDAO(transaction); Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java =================================================================== --- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java 2012-03-02 10:08:45 UTC (rev 2415) +++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java 2012-03-02 10:08:59 UTC (rev 2416) @@ -35,16 +35,9 @@ import org.junit.BeforeClass; import org.junit.Test; import org.nuiton.i18n.I18n; -import org.nuiton.topia.TestHelper; -import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaContextFactory; -import org.nuiton.topia.TopiaException; +import org.nuiton.topia.TopiaDatabase; import org.nuiton.topia.TopiaNotFoundException; -import org.nuiton.topia.TopiaTestDAOHelper; -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 org.nuiton.topiatest.persistence.Entity1; import org.nuiton.topiatest.persistence.Entity1Impl; import org.nuiton.topiatest.service.FakeService; @@ -74,7 +67,7 @@ @BeforeClass public static void setUpClass() throws Exception { - testBasedir = TestHelper.getTestBasedir(TopiaContextImplTest.class); + testBasedir = TopiaDatabase.getTestSpecificDirectory(TopiaContextImplTest.class, "dummy"); I18n.init(null, Locale.FRENCH); } @@ -371,102 +364,102 @@ // Note : maybe add a test to load classes from services } - @Test - public void replicateEntity() throws Exception { +// @Test +// public void replicateEntity() throws Exception { +// +// Properties configSource = TestHelper.initTopiaContextConfiguration( +// testBasedir, +// "/TopiaContextImpl.properties", +// "replicateSource"); +// +// Properties configTarget = TestHelper.initTopiaContextConfiguration( +// testBasedir, +// "/TopiaContextImpl.properties", +// "replicateTarget"); +// +// +// TopiaContext contextSource = null; +// TopiaContext contextTarget = null; +// +// 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 = TopiaTestDAOHelper.getPersonDAO(txSource); +// petDAOSource = TopiaTestDAOHelper.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 = TopiaTestDAOHelper.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 = TopiaTestDAOHelper.getPersonDAO(txTarget); +// petDAOTarget = TopiaTestDAOHelper.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); +// } +// +// } +// +// protected static void closeDb(TopiaContext contextSource) { +// if (contextSource != null && !contextSource.isClosed()) +// try { +// contextSource.clear(false); +// } catch (TopiaException e) { +// if (log.isErrorEnabled()) { +// log.error("Could not close db " + contextSource, e); +// } +// } +// } - Properties configSource = TestHelper.initTopiaContextConfiguration( - testBasedir, - "/TopiaContextImpl.properties", - "replicateSource"); - Properties configTarget = TestHelper.initTopiaContextConfiguration( - testBasedir, - "/TopiaContextImpl.properties", - "replicateTarget"); - - - TopiaContext contextSource = null; - TopiaContext contextTarget = null; - - 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 = TopiaTestDAOHelper.getPersonDAO(txSource); - petDAOSource = TopiaTestDAOHelper.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 = TopiaTestDAOHelper.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 = TopiaTestDAOHelper.getPersonDAO(txTarget); - petDAOTarget = TopiaTestDAOHelper.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); - } - - } - - protected static void closeDb(TopiaContext contextSource) { - if (contextSource != null && !contextSource.isClosed()) - try { - contextSource.clear(false); - } catch (TopiaException e) { - if (log.isErrorEnabled()) { - log.error("Could not close db " + contextSource, e); - } - } - } - - // // @Test // public void testGetHibernateConfiguration() throws Exception { Added: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java =================================================================== --- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java (rev 0) +++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java 2012-03-02 10:08:59 UTC (rev 2416) @@ -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.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.TopiaDatabase; +import org.nuiton.topia.TopiaTestDAOHelper; +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 = TopiaTestDAOHelper.getPersonDAO(txSource); + petDAOSource = TopiaTestDAOHelper.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 = TopiaTestDAOHelper.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 = TopiaTestDAOHelper.getPersonDAO(txTarget); + petDAOTarget = TopiaTestDAOHelper.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/src/test/java/org/nuiton/topia/framework/TopiaContextReplicateTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaQueryTest.java =================================================================== --- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaQueryTest.java 2012-03-02 10:08:45 UTC (rev 2415) +++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaQueryTest.java 2012-03-02 10:08:59 UTC (rev 2416) @@ -46,7 +46,7 @@ query.addEquals(QueriedEntity.PROPERTY_TEST_ADD, value); Assert.assertEquals( "FROM org.nuiton.topiatest.QueriedEntity " + - "WHERE testAdd = :testAdd", + "WHERE testAdd = :testAdd", query.fullQuery()); // Test with null paramValue @@ -55,7 +55,7 @@ query.addEquals(QueriedEntity.PROPERTY_TEST_ADD, new Object[]{null}); Assert.assertEquals( "FROM org.nuiton.topiatest.QueriedEntity " + - "WHERE testAdd IS NULL", + "WHERE testAdd IS NULL", query.fullQuery()); // Test with two paramValues @@ -64,7 +64,7 @@ query.addEquals(QueriedEntity.PROPERTY_TEST_ADD, value, value2); Assert.assertEquals( "FROM org.nuiton.topiatest.QueriedEntity " + - "WHERE testAdd IN (:testAdd1, :testAdd2)", + "WHERE testAdd IN (:testAdd1, :testAdd2)", query.fullQuery()); // Test with two paramValues + null @@ -72,7 +72,7 @@ query.addEquals(QueriedEntity.PROPERTY_TEST_ADD, value, value2, null); Assert.assertEquals( "FROM org.nuiton.topiatest.QueriedEntity " + - "WHERE testAdd IN (:testAdd1, :testAdd2) OR testAdd IS NULL", + "WHERE testAdd IN (:testAdd1, :testAdd2) OR testAdd IS NULL", query.fullQuery()); } @@ -139,12 +139,10 @@ query.addSubQuery(QueriedEntity.PROPERTY_TEST_ADD + " IN (?)", subquery); log.debug(query); - Assert.assertEquals(4, query.getParams().size()); + Assert.assertEquals(4, query.getParams().size()); } - /** - * Test of addFilter method, of class TopiaQuery. - */ + /** Test of addFilter method, of class TopiaQuery. */ @Test public void testAddFilter() { log.info("testAddFilter"); @@ -159,8 +157,8 @@ log.debug("Query : " + query); Assert.assertEquals("FROM " + QueriedEntity.class.getName() + - " ORDER BY " + QueriedEntity.PROPERTY_TEST_ADD, - query.fullQuery()); + " ORDER BY " + QueriedEntity.PROPERTY_TEST_ADD, + query.fullQuery()); filter.setOrderBy(null); @@ -169,8 +167,8 @@ log.debug("Query : " + query); Assert.assertEquals("FROM " + QueriedEntity.class.getName() + - " ORDER BY " + TopiaEntity.TOPIA_CREATE_DATE + " DESC", - query.fullQuery()); + " ORDER BY " + TopiaEntity.TOPIA_CREATE_DATE + " DESC", + query.fullQuery()); } @@ -184,8 +182,8 @@ log.debug("Query : " + query); Assert.assertEquals("FROM " + QueriedEntity.class.getName() + - " WHERE lower(name) LIKE :lower_name_", - query.fullQuery()); + " WHERE lower(name) LIKE :lower_name_", + query.fullQuery()); } } Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaUtilTest.java =================================================================== --- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaUtilTest.java 2012-03-02 10:08:45 UTC (rev 2415) +++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaUtilTest.java 2012-03-02 10:08:59 UTC (rev 2416) @@ -25,15 +25,13 @@ package org.nuiton.topia.framework; -import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; -import org.nuiton.topia.TestHelper; import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaDatabase; import org.nuiton.topia.test.entities.PersonImpl; import org.nuiton.topiatest.Personne; -import java.io.File; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -56,24 +54,9 @@ protected static final String PERSON_ID2 = "org.nuiton.topiatest.Personne#1226701039001#0.6502325993664999"; - private static TopiaContext rootContext; + @Rule + public final TopiaDatabase db = new TopiaDatabase(); - @BeforeClass - public static void setUpClass() throws Exception { - - - File testBasedir = TestHelper.getTestBasedir(TopiaUtilTest.class); - - rootContext = TestHelper.initTopiaContext(testBasedir, "topiautilest"); - } - - @AfterClass - public static void tearDownClass() throws Exception { - if (rootContext != null) { - rootContext.closeContext(); - } - } - @Test public void testGetTopiaIdPattern() throws Exception { String expected; @@ -109,27 +92,22 @@ @Test(expected = IllegalArgumentException.class) public void testIsSchemaExistFailed() throws Exception { - TopiaUtil.isSchemaExist(rootContext, "fake"); + 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(); - try { - tx.createSchema(); - actual = TopiaUtil.isSchemaExist(rootContext, PersonImpl.class.getName()); + tx.createSchema(); + actual = TopiaUtil.isSchemaExist(rootContext, PersonImpl.class.getName()); - assertTrue(actual); - } finally { - if (tx != null) { - tx.closeContext(); - } - } + assertTrue(actual); } } Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaGeneratorUtilTest.java =================================================================== --- trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaGeneratorUtilTest.java 2012-03-02 10:08:45 UTC (rev 2415) +++ trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaGeneratorUtilTest.java 2012-03-02 10:08:59 UTC (rev 2416) @@ -26,12 +26,10 @@ package org.nuiton.topia.generator; import org.junit.Test; -import static org.junit.Assert.*; -/** - * - * @author tchemit <chemit@codelutin.com> - */ +import static org.junit.Assert.assertEquals; + +/** @author tchemit <chemit@codelutin.com> */ public class TopiaGeneratorUtilTest { @Deprecated @@ -47,7 +45,7 @@ expResult = "ABC"; result = TopiaGeneratorUtil.convertVariableNameToConstantName(variableName); assertEquals(expResult, result); - + variableName = "abC"; expResult = "AB_C"; result = TopiaGeneratorUtil.convertVariableNameToConstantName(variableName); Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaTestCase.java =================================================================== --- trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaTestCase.java 2012-03-02 10:08:45 UTC (rev 2415) +++ trunk/topia-persistence/src/test/java/org/nuiton/topia/generator/TopiaTestCase.java 2012-03-02 10:08:59 UTC (rev 2416) @@ -27,26 +27,18 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.AfterClass; import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; -import org.nuiton.topia.TestHelper; import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaContextFactory; +import org.nuiton.topia.TopiaDatabase; import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaNotFoundException; import org.nuiton.topia.TopiaTestDAOHelper; import org.nuiton.topiatest.Company; import org.nuiton.topiatest.CompanyDAO; import org.nuiton.topiatest.Department; import org.nuiton.topiatest.DepartmentDAO; -import java.io.File; -import java.io.IOException; -import java.util.Properties; - /** * TopiaTestCase. * @@ -61,115 +53,118 @@ /** Logger */ private final static Log log = LogFactory.getLog(TopiaTestCase.class); - /** Proprietes */ - protected static Properties config; + @Rule + public final TopiaDatabase db = new TopiaDatabase(); - /** TopiaContext */ - protected static TopiaContext context; +// /** 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 { +// /** +// * 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", TopiaTestDAOHelper.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); +// } - File testBasedir = TestHelper.getTestBasedir(TopiaTestCase.class); - - config = TestHelper.initTopiaContextConfiguration( - testBasedir, - "/TopiaContextImpl.properties", - "TopiaTestCaseDb"); -// config = new Properties(); -// config.setProperty("topia.persistence.classes", TopiaTestDAOHelper.getImplementationClassesAsString()); +// /** Create base with schema created. */ +// @Before +// public void setUp() { // -// 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()); - } +// 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); +// } +// } - @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() { + public void testCompositeAssociations() throws TopiaException { if (log.isDebugEnabled()) { log.debug("Junit Test testCompositeAssociations"); } - try { - TopiaContext newContext = context.beginTransaction(); +// try { + TopiaContext newContext = db.beginTransaction(); - CompanyDAO companyDAO = TopiaTestDAOHelper.getCompanyDAO(newContext); - DepartmentDAO departmentDAO = TopiaTestDAOHelper.getDepartmentDAO(newContext); + CompanyDAO companyDAO = TopiaTestDAOHelper.getCompanyDAO(newContext); + DepartmentDAO departmentDAO = TopiaTestDAOHelper.getDepartmentDAO(newContext); - Company company = companyDAO.create(); - company.setName("Ma société"); + 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"); + 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); + departmentDAO.update(dep1); + departmentDAO.update(dep2); + departmentDAO.update(dep3); + departmentDAO.update(dep4); - company.addDepartment(dep1); - company.addDepartment(dep2); - company.addDepartment(dep3); - company.addDepartment(dep4); + company.addDepartment(dep1); + company.addDepartment(dep2); + company.addDepartment(dep3); + company.addDepartment(dep4); - companyDAO.update(company); - newContext.commitTransaction(); + companyDAO.update(company); + newContext.commitTransaction(); - newContext = context.beginTransaction(); + newContext = db.beginTransaction(); - companyDAO = TopiaTestDAOHelper.getCompanyDAO(newContext); + companyDAO = TopiaTestDAOHelper.getCompanyDAO(newContext); - company = companyDAO.findByTopiaId(company.getTopiaId()); + company = companyDAO.findByTopiaId(company.getTopiaId()); - Assert.assertEquals(company.getName(), "Ma société"); - Assert.assertEquals(company.getDepartment().size(), 4); + 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); - } + newContext.commitTransaction(); +// newContext.closeContext(); +// } catch (TopiaException e) { +// log.error("Erreur pendant le test testCompositeAssociations", e); +// } } } Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/EntityVisitorExportXmlTest.java =================================================================== --- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/EntityVisitorExportXmlTest.java 2012-03-02 10:08:45 UTC (rev 2415) +++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/EntityVisitorExportXmlTest.java 2012-03-02 10:08:59 UTC (rev 2416) @@ -27,15 +27,11 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.hibernate.cfg.Environment; -import org.junit.After; -import org.junit.AfterClass; import org.junit.Before; -import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; -import org.nuiton.topia.TestHelper; import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaContextFactory; +import org.nuiton.topia.TopiaDatabase; import org.nuiton.topia.TopiaException; import org.nuiton.topia.TopiaTestDAOHelper; import org.nuiton.topiatest.Address; @@ -46,12 +42,7 @@ import org.nuiton.topiatest.DepartmentDAO; import org.nuiton.topiatest.Employe; import org.nuiton.topiatest.EmployeDAO; -import org.nuiton.util.FileUtil; -import java.io.File; -import java.io.IOException; -import java.util.Properties; - /** * Test de visitor. * @@ -63,122 +54,57 @@ */ public class EntityVisitorExportXmlTest { - private static Log log = LogFactory.getLog(EntityVisitorExportXmlTest.class); + private static final Log log = + LogFactory.getLog(EntityVisitorExportXmlTest.class); - protected static File tempDir; + @Rule + public final TopiaDatabase db = new TopiaDatabase(); - protected static Properties config; - /** - * Init les données de tous les tests. - * - * @throws IOException - */ - @BeforeClass - public static void init() throws IOException { - - - File testBasedir = TestHelper.getTestBasedir(EntityVisitorExportXmlTest.class); - - tempDir = FileUtil.createTempDirectory("h2", "-exportxml", testBasedir); - - // init dburl - String dburl = "file:" + tempDir.getAbsolutePath() + File.separator + "data"; - - // init config - - config = new Properties(); - config.setProperty("topia.persistence.classes", TopiaTestDAOHelper.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:" + dburl); - } - - /** Remove temp directory */ - @AfterClass - public static void clear() { - // tchemit 2010-11-28 No! never delete tests data, how to see what's happening if something is wrong ??? -// FileUtil.deleteRecursively(tempDir); - } - - /** * Prepare test. * <p/> * Add all tests commons data * - * @throws TopiaException + * @throws TopiaException if could not create datas */ @Before public void setUp() throws TopiaException { - TopiaContext context = TopiaContextFactory.getContext(config); - context.createSchema(); - addData(context); - } + TopiaContext newContext = db.beginTransaction(); + try { + // company + CompanyDAO companyDAO = TopiaTestDAOHelper.getCompanyDAO(newContext); + Company clCompany = companyDAO.create(Company.PROPERTY_NAME, "CodeLutin"); - /** - * Add tests data. - * - * @param context the context to add - * @throws TopiaException - */ - protected void addData(TopiaContext context) throws TopiaException { + // employe + EmployeDAO employeDAO = TopiaTestDAOHelper.getEmployeDAO(newContext); + Employe empl1 = employeDAO.create(Employe.PROPERTY_NAME, "boss", Employe.PROPERTY_SALARY, 30000); - TopiaContext newContext = context.beginTransaction(); + AddressDAO adressDAO = TopiaTestDAOHelper.getAddressDAO(newContext); + Address addr1 = adressDAO.create(Address.PROPERTY_CITY, "Nantes", Address.PROPERTY_ADRESS, "12 Avenue Jules Vernes"); + empl1.setAddress(addr1); - // company - CompanyDAO companyDAO = TopiaTestDAOHelper.getCompanyDAO(newContext); - Company clCompany = companyDAO.create(); - clCompany.setName("CodeLutin"); + 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); - // employe - EmployeDAO employeDAO = TopiaTestDAOHelper.getEmployeDAO(newContext); - Employe empl1 = employeDAO.create(); - empl1.setName("boss"); - empl1.setSalary(30000); + // departement + DepartmentDAO departmentDAO = TopiaTestDAOHelper.getDepartmentDAO(newContext); + Department depComm = departmentDAO.create(Department.PROPERTY_NAME, "Commercial"); + depComm.setLeader(empl1); - AddressDAO adressDAO = TopiaTestDAOHelper.getAddressDAO(newContext); - Address addr1 = adressDAO.create(); - addr1.setCity("nantes"); - addr1.setAdress("bd des pas enchantés"); - empl1.setAddress(addr1); + Department depDev = departmentDAO.create(Department.PROPERTY_NAME, "Dev"); + depDev.setLeader(empl2); + clCompany.addDepartment(depComm); + clCompany.addDepartment(depDev); - Employe empl2 = employeDAO.create(); - empl2.setName("boss2"); - empl2.setSalary(29000); - Address addr2 = adressDAO.create(); - addr2.setCity("nantes"); - addr2.setAdress("bd des pas enchantés"); - empl2.setAddress(addr2); + newContext.commitTransaction(); + } finally { - // departement - DepartmentDAO departmentDAO = TopiaTestDAOHelper.getDepartmentDAO(newContext); - Department depComm = departmentDAO.create(); - depComm.setName("Commercial"); - depComm.setLeader(empl1); - - Department depDev = departmentDAO.create(); - depDev.setName("Dev"); - depDev.setLeader(empl2); - clCompany.addDepartment(depComm); - clCompany.addDepartment(depDev); - - newContext.commitTransaction(); - newContext.closeContext(); + newContext.closeContext(); + } } - /** Clean tests. */ - @After - public void tearDown() { - // tchemit 2010-11-28 No! never delete tests data, how to see what's happening if something is wrong ??? -// if(tempDir.exists()) { -// tempDir.delete(); -// } - } /** * Test l'export XML via un visiteur. @@ -189,9 +115,8 @@ */ @Test public void testExportXMLDepth() throws TopiaException { - TopiaContext rootContext = TopiaContextFactory.getContext(config); - TopiaContext context = rootContext.beginTransaction(); + TopiaContext context = db.beginTransaction(); CompanyDAO companyDAO = TopiaTestDAOHelper.getCompanyDAO(context); Company clCompany = companyDAO.findByName("CodeLutin"); @@ -199,7 +124,6 @@ EntityVisitor delegateVisitor = new ExportXMLVisitor(); EntityVisitor visitor = new DepthEntityVisitor(delegateVisitor); clCompany.accept(visitor); - context.closeContext(); if (log.isInfoEnabled()) { log.info("Export XML = \n" + delegateVisitor.toString()); Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java =================================================================== --- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java 2012-03-02 10:08:45 UTC (rev 2415) +++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/NaturalIdTest.java 2012-03-02 10:08:59 UTC (rev 2416) @@ -29,19 +29,15 @@ import org.apache.commons.logging.LogFactory; import org.hibernate.PropertyValueException; import org.junit.Assert; -import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; -import org.nuiton.topia.TestHelper; import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaDatabase; import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaNotFoundException; import org.nuiton.topia.TopiaTestDAOHelper; import org.nuiton.topiatest.NaturalizedEntity; import org.nuiton.topiatest.NaturalizedEntityDAO; -import java.io.File; -import java.io.IOException; - /** * NaturalIdTest * <p/> @@ -57,26 +53,13 @@ private static final Log log = LogFactory.getLog(NaturalIdTest.class); - protected static File testBasedir; + @Rule + public final TopiaDatabase db = new TopiaDatabase(); - @BeforeClass - public static void setUpClass() throws Exception { - - testBasedir = TestHelper.getTestBasedir(NaturalIdTest.class); - } - - protected TopiaContext initTopiaContext(String testName) throws IOException, TopiaNotFoundException { - TopiaContext root = TestHelper.initTopiaContext(testBasedir, - "/TopiaContextImpl.properties", - testName); - return root; - } - @Test public void testCreateSucessfull() throws Exception { log.debug("Test naturalId : create succesfull"); - TopiaContext root = initTopiaContext("createSucessfull"); - TopiaContext transaction = root.beginTransaction(); + TopiaContext transaction = db.beginTransaction(); NaturalizedEntityDAO dao = TopiaTestDAOHelper.getNaturalizedEntityDAO(transaction); @@ -89,16 +72,12 @@ // No exception will only the need property dao.create(NaturalizedEntity.PROPERTY_NATURAL_ID_NOT_NULL, 3); transaction.commitTransaction(); - - transaction.closeContext(); - root.closeContext(); } @Test public void testCreateFailed() throws Exception { log.debug("Test naturalId : create failed"); - TopiaContext root = initTopiaContext("createFailed"); - TopiaContext transaction = root.beginTransaction(); + TopiaContext transaction = db.beginTransaction(); NaturalizedEntityDAO dao = TopiaTestDAOHelper.getNaturalizedEntityDAO(transaction); @@ -113,17 +92,13 @@ } catch (PropertyValueException eee) { Assert.assertEquals("naturalIdNotNull", eee.getPropertyName()); } - - transaction.closeContext(); - root.closeContext(); } @Test public void testUpdateFailed() throws Exception { log.debug("Test naturalId : update failed"); - TopiaContext root = initTopiaContext("updateFailed"); - TopiaContext transaction = root.beginTransaction(); + TopiaContext transaction = db.beginTransaction(); NaturalizedEntityDAO dao = TopiaTestDAOHelper.getNaturalizedEntityDAO(transaction); @@ -140,17 +115,13 @@ } catch (TopiaException eee) { Assert.assertEquals("org.hibernate.HibernateException", eee.getCause().getClass().getName()); - } finally { - transaction.closeContext(); - root.closeContext(); } } @Test public void testFindByNaturalId() throws Exception { log.debug("Test naturalId : findByNaturalId"); - TopiaContext root = initTopiaContext("findByNaturalId"); - TopiaContext transaction = root.beginTransaction(); + TopiaContext transaction = db.beginTransaction(); NaturalizedEntityDAO dao = TopiaTestDAOHelper.getNaturalizedEntityDAO(transaction); @@ -163,16 +134,12 @@ NaturalizedEntity result = dao.findByNaturalId(5, "str"); Assert.assertEquals(entity, result); - - transaction.closeContext(); - root.closeContext(); } @Test public void testExistNaturalId() throws Exception { log.debug("Test naturalId : existNaturalId"); - TopiaContext root = initTopiaContext("existNaturalId"); - TopiaContext transaction = root.beginTransaction(); + TopiaContext transaction = db.beginTransaction(); NaturalizedEntityDAO dao = TopiaTestDAOHelper.getNaturalizedEntityDAO(transaction); @@ -189,8 +156,5 @@ result = dao.existByNaturalId(8, "str"); Assert.assertFalse(result); - - transaction.closeContext(); - root.closeContext(); } } Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/TopiaDAOTest.java =================================================================== --- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/TopiaDAOTest.java 2012-03-02 10:08:45 UTC (rev 2415) +++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/TopiaDAOTest.java 2012-03-02 10:08:59 UTC (rev 2416) @@ -25,75 +25,53 @@ package org.nuiton.topia.persistence; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.junit.Assert; -import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; import org.junit.matchers.JUnitMatchers; -import org.nuiton.topia.TestHelper; import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; +import org.nuiton.topia.TopiaDatabase; import org.nuiton.topia.TopiaTestDAOHelper; -import org.nuiton.topia.framework.TopiaUtilTest; import org.nuiton.topia.test.entities.Person; import org.nuiton.topia.test.entities.PersonDAO; -import java.io.File; -import java.io.IOException; import java.util.List; /** * Test on {@link TopiaDAO}. + * <p/> + * Last update : $Date$ + * By : $Author$ * * @author chatellier * @version $Revision$ - * <p/> - * Last update : $Date$ - * By : $Author$ */ public class TopiaDAOTest { - private static final Log log = LogFactory.getLog(TopiaUtilTest.class); + @Rule + public final TopiaDatabase db = new TopiaDatabase(); - protected static File testBasedir; - - @BeforeClass - public static void setUpClass() throws Exception { - - testBasedir = TestHelper.getTestBasedir(TopiaDAOTest.class); - } - /** * Test de creer une entité et de verifier qu'elle est * présente dans la persistence au sein de la transaction. * - * @throws TopiaException - * @throws IOException + * @throws Exception if any exception while test */ @Test - public void testCreateAndFindInTransaction() throws TopiaException, IOException { + public void testCreateAndFindInTransaction() throws Exception { - TopiaContext rootContext = TestHelper.initTopiaContext( - testBasedir, - "/TopiaContextImpl.properties", - "testCreateAndFindInTransaction" - ); + TopiaContext context = db.beginTransaction(); - TopiaContext context = rootContext.beginTransaction(); - PersonDAO personDAO = TopiaTestDAOHelper.getPersonDAO(context); // appel 1 find all - Person person = personDAO.create(); - person.setName("toto"); + Person person = personDAO.create(Person.PROPERTY_NAME, "toto"); List<Person> allPerson = personDAO.findAll(); Assert.assertEquals(1, allPerson.size()); context.commitTransaction(); // recherce la personne créée dans la même transaction - Person person2 = personDAO.create(); - person2.setName("titi"); + Person person2 = personDAO.create(Person.PROPERTY_NAME, "titi"); allPerson = personDAO.findAll(); Assert.assertEquals(2, allPerson.size()); Assert.assertThat(allPerson, JUnitMatchers.hasItem(person2)); @@ -101,13 +79,11 @@ context.rollbackTransaction(); // meme test apres roolback - Person person3 = personDAO.create(); - person3.setName("tata"); + Person person3 = personDAO.create(Person.PROPERTY_NAME, "tata"); allPerson = personDAO.findAll(); Assert.assertEquals(2, allPerson.size()); Assert.assertThat(allPerson, JUnitMatchers.hasItem(person3)); context.commitTransaction(); - rootContext.closeContext(); } } Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/TopiaEntityRefTester.java =================================================================== --- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/TopiaEntityRefTester.java 2012-03-02 10:08:45 UTC (rev 2415) +++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/util/TopiaEntityRefTester.java 2012-03-02 10:08:59 UTC (rev 2416) @@ -273,7 +273,7 @@ TopiaEntity... expected) { Assert.assertNotNull(refs); Assert.assertTrue("no index [" + index + "] in refs of size " + - refs.size(), index < refs.size()); + refs.size(), index < refs.size()); TopiaEntityRef actual = refs.get(index); Assert.assertEquals(actual.getInvoker(), invoker); Assert.assertEquals(actual.getInvokerProperty(), invokerProperty); Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/test/ano1882/DAOAbstractTransformerTest.java =================================================================== --- trunk/topia-persistence/src/test/java/org/nuiton/topia/test/ano1882/DAOAbstractTransformerTest.java 2012-03-02 10:08:45 UTC (rev 2415) +++ trunk/topia-persistence/src/test/java/org/nuiton/topia/test/ano1882/DAOAbstractTransformerTest.java 2012-03-02 10:08:59 UTC (rev 2416) @@ -24,58 +24,34 @@ */ package org.nuiton.topia.test.ano1882; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; -import org.nuiton.topia.TestHelper; import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaNotFoundException; +import org.nuiton.topia.TopiaDatabase; import org.nuiton.topia.TopiaTestDAOHelper; -import org.nuiton.topia.persistence.NaturalIdTest; -import java.io.File; -import java.io.IOException; import java.util.Arrays; public class DAOAbstractTransformerTest { - private static final Log log = LogFactory.getLog(NaturalIdTest.class); + @Rule + public final TopiaDatabase db = new TopiaDatabase(); - protected static File testBasedir; - - @BeforeClass - public static void setUpClass() throws Exception { - - testBasedir = TestHelper.getTestBasedir(NaturalIdTest.class); - } - - protected TopiaContext initTopiaContext(String testName) throws IOException, TopiaNotFoundException { - TopiaContext root = TestHelper.initTopiaContext(testBasedir, - "/TopiaContextImpl.properties", - testName); - return root; - } - @Test public void testAno1882() throws Exception { - TopiaContext rootContext = initTopiaContext("testAno1882"); - TopiaContext transaction = rootContext.beginTransaction(); - try { - FrenchCompanyDAO dao = TopiaTestDAOHelper.getFrenchCompanyDAO(transaction); - SIRETDAO siretDAO = TopiaTestDAOHelper.getSIRETDAO(transaction); - SIRET siret = siretDAO.create(); - FrenchCompany entity = - dao.create( - FrenchCompany.PROPERTY_S_IREN, null, - FrenchCompany.PROPERTY_SIREN2, null, - FrenchCompany.PROPERTY_S_IRET, Arrays.asList(siret), - FrenchCompany.PROPERTY_SIRET2, null); - transaction.commitTransaction(); - dao.delete(entity); - transaction.commitTransaction(); - } finally { - rootContext.closeContext(); - } + TopiaContext transaction = db.beginTransaction(); + + FrenchCompanyDAO dao = TopiaTestDAOHelper.getFrenchCompanyDAO(transaction); + SIRETDAO siretDAO = TopiaTestDAOHelper.getSIRETDAO(transaction); + SIRET siret = siretDAO.create(); + FrenchCompany entity = + dao.create( + FrenchCompany.PROPERTY_S_IREN, null, + FrenchCompany.PROPERTY_SIREN2, null, + FrenchCompany.PROPERTY_S_IRET, Arrays.asList(siret), + FrenchCompany.PROPERTY_SIRET2, null); + transaction.commitTransaction(); + dao.delete(entity); + transaction.commitTransaction(); } } Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topia/test/ano1882/DAOAbstractTransformerTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/test/evo1912/EntityDTOTransformerTest.java =================================================================== --- trunk/topia-persistence/src/test/java/org/nuiton/topia/test/evo1912/EntityDTOTransformerTest.java 2012-03-02 10:08:45 UTC (rev 2415) +++ trunk/topia-persistence/src/test/java/org/nuiton/topia/test/evo1912/EntityDTOTransformerTest.java 2012-03-02 10:08:59 UTC (rev 2416) @@ -28,9 +28,7 @@ import org.junit.Test; import org.nuiton.topiatest.CompanyDTO; -/** - * @author ymartel <martel@codelutin.com> - */ +/** @author ymartel <martel@codelutin.com> */ public class EntityDTOTransformerTest { @Test Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topia/test/evo1912/EntityDTOTransformerTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/EnumTest.java =================================================================== --- trunk/topia-persistence/src/test/java/org/nuiton/topiatest/EnumTest.java 2012-03-02 10:08:45 UTC (rev 2415) +++ trunk/topia-persistence/src/test/java/org/nuiton/topiatest/EnumTest.java 2012-03-02 10:08:59 UTC (rev 2416) @@ -25,52 +25,33 @@ package org.nuiton.topiatest; import junit.framework.Assert; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; -import org.nuiton.topia.TestHelper; import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaNotFoundException; +import org.nuiton.topia.TopiaDatabase; +import org.nuiton.topia.TopiaException; import org.nuiton.topia.TopiaTestDAOHelper; -import java.io.File; -import java.io.IOException; - /** * Test the support of possibility to have an attribute of type enumeration * in a entity */ public class EnumTest { - private static final Log log = LogFactory.getLog(EnumTest.class); + @Rule + public final TopiaDatabase db = new TopiaDatabase(); - protected static File testBasedir; - - @BeforeClass - public static void setUpClass() throws Exception { - testBasedir = TestHelper.getTestBasedir(EnumTest.class); - } - - protected TopiaContext initTopiaContext(String testName) throws IOException, TopiaNotFoundException { - TopiaContext root = TestHelper.initTopiaContext(testBasedir, - "/TopiaContextImpl.properties", - testName); - return root; - } - /** * Create an entity having two field of type enumeration. One is stored * using ordinal, the other using the name. - * + * <p/> * The test check that values are stored, and that find methods works * - * @throws Exception + * @throws TopiaException if any exception with db */ @Test - public void storeEntityWithEnumValue() throws Exception { - TopiaContext root = initTopiaContext("storeEntityWithEnumValue"); - TopiaContext transaction = root.beginTransaction(); + public void storeEntityWithEnumValue() throws TopiaException { + TopiaContext transaction = db.beginTransaction(); PersonneDAO dao = TopiaTestDAOHelper.getPersonneDAO(transaction); Personne personne = new PersonneImpl(); @@ -81,7 +62,7 @@ transaction.commitTransaction(); transaction.closeContext(); - transaction = root.beginTransaction(); + transaction = db.beginTransaction(); dao = TopiaTestDAOHelper.getPersonneDAO(transaction); dao.findByTopiaId(topiaId); Assert.assertEquals(Gender.FEMALE, personne.getGender()); Modified: trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java =================================================================== --- trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java 2012-03-02 10:08:45 UTC (rev 2415) +++ trunk/topia-persistence/src/test/java/org/nuiton/topiatest/deletetest/DeleteEntityTest.java 2012-03-02 10:08:59 UTC (rev 2416) @@ -40,19 +40,16 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; -import org.nuiton.topia.TestHelper; import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaDatabase; import org.nuiton.topia.TopiaException; import org.nuiton.topia.TopiaTestDAOHelper; import org.nuiton.topia.generator.DAOAbstractTransformer; import org.nuiton.topiatest.Personne; import org.nuiton.topiatest.PersonneDAO; -import java.io.File; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -66,97 +63,60 @@ */ public class DeleteEntityTest { - private static TopiaContext rootContext; - private static final Log log = LogFactory.getLog(DeleteEntityTest.class); + @Rule + public final TopiaDatabase db = new TopiaDatabase(); - protected static File testBasedir; - - @BeforeClass - public static void setUpClass() throws Exception { - - testBasedir = TestHelper.getTestBasedir(DeleteEntityTest.class); - - rootContext = TestHelper.initTopiaContext(testBasedir, - "/TopiaContextImpl.properties", - "deleteEntityDb"); -// -// try { -// Properties conf = new Properties(); -// URL url = Resource.getURL("TopiaContextImpl.properties"); -// if (log.isDebugEnabled()) { -// log.debug(url); -// } -// conf.load(url.openStream()); -// conf.setProperty("topia.persistence.classes", TopiaTestDAOHelper.getImplementationClassesAsString()); -// -// rootContext = TopiaContextFactory.getContext(conf); -// if (log.isInfoEnabled()) { -// log.info("Context Ready !"); -// } -// } catch (Exception ex) { -// log.error("Initialize error !!", ex); -// } - } - - - @AfterClass - public static void tearDownClass() throws Exception { - rootContext.closeContext(); - } - /** * Test for deleting entities with inheritance. Delete from the DAO linked * with the subclass entity and from the DAO linked with the superclass * entity. In the test model, the two entities have NMultiplicity * relationship without association class entity. + * + * @throws TopiaException if any exception while manipulating db */ @Test - public void testDeleteEntityWithInheritance() { + public void testDeleteEntityWithInheritance() throws TopiaException { log.debug("START TEST : testDeleteEntityWithInheritance"); - try { - TopiaContext transaction = rootContext.beginTransaction(); - log.debug("DAO : PersonneDAO"); - PersonneDAO dao = TopiaTestDAOHelper.getPersonneDAO(transaction); + TopiaContext transaction = db.beginTransaction(); - log.debug("CREATE PERSONNE : Bob Marley"); - Personne personne = dao.create(Personne.PROPERTY_NAME, "Bob Marley"); - transaction.commitTransaction(); - String idPersonne = personne.getTopiaId(); - assertNotNull(idPersonne); - log.debug("ENTITY PERSONNE SAVED !"); + log.debug("DAO : PersonneDAO"); + PersonneDAO dao = TopiaTestDAOHelper.getPersonneDAO(transaction); - log.debug("DELETE PERSONNE"); - dao.delete(personne); - transaction.commitTransaction(); - Personne res = dao.findByTopiaId(idPersonne); - assertNull(res); - log.debug("ENTITY PERSONNE DELETED !"); + log.debug("CREATE PERSONNE : Bob Marley"); + Personne personne = dao.create(Personne.PROPERTY_NAME, "Bob Marley"); + transaction.commitTransaction(); + String idPersonne = personne.getTopiaId(); + assertNotNull(idPersonne); + log.debug("ENTITY PERSONNE SAVED !"); - log.debug("CREATE PERSONNE : Ziggy Marley"); - Personne personne2 = dao.create(Personne.PROPERTY_NAME, "Ziggy Marley"); - transaction.commitTransaction(); - String idPersonne2 = personne2.getTopiaId(); - assertNotNull(idPersonne2); - log.debug("ENTITY PERSONNE SAVED !"); + log.debug("DELETE PERSONNE"); + dao.delete(personne); + transaction.commitTransaction(); + Personne res = dao.findByTopiaId(idPersonne); + assertNull(res); + log.debug("ENTITY PERSONNE DELETED !"); - log.debug("DAO parent (abstract) : PartyDAO"); - Party2DAO dao2 = TopiaTestDAOHelper.getParty2DAO(transaction); + log.debug("CREATE PERSONNE : Ziggy Marley"); + Personne personne2 = dao.create(Personne.PROPERTY_NAME, "Ziggy Marley"); + transaction.commitTransaction(); + String idPersonne2 = personne2.getTopiaId(); + assertNotNull(idPersonne2); + log.debug("ENTITY PERSONNE SAVED !"); - log.debug("DELETE PERSONNE with PartyDAO"); - dao2.delete(personne2); - transaction.commitTransaction(); - Party2 res2 = dao2.findByTopiaId(idPersonne2); - assertNull(res2); - log.debug("ENTITY PERSONNE DELETED !"); + log.debug("DAO parent (abstract) : PartyDAO"); + Party2DAO dao2 = TopiaTestDAOHelper.getParty2DAO(transaction); - transaction.closeContext(); - } catch (TopiaException ex) { - log.error("TopiaException", ex); - } - log.debug("END TEST"); + log.debug("DELETE PERSONNE with PartyDAO"); + dao2.delete(personne2); + transaction.commitTransaction(); + Party2 res2 = dao2.findByTopiaId(idPersonne2); + assertNull(res2); + log.debug("ENTITY PERSONNE DELETED !"); + + } /** @@ -165,60 +125,55 @@ * between two entities with NMultiplicity relation. In the test model, the * two entities have both inheritance. * + * @throws TopiaException if any exception while manipulating db * @see DAOAbstractTransformer */ @Test - public void testDeleteEntityWithManyToManyRelation() { + public void testDeleteEntityWithManyToManyRelation() throws TopiaException { log.debug("START TEST : testDeleteEntityWithManyToManyRelation"); - try { - TopiaContext transaction = rootContext.beginTransaction(); - PersonneDAO dao = TopiaTestDAOHelper.getPersonneDAO(transaction); + TopiaContext transaction = db.beginTransaction(); - log.debug("CREATE PERSONNE : Bob Marley"); - Personne personne = dao.create(Personne.PROPERTY_NAME, "Bob Marley"); - transaction.commitTransaction(); - String idPersonne = personne.getTopiaId(); - assertNotNull(idPersonne); - log.debug("ENTITY PERSONNE SAVED !"); + PersonneDAO dao = TopiaTestDAOHelper.getPersonneDAO(transaction); - Contact2DAO contactDAO = TopiaTestDAOHelper.getContact2DAO(transaction); + log.debug("CREATE PERSONNE : Bob Marley"); + Personne personne = dao.create(Personne.PROPERTY_NAME, "Bob Marley"); + transaction.commitTransaction(); + String idPersonne = personne.getTopiaId(); + assertNotNull(idPersonne); + log.debug("ENTITY PERSONNE SAVED !"); - log.debug("CREATE CONTACT : jaja@codelutin.com"); - Contact2 contact = contactDAO.create(Contact2.PROPERTY_CONTACT_VALUE, "jaja@codelutin.com"); - transaction.commitTransaction(); - String idContact = contact.getTopiaId(); - assertNotNull(idContact); - log.debug("ENTITY CONTACT SAVED !"); + Contact2DAO contactDAO = TopiaTestDAOHelper.getContact2DAO(transaction); - log.debug("ADD CONTACT TO PERSONNE"); - personne.addContacts(contact); - transaction.commitTransaction(); - assertEquals(1, personne.getContacts().size()); - log.debug("CONTACT ADDED !"); + log.debug("CREATE CONTACT : jaja@codelutin.com"); + Contact2 contact = contactDAO.create(Contact2.PROPERTY_CONTACT_VALUE, "jaja@codelutin.com"); + transaction.commitTransaction(); + String idContact = contact.getTopiaId(); + assertNotNull(idContact); + log.debug("ENTITY CONTACT SAVED !"); - log.debug("DELETE PERSONNE"); - dao.delete(personne); - transaction.commitTransaction(); - Personne res = dao.findByTopiaId(idPersonne); - assertNull(res); - log.debug("ENTITY PERSONNE DELETED !"); + log.debug("ADD CONTACT TO PERSONNE"); + personne.addContacts(contact); + transaction.commitTransaction(); + assertEquals(1, personne.getContacts().size()); + log.debug("CONTACT ADDED !"); - assertEquals(0, contact.getParty2().size()); + log.debug("DELETE PERSONNE"); + dao.delete(personne); + transaction.commitTransaction(); + Personne res = dao.findByTopiaId(idPersonne); + assertNull(res); + log.debug("ENTITY PERSONNE DELETED !"); - log.debug("DELETE CONTACT"); - contactDAO.delete(contact); - transaction.commitTransaction(); - Contact2 res2 = contactDAO.findByTopiaId(idContact); - assertNull(res2); - log.debug("ENTITY PERSONNE DELETED !"); + assertEquals(0, contact.getParty2().size()); + log.debug("DELETE CONTACT"); + contactDAO.delete(contact); + transaction.commitTransaction(); + Contact2 res2 = contactDAO.findByTopiaId(idContact); + assertNull(res2); + log.debug("ENTITY PERSONNE DELETED !"); - transaction.closeContext(); - } catch (TopiaException ex) { - log.error("TopiaException", ex); - } - log.debug("END TEST"); } }
participants (1)
-
tchemit@users.nuiton.org