Author: athimel Date: 2014-03-14 18:23:52 +0100 (Fri, 14 Mar 2014) New Revision: 3032 Url: http://forge.nuiton.org/projects/topia/repository/revisions/3032 Log: fixes #2774 Migrate IT mapping tests Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaItLegacyDatabase.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/AbstractMappingTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/TopiaItMappingDatabase.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test1/ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test1/BiDirectionalOneToManyRelationTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test1/BiDirectionalOneToManyRelationWithRoleNamedTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test1/SimpleOneToManyRelationTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test1/SimpleOneToManyRelationWithRoleNamedTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test10/ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test11/ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test11/EntityWithBasicUniqueFieldsTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test11/SimpleManyToManyUniqueTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test11/SimpleManyToManyWithRoleNamedUniqueTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test11/SimpleOneToManyUniqueTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test11/SimpleOneToManyWithRoleNamedUniqueTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test12/ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test12/EntityWithBasicNotNullFieldsTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test13/ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test13/EntityWithNaturalIdTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test14/ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test14/BidiAssociationClassTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test14/ManyToManyAssociationClassTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test14/OneToManyAssociationClassTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test2/ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test2/BiDirectionalManyToOneRelationTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test2/BiDirectionalManyToOneRelationWithRoleNamedTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test2/SimpleManyToOneRelationTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test2/SimpleManyToOneRelationWithRoleNamedTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test3/ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test3/BiDirectionalManyToManyRelationTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test3/BiDirectionalManyToManyRelationWithRoleNamedTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test3/SimpleManyToManyRelationTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test3/SimpleManyToManyRelationWithRoleNamedTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test4/ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test4/ElementCollectionTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test5/ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test5/BiDirectionalOneToManyCompositionTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test5/OneToManyCompositionTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test6/ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test6/SimpleOneToManyIndexedTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test6/SimpleOneToManyWithRoleNamedIndexedTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test7/ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test7/SimpleOneToManyOrderByTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test7/SimpleOneToManyOrderedTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test8/ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test9/ Removed: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaDatabase.java Modified: trunk/pom.xml trunk/topia-it/src/main/xmi/topia-it-mapping.properties trunk/topia-it/src/main/xmi/topia-it-mapping.zargo trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaJpaSupportTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/framework/TopiaConnectionProviderTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/framework/TopiaContextReplicateTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/framework/TopiaUtilTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/generator/TopiaTestCase.java trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/persistence/EntityVisitorExportXmlTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/persistence/NaturalIdTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/test/ano1882/DAOAbstractTransformerTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/CascadeSaveTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/EnumTest.java trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/deletetest/DeleteEntityTest.java trunk/topia-it/src/test/java/org/nuiton/topia/persistence/internal/TopiaDaoTest.java trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityHibernateMappingGenerator.java Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2014-03-14 16:31:08 UTC (rev 3031) +++ trunk/pom.xml 2014-03-14 17:23:52 UTC (rev 3032) @@ -29,7 +29,7 @@ <parent> <groupId>org.nuiton</groupId> <artifactId>mavenpom4redmineAndCentral</artifactId> - <version>5.0</version> + <version>5.0.1</version> </parent> <artifactId>topia</artifactId> @@ -230,6 +230,9 @@ <!-- pour un muli module on doit fixer le projectId --> <projectId>topia</projectId> + <!-- Allow SVN keywords in license headers in ToPIA --> + <license.addSvnKeyWords>true</license.addSvnKeyWords> + <!-- do not relativize links in generated site --> <relativizeDecorationLinks>false</relativizeDecorationLinks> Modified: trunk/topia-it/src/main/xmi/topia-it-mapping.properties =================================================================== --- trunk/topia-it/src/main/xmi/topia-it-mapping.properties 2014-03-14 16:31:08 UTC (rev 3031) +++ trunk/topia-it/src/main/xmi/topia-it-mapping.properties 2014-03-14 17:23:52 UTC (rev 3032) @@ -2,8 +2,8 @@ # #%L # ToPIA :: Persistence # -# $Id: topia-it-mapping.properties 2548 2012-05-29 14:08:35Z athimel $ -# $HeadURL: http://svn.nuiton.org/svn/topia/branches/topia-jpa/topia-persistence-tck/src... $ +# $Id$ +# $HeadURL$ # %% # Copyright (C) 2004 - 2010 CodeLutin # %% Property changes on: trunk/topia-it/src/main/xmi/topia-it-mapping.properties ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Property changes on: trunk/topia-it/src/main/xmi/topia-it-mapping.zargo ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Deleted: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaDatabase.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaDatabase.java 2014-03-14 16:31:08 UTC (rev 3031) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaDatabase.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -1,79 +0,0 @@ -package org.nuiton.topia.it.legacy; - -/* - * #%L - * ToPIA :: IT - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2014 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% - */ - -import org.nuiton.topia.junit.AbstractDatabaseResource; - -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 AbstractDatabaseResource<TopiaItLegacyTopiaPersistenceContext, TopiaItLegacyTopiaApplicationContext> { - - public static final String DEFAULT_CONFIGURATION_LOCATION = "/TopiaContextImpl.properties"; - - public TopiaDatabase() { - this(DEFAULT_CONFIGURATION_LOCATION); - } - - public TopiaDatabase(String configurationPath) { - super(configurationPath); - } - - @Override - protected TopiaItLegacyTopiaApplicationContext createApplicationContext(Properties dbConfiguration) { - return new TopiaItLegacyTopiaApplicationContext(dbConfiguration); - } - - @Override - protected String getImplementationClassesAsString() { - return TopiaItLegacyEntityEnum.getImplementationClassesAsString(); - } - -} - Copied: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaItLegacyDatabase.java (from rev 3031, trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaDatabase.java) =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaItLegacyDatabase.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaItLegacyDatabase.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,79 @@ +package org.nuiton.topia.it.legacy; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import org.nuiton.topia.junit.AbstractDatabaseResource; + +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 TopiaItLegacyDatabase db = new TopiaItLegacyDatabase(); + * + * \@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 TopiaItLegacyDatabase extends AbstractDatabaseResource<TopiaItLegacyTopiaPersistenceContext, TopiaItLegacyTopiaApplicationContext> { + + public static final String DEFAULT_CONFIGURATION_LOCATION = "/TopiaContextImpl.properties"; + + public TopiaItLegacyDatabase() { + this(DEFAULT_CONFIGURATION_LOCATION); + } + + public TopiaItLegacyDatabase(String configurationPath) { + super(configurationPath); + } + + @Override + protected TopiaItLegacyTopiaApplicationContext createApplicationContext(Properties dbConfiguration) { + return new TopiaItLegacyTopiaApplicationContext(dbConfiguration); + } + + @Override + protected String getImplementationClassesAsString() { + return TopiaItLegacyEntityEnum.getImplementationClassesAsString(); + } + +} + Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaJpaSupportTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaJpaSupportTest.java 2014-03-14 16:31:08 UTC (rev 3031) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/TopiaJpaSupportTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -53,7 +53,7 @@ public class TopiaJpaSupportTest { @Rule - public final TopiaDatabase db = new TopiaDatabase(); + public final TopiaItLegacyDatabase db = new TopiaItLegacyDatabase(); protected TopiaItLegacyTopiaPersistenceContext persistenceContext; Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/framework/TopiaConnectionProviderTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/framework/TopiaConnectionProviderTest.java 2014-03-14 16:31:08 UTC (rev 3031) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/framework/TopiaConnectionProviderTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -34,7 +34,7 @@ import org.nuiton.topia.persistence.TopiaConfigurationConstants; import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.persistence.internal.TopiaConnectionProvider; -import org.nuiton.topia.it.legacy.TopiaDatabase; +import org.nuiton.topia.it.legacy.TopiaItLegacyDatabase; import org.nuiton.topia.it.legacy.TopiaItLegacyTopiaPersistenceContext; import org.nuiton.topia.it.legacy.test.entities.Person; import org.nuiton.topia.it.legacy.test.entities.PersonTopiaDao; @@ -57,8 +57,8 @@ public static final String TEST_URL = "testURL"; @Rule - public final TopiaDatabase db = - new TopiaDatabase("/TopiaConnectionProviderHardcoded.properties") { + public final TopiaItLegacyDatabase db = + new TopiaItLegacyDatabase("/TopiaConnectionProviderHardcoded.properties") { @Override protected void onDbConfigurationCreate(Properties configuration, Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/framework/TopiaContextReplicateTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/framework/TopiaContextReplicateTest.java 2014-03-14 16:31:08 UTC (rev 3031) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/framework/TopiaContextReplicateTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -31,7 +31,7 @@ import org.junit.Rule; import org.junit.Test; import org.nuiton.topia.persistence.TopiaConfigurationConstants; -import org.nuiton.topia.it.legacy.TopiaDatabase; +import org.nuiton.topia.it.legacy.TopiaItLegacyDatabase; import org.nuiton.topia.it.legacy.TopiaItLegacyTopiaPersistenceContext; import org.nuiton.topia.it.legacy.test.entities.Person; import org.nuiton.topia.it.legacy.test.entities.PersonTopiaDao; @@ -47,8 +47,8 @@ public class TopiaContextReplicateTest { @Rule - public final TopiaDatabase dbSource = - new TopiaDatabase() { + public final TopiaItLegacyDatabase dbSource = + new TopiaItLegacyDatabase() { @Override protected void onDbConfigurationCreate(Properties configuration, File testDir, String dbPath) { @@ -59,8 +59,8 @@ }; @Rule - public final TopiaDatabase dbTarget = - new TopiaDatabase() { + public final TopiaItLegacyDatabase dbTarget = + new TopiaItLegacyDatabase() { @Override protected void onDbConfigurationCreate(Properties configuration, File testDir, String dbPath) { Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/framework/TopiaUtilTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/framework/TopiaUtilTest.java 2014-03-14 16:31:08 UTC (rev 3031) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/framework/TopiaUtilTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -30,7 +30,7 @@ import org.hibernate.cfg.Configuration; import org.junit.Rule; import org.junit.Test; -import org.nuiton.topia.it.legacy.TopiaDatabase; +import org.nuiton.topia.it.legacy.TopiaItLegacyDatabase; import org.nuiton.topia.persistence.util.TopiaUtil; import org.nuiton.topia.it.legacy.test.entities.PersonImpl; import org.nuiton.topia.it.legacy.topiatest.Personne; @@ -51,7 +51,7 @@ protected static final String PERSON_ID2 = "org.nuiton.topia.it.legacy.topiatest.Personne#1226701039001#0.6502325993664999"; @Rule - public final TopiaDatabase db = new TopiaDatabase(); + public final TopiaItLegacyDatabase db = new TopiaItLegacyDatabase(); @Test public void testGetTopiaIdPattern() throws Exception { Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/generator/TopiaTestCase.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/generator/TopiaTestCase.java 2014-03-14 16:31:08 UTC (rev 3031) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/generator/TopiaTestCase.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -29,8 +29,8 @@ import org.junit.Assert; import org.junit.Rule; import org.junit.Test; +import org.nuiton.topia.it.legacy.TopiaItLegacyDatabase; import org.nuiton.topia.persistence.TopiaException; -import org.nuiton.topia.it.legacy.TopiaDatabase; import org.nuiton.topia.it.legacy.TopiaItLegacyTopiaPersistenceContext; import org.nuiton.topia.it.legacy.topiatest.Company; import org.nuiton.topia.it.legacy.topiatest.CompanyTopiaDao; @@ -48,7 +48,7 @@ private final static Log log = LogFactory.getLog(TopiaTestCase.class); @Rule - public final TopiaDatabase db = new TopiaDatabase(); + public final TopiaItLegacyDatabase db = new TopiaItLegacyDatabase(); // /** Proprietes */ // protected static Properties config; Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/persistence/EntityVisitorExportXmlTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/persistence/EntityVisitorExportXmlTest.java 2014-03-14 16:31:08 UTC (rev 3031) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/persistence/EntityVisitorExportXmlTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -29,7 +29,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.nuiton.topia.it.legacy.TopiaDatabase; +import org.nuiton.topia.it.legacy.TopiaItLegacyDatabase; import org.nuiton.topia.persistence.TopiaEntityVisitor; import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.it.legacy.TopiaItLegacyTopiaPersistenceContext; @@ -54,7 +54,7 @@ LogFactory.getLog(EntityVisitorExportXmlTest.class); @Rule - public final TopiaDatabase db = new TopiaDatabase(); + public final TopiaItLegacyDatabase db = new TopiaItLegacyDatabase(); /** * Prepare test. Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/persistence/NaturalIdTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/persistence/NaturalIdTest.java 2014-03-14 16:31:08 UTC (rev 3031) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/persistence/NaturalIdTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -30,7 +30,7 @@ import org.junit.Assert; import org.junit.Rule; import org.junit.Test; -import org.nuiton.topia.it.legacy.TopiaDatabase; +import org.nuiton.topia.it.legacy.TopiaItLegacyDatabase; import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.it.legacy.TopiaItLegacyEntityEnum; import org.nuiton.topia.it.legacy.TopiaItLegacyTopiaPersistenceContext; @@ -49,7 +49,7 @@ private static final Log log = LogFactory.getLog(NaturalIdTest.class); @Rule - public final TopiaDatabase db = new TopiaDatabase(); + public final TopiaItLegacyDatabase db = new TopiaItLegacyDatabase(); @Test public void testCreateSucessfull() throws Exception { Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/test/ano1882/DAOAbstractTransformerTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/test/ano1882/DAOAbstractTransformerTest.java 2014-03-14 16:31:08 UTC (rev 3031) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/test/ano1882/DAOAbstractTransformerTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -28,13 +28,13 @@ import org.junit.Rule; import org.junit.Test; -import org.nuiton.topia.it.legacy.TopiaDatabase; +import org.nuiton.topia.it.legacy.TopiaItLegacyDatabase; import org.nuiton.topia.it.legacy.TopiaItLegacyTopiaPersistenceContext; public class DAOAbstractTransformerTest { @Rule - public final TopiaDatabase db = new TopiaDatabase(); + public final TopiaItLegacyDatabase db = new TopiaItLegacyDatabase(); @Test public void testAno1882() throws Exception { Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/CascadeSaveTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/CascadeSaveTest.java 2014-03-14 16:31:08 UTC (rev 3031) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/CascadeSaveTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -27,7 +27,7 @@ import org.junit.Rule; import org.junit.Test; import org.nuiton.topia.persistence.TopiaException; -import org.nuiton.topia.it.legacy.TopiaDatabase; +import org.nuiton.topia.it.legacy.TopiaItLegacyDatabase; import org.nuiton.topia.it.legacy.TopiaItLegacyTopiaPersistenceContext; /** @@ -36,7 +36,7 @@ public class CascadeSaveTest { @Rule - public final TopiaDatabase db = new TopiaDatabase(); + public final TopiaItLegacyDatabase db = new TopiaItLegacyDatabase(); /** * The following test will fail if no topiaId is injected on cascade save. This will test code within this method : Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/EnumTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/EnumTest.java 2014-03-14 16:31:08 UTC (rev 3031) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/EnumTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -27,7 +27,7 @@ import org.junit.Assert; import org.junit.Rule; import org.junit.Test; -import org.nuiton.topia.it.legacy.TopiaDatabase; +import org.nuiton.topia.it.legacy.TopiaItLegacyDatabase; import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.it.legacy.TopiaItLegacyTopiaPersistenceContext; @@ -38,7 +38,7 @@ public class EnumTest { @Rule - public final TopiaDatabase db = new TopiaDatabase(); + public final TopiaItLegacyDatabase db = new TopiaItLegacyDatabase(); /** * Create an entity having two field of type enumeration. One is stored Modified: trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/deletetest/DeleteEntityTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/deletetest/DeleteEntityTest.java 2014-03-14 16:31:08 UTC (rev 3031) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/legacy/topiatest/deletetest/DeleteEntityTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -30,7 +30,7 @@ import org.junit.Rule; import org.junit.Test; import org.nuiton.topia.persistence.TopiaException; -import org.nuiton.topia.it.legacy.TopiaDatabase; +import org.nuiton.topia.it.legacy.TopiaItLegacyDatabase; import org.nuiton.topia.it.legacy.TopiaItLegacyTopiaPersistenceContext; import org.nuiton.topia.it.legacy.topiatest.Gender; import org.nuiton.topia.it.legacy.topiatest.Personne; @@ -52,7 +52,7 @@ private static final Log log = LogFactory.getLog(DeleteEntityTest.class); @Rule - public final TopiaDatabase db = new TopiaDatabase(); + public final TopiaItLegacyDatabase db = new TopiaItLegacyDatabase(); /** * Test for deleting entities with inheritance. Delete from the DAO linked Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/AbstractMappingTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/AbstractMappingTest.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/AbstractMappingTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,52 @@ + +package org.nuiton.topia.it.mapping; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import org.junit.Rule; + + +import org.nuiton.topia.persistence.TopiaDao; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.TopiaException; + + +/** + * Base test for all tests using the {@code mapping} model. + * + * @author tchemit <chemit@codelutin.com> + * @since 3.0 + */ +public abstract class AbstractMappingTest { + + @Rule + public final TopiaItMappingDatabase db = new TopiaItMappingDatabase(); + + protected <E extends TopiaEntity, D extends TopiaDao<E>> D getDao( + TopiaItMappingTopiaPersistenceContext tx, Class<E> entityType) throws TopiaException { + D dao = (D)tx.getDao(entityType); + return dao; + } +} Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/AbstractMappingTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/TopiaItMappingDatabase.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/TopiaItMappingDatabase.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/TopiaItMappingDatabase.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,60 @@ + +package org.nuiton.topia.it.mapping; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import java.util.Properties; + +import org.nuiton.topia.junit.AbstractDatabaseResource; + +/** + * Concrete topia database for {@code mapping} model. + * + * @author tchemit <chemit@codelutin.com> + * @since 3.0 + */ +public class TopiaItMappingDatabase extends AbstractDatabaseResource<TopiaItMappingTopiaPersistenceContext, TopiaItMappingTopiaApplicationContext> { + + public static final String DEFAULT_CONFIGURATION_LOCATION = "/TopiaContextImpl.properties"; + + public TopiaItMappingDatabase() { + this(DEFAULT_CONFIGURATION_LOCATION); + } + + public TopiaItMappingDatabase(String configurationPath) { + super(configurationPath); + } + + @Override + protected TopiaItMappingTopiaApplicationContext createApplicationContext(Properties dbConfiguration) { + return new TopiaItMappingTopiaApplicationContext(dbConfiguration); + } + + @Override + protected String getImplementationClassesAsString() { + return TopiaItMappingEntityEnum.getImplementationClassesAsString(); + } + +} Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/TopiaItMappingDatabase.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test1/BiDirectionalOneToManyRelationTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test1/BiDirectionalOneToManyRelationTest.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test1/BiDirectionalOneToManyRelationTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,124 @@ +package org.nuiton.topia.it.mapping.test1; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +import org.nuiton.topia.it.mapping.AbstractMappingTest; +import org.nuiton.topia.it.mapping.TopiaItMappingTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; + +/** + * Tests a bi-directional OnetoMany relation. + * + * @author tchemit <chemit@codelutin.com> + * @since 3.0 + */ +public class BiDirectionalOneToManyRelationTest extends AbstractMappingTest { + + protected TopiaItMappingTopiaPersistenceContext tx; + + protected A12TopiaDao aDAO; + + protected B12TopiaDao bDAO; + + @Before + public void before() throws TopiaException { + tx = db.beginTransaction(); + aDAO = getDao(tx, A12.class); + bDAO = getDao(tx, B12.class); + } + + @Test + public void create() throws TopiaException { + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + + A12 a = aDAO.create(); + B12 b = bDAO.create(); + + a.addB12(b); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A12 aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + Assert.assertEquals(1, aBis.sizeB12()); + Assert.assertEquals(a.getB12().iterator().next(), + aBis.getB12().iterator().next()); + Assert.assertEquals(b, aBis.getB12().iterator().next()); + + B12 bBis = bDAO.findByTopiaId(b.getTopiaId()); + Assert.assertEquals(b, bBis); + Assert.assertEquals(aBis.getB12().iterator().next(), bBis); + Assert.assertEquals(aBis, bBis.getA12()); + } + @Test + public void delete() throws TopiaException { + + create(); + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A12 a = aDAO.findAll().get(0); + aDAO.delete(a); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(1, nbB); + + B12 b = bDAO.findAll().get(0); + bDAO.delete(b); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + } +} Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test1/BiDirectionalOneToManyRelationTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test1/BiDirectionalOneToManyRelationWithRoleNamedTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test1/BiDirectionalOneToManyRelationWithRoleNamedTest.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test1/BiDirectionalOneToManyRelationWithRoleNamedTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,127 @@ +package org.nuiton.topia.it.mapping.test1; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +import org.nuiton.topia.it.mapping.AbstractMappingTest; +import org.nuiton.topia.it.mapping.TopiaItMappingTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; + +/** + * Tests a bi-directional OnetoMany relation with role renamed into + * {@code roleA} and {@code roleB}. + * + * @author tchemit <chemit@codelutin.com> + * @since 3.0 + */ +public class BiDirectionalOneToManyRelationWithRoleNamedTest extends AbstractMappingTest { + + protected TopiaItMappingTopiaPersistenceContext tx; + + protected A13TopiaDao aDAO; + + protected B13TopiaDao bDAO; + + @Before + public void before() throws TopiaException { + tx = db.beginTransaction(); + aDAO = getDao(tx, A13.class); + bDAO = getDao(tx, B13.class); + } + + @Test + public void create() throws TopiaException { + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + + A13 a = aDAO.create(); + B13 b = bDAO.create(); + + a.addRoleB13(b); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A13 aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + Assert.assertEquals(1, aBis.sizeRoleB13()); + Assert.assertEquals(a.getRoleB13().iterator().next(), + aBis.getRoleB13().iterator().next()); + + Assert.assertEquals(b, aBis.getRoleB13().iterator().next()); + + B13 bBis = bDAO.findByTopiaId(b.getTopiaId()); + Assert.assertEquals(b, bBis); + Assert.assertEquals(aBis.getRoleB13().iterator().next(), bBis); + Assert.assertEquals(a, bBis.getRoleA13()); + } + @Test + public void delete() throws TopiaException { + + create(); + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A13 a = aDAO.findAll().get(0); + aDAO.delete(a); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(1, nbB); + + B13 b = bDAO.findAll().get(0); + Assert.assertNull(b.getRoleA13()); + bDAO.delete(b); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + } +} Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test1/BiDirectionalOneToManyRelationWithRoleNamedTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test1/SimpleOneToManyRelationTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test1/SimpleOneToManyRelationTest.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test1/SimpleOneToManyRelationTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,124 @@ + +package org.nuiton.topia.it.mapping.test1; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +import org.nuiton.topia.it.mapping.AbstractMappingTest; +import org.nuiton.topia.it.mapping.TopiaItMappingTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; + +/** + * To test a simple OnetoMany relation betewwen two classes A1 and B1. + * + * @author tchemit <chemit@codelutin.com> + * @since 3.0 + */ +public class SimpleOneToManyRelationTest extends AbstractMappingTest { + + protected TopiaItMappingTopiaPersistenceContext tx; + + protected A1TopiaDao aDAO; + + protected B1TopiaDao bDAO; + + @Before + public void before() throws TopiaException { + tx = db.beginTransaction(); + aDAO = getDao(tx, A1.class); + bDAO = getDao(tx, B1.class); + } + + @Test + public void create() throws TopiaException { + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + + A1 a = aDAO.create(); + B1 b = bDAO.create(); + + a.addB1(b); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A1 aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + Assert.assertEquals(1, aBis.sizeB1()); + Assert.assertEquals(a.getB1().iterator().next(), + aBis.getB1().iterator().next()); + + B1 bBis = bDAO.findByTopiaId(b.getTopiaId()); + Assert.assertEquals(b, bBis); + Assert.assertEquals(aBis.getB1().iterator().next(), bBis); + } + @Test + public void delete() throws TopiaException { + + create(); + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A1 a = aDAO.findAll().get(0); + aDAO.delete(a); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(1, nbB); + + B1 b = bDAO.findAll().get(0); + bDAO.delete(b); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + } + +} Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test1/SimpleOneToManyRelationTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test1/SimpleOneToManyRelationWithRoleNamedTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test1/SimpleOneToManyRelationWithRoleNamedTest.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test1/SimpleOneToManyRelationWithRoleNamedTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,124 @@ + +package org.nuiton.topia.it.mapping.test1; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +import org.nuiton.topia.it.mapping.AbstractMappingTest; +import org.nuiton.topia.it.mapping.TopiaItMappingTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; + +/** + * Tests a simple OnetoMany relation with role renamed into {@code roleB}. + * + * @author tchemit <chemit@codelutin.com> + * @since 3.0 + */ +public class SimpleOneToManyRelationWithRoleNamedTest extends AbstractMappingTest { + + protected TopiaItMappingTopiaPersistenceContext tx; + + protected A11TopiaDao aDAO; + + protected B11TopiaDao bDAO; + + @Before + public void before() throws TopiaException { + tx = db.beginTransaction(); + aDAO = getDao(tx, A11.class); + bDAO = getDao(tx, B11.class); + } + + @Test + public void create() throws TopiaException { + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + + A11 a = aDAO.create(); + B11 b = bDAO.create(); + + a.addRoleB11(b); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A11 aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + Assert.assertEquals(1, aBis.sizeRoleB11()); + Assert.assertEquals(a.getRoleB11().iterator().next(), + aBis.getRoleB11().iterator().next()); + + B11 bBis = bDAO.findByTopiaId(b.getTopiaId()); + Assert.assertEquals(b, bBis); + Assert.assertEquals(aBis.getRoleB11().iterator().next(), bBis); + } + + @Test + public void delete() throws TopiaException { + + create(); + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A11 a = aDAO.findAll().get(0); + aDAO.delete(a); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(1, nbB); + + B11 b = bDAO.findAll().get(0); + bDAO.delete(b); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + } +} Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test1/SimpleOneToManyRelationWithRoleNamedTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test11/EntityWithBasicUniqueFieldsTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test11/EntityWithBasicUniqueFieldsTest.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test11/EntityWithBasicUniqueFieldsTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,103 @@ + +package org.nuiton.topia.it.mapping.test11; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +import org.nuiton.topia.it.mapping.AbstractMappingTest; +import org.nuiton.topia.it.mapping.TopiaItMappingTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; + +/** + * Tests basic unique fields on a entity. + * + * @author tchemit <chemit@codelutin.com> + * @since 3.0 + */ +public class EntityWithBasicUniqueFieldsTest extends AbstractMappingTest { + + protected TopiaItMappingTopiaPersistenceContext tx; + + protected A11ETopiaDao aDAO; + + @Before + public void before() throws TopiaException { + tx = db.beginTransaction(); + aDAO = getDao(tx, A11E.class); + } + + @Test + public void create() throws TopiaException { + + long nbA = aDAO.count(); + + Assert.assertEquals(0, nbA); + + // a with all fields to null + A11E a = aDAO.create(); + + tx.commit(); + + nbA = aDAO.count(); + Assert.assertEquals(1, nbA); + + A11E aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + + // try another one with null value, can do it since null is not unique ? + A11E a2 = aDAO.create(); + tx.commit(); + + nbA = aDAO.count(); + Assert.assertEquals(2, nbA); + + aBis = aDAO.findByTopiaId(a2.getTopiaId()); + Assert.assertEquals(a2, aBis); + + A11E a3 = aDAO.create(A11E.PROPERTY_INTEGER_FIELD, 1); + tx.commit(); + + nbA = aDAO.count(); + Assert.assertEquals(3, nbA); + + aBis = aDAO.findByTopiaId(a3.getTopiaId()); + Assert.assertEquals(a3, aBis); + + A11E a4 = aDAO.create(A11E.PROPERTY_INTEGER_FIELD, 1); + try { + tx.commit(); + Assert.fail(); + + } catch (TopiaException e) { + // ok duplicate key + tx.rollback(); + } + + } +} \ No newline at end of file Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test11/EntityWithBasicUniqueFieldsTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test11/SimpleManyToManyUniqueTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test11/SimpleManyToManyUniqueTest.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test11/SimpleManyToManyUniqueTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,92 @@ + +package org.nuiton.topia.it.mapping.test11; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +import org.nuiton.topia.it.mapping.AbstractMappingTest; +import org.nuiton.topia.it.mapping.TopiaItMappingTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; + +import java.util.Collection; +import java.util.Iterator; + +/** + * Tests the tag-value {@code unique} on a {@code ManyToMany} relation. + * + * @author tchemit <chemit@codelutin.com> + * @since 3.0 + */ +public class SimpleManyToManyUniqueTest extends AbstractMappingTest { + + protected TopiaItMappingTopiaPersistenceContext tx; + + protected A11CTopiaDao aDAO; + + protected B11CTopiaDao bDAO; + + @Before + public void before() throws TopiaException { + tx = db.beginTransaction(); + aDAO = getDao(tx, A11C.class); + bDAO = getDao(tx, B11C.class); + } + + @Test + public void create() throws TopiaException { + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + + A11C a = aDAO.create(); + B11C b = bDAO.create(); + + a.addB11C(b); + a.addB11C(b); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A11C aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + Assert.assertEquals(1, aBis.sizeB11C()); + Collection<B11C> bs = aBis.getB11C(); + Iterator<B11C> iterator = bs.iterator(); + Assert.assertEquals(b, iterator.next()); + + } +} \ No newline at end of file Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test11/SimpleManyToManyUniqueTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test11/SimpleManyToManyWithRoleNamedUniqueTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test11/SimpleManyToManyWithRoleNamedUniqueTest.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test11/SimpleManyToManyWithRoleNamedUniqueTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,93 @@ + +package org.nuiton.topia.it.mapping.test11; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +import org.nuiton.topia.it.mapping.AbstractMappingTest; +import org.nuiton.topia.it.mapping.TopiaItMappingTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; + +import java.util.Collection; +import java.util.Iterator; + +/** + * Tests the tag-value {@code unique} on a {@code ManyToMany} relation with a + * renamed role. + * + * @author tchemit <chemit@codelutin.com> + * @since 3.0 + */ +public class SimpleManyToManyWithRoleNamedUniqueTest extends AbstractMappingTest { + + protected TopiaItMappingTopiaPersistenceContext tx; + + protected A11DTopiaDao aDAO; + + protected B11DTopiaDao bDAO; + + @Before + public void before() throws TopiaException { + tx = db.beginTransaction(); + aDAO = getDao(tx, A11D.class); + bDAO = getDao(tx, B11D.class); + } + + @Test + public void create() throws TopiaException { + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + + A11D a = aDAO.create(); + B11D b = bDAO.create(); + + a.addRoleB113(b); + a.addRoleB113(b); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A11D aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + Assert.assertEquals(1, aBis.sizeRoleB113()); + Collection<B11D> bs = aBis.getRoleB113(); + Iterator<B11D> iterator = bs.iterator(); + Assert.assertEquals(b, iterator.next()); + + } +} \ No newline at end of file Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test11/SimpleManyToManyWithRoleNamedUniqueTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test11/SimpleOneToManyUniqueTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test11/SimpleOneToManyUniqueTest.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test11/SimpleOneToManyUniqueTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,92 @@ + +package org.nuiton.topia.it.mapping.test11; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +import org.nuiton.topia.it.mapping.AbstractMappingTest; +import org.nuiton.topia.it.mapping.TopiaItMappingTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; + +import java.util.Collection; +import java.util.Iterator; + +/** + * Tests the tag-value {@code unique} on a {@code OneToMany} relation. + * + * @author tchemit <chemit@codelutin.com> + * @since 3.0 + */ +public class SimpleOneToManyUniqueTest extends AbstractMappingTest { + + protected TopiaItMappingTopiaPersistenceContext tx; + + protected A11ATopiaDao aDAO; + + protected B11ATopiaDao bDAO; + + @Before + public void before() throws TopiaException { + tx = db.beginTransaction(); + aDAO = getDao(tx, A11A.class); + bDAO = getDao(tx, B11A.class); + } + + @Test + public void create() throws TopiaException { + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + + A11A a = aDAO.create(); + B11A b = bDAO.create(); + + a.addB11A(b); + a.addB11A(b); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A11A aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + Assert.assertEquals(1, aBis.sizeB11A()); + Collection<B11A> bs = aBis.getB11A(); + Iterator<B11A> iterator = bs.iterator(); + Assert.assertEquals(b, iterator.next()); + + } +} \ No newline at end of file Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test11/SimpleOneToManyUniqueTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test11/SimpleOneToManyWithRoleNamedUniqueTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test11/SimpleOneToManyWithRoleNamedUniqueTest.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test11/SimpleOneToManyWithRoleNamedUniqueTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,93 @@ + +package org.nuiton.topia.it.mapping.test11; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +import org.nuiton.topia.it.mapping.AbstractMappingTest; +import org.nuiton.topia.it.mapping.TopiaItMappingTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; + +import java.util.Collection; +import java.util.Iterator; + +/** + * Tests the tag-value {@code unique} on a {@code OneToMany} relation with a + * renamed role. + * + * @author tchemit <chemit@codelutin.com> + * @since 3.0 + */ +public class SimpleOneToManyWithRoleNamedUniqueTest extends AbstractMappingTest { + + protected TopiaItMappingTopiaPersistenceContext tx; + + protected A11BTopiaDao aDAO; + + protected B11BTopiaDao bDAO; + + @Before + public void before() throws TopiaException { + tx = db.beginTransaction(); + aDAO = getDao(tx, A11B.class); + bDAO = getDao(tx, B11B.class); + } + + @Test + public void create() throws TopiaException { + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + + A11B a = aDAO.create(); + B11B b = bDAO.create(); + + a.addRoleB111(b); + a.addRoleB111(b); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A11B aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + Assert.assertEquals(1, aBis.sizeRoleB111()); + Collection<B11B> bs = aBis.getRoleB111(); + Iterator<B11B> iterator = bs.iterator(); + Assert.assertEquals(b, iterator.next()); + + } +} \ No newline at end of file Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test11/SimpleOneToManyWithRoleNamedUniqueTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test12/EntityWithBasicNotNullFieldsTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test12/EntityWithBasicNotNullFieldsTest.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test12/EntityWithBasicNotNullFieldsTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,92 @@ + +package org.nuiton.topia.it.mapping.test12; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +import org.nuiton.topia.it.mapping.TopiaItMappingTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.it.mapping.AbstractMappingTest; + +import java.util.Date; + +/** + * Tests entity with basic {@code not null} fields. + * + * @author tchemit <chemit@codelutin.com> + * @since 3.0 + */ +public class EntityWithBasicNotNullFieldsTest extends AbstractMappingTest { + + protected TopiaItMappingTopiaPersistenceContext tx; + + protected A12ATopiaDao aDAO; + + @Before + public void before() throws TopiaException { + tx = db.beginTransaction(); + aDAO = getDao(tx, A12A.class); + } + + @Test(expected = TopiaException.class) + public void createWithNull() throws TopiaException { + + long nbA = aDAO.count(); + + Assert.assertEquals(0, nbA); + + // a with all fields to null + aDAO.create(); + tx.commit(); + } + + @Test + public void create() throws TopiaException { + + long nbA = aDAO.count(); + + Assert.assertEquals(0, nbA); + + // a with all fields to null + A12A a = aDAO.create( + A12A.PROPERTY_STRING_FIELD, "string", + A12A.PROPERTY_INTEGER_FIELD, 1, + A12A.PROPERTY_DATE_FIELD, new Date() + ); + + tx.commit(); + + nbA = aDAO.count(); + Assert.assertEquals(1, nbA); + + A12A aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + + } +} \ No newline at end of file Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test12/EntityWithBasicNotNullFieldsTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test13/EntityWithNaturalIdTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test13/EntityWithNaturalIdTest.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test13/EntityWithNaturalIdTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,111 @@ + +package org.nuiton.topia.it.mapping.test13; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +import org.nuiton.topia.it.mapping.TopiaItMappingTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.it.mapping.AbstractMappingTest; + +import java.util.Date; + +/** + * Tests a entity with a {@code natural id}. + * + * @author tchemit <chemit@codelutin.com> + * @since 3.0 + */ +public class EntityWithNaturalIdTest extends AbstractMappingTest { + + protected TopiaItMappingTopiaPersistenceContext tx; + + protected A13ATopiaDao aDAO; + + @Before + public void before() throws TopiaException { + tx = db.beginTransaction(); + aDAO = getDao(tx, A13A.class); + } + + @Test(expected = TopiaException.class) + public void createWithNull() throws TopiaException { + + long nbA = aDAO.count(); + + Assert.assertEquals(0, nbA); + + // a with all fields to null + aDAO.create(); + tx.commit(); + } + + @Test + public void create() throws TopiaException { + + long nbA = aDAO.count(); + + Assert.assertEquals(0, nbA); + + // a with all fields to null + Date date = new Date(); + A13A a = aDAO.create( + A13A.PROPERTY_NATURAL_ID_STRING, "string", + A13A.PROPERTY_NATURAL_ID_INTEGER, 1, + A13A.PROPERTY_NATURAL_ID_DATE, date + ); + a.setIntegerField(10); + + tx.commit(); + + nbA = aDAO.count(); + Assert.assertEquals(1, nbA); + + A13A aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + + aBis = aDAO.findByNaturalId(1, "string", date); + Assert.assertEquals(a, aBis); + + aDAO.create( + A13A.PROPERTY_NATURAL_ID_STRING, "string", + A13A.PROPERTY_NATURAL_ID_INTEGER, 1, + A13A.PROPERTY_NATURAL_ID_DATE, date + ); + + try { + tx.commit(); + // duplicated natural id + Assert.fail(); + } catch (TopiaException e) { + Assert.assertTrue(true); + } + + } +} \ No newline at end of file Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test13/EntityWithNaturalIdTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test14/BidiAssociationClassTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test14/BidiAssociationClassTest.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test14/BidiAssociationClassTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,165 @@ +package org.nuiton.topia.it.mapping.test14; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + + +import org.nuiton.topia.it.mapping.TopiaItMappingTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.it.mapping.AbstractMappingTest; + +import java.util.List; + +/** + * @author Arnaud Thimel <thimel@codelutin.com> + */ +public class BidiAssociationClassTest extends AbstractMappingTest { + + protected TopiaItMappingTopiaPersistenceContext tx; + + protected A14ATopiaDao aDAO; + + protected B14ATopiaDao bDAO; + + protected Assoc14ATopiaDao assocDAO; + + @Before + public void before() throws TopiaException { + tx = db.beginTransaction(); + aDAO = getDao(tx, A14A.class); + bDAO = getDao(tx, B14A.class); + assocDAO = getDao(tx, Assoc14A.class); + } + + @Test + public void testCreate() throws TopiaException { + + A14A a = aDAO.create(); + B14A b = bDAO.create(); + + Assoc14A assoc = assocDAO.create(Assoc14A.PROPERTY_A14_A, a, Assoc14A.PROPERTY_ROLE_B, b); + tx.commit(); + Assert.assertNotNull(assoc.getTopiaId()); + + Assoc14A assocFound = assocDAO.findByTopiaId(assoc.getTopiaId()); + A14A aFound = assocFound.getA14A(); + B14A bFound = assocFound.getRoleB(); + + Assert.assertNotNull(aFound); + Assert.assertEquals(a, aFound); + Assert.assertNotNull(bFound); + Assert.assertEquals(b, bFound); + } + + @Test(expected = TopiaException.class) + public void testCreateWithNull() throws TopiaException { + + A14A a = aDAO.create(); + + Assert.assertNotNull(a.getTopiaId()); + + Assoc14A assoc = assocDAO.create(Assoc14A.PROPERTY_A14_A, a); + Assert.assertNotNull(assoc.getTopiaId()); + + // Will throw an exception because 'b' is mandatory + tx.commit(); + } + + @Test + public void testFindAll() throws TopiaException { + + A14A a1 = aDAO.create(); + A14A a2 = aDAO.create(); + B14A b = bDAO.create(); + + Assoc14A assoc = assocDAO.create(Assoc14A.PROPERTY_A14_A, a1, Assoc14A.PROPERTY_ROLE_B, b); + a1.setRoleB(assoc); + aDAO.update(a1); + b.setA14AAssoc14A(assoc); + bDAO.update(b); + + tx.commit(); + + A14A aFound = aDAO.findByAssoc14A(assoc); + Assert.assertEquals(a1, aFound); + + aFound = aDAO.findByRoleB(b); + Assert.assertEquals(a1, aFound); + + B14A bFound = bDAO.findByA14A(a1); + Assert.assertEquals(b, bFound); + + bFound = bDAO.findByA14A(a2); + Assert.assertNull(bFound); + + bFound = bDAO.findByAssoc14A(assoc); + Assert.assertEquals(b, bFound); + + } + + @Test + @Ignore //FIXME AThimel 09/07/2012 #2177: Test is ignored as cascade-delete does not work as expected + public void testDeleteCascade() throws TopiaException { + + A14A a1 = aDAO.create(); + A14A a2 = aDAO.create(); + B14A b1 = bDAO.create(); + B14A b2 = bDAO.create(); + + Assoc14A assoc11 = assocDAO.create(Assoc14A.PROPERTY_A14_A, a1, Assoc14A.PROPERTY_ROLE_B, b1); + Assoc14A assoc22 = assocDAO.create(Assoc14A.PROPERTY_A14_A, a2, Assoc14A.PROPERTY_ROLE_B, b2); + + a1.setRoleB(assoc11); + a2.setRoleB(assoc22); + b1.setA14AAssoc14A(assoc11); + b2.setA14AAssoc14A(assoc22); + + aDAO.update(a1); + aDAO.update(a2); + bDAO.update(b1); + bDAO.update(b2); + + tx.commit(); + + Assert.assertEquals(2, assocDAO.count()); + + aDAO.delete(a1); + + tx.commit(); + + Assert.assertEquals(1, assocDAO.count()); + + List<Assoc14A> all = assocDAO.findAll(); + Assert.assertEquals(1, all.size()); + Assoc14A first = all.iterator().next(); + Assert.assertEquals(a2, first.getA14A()); + Assert.assertEquals(b2, first.getRoleB()); + } + +} Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test14/BidiAssociationClassTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test14/ManyToManyAssociationClassTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test14/ManyToManyAssociationClassTest.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test14/ManyToManyAssociationClassTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,165 @@ +package org.nuiton.topia.it.mapping.test14; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + + +import org.nuiton.topia.it.mapping.AbstractMappingTest; +import org.nuiton.topia.it.mapping.TopiaItMappingTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; + +import java.util.List; + +/** + * @author Arnaud Thimel <thimel@codelutin.com> + */ +public class ManyToManyAssociationClassTest extends AbstractMappingTest { + + protected TopiaItMappingTopiaPersistenceContext tx; + + protected A14DTopiaDao aDAO; + + protected B14DTopiaDao bDAO; + + protected Assoc14DTopiaDao assocDAO; + + @Before + public void before() throws TopiaException { + tx = db.beginTransaction(); + aDAO = getDao(tx, A14D.class); + bDAO = getDao(tx, B14D.class); + assocDAO = getDao(tx, Assoc14D.class); + } + + @Test + public void testCreate() throws TopiaException { + + A14D a = aDAO.create(); + B14D b = bDAO.create(); + + Assoc14D assoc = assocDAO.create(Assoc14D.PROPERTY_ROLE_A, a, Assoc14D.PROPERTY_B14_D, b); + a.addB14DAssoc14D(assoc); + b.addRoleA(assoc); + aDAO.update(a); + bDAO.update(b); + tx.commit(); + + + Assoc14D assocFound = assocDAO.findByTopiaId(assoc.getTopiaId()); + A14D aFound = assocFound.getRoleA(); + Assert.assertEquals(a, aFound); + B14D bFound = assocFound.getB14D(); + Assert.assertEquals(b, bFound); + + Assert.assertEquals(1, aFound.sizeB14DAssoc14D()); + Assert.assertEquals(1, bFound.sizeRoleA()); + + } + + + @Test + public void testFindAll() throws TopiaException { + + A14D a1 = aDAO.create(); + A14D a2 = aDAO.create(); + B14D b1 = bDAO.create(); + B14D b2 = bDAO.create(); + + Assoc14D assoc11 = assocDAO.create(Assoc14D.PROPERTY_ROLE_A, a1, Assoc14D.PROPERTY_B14_D, b1); + Assoc14D assoc12 = assocDAO.create(Assoc14D.PROPERTY_ROLE_A, a1, Assoc14D.PROPERTY_B14_D, b2); + Assoc14D assoc21 = assocDAO.create(Assoc14D.PROPERTY_ROLE_A, a2, Assoc14D.PROPERTY_B14_D, b1); + + a1.addB14DAssoc14D(assoc11); + a1.addB14DAssoc14D(assoc12); + a2.addB14DAssoc14D(assoc21); + b1.addRoleA(assoc11); + b1.addRoleA(assoc21); + b2.addRoleA(assoc12); + + aDAO.update(a1); + aDAO.update(a2); + bDAO.update(b1); + bDAO.update(b2); + + tx.commit(); + + Assert.assertEquals(3, assocDAO.count()); + + List<Assoc14D> allByB14D = assocDAO.forProperties(Assoc14D.PROPERTY_B14_D, b1).findAll(); + Assert.assertEquals(2, allByB14D.size()); + + List<Assoc14D> allByRoleA = assocDAO.forProperties(Assoc14D.PROPERTY_ROLE_A, a2).findAll(); + Assert.assertEquals(1, allByRoleA.size()); + + } + + @Test + @Ignore + //FIXME AThimel 09/07/2012 #2177: Test is ignored as cascade-delete does not work as expected + public void testDeleteCascade() throws TopiaException { + + A14D a1 = aDAO.create(); + A14D a2 = aDAO.create(); + B14D b1 = bDAO.create(); + B14D b2 = bDAO.create(); + + Assoc14D assoc11 = assocDAO.create(Assoc14D.PROPERTY_ROLE_A, a1, Assoc14D.PROPERTY_B14_D, b1); + Assoc14D assoc12 = assocDAO.create(Assoc14D.PROPERTY_ROLE_A, a1, Assoc14D.PROPERTY_B14_D, b2); + Assoc14D assoc21 = assocDAO.create(Assoc14D.PROPERTY_ROLE_A, a2, Assoc14D.PROPERTY_B14_D, b1); + + a1.addB14DAssoc14D(assoc11); + a1.addB14DAssoc14D(assoc12); + a2.addB14DAssoc14D(assoc21); + b1.addRoleA(assoc11); + b1.addRoleA(assoc21); + b2.addRoleA(assoc12); + + aDAO.update(a1); + aDAO.update(a2); + bDAO.update(b1); + bDAO.update(b2); + + tx.commit(); + + Assert.assertEquals(3, assocDAO.count()); + + aDAO.delete(a1); + + tx.commit(); + + Assert.assertEquals(1, assocDAO.count()); + + List<Assoc14D> all = assocDAO.findAll(); + Assert.assertEquals(1, all.size()); + Assoc14D first = all.iterator().next(); + Assert.assertEquals(a2, first.getRoleA()); + Assert.assertEquals(b1, first.getB14D()); + } + +} Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test14/ManyToManyAssociationClassTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test14/OneToManyAssociationClassTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test14/OneToManyAssociationClassTest.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test14/OneToManyAssociationClassTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,127 @@ +package org.nuiton.topia.it.mapping.test14; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +import org.nuiton.topia.it.mapping.AbstractMappingTest; +import org.nuiton.topia.it.mapping.TopiaItMappingTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; + +import java.util.List; + +/** + * @author Arnaud Thimel <thimel@codelutin.com> + */ +public class OneToManyAssociationClassTest extends AbstractMappingTest { + + protected TopiaItMappingTopiaPersistenceContext tx; + + protected A14CTopiaDao aDAO; + + protected B14CTopiaDao bDAO; + + protected Assoc14CTopiaDao assocDAO; + + @Before + public void before() throws TopiaException { + tx = db.beginTransaction(); + aDAO = getDao(tx, A14C.class); + bDAO = getDao(tx, B14C.class); + assocDAO = getDao(tx, Assoc14C.class); + } + + @Test + public void testCreate() throws TopiaException { + + A14C a = aDAO.create(); + B14C b = bDAO.create(); + + Assoc14C assoc = assocDAO.create(Assoc14C.PROPERTY_A14_C, a, Assoc14C.PROPERTY_B14_C, b); + a.addB14CAssoc14C(assoc); + b.setA14CAssoc14C(assoc); + aDAO.update(a); + bDAO.update(b); + tx.commit(); + + + Assoc14C assocFound = assocDAO.findByTopiaId(assoc.getTopiaId()); + A14C aFound = assocFound.getA14C(); + Assert.assertEquals(a, aFound); + Assert.assertEquals(b, assocFound.getB14C()); + + Assert.assertEquals(1, aFound.sizeB14CAssoc14C()); + Assert.assertEquals(b, aFound.getB14CAssoc14C().iterator().next().getB14C()); + + } + + + @Test + public void testFindAll() throws TopiaException { + + A14C a = aDAO.create(); + B14C b1 = bDAO.create(); + B14C b2 = bDAO.create(); + + Assoc14C assoc1 = assocDAO.create(Assoc14C.PROPERTY_A14_C, a, Assoc14C.PROPERTY_B14_C, b1); + a.addB14CAssoc14C(assoc1); + b1.setA14CAssoc14C(assoc1); + aDAO.update(a); + bDAO.update(b1); + + tx.commit(); + + List<B14C> allByA14C = bDAO.findAllByA14C(a); + Assert.assertEquals(1, allByA14C.size()); + Assert.assertEquals(b1, allByA14C.iterator().next()); + + B14C bFound = bDAO.findByAssoc14C(assoc1); + Assert.assertEquals(b1, bFound); + + Assoc14C assoc2 = assocDAO.create(Assoc14C.PROPERTY_A14_C, a, Assoc14C.PROPERTY_B14_C, b2); + a.addB14CAssoc14C(assoc2); + b2.setA14CAssoc14C(assoc2); + + aDAO.update(a); + bDAO.update(b2); + + tx.commit(); + + bFound = bDAO.findByAssoc14C(assoc1); + Assert.assertEquals(b1, bFound); + bFound = bDAO.findByAssoc14C(assoc2); + Assert.assertEquals(b2, bFound); + + allByA14C = bDAO.findAllByA14C(a); + Assert.assertEquals(2, allByA14C.size()); + A14C aFound = allByA14C.iterator().next().getA14CAssoc14C().getA14C(); + Assert.assertEquals(2, aFound.sizeB14CAssoc14C()); + + } + +} Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test14/OneToManyAssociationClassTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test2/BiDirectionalManyToOneRelationTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test2/BiDirectionalManyToOneRelationTest.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test2/BiDirectionalManyToOneRelationTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,124 @@ + +package org.nuiton.topia.it.mapping.test2; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +import org.nuiton.topia.it.mapping.AbstractMappingTest; +import org.nuiton.topia.it.mapping.TopiaItMappingTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; + +/** + * Tests a bi-directional ManyToOne relation. + * + * @author tchemit <chemit@codelutin.com> + * @since 3.0 + */ +public class BiDirectionalManyToOneRelationTest extends AbstractMappingTest { + + protected TopiaItMappingTopiaPersistenceContext tx; + + protected A22TopiaDao aDAO; + + protected B22TopiaDao bDAO; + + @Before + public void before() throws TopiaException { + tx = db.beginTransaction(); + aDAO = getDao(tx, A22.class); + bDAO = getDao(tx, B22.class); + } + + @Test + public void create() throws TopiaException { + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + + A22 a = aDAO.create(); + B22 b = bDAO.create(); + + b.addA22(a); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A22 aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + Assert.assertEquals(b, aBis.getB22()); + Assert.assertEquals(a.getB22(), aBis.getB22()); + + B22 bBis = bDAO.findByTopiaId(b.getTopiaId()); + Assert.assertEquals(b, bBis); + Assert.assertEquals(1, bBis.sizeA22()); + Assert.assertEquals(a, bBis.getA22().iterator().next()); + } + + @Test + public void delete() throws TopiaException { + + create(); + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A22 a = aDAO.findAll().get(0); + aDAO.delete(a); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(1, nbB); + + B22 b = bDAO.findAll().get(0); + bDAO.delete(b); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + } +} Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test2/BiDirectionalManyToOneRelationTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test2/BiDirectionalManyToOneRelationWithRoleNamedTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test2/BiDirectionalManyToOneRelationWithRoleNamedTest.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test2/BiDirectionalManyToOneRelationWithRoleNamedTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,123 @@ + +package org.nuiton.topia.it.mapping.test2; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +import org.nuiton.topia.it.mapping.AbstractMappingTest; +import org.nuiton.topia.it.mapping.TopiaItMappingTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; + +/** + * Tests a bi-directional ManyToOne relation with role renamed into + * {@code roleA} and {@code roleB}. + * + * @author tchemit <chemit@codelutin.com> + * @since 3.0 + */ +public class BiDirectionalManyToOneRelationWithRoleNamedTest extends AbstractMappingTest { + + protected TopiaItMappingTopiaPersistenceContext tx; + + protected A23TopiaDao aDAO; + + protected B23TopiaDao bDAO; + + @Before + public void before() throws TopiaException { + tx = db.beginTransaction(); + aDAO = getDao(tx, A23.class); + bDAO = getDao(tx, B23.class); + } + + @Test + public void create() throws TopiaException { + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + + A23 a = aDAO.create(); + B23 b = bDAO.create(); + + b.addRoleA23(a); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A23 aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + Assert.assertEquals(b, aBis.getRoleB23()); + + B23 bBis = bDAO.findByTopiaId(b.getTopiaId()); + Assert.assertEquals(b, bBis); + Assert.assertEquals(1, bBis.sizeRoleA23()); + Assert.assertEquals(a, bBis.getRoleA23().iterator().next()); + } + @Test + public void delete() throws TopiaException { + + create(); + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A23 a = aDAO.findAll().get(0); + aDAO.delete(a); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(1, nbB); + + B23 b = bDAO.findAll().get(0); + bDAO.delete(b); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + } +} Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test2/BiDirectionalManyToOneRelationWithRoleNamedTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test2/SimpleManyToOneRelationTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test2/SimpleManyToOneRelationTest.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test2/SimpleManyToOneRelationTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,121 @@ + +package org.nuiton.topia.it.mapping.test2; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +import org.nuiton.topia.it.mapping.AbstractMappingTest; +import org.nuiton.topia.it.mapping.TopiaItMappingTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; + +/** + * Tests a simple ManyToOne relation. + * + * @author tchemit <chemit@codelutin.com> + * @since 3.0 + */ +public class SimpleManyToOneRelationTest extends AbstractMappingTest { + + protected TopiaItMappingTopiaPersistenceContext tx; + + protected A2TopiaDao aDAO; + + protected B2TopiaDao bDAO; + + @Before + public void before() throws TopiaException { + tx = db.beginTransaction(); + aDAO = getDao(tx, A2.class); + bDAO = getDao(tx, B2.class); + } + + @Test + public void create() throws TopiaException { + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + + A2 a = aDAO.create(); + B2 b = bDAO.create(); + + a.setB2(b); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A2 aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + Assert.assertEquals(b, aBis.getB2()); + + B2 bBis = bDAO.findByTopiaId(b.getTopiaId()); + Assert.assertEquals(b, bBis); + Assert.assertEquals(aBis.getB2(), bBis); + } + @Test + public void delete() throws TopiaException { + + create(); + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A2 a = aDAO.findAll().get(0); + aDAO.delete(a); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(1, nbB); + + B2 b = bDAO.findAll().get(0); + bDAO.delete(b); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + } +} Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test2/SimpleManyToOneRelationTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test2/SimpleManyToOneRelationWithRoleNamedTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test2/SimpleManyToOneRelationWithRoleNamedTest.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test2/SimpleManyToOneRelationWithRoleNamedTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,121 @@ + +package org.nuiton.topia.it.mapping.test2; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +import org.nuiton.topia.it.mapping.AbstractMappingTest; +import org.nuiton.topia.it.mapping.TopiaItMappingTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; + +/** + * Tests a simple ManyToOne relation with role renamed into {@code roleB}. + * + * @author tchemit <chemit@codelutin.com> + * @since 3.0 + */ +public class SimpleManyToOneRelationWithRoleNamedTest extends AbstractMappingTest { + + protected TopiaItMappingTopiaPersistenceContext tx; + + protected A21TopiaDao aDAO; + + protected B21TopiaDao bDAO; + + @Before + public void before() throws TopiaException { + tx = db.beginTransaction(); + aDAO = getDao(tx, A21.class); + bDAO = getDao(tx, B21.class); + } + + @Test + public void create() throws TopiaException { + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + + A21 a = aDAO.create(); + B21 b = bDAO.create(); + + a.setRoleB21(b); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A21 aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + Assert.assertEquals(b, aBis.getRoleB21()); + + B21 bBis = bDAO.findByTopiaId(b.getTopiaId()); + Assert.assertEquals(b, bBis); + Assert.assertEquals(aBis.getRoleB21(), bBis); + } + @Test + public void delete() throws TopiaException { + + create(); + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A21 a = aDAO.findAll().get(0); + aDAO.delete(a); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(1, nbB); + + B21 b = bDAO.findAll().get(0); + bDAO.delete(b); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + } +} Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test2/SimpleManyToOneRelationWithRoleNamedTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test3/BiDirectionalManyToManyRelationTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test3/BiDirectionalManyToManyRelationTest.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test3/BiDirectionalManyToManyRelationTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,125 @@ + +package org.nuiton.topia.it.mapping.test3; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +import org.nuiton.topia.it.mapping.AbstractMappingTest; +import org.nuiton.topia.it.mapping.TopiaItMappingTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; + +/** + * Tests a bi-directional ManyToMany relation. + * + * @author tchemit <chemit@codelutin.com> + * @since 3.0 + */ +public class BiDirectionalManyToManyRelationTest extends AbstractMappingTest { + + protected TopiaItMappingTopiaPersistenceContext tx; + + protected A32TopiaDao aDAO; + + protected B32TopiaDao bDAO; + + @Before + public void before() throws TopiaException { + tx = db.beginTransaction(); + aDAO = getDao(tx, A32.class); + bDAO = getDao(tx, B32.class); + } + + @Test + public void create() throws TopiaException { + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + + A32 a = aDAO.create(); + B32 b = bDAO.create(); + + b.addA32(a); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A32 aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + Assert.assertEquals(1, aBis.sizeB32()); + Assert.assertEquals(b, aBis.getB32().iterator().next()); + Assert.assertEquals(a.getB32(), aBis.getB32()); + + B32 bBis = bDAO.findByTopiaId(b.getTopiaId()); + Assert.assertEquals(b, bBis); + Assert.assertEquals(1, bBis.sizeA32()); + Assert.assertEquals(a, bBis.getA32().iterator().next()); + } + + @Test + public void delete() throws TopiaException { + + create(); + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A32 a = aDAO.findAll().get(0); + aDAO.delete(a); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(1, nbB); + + B32 b = bDAO.findAll().get(0); + bDAO.delete(b); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + } +} Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test3/BiDirectionalManyToManyRelationTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test3/BiDirectionalManyToManyRelationWithRoleNamedTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test3/BiDirectionalManyToManyRelationWithRoleNamedTest.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test3/BiDirectionalManyToManyRelationWithRoleNamedTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,125 @@ + +package org.nuiton.topia.it.mapping.test3; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +import org.nuiton.topia.it.mapping.AbstractMappingTest; +import org.nuiton.topia.it.mapping.TopiaItMappingTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; + +/** + * Tests a bi-directional ManyToMany relation. + * + * @author tchemit <chemit@codelutin.com> + * @since 3.0 + */ +public class BiDirectionalManyToManyRelationWithRoleNamedTest extends AbstractMappingTest { + + protected TopiaItMappingTopiaPersistenceContext tx; + + protected A33TopiaDao aDAO; + + protected B33TopiaDao bDAO; + + @Before + public void before() throws TopiaException { + tx = db.beginTransaction(); + aDAO = getDao(tx, A33.class); + bDAO = getDao(tx, B33.class); + } + + @Test + public void create() throws TopiaException { + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + + A33 a = aDAO.create(); + B33 b = bDAO.create(); + + b.addRoleA33(a); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A33 aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + Assert.assertEquals(1, aBis.sizeRoleB33()); + Assert.assertEquals(b, aBis.getRoleB33().iterator().next()); + Assert.assertEquals(a.getRoleB33(), aBis.getRoleB33()); + + B33 bBis = bDAO.findByTopiaId(b.getTopiaId()); + Assert.assertEquals(b, bBis); + Assert.assertEquals(1, bBis.sizeRoleA33()); + Assert.assertEquals(a, bBis.getRoleA33().iterator().next()); + } + + @Test + public void delete() throws TopiaException { + + create(); + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A33 a = aDAO.findAll().get(0); + aDAO.delete(a); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(1, nbB); + + B33 b = bDAO.findAll().get(0); + bDAO.delete(b); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + } +} Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test3/BiDirectionalManyToManyRelationWithRoleNamedTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test3/SimpleManyToManyRelationTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test3/SimpleManyToManyRelationTest.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test3/SimpleManyToManyRelationTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,123 @@ + +package org.nuiton.topia.it.mapping.test3; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +import org.nuiton.topia.it.mapping.AbstractMappingTest; +import org.nuiton.topia.it.mapping.TopiaItMappingTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; + +/** + * Tests a simple ManyToMany relation. + * + * @author tchemit <chemit@codelutin.com> + * @since 3.0 + */ +public class SimpleManyToManyRelationTest extends AbstractMappingTest { + + protected TopiaItMappingTopiaPersistenceContext tx; + + protected A3TopiaDao aDAO; + + protected B3TopiaDao bDAO; + + @Before + public void before() throws TopiaException { + tx = db.beginTransaction(); + aDAO = getDao(tx, A3.class); + bDAO = getDao(tx, B3.class); + } + + @Test + public void create() throws TopiaException { + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + + A3 a = aDAO.create(); + B3 b = bDAO.create(); + + a.addB3(b); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A3 aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + Assert.assertEquals(1, aBis.sizeB3()); + Assert.assertEquals(b, aBis.getB3().iterator().next()); + + B3 bBis = bDAO.findByTopiaId(b.getTopiaId()); + Assert.assertEquals(b, bBis); + Assert.assertEquals(aBis.getB3().iterator().next(), bBis); + } + + @Test + public void delete() throws TopiaException { + + create(); + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A3 a = aDAO.findAll().get(0); + aDAO.delete(a); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(1, nbB); + + B3 b = bDAO.findAll().get(0); + bDAO.delete(b); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + } +} Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test3/SimpleManyToManyRelationTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test3/SimpleManyToManyRelationWithRoleNamedTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test3/SimpleManyToManyRelationWithRoleNamedTest.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test3/SimpleManyToManyRelationWithRoleNamedTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,123 @@ + +package org.nuiton.topia.it.mapping.test3; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +import org.nuiton.topia.it.mapping.AbstractMappingTest; +import org.nuiton.topia.it.mapping.TopiaItMappingTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; + +/** + * Tests a simple ManyToMany relation. + * + * @author tchemit <chemit@codelutin.com> + * @since 3.0 + */ +public class SimpleManyToManyRelationWithRoleNamedTest extends AbstractMappingTest { + + protected TopiaItMappingTopiaPersistenceContext tx; + + protected A31TopiaDao aDAO; + + protected B31TopiaDao bDAO; + + @Before + public void before() throws TopiaException { + tx = db.beginTransaction(); + aDAO = getDao(tx, A31.class); + bDAO = getDao(tx, B31.class); + } + + @Test + public void create() throws TopiaException { + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + + A31 a = aDAO.create(); + B31 b = bDAO.create(); + + a.addRoleB31(b); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A31 aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + Assert.assertEquals(1, aBis.sizeRoleB31()); + Assert.assertEquals(b, aBis.getRoleB31().iterator().next()); + + B31 bBis = bDAO.findByTopiaId(b.getTopiaId()); + Assert.assertEquals(b, bBis); + Assert.assertEquals(aBis.getRoleB31().iterator().next(), bBis); + } + + @Test + public void delete() throws TopiaException { + + create(); + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A31 a = aDAO.findAll().get(0); + aDAO.delete(a); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(1, nbB); + + B31 b = bDAO.findAll().get(0); + bDAO.delete(b); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + } +} Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test3/SimpleManyToManyRelationWithRoleNamedTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test4/ElementCollectionTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test4/ElementCollectionTest.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test4/ElementCollectionTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,101 @@ + +package org.nuiton.topia.it.mapping.test4; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +import org.nuiton.topia.it.mapping.AbstractMappingTest; +import org.nuiton.topia.it.mapping.TopiaItMappingTopiaPersistenceContext; +import org.nuiton.topia.it.mapping.test3.B3TopiaDao; +import org.nuiton.topia.persistence.TopiaException; + +import java.util.Arrays; + +/** + * Tests that everything is ok with fields with multiplicity > 1 on primitive + * data. + * + * @author tchemit <chemit@codelutin.com> + * @since 3.0 + */ +public class ElementCollectionTest extends AbstractMappingTest { + + protected TopiaItMappingTopiaPersistenceContext tx; + + protected A4TopiaDao aDAO; + + protected B3TopiaDao bDAO; + + @Before + public void before() throws TopiaException { + tx = db.beginTransaction(); + aDAO = getDao(tx, A4.class); + } + + @Test + public void create() throws TopiaException { + + A4 a = aDAO.create(); + a.setStrings(Arrays.asList("a", "b", "c")); + a.setEnumerations(Arrays.asList(E4.LITERAL1, E4.LITERAL2)); + + tx.commit(); + + A4 aBis = aDAO.findByTopiaId(a.getTopiaId()); + + Assert.assertNotNull(aBis); + Assert.assertEquals(a, aBis); + Assert.assertNotNull(aBis.getStrings()); + Assert.assertEquals(3, aBis.sizeStrings()); + Assert.assertEquals(a.getStrings(), aBis.getStrings()); + + Assert.assertNotNull(aBis.getEnumerations()); + Assert.assertEquals(2, aBis.sizeEnumerations()); + Assert.assertEquals(a.getEnumerations(), aBis.getEnumerations()); + } + + @Test + public void delete() throws TopiaException { + + create(); + + long nbA = aDAO.count(); + + Assert.assertEquals(1, nbA); + + A4 a = aDAO.findAll().get(0); + aDAO.delete(a); + + tx.commit(); + + nbA = aDAO.count(); + + Assert.assertEquals(0, nbA); + } +} \ No newline at end of file Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test4/ElementCollectionTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test5/BiDirectionalOneToManyCompositionTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test5/BiDirectionalOneToManyCompositionTest.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test5/BiDirectionalOneToManyCompositionTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,112 @@ + +package org.nuiton.topia.it.mapping.test5; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +import org.nuiton.topia.it.mapping.AbstractMappingTest; +import org.nuiton.topia.it.mapping.TopiaItMappingTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; + +/** + * Test behaviour of a bi-directional OnetoMany (composition) relation. + * + * @author tchemit <chemit@codelutin.com> + * @since 3.0 + */ +public class BiDirectionalOneToManyCompositionTest extends AbstractMappingTest { + + protected TopiaItMappingTopiaPersistenceContext tx; + + protected A51TopiaDao aDAO; + + protected B51TopiaDao bDAO; + + @Before + public void before() throws TopiaException { + tx = db.beginTransaction(); + aDAO = getDao(tx, A51.class); + bDAO = getDao(tx, B51.class); + } + + @Test + public void create() throws TopiaException { + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + + A51 a = aDAO.create(); + B51 b = bDAO.create(); + + a.addB51(b); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A51 aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + Assert.assertEquals(1, aBis.sizeB51()); + Assert.assertEquals(b, aBis.getB51().iterator().next()); + + B51 bBis = bDAO.findByTopiaId(b.getTopiaId()); + Assert.assertEquals(b, bBis); + Assert.assertEquals(aBis.getB51().iterator().next(), bBis); + } + + @Test + public void delete() throws TopiaException { + + create(); + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A51 a = aDAO.findAll().get(0); + aDAO.delete(a); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + } +} \ No newline at end of file Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test5/BiDirectionalOneToManyCompositionTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test5/OneToManyCompositionTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test5/OneToManyCompositionTest.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test5/OneToManyCompositionTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,112 @@ + +package org.nuiton.topia.it.mapping.test5; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +import org.nuiton.topia.it.mapping.AbstractMappingTest; +import org.nuiton.topia.it.mapping.TopiaItMappingTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; + +/** + * Test behaviour of a OnetoMany (composition) relation. + * + * @author tchemit <chemit@codelutin.com> + * @since 3.0 + */ +public class OneToManyCompositionTest extends AbstractMappingTest { + + protected TopiaItMappingTopiaPersistenceContext tx; + + protected A5TopiaDao aDAO; + + protected B5TopiaDao bDAO; + + @Before + public void before() throws TopiaException { + tx = db.beginTransaction(); + aDAO = getDao(tx, A5.class); + bDAO = getDao(tx, B5.class); + } + + @Test + public void create() throws TopiaException { + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + + A5 a = aDAO.create(); + B5 b = bDAO.create(); + + a.addB5(b); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A5 aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + Assert.assertEquals(1, aBis.sizeB5()); + Assert.assertEquals(b, aBis.getB5().iterator().next()); + + B5 bBis = bDAO.findByTopiaId(b.getTopiaId()); + Assert.assertEquals(b, bBis); + Assert.assertEquals(aBis.getB5().iterator().next(), bBis); + } + + @Test + public void delete() throws TopiaException { + + create(); + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(1, nbB); + + A5 a = aDAO.findAll().get(0); + aDAO.delete(a); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + } +} \ No newline at end of file Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test5/OneToManyCompositionTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test6/SimpleOneToManyIndexedTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test6/SimpleOneToManyIndexedTest.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test6/SimpleOneToManyIndexedTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,126 @@ + +package org.nuiton.topia.it.mapping.test6; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import com.google.common.collect.Lists; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +import org.nuiton.topia.it.mapping.AbstractMappingTest; +import org.nuiton.topia.it.mapping.TopiaItMappingTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; + +import java.util.List; + +/** + * To test a simple OneToMany indexed relation (usage of JPA order-colum) + * + * @author tchemit <chemit@codelutin.com> + * @since 3.0 + */ +public class SimpleOneToManyIndexedTest extends AbstractMappingTest { + + protected TopiaItMappingTopiaPersistenceContext tx; + + protected A6TopiaDao aDAO; + + protected B6TopiaDao bDAO; + + @Before + public void before() throws TopiaException { + tx = db.beginTransaction(); + aDAO = getDao(tx, A6.class); + bDAO = getDao(tx, B6.class); + } + + @Test + public void create() throws TopiaException { + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + + A6 a = aDAO.create(); + B6 b = bDAO.create(); + B6 b2 = bDAO.create(); + B6 b3 = bDAO.create(); + + a.addB6(b); + a.addB6(b2); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(3, nbB); + + A6 aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + Assert.assertEquals(2, aBis.sizeB6()); + List<B6> bs = aBis.getB6(); + Assert.assertEquals(b, bs.get(0)); + Assert.assertEquals(b2, bs.get(1)); + + // change order + List<B6> bsBis; + + bsBis = Lists.newArrayList(); + bsBis.add(b2); + bsBis.add(b); + a.setB6(bsBis); + tx.commit(); + + aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + Assert.assertEquals(2, aBis.sizeB6()); + bs = aBis.getB6(); + Assert.assertEquals(b2, bs.get(0)); + Assert.assertEquals(b, bs.get(1)); + + // rechange order + + bsBis = Lists.newArrayList(); + bsBis.add(b3); + bsBis.add(b2); + bsBis.add(b); + a.setB6(bsBis); + tx.commit(); + + aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + Assert.assertEquals(3, aBis.sizeB6()); + bs = aBis.getB6(); + Assert.assertEquals(b3, bs.get(0)); + Assert.assertEquals(b2, bs.get(1)); + Assert.assertEquals(b, bs.get(2)); + } +} \ No newline at end of file Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test6/SimpleOneToManyIndexedTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test6/SimpleOneToManyWithRoleNamedIndexedTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test6/SimpleOneToManyWithRoleNamedIndexedTest.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test6/SimpleOneToManyWithRoleNamedIndexedTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,127 @@ + +package org.nuiton.topia.it.mapping.test6; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import com.google.common.collect.Lists; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +import org.nuiton.topia.it.mapping.AbstractMappingTest; +import org.nuiton.topia.it.mapping.TopiaItMappingTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; + +import java.util.List; + +/** + * To test a simple OneToMany indexed relation (usage of JPA order-colum) + * + * @author tchemit <chemit@codelutin.com> + * @since 3.0 + */ +public class SimpleOneToManyWithRoleNamedIndexedTest extends AbstractMappingTest { + + protected TopiaItMappingTopiaPersistenceContext tx; + + protected A61TopiaDao aDAO; + + protected B61TopiaDao bDAO; + + @Before + public void before() throws TopiaException { + tx = db.beginTransaction(); + aDAO = getDao(tx, A61.class); + bDAO = getDao(tx, B61.class); + } + + @Test + public void create() throws TopiaException { + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + + A61 a = aDAO.create(); + B61 b = bDAO.create(); + B61 b2 = bDAO.create(); + B61 b3 = bDAO.create(); + + a.addRoleB61(b); + a.addRoleB61(b2); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(3, nbB); + + A61 aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + Assert.assertEquals(2, aBis.sizeRoleB61()); + List<B61> bs = aBis.getRoleB61(); + Assert.assertEquals(b, bs.get(0)); + Assert.assertEquals(b2, bs.get(1)); + + // change order + List<B61> bsBis; + + bsBis = Lists.newArrayList(); + bsBis.add(b2); + bsBis.add(b); + a.setRoleB61(bsBis); + tx.commit(); + + aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + Assert.assertEquals(2, aBis.sizeRoleB61()); + bs = aBis.getRoleB61(); + Assert.assertEquals(b2, bs.get(0)); + Assert.assertEquals(b, bs.get(1)); + + // rechange order + + bsBis = Lists.newArrayList(); + bsBis.add(b3); + bsBis.add(b2); + bsBis.add(b); + a.setRoleB61(bsBis); + tx.commit(); + + aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + Assert.assertEquals(3, aBis.sizeRoleB61()); + bs = aBis.getRoleB61(); + Assert.assertEquals(b3, bs.get(0)); + Assert.assertEquals(b2, bs.get(1)); + Assert.assertEquals(b, bs.get(2)); + } + +} \ No newline at end of file Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test6/SimpleOneToManyWithRoleNamedIndexedTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test7/SimpleOneToManyOrderByTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test7/SimpleOneToManyOrderByTest.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test7/SimpleOneToManyOrderByTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,135 @@ + +package org.nuiton.topia.it.mapping.test7; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import com.google.common.collect.Lists; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +import org.nuiton.topia.it.mapping.AbstractMappingTest; +import org.nuiton.topia.it.mapping.TopiaItMappingTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; + +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +/** + * Tests the tag-value {@code ordere-by} on a {@code OneToMany} relation. + * + * @author tchemit <chemit@codelutin.com> + * @since 3.0 + */ +public class SimpleOneToManyOrderByTest extends AbstractMappingTest { + + protected TopiaItMappingTopiaPersistenceContext tx; + + protected A71TopiaDao aDAO; + + protected B71TopiaDao bDAO; + + @Before + public void before() throws TopiaException { + tx = db.beginTransaction(); + aDAO = getDao(tx, A71.class); + bDAO = getDao(tx, B71.class); + } + + @Test + public void create() throws TopiaException { + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + + A71 a = aDAO.create(); + B71 b = bDAO.create(B71.PROPERTY_NAME, "A"); + B71 b2 = bDAO.create(B71.PROPERTY_NAME, "B"); + B71 b3 = bDAO.create(B71.PROPERTY_NAME, "C"); + + a.addB71(b); + a.addB71(b2); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(3, nbB); + + A71 aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + Assert.assertEquals(2, aBis.sizeB71()); + Collection<B71> bs = aBis.getB71(); + Iterator<B71> iterator = bs.iterator(); + Assert.assertEquals(b, iterator.next()); + Assert.assertEquals(b2, iterator.next()); + + // change order + List<B71> bsBis; + + bsBis = Lists.newArrayList(); + bsBis.add(b2); + bsBis.add(b); + aBis.setB71(bsBis); + tx.commit(); + + tx.getHibernateSupport().getHibernateSession().clear(); + + aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + Assert.assertEquals(2, aBis.sizeB71()); + bs = aBis.getB71(); + iterator = bs.iterator(); + Assert.assertEquals(b, iterator.next()); + Assert.assertEquals(b2, iterator.next()); + + // rechange order + + bsBis = Lists.newArrayList(); + bsBis.add(b3); + bsBis.add(b2); + bsBis.add(b); + aBis.setB71(bsBis); + tx.commit(); + + tx.getHibernateSupport().getHibernateSession().clear(); + + aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + Assert.assertEquals(3, aBis.sizeB71()); + bs = aBis.getB71(); + iterator = bs.iterator(); + Assert.assertEquals(b, iterator.next()); + Assert.assertEquals(b2, iterator.next()); + Assert.assertEquals(b3, iterator.next()); + } +} \ No newline at end of file Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test7/SimpleOneToManyOrderByTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test7/SimpleOneToManyOrderedTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test7/SimpleOneToManyOrderedTest.java (rev 0) +++ trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test7/SimpleOneToManyOrderedTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -0,0 +1,126 @@ + +package org.nuiton.topia.it.mapping.test7; + +/* + * #%L + * ToPIA :: IT + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2014 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% + */ + +import com.google.common.collect.Lists; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +import org.nuiton.topia.it.mapping.AbstractMappingTest; +import org.nuiton.topia.it.mapping.TopiaItMappingTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; + +import java.util.List; + +/** + * Tests the stereotype {@code orderered} on a {@code OneToMany} relation. + * + * @author tchemit <chemit@codelutin.com> + * @since 3.0 + */ +public class SimpleOneToManyOrderedTest extends AbstractMappingTest { + + protected TopiaItMappingTopiaPersistenceContext tx; + + protected A7TopiaDao aDAO; + + protected B7TopiaDao bDAO; + + @Before + public void before() throws TopiaException { + tx = db.beginTransaction(); + aDAO = getDao(tx, A7.class); + bDAO = getDao(tx, B7.class); + } + + @Test + public void create() throws TopiaException { + + long nbA = aDAO.count(); + long nbB = bDAO.count(); + + Assert.assertEquals(0, nbA); + Assert.assertEquals(0, nbB); + + A7 a = aDAO.create(); + B7 b = bDAO.create(); + B7 b2 = bDAO.create(); + B7 b3 = bDAO.create(); + + a.addB7(b); + a.addB7(b2); + + tx.commit(); + + nbA = aDAO.count(); + nbB = bDAO.count(); + + Assert.assertEquals(1, nbA); + Assert.assertEquals(3, nbB); + + A7 aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + Assert.assertEquals(2, aBis.sizeB7()); + List<B7> bs = aBis.getB7(); + Assert.assertEquals(b, bs.get(0)); + Assert.assertEquals(b2, bs.get(1)); + + // change order + List<B7> bsBis; + + bsBis = Lists.newArrayList(); + bsBis.add(b2); + bsBis.add(b); + a.setB7(bsBis); + tx.commit(); + + aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + Assert.assertEquals(2, aBis.sizeB7()); + bs = aBis.getB7(); + Assert.assertEquals(b2, bs.get(0)); + Assert.assertEquals(b, bs.get(1)); + + // rechange order + + bsBis = Lists.newArrayList(); + bsBis.add(b3); + bsBis.add(b2); + bsBis.add(b); + a.setB7(bsBis); + tx.commit(); + + aBis = aDAO.findByTopiaId(a.getTopiaId()); + Assert.assertEquals(a, aBis); + Assert.assertEquals(3, aBis.sizeB7()); + bs = aBis.getB7(); + Assert.assertEquals(b3, bs.get(0)); + Assert.assertEquals(b2, bs.get(1)); + Assert.assertEquals(b, bs.get(2)); + } +} \ No newline at end of file Property changes on: trunk/topia-it/src/test/java/org/nuiton/topia/it/mapping/test7/SimpleOneToManyOrderedTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/topia-it/src/test/java/org/nuiton/topia/persistence/internal/TopiaDaoTest.java =================================================================== --- trunk/topia-it/src/test/java/org/nuiton/topia/persistence/internal/TopiaDaoTest.java 2014-03-14 16:31:08 UTC (rev 3031) +++ trunk/topia-it/src/test/java/org/nuiton/topia/persistence/internal/TopiaDaoTest.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -32,7 +32,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.nuiton.topia.it.legacy.TopiaDatabase; +import org.nuiton.topia.it.legacy.TopiaItLegacyDatabase; import org.nuiton.topia.it.legacy.TopiaItLegacyTopiaPersistenceContext; import org.nuiton.topia.it.legacy.test.entities.Person; import org.nuiton.topia.it.legacy.test.entities.PersonTopiaDao; @@ -50,7 +50,7 @@ public class TopiaDaoTest { // Should not be located in topia-it module @Rule - public final TopiaDatabase db = new TopiaDatabase(); + public final TopiaItLegacyDatabase db = new TopiaItLegacyDatabase(); protected TopiaItLegacyTopiaPersistenceContext context; Modified: trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityHibernateMappingGenerator.java =================================================================== --- trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityHibernateMappingGenerator.java 2014-03-14 16:31:08 UTC (rev 3031) +++ trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityHibernateMappingGenerator.java 2014-03-14 17:23:52 UTC (rev 3032) @@ -315,7 +315,8 @@ // / *{ <one-to-one name="<%=getName(attr, true)%>" class="<%=getType(attr, true)%>"<%=(TopiaGeneratorUtil.notEmpty(attr.getTagValue(TopiaGeneratorUtil.TAG_LENGTH))?(" length=\"" + attr.getTagValue(TopiaGeneratorUtil.TAG_LENGTH) + "\""):"")%><%=(attr.isComposite()?" cascade=\"delete\"":"")%>/> // } */ // } else { - String notNull = " " + generateFromTagValue(HIBERNATE_ATTRIBUTE_NOT_NULL, TopiaGeneratorUtil.getNotNullTagValue(attr)); +// String notNull = " " + generateFromTagValue(HIBERNATE_ATTRIBUTE_NOT_NULL, TopiaGeneratorUtil.getNotNullTagValue(attr)); + String notNull = " " + generateFromTagValue(HIBERNATE_ATTRIBUTE_NOT_NULL, "true"); // AThimel 14/03/2014 I think both assoc class participants must always be not-null String attrName = getName(attr, true); String attrType = getType(attr, true); String lazy = generateFromTagValue(HIBERNATE_ATTRIBUTE_LAZY, TopiaGeneratorUtil.getLazyTagValue(attr));