r2524 - in trunk: . topia-persistence-hibernate/src/test/resources topia-persistence-tck topia-persistence-tck/src/test/java/org/nuiton/topia/tck topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/operation topia-persistence-tck/src/test/resources/META-INF/services topia-service-migration/src/main/java/org/nuiton/topia/migration/mappings topia-service-replication topia-service-replication/src/main/java/org
Author: tchemit Date: 2012-05-24 09:53:22 +0200 (Thu, 24 May 2012) New Revision: 2524 Url: http://nuiton.org/repositories/revision/topia/2524 Log: move replication test in tck Added: trunk/topia-persistence-hibernate/src/test/resources/TopiaContext-replication.properties trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/AbstractTopiaReplicationServiceTest.java trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/ReplicationModelFixtures.java trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/TopiaDatabaseReplication.java trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/TopiaReplicationOperationTest.java trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/TopiaReplicationServiceImplAllTest.java trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/TopiaReplicationServiceImplTest.java trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/operation/ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/operation/FakeOperation.java trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/operation/UncreatableOperation.java trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/operation/UnregistredOperation.java trunk/topia-persistence-tck/src/test/resources/META-INF/services/org.nuiton.topia.replication.TopiaReplicationOperation Removed: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/AbstractTopiaReplicationServiceTest.java trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/ModelFixture.java trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaDatabaseLegacy.java trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationOperationTest.java trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplAllTest.java trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplTest.java trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/FakeOperation.java trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/UncreatableOperation.java trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/UnregistredOperation.java trunk/topia-service-replication/src/test/resources/META-INF/services/org.nuiton.topia.replication.TopiaReplicationOperation trunk/topia-service-replication/src/test/resources/TopiaContext-legacy.properties Modified: trunk/pom.xml trunk/topia-persistence-tck/pom.xml trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/mappings/TMSVersionDAO.java trunk/topia-service-replication/pom.xml trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationModelBuilder.java Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2012-05-23 18:34:02 UTC (rev 2523) +++ trunk/pom.xml 2012-05-24 07:53:22 UTC (rev 2524) @@ -40,9 +40,9 @@ <modules> <module>topia-persistence</module> + <module>topia-service-replication</module> <module>topia-persistence-tck</module> <module>topia-persistence-hibernate</module> - <module>topia-service-replication</module> <module>topia-service-migration</module> <module>topia-service-security</module> <!-- Copied: trunk/topia-persistence-hibernate/src/test/resources/TopiaContext-replication.properties (from rev 2523, trunk/topia-service-replication/src/test/resources/TopiaContext-legacy.properties) =================================================================== --- trunk/topia-persistence-hibernate/src/test/resources/TopiaContext-replication.properties (rev 0) +++ trunk/topia-persistence-hibernate/src/test/resources/TopiaContext-replication.properties 2012-05-24 07:53:22 UTC (rev 2524) @@ -0,0 +1,16 @@ +# Proprietes par defaut pour une base de donnees de type H2 et le model legacy +hibernate.hbm2ddl.auto=update +hibernate.show_sql=false + +hibernate.dialect=org.hibernate.dialect.H2Dialect + +topia.use.hibernate.mapping.files=false +topia.connection.username=sa +topia.connection.password=sa +topia.connection.driver_class=org.h2.Driver + +#Not necessary, but useful +hibernate.connection.provider_class=org.nuiton.topia.framework.TopiaHibernateConnectionProvider + +# replication service +topia.service.replication=org.nuiton.topia.replication.TopiaReplicationServiceImpl \ No newline at end of file Modified: trunk/topia-persistence-tck/pom.xml =================================================================== --- trunk/topia-persistence-tck/pom.xml 2012-05-23 18:34:02 UTC (rev 2523) +++ trunk/topia-persistence-tck/pom.xml 2012-05-24 07:53:22 UTC (rev 2524) @@ -28,6 +28,12 @@ </dependency> <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>topia-service-replication</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-jpa_2.0_spec</artifactId> </dependency> Copied: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/AbstractTopiaReplicationServiceTest.java (from rev 2523, trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/AbstractTopiaReplicationServiceTest.java) =================================================================== --- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/AbstractTopiaReplicationServiceTest.java (rev 0) +++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/AbstractTopiaReplicationServiceTest.java 2012-05-24 07:53:22 UTC (rev 2524) @@ -0,0 +1,653 @@ +/* + * #%L + * ToPIA :: Service Replication + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package org.nuiton.topia.tck.replication; + +import org.apache.commons.logging.Log; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.nuiton.i18n.I18n; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaContextImplementor; +import org.nuiton.topia.framework.TopiaUtil; +import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.TopiaEntityEnum; +import org.nuiton.topia.persistence.util.EntityOperator; +import org.nuiton.topia.persistence.util.EntityOperatorStore; +import org.nuiton.topia.persistence.util.TopiaEntityHelper; +import org.nuiton.topia.replication.TopiaReplicationModelBuilder; +import org.nuiton.topia.replication.TopiaReplicationOperation; +import org.nuiton.topia.replication.TopiaReplicationService; +import org.nuiton.topia.replication.model.ReplicationModel; +import org.nuiton.topia.replication.model.ReplicationNode; +import org.nuiton.topia.replication.model.ReplicationOperationDef; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Set; + +/** + * TopiaReplicationServiceImplTest. + * <p/> + * Created: 07 jun. 09 17:14:22 + * + * @author tchemit <chemit@codelutin.com> + * @version $Id$ + * @since 2.2.0 + */ +public abstract class AbstractTopiaReplicationServiceTest extends Assert { + + protected TopiaContext context; + + protected TopiaContext ctxt; + + protected TopiaContextImplementor dstCtxt; + + protected TopiaReplicationService service; + + protected ReplicationModel model; + + @Rule + public final TopiaDatabaseReplication db = new TopiaDatabaseReplication("-source"); + + protected TopiaDatabaseReplication db2; + + @BeforeClass + public static void before() { + I18n.setDefaultLocale(Locale.FRANCE); + } + + public void setUp() throws Exception { + + context = db.getRootCtxt(); + + db.createDb(); + + ctxt = db.beginTransaction(); + + service = db.getReplicationService(); + } + + public void tearDown() throws Exception { + service = null; + context = null; + ctxt = null; + dstCtxt = null; + model = null; + if (db2 != null) { + db2.finished(db2.getDescription()); + } + + } + + protected TopiaReplicationModelBuilder getModelBuilder() { + return service.getModelBuilder(); + } + + protected TopiaContext createDb2(String name) throws Exception { + + db2 = new TopiaDatabaseReplication(name + "-target"); + + // creates new db + db2.starting(db.getDescription()); + + return db2.getRootCtxt(); + } + + protected TopiaContext createReplicateDb(Object contract) throws Exception { + TopiaContext rootCtxt = createDb2(contract.toString() + dbCounter++); + return rootCtxt; + } + + protected abstract TopiaEntityEnum[] getContracts(); + + protected abstract Log getLog(); + + /** + * Test of detectTypes method, of class ReplicationServiceImplementor. + * + * @throws Exception if any error + */ + public void testDetectTypes() throws Exception { + } + + /** + * Test of getOperation method, of class ReplicationServiceImplementor. + * + * @throws Exception if any error + */ + public void testGetOperation() throws Exception { + } + + /** + * Test of detectAssociations method, of class ReplicationModel. + * + * @throws Exception if any error + */ + public void testDetectAssociations() throws Exception { + } + + /** + * Test of detectDirectDependencies method, of class ReplicationModel. + * + * @throws Exception if any error + */ + public void testDetectDirectDependencies() throws Exception { + } + + /** + * Test of detectShell method, of class ReplicationModel. + * + * @throws Exception if any error + */ + public void testDetectShell() throws Exception { + } + + /** + * Test of detectDependencies method, of class ReplicationModel. + * + * @throws Exception if any error + */ + public void testDetectDependencies() throws Exception { + } + + /** + * Test of detectObjectsToDettach method, of class ReplicationModel. + * + * @throws Exception if any error + */ + public void testDetectObjectsToDettach() throws Exception { + } + + /** + * Test of detectOperations method, of class ReplicationModel. + * + * @throws Exception if any error + */ + public void testDetectOperations() throws Exception { + } + + /** + * Test of doReplicate method, of class ReplicationService. + * + * @throws Exception if any error + */ + public void testDoReplicate() throws Exception { + } + + protected void detectTypes(TopiaEntity entity, Object... expectedCouple) throws TopiaException { + + Set<?> detectTypes; + + detectTypes = service.getModelBuilder().detectTypes(context, getContracts(), entity.getTopiaId()); + assertEquals("expected types : " + + Arrays.toString(expectedCouple) + + " but was " + detectTypes, + expectedCouple.length, detectTypes.size()); + for (Object o : expectedCouple) { + assertTrue(detectTypes.contains(o)); + } + } + + protected void getOperation(Class<? extends TopiaReplicationOperation> operationClass, boolean shouldExist) throws TopiaException { + TopiaReplicationOperation operation = getModelBuilder().getOperationProvider().getOperation(operationClass); + assertEquals(shouldExist, operation != null); + } + + protected void detectAssociations(TopiaEntity entity, + Object... expectedCouple) + throws TopiaException { + + createModel(entity); + model.detectAssociations(); + + assertEquals(0, expectedCouple.length % 2); + + for (int i = 0, j = expectedCouple.length / 2; i < j; i++) { + TopiaEntityEnum src = (TopiaEntityEnum) expectedCouple[2 * i]; + String name = (String) expectedCouple[2 * i + 1]; + ReplicationNode nodeSrc = model.getNode(src); + assertNotNull("association " + name + " not found", nodeSrc); + assertTrue(nodeSrc.hasAssociation()); + assertTrue(nodeSrc.getAssociations().containsKey(name)); + } + } + + protected void detectDirectDependencies(TopiaEntity entity, + Object... expectedCouple) + throws TopiaException { + + createModel(entity); + model.detectDirectDependencies(); + + assertEquals(0, expectedCouple.length % 2); + + for (int i = 0, j = expectedCouple.length / 2; i < j; i++) { + TopiaEntityEnum src = (TopiaEntityEnum) expectedCouple[2 * i]; + String name = (String) expectedCouple[2 * i + 1]; + ReplicationNode nodeSrc = model.getNode(src); + assertTrue(nodeSrc + " should have dependency but was not!", nodeSrc.hasDependency()); + assertTrue(nodeSrc + " should contain dependency " + name + "but was not! (" + nodeSrc.getDependencies() + ")", nodeSrc.getDependencies().containsKey(name)); + } + } + + protected void detectShell(TopiaEntity entity, + TopiaEntityEnum... expected) throws + TopiaException { + Set<ReplicationNode> shell; + + createModel(entity); + model.detectAssociations(); + model.detectDirectDependencies(); + model.detectShell(); + + TopiaEntityEnum c = TopiaEntityHelper.getEntityEnum( + entity.getClass(), getContracts()); + assertNotNull(c); + shell = model.getNode(c).getShell(); + assertEquals( + "expected shell : " + Arrays.toString(expected) + ", but was " + + shell, expected.length, shell.size()); + + for (TopiaEntityEnum type : expected) { + ReplicationNode node = model.getNode(type); + assertTrue(shell.contains(node)); + assertEquals(type, node.getContract()); + } + } + + protected void detectDependencies( + TopiaEntity entity, + TopiaEntityEnum[]... expected) throws TopiaException { + + createModel(entity); + model.detectAssociations(); + model.detectDirectDependencies(); + model.detectShell(); + model.detectDependencies(); + List<ReplicationNode> dependencies = model.getOrder(); + + int i = 0; + for (ReplicationNode level : dependencies) { + getLog().info("level " + level + " = " + level); + } + +// assertEquals("expected " + expected.length + " levels but had " + dependencies.size(), expected.length, dependencies.size()); +// +// Iterator<List<ReplicationNode>> order = dependencies.iterator(); +// if (entity != null) { +// getLog().info("for " + entity.getTopiaId()); +// } +// int index = 0; +// for (TopiaEntityEnum[] expectedLevel : expected) { +// +// List<ReplicationNode> next = order.next(); +// getLog().info("level " + (index++) + " : " + next); +// for (TopiaEntityEnum ee : expectedLevel) { +// ReplicationNode expectedNode = model.getNode(ee); +// +// assertTrue("should have contains node " + expectedNode, next.contains(expectedNode)); +// } +// +// } + } + + protected void detectObjectsToDettach(TopiaEntity entity, Object... expected) throws TopiaException { + + assertEquals(0, expected.length % 2); + + createModel(entity); + model.detectAssociations(); + model.detectDirectDependencies(); + model.detectShell(); + model.detectDependencies(); + model.detectObjectsToDettach(); + Set<ReplicationNode> nodes = new HashSet<ReplicationNode>(); + + for (int i = 0, j = expected.length / 2; i < j; i++) { + TopiaEntityEnum e = (TopiaEntityEnum) expected[2 * i]; + ReplicationNode node = model.getNode(e); + String[] ids = (String[]) expected[2 * i + 1]; + assertEquals(ids.length > 0, node.hasAssociationsToDettach()); + for (String id : ids) { + assertTrue(node.getAssociationsToDettach().contains(id)); + } + nodes.add(node); + } + + for (ReplicationNode node : model.getNodes()) { + if (!nodes.contains(node)) { + // on verifie bien qu'il n' y a pas d'associations dettachee + assertFalse(node.hasAssociationsToDettach()); + } + } + + } + + protected void detectOperations(TopiaEntity entity, Object... expected) throws TopiaException { + + assertEquals(0, expected.length % 2); + + if (entity == null) { + prepareModel(); + } else { + prepareModel(entity.getTopiaId()); + } +// createModel(entity); +// model.detectAssociations(); +// model.detectDirectDependencies(); +// model.detectShell(); +// model.detectDependencies(); +// model.detectObjectsToDettach(); +// model.detectOperations(); + + if (getLog().isInfoEnabled()) { + getLog().info("=========================================================================="); + if (entity == null) { + + getLog().info("resume of operations for all "); + } else { + getLog().info("resume of operations for entity " + entity.getTopiaId()); + } + + for (ReplicationNode node : model.getOrder()) { + ReplicationOperationDef[] operations = node.getOperations(); + for (ReplicationOperationDef op : operations) { + getLog().info("[" + node + "] : operation " + op); + } + } + getLog().info("=========================================================================="); + } + } + + private static int dbCounter; + + protected void doReplicate(TopiaEntityEnum contract, + TopiaEntity... entity) throws Exception { + + TopiaContext rootCtxt = createReplicateDb("doReplicate_" + contract); + + List<String> ids = TopiaUtil.getTopiaIdList(Arrays.asList(entity)); + getLog().info("entity " + ids); + + prepareModel(ids.toArray(new String[ids.size()])); + + dstCtxt = (TopiaContextImplementor) rootCtxt; + + service.doReplicate(model, dstCtxt); + + //dstCtxt.closeContext(); + + if (entity.length == 0) { + + return; + } + dstCtxt = (TopiaContextImplementor) rootCtxt.beginTransaction(); + + for (TopiaEntity e : entity) { + TopiaEntity actual = dstCtxt.findByTopiaId(e.getTopiaId()); + assertNotNull(actual); + assertEquals(e, actual); + } + + dstCtxt.closeContext(); + + dstCtxt = (TopiaContextImplementor) rootCtxt; + } + + protected void doReplicateAll() throws Exception { + + TopiaContext rootCtxt = createReplicateDb("doReplicateAll"); + + prepareModelAll(); + + dstCtxt = (TopiaContextImplementor) rootCtxt; + + service.doReplicate(model, dstCtxt); + + TopiaContextImplementor ctxt2 = (TopiaContextImplementor) ctxt; + dstCtxt = (TopiaContextImplementor) rootCtxt.beginTransaction(); + + assertDbEquals(model.getContracts(), (TopiaContextImplementor) ctxt, ctxt2); + + dstCtxt.closeContext(); + + dstCtxt = (TopiaContextImplementor) rootCtxt; + } + + protected void doReplicateWithComputedOrder(TopiaEntity... entity) throws Exception { + + TopiaContext rootCtxt = createReplicateDb("doReplicateWithComputedOrder"); + + List<String> ids = TopiaUtil.getTopiaIdList(Arrays.asList(entity)); + + prepareModelWithComputedOrder(ids.toArray(new String[ids.size()])); + + dstCtxt = (TopiaContextImplementor) rootCtxt; + + service.doReplicate(model, dstCtxt); + + getLog().info("replication is done for " + Arrays.toString(entity) + ", will verify data..."); + + TopiaContextImplementor ctxt2 = (TopiaContextImplementor) ctxt; + dstCtxt = (TopiaContextImplementor) rootCtxt.beginTransaction(); + + assertDbEquals(model.getContracts(), (TopiaContextImplementor) ctxt, ctxt2); + + dstCtxt.closeContext(); + + dstCtxt = (TopiaContextImplementor) rootCtxt; + } + + protected void assertDbEquals(TopiaEntityEnum[] contracts, + TopiaContextImplementor ctxt, + TopiaContextImplementor ctxt2) throws TopiaException { + Set<String> ids = new HashSet<String>(); + + if (getLog().isInfoEnabled()) { + getLog().info("will verify db for contracts " + Arrays.toString(contracts)); + } + for (TopiaEntityEnum c : contracts) { + if (getLog().isDebugEnabled()) { + getLog().debug("verify for contract " + c); + } + TopiaDAO<? extends TopiaEntity> daoSrc = ctxt.getDAO(c.getContract()); + TopiaDAO<? extends TopiaEntity> daoDst = ctxt2.getDAO(c.getContract()); + long nbSrc = daoSrc.count(); + long nbDst = daoDst.count(); + assertEquals("le nombres d'entites de type " + c + " devrait etre " + nbSrc + " mais est " + nbDst, nbSrc, nbDst); + List<String> idsSrc = daoSrc.findAllIds(); + List<String> idsDst = daoDst.findAllIds(); + Collections.sort(idsSrc); + Collections.sort(idsDst); + assertEquals(idsSrc, idsDst); + for (String id : idsSrc) { + if (getLog().isDebugEnabled()) { + getLog().debug("verify for entity " + id); + } + TopiaEntity eSrc = daoSrc.findByTopiaId(id); + TopiaEntity eDst = daoDst.findByTopiaId(id); + assertEquals(eSrc, eDst); + assertEntityEquals(eSrc, eDst, ids); + } + } + } + + protected void assertEntityEquals(TopiaEntity expected, + TopiaEntity actual, + Set<String> treated) { + if (treated == null) { + treated = new HashSet<String>(); + } + if (treated.contains(actual.getTopiaId())) { + return; + } + if (getLog().isDebugEnabled()) { + getLog().debug(expected); + } + assertEquals(actual.getTopiaId(), expected.getTopiaId()); + treated.add(actual.getTopiaId()); + if (getLog().isDebugEnabled()) { + getLog().debug("expected : " + expected + " / actual " + actual); + } + TopiaEntityEnum contract = TopiaEntityHelper.getEntityEnum(expected.getClass(), getContracts()); + if (contract == null) { + // this type of entity in not dealed here... + getLog().debug("untested property type " + expected.getClass()); + return; + } + Assert.assertNotNull( + "contract not found for " + expected.getClass() + " in " + + Arrays.toString(getContracts()), contract); + EntityOperator<TopiaEntity> operator = EntityOperatorStore.getOperator(contract); + List<String> associationProperties = operator.getAssociationProperties(); + for (String name : associationProperties) { + if (getLog().isDebugEnabled()) { + getLog().debug("association " + name); + } + if (operator.isChildEmpty(name, expected)) { + assertTrue("l'association " + name + " devrait etre vide mais possede " + operator.sizeChild(name, actual) + " entrees", operator.isChildEmpty(name, actual)); + } else { + assertFalse("l'association " + name + " devrait posseder " + operator.isChildEmpty(name, expected) + " mais est vide", operator.isChildEmpty(name, actual)); + + } + assertEquals(operator.isChildEmpty(name, actual), operator.isChildEmpty(name, expected)); + + Class<?> type = operator.getAssociationPropertyType(name); + Collection<?> src = (Collection<?>) operator.get(name, expected); + Collection<?> dst = (Collection<?>) operator.get(name, actual); +// assertEquals(src, dst); + Iterator<?> itrSrc = src.iterator(); + Iterator<?> itrDst = dst.iterator(); + while (itrSrc.hasNext()) { + if (TopiaEntity.class.isAssignableFrom(type)) { + assertEntityEquals((TopiaEntity) itrSrc.next(), (TopiaEntity) itrDst.next(), treated); + } else { + assertEquals(itrSrc.next(), itrDst.next()); + } + } + } + + for (String name : operator.getProperties()) { + if (getLog().isDebugEnabled()) { + getLog().debug("dependency " + name); + } + if (associationProperties.contains(name)) { + // deja traite au dessus + continue; + } + Class<?> type = operator.getPropertyType(name); + Object src = operator.get(name, expected); + Object dst = operator.get(name, actual); + assertFalse(src == null && dst != null); + assertFalse(src != null && dst == null); + if (src == null) { + continue; + } + if (TopiaEntity.class.isAssignableFrom(type)) { + assertEntityEquals((TopiaEntity) src, (TopiaEntity) dst, treated); + } else { + assertEquals(src, dst); + } + } + } + + protected void createSupportedBeforeOperation(TopiaEntityEnum contract, + TopiaEntity entity, + Class<? extends TopiaReplicationOperation> operationClass, + Object... parameters) throws Exception { + + getLog().info("entity " + entity.getTopiaId()); + prepareModel(entity.getTopiaId()); + + getModelBuilder().addBeforeOperation(model, contract, operationClass, parameters); + // on doit avoir le droit de creer cette operation + Assert.assertTrue(true); + } + + protected void createSupportedAfterOperation( + TopiaEntityEnum contract, + TopiaEntity entity, + Class<? extends TopiaReplicationOperation> operationClass, + Object... parameters) throws Exception { + + getLog().info("entity " + entity.getTopiaId()); + prepareModel(entity.getTopiaId()); +// model = service.createModel(getContracts()); +// model.detectDirectDependencies(); + getModelBuilder().addAfterOperation(model, contract, operationClass, parameters); + // on doit avoir le droit de creer cette operation + Assert.assertTrue(true); + } + +// protected Long getTestsTimeStamp() { +// if (testsTimeStamp == null) { +// testsTimeStamp = System.currentTimeMillis(); +// getLog().info("tests timestamp : " + testsTimeStamp); +// } +// return testsTimeStamp; +// } + +// protected File getTestDir(Class<?> testClass) { +// if (testsBasedir == null) { +// String tmp = System.getProperty("basedir"); +// if (tmp == null) { +// tmp = new File("").getAbsolutePath(); +// } +// String name = String.format(TEST_BASEDIR, File.separator, new Date(getTestsTimeStamp())); +// testsBasedir = new File(new File(tmp), name); +// getLog().info("tests basedir : " + testsBasedir); +// } +// return new File(testsBasedir, testClass.getSimpleName()); +// } + + protected void createModel(TopiaEntity entity) throws TopiaException { + model = getModelBuilder().createModel(context, + getContracts(), + true, + entity.getTopiaId() + ); + } + + protected void prepareModel(String... ids) throws TopiaException { + model = service.prepare(getContracts(), true, ids); + } + + protected void prepareModelAll() throws TopiaException { + model = service.prepareForAll(getContracts()); + } + + protected void prepareModelWithComputedOrder(String... ids) throws TopiaException { + model = service.prepare(getContracts(), false, ids); + } +} Property changes on: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/AbstractTopiaReplicationServiceTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/ReplicationModelFixtures.java (from rev 2523, trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/ModelFixture.java) =================================================================== --- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/ReplicationModelFixtures.java (rev 0) +++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/ReplicationModelFixtures.java 2012-05-24 07:53:22 UTC (rev 2524) @@ -0,0 +1,113 @@ +package org.nuiton.topia.tck.replication; + +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaContextImplementor; +import org.nuiton.topia.tck.legacy.TopiaTckLegacyDAOHelper; +import org.nuiton.topia.tck.legacy.entities.Person; +import org.nuiton.topia.tck.legacy.entities.PersonDAO; +import org.nuiton.topia.tck.legacy.entities.Pet; +import org.nuiton.topia.tck.legacy.entities.PetDAO; +import org.nuiton.topia.tck.legacy.entities.Race; +import org.nuiton.topia.tck.legacy.entities.RaceDAO; + +/** + * Fixtures to test replication serivce. + * + * @author tchemit <chemit@codelutin.com> + * @since 3.0 + */ +public class ReplicationModelFixtures { + + public static final String PERSON_NAME = "pudding master"; + + public static final String PERSON2_NAME = "pudding II master"; + + public static final String RACE_NAME = "race I"; + + public static final String RACE2_NAME = "race II"; + + public static final String PET_NAME = "pudding"; + + public static final String PET2_NAME = "pudding II"; + + public static final String RACE3_NAME = "race III"; + + public static final String PET3_NAME = "pudding III"; + + public void createDb(TopiaContext context) throws TopiaException { + + TopiaContextImplementor tx = + (TopiaContextImplementor) context.beginTransaction(); + + try { + PersonDAO personDAO = TopiaTckLegacyDAOHelper.getPersonDAO(tx); + RaceDAO raceDAO = TopiaTckLegacyDAOHelper.getRaceDAO(tx); + PetDAO petDAO = TopiaTckLegacyDAOHelper.getPetDAO(tx); + + Person person = personDAO.create(Person.PROPERTY_NAME, PERSON_NAME); + Race race = raceDAO.create(Race.PROPERTY_NAME, RACE_NAME); + petDAO.create(Pet.PROPERTY_NAME, PET_NAME, Pet.PROPERTY_PERSON, person, Pet.PROPERTY_RACE, race); + + personDAO.create(Person.PROPERTY_NAME, PERSON2_NAME); + petDAO.create(Pet.PROPERTY_NAME, PET2_NAME); + raceDAO.create(Race.PROPERTY_NAME, RACE2_NAME); + + Race race3 = raceDAO.create(Race.PROPERTY_NAME, RACE3_NAME); + petDAO.create(Pet.PROPERTY_NAME, PET3_NAME, Pet.PROPERTY_RACE, race3); + + tx.commitTransaction(); + } finally { + tx.closeContext(); + } + } + + public Person getPerson(TopiaContext tx) throws TopiaException { + PersonDAO personDAO = TopiaTckLegacyDAOHelper.getPersonDAO(tx); + Person result = personDAO.findByName(PERSON_NAME); + return result; + } + + public Person getPerson2(TopiaContext tx) throws TopiaException { + PersonDAO personDAO = TopiaTckLegacyDAOHelper.getPersonDAO(tx); + Person result = personDAO.findByName(PERSON2_NAME); + return result; + } + + public Race getRace(TopiaContext tx) throws TopiaException { + RaceDAO raceDAO = TopiaTckLegacyDAOHelper.getRaceDAO(tx); + Race race = raceDAO.findByName(RACE_NAME); + return race; + } + + public Race getRace2(TopiaContext tx) throws TopiaException { + RaceDAO raceDAO = TopiaTckLegacyDAOHelper.getRaceDAO(tx); + Race race = raceDAO.findByName(RACE2_NAME); + return race; + } + + public Race getRace3(TopiaContext tx) throws TopiaException { + RaceDAO raceDAO = TopiaTckLegacyDAOHelper.getRaceDAO(tx); + Race race = raceDAO.findByName(RACE3_NAME); + return race; + } + + public Pet getPet(TopiaContext tx) throws TopiaException { + PetDAO petDAO = TopiaTckLegacyDAOHelper.getPetDAO(tx); + Pet pet = petDAO.findByName(PET_NAME); + return pet; + } + + public Pet getPet2(TopiaContext tx) throws TopiaException { + PetDAO petDAO = TopiaTckLegacyDAOHelper.getPetDAO(tx); + Pet pet = petDAO.findByName(PET2_NAME); + return pet; + } + + public Pet getPet3(TopiaContext tx) throws TopiaException { + PetDAO petDAO = TopiaTckLegacyDAOHelper.getPetDAO(tx); + Pet pet = petDAO.findByName(PET3_NAME); + return pet; + } + +} Copied: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/TopiaDatabaseReplication.java (from rev 2523, trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaDatabaseLegacy.java) =================================================================== --- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/TopiaDatabaseReplication.java (rev 0) +++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/TopiaDatabaseReplication.java 2012-05-24 07:53:22 UTC (rev 2524) @@ -0,0 +1,61 @@ +package org.nuiton.topia.tck.replication; + +import org.junit.runner.Description; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.replication.TopiaReplicationService; +import org.nuiton.topia.tck.TopiaDatabase; +import org.nuiton.topia.tck.legacy.TopiaTckLegacyDAOHelper; + +/** + * Concrete topia database for {@code it} model. + * + * @author tchemit <chemit@codelutin.com> + * @since 3.0 + */ +public class TopiaDatabaseReplication extends TopiaDatabase { + + private ReplicationModelFixtures fixtures; + + private TopiaReplicationService replicationService; + + public TopiaDatabaseReplication(String classifier) { + super("/TopiaContext-replication.properties", classifier); + } + + @Override + protected Class<? extends TopiaEntity>[] getImplementationClasses() { + return TopiaTckLegacyDAOHelper.getImplementationClasses(); + } + + public ReplicationModelFixtures getFixtures() { + if (fixtures == null) { + fixtures = new ReplicationModelFixtures(); + } + return fixtures; + } + + public TopiaReplicationService getReplicationService() throws TopiaException { + if (replicationService == null) { + replicationService = + getRootCtxt().getService(TopiaReplicationService.class); + } + return replicationService; + } + + public void createDb() throws TopiaException { + + getFixtures().createDb(getRootCtxt()); + + } + + @Override + public void starting(Description description) { + super.starting(description); + } + + @Override + public void finished(Description description) { + super.finished(description); + } +} Copied: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/TopiaReplicationOperationTest.java (from rev 2523, trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationOperationTest.java) =================================================================== --- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/TopiaReplicationOperationTest.java (rev 0) +++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/TopiaReplicationOperationTest.java 2012-05-24 07:53:22 UTC (rev 2524) @@ -0,0 +1,283 @@ +/* + * #%L + * ToPIA :: Service Replication + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package org.nuiton.topia.tck.replication; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Before; +import org.junit.Test; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.persistence.TopiaEntityEnum; +import org.nuiton.topia.replication.TopiaReplicationModelBuilder; +import org.nuiton.topia.replication.TopiaReplicationOperation; +import org.nuiton.topia.replication.model.ReplicationOperationPhase; +import org.nuiton.topia.replication.operation.DettachAssociation; +import org.nuiton.topia.replication.operation.Duplicate; +import org.nuiton.topia.tck.replication.operation.FakeOperation; +import org.nuiton.topia.tck.replication.operation.UncreatableOperation; +import org.nuiton.topia.tck.replication.operation.UnregistredOperation; +import org.nuiton.topia.tck.legacy.entities.Person; +import org.nuiton.topia.tck.legacy.entities.Pet; +import org.nuiton.topia.tck.legacy.entities.Race; + +import java.io.File; + +import static org.nuiton.topia.tck.legacy.TopiaTckLegacyDAOHelper.TopiaTckLegacyEntityEnum; + +/** + * TopiaReplicationServiceImplTest on model TopiaTest + * <p/> + * Created: 07 jun. 09 17:14:22 + * + * @author tchemit <chemit@codelutin.com> + * @since 2.2.0 + */ +public class TopiaReplicationOperationTest extends AbstractTopiaReplicationServiceTest { + + /** Logger */ + private static final Log log = + LogFactory.getLog(TopiaReplicationOperationTest.class); + + protected static final TopiaEntityEnum[] contracts = { + TopiaTckLegacyEntityEnum.Person, + TopiaTckLegacyEntityEnum.Pet, + TopiaTckLegacyEntityEnum.Race + }; + +// protected static final String entitiesList = +// PersonImpl.class.getName() + "," + +// PetImpl.class.getName() + "," + +// RaceImpl.class.getName(); + + static protected Person person, person2; + + static protected Pet pet, pet2; + + static protected Race race, race2; + + protected static File tesDir; + + @Before + @Override + public void setUp() throws Exception { + + super.setUp(); + + ReplicationModelFixtures fixtures = db.getFixtures(); + + person = fixtures.getPerson(ctxt); + person2 = fixtures.getPerson2(ctxt); + pet = fixtures.getPet(ctxt); + pet2 = fixtures.getPet2(ctxt); + race = fixtures.getRace(ctxt); + race2 = fixtures.getRace2(ctxt); + + } + + @Test(expected = NullPointerException.class) + public void testGetOperation_nullOperationClass() throws Exception { + getModelBuilder().getOperationProvider().getOperation((Class<? extends TopiaReplicationOperation>) null); + } + + protected TopiaReplicationModelBuilder getModelBuilder() { + return service.getModelBuilder(); + } + + @Test + @Override + public void testGetOperation() throws Exception { + + getOperation(UnregistredOperation.class, false); + getOperation(UncreatableOperation.class, true); + getOperation(FakeOperation.class, true); + getOperation(Duplicate.class, true); + getOperation(DettachAssociation.class, true); + } + + @Test(expected = NullPointerException.class) + public void testCreateOperation_nullModel() throws Exception { + getModelBuilder().createOperation(null, null, null, null); + } + + @Test(expected = NullPointerException.class) + public void testCreateOperation_nullType() throws Exception { + + model = getModelBuilder().createModel(context, contracts, true); + getModelBuilder().createOperation(model, null, null, null); + } + + @Test(expected = NullPointerException.class) + public void testCreateOperation_nullPhase() throws Exception { + + model = getModelBuilder().createModel(context, contracts, true); + getModelBuilder().createOperation(model, TopiaTckLegacyEntityEnum.Pet, null, null); + } + + @Test(expected = NullPointerException.class) + public void testCreateOperation_nullOperationClass() throws Exception { + + model = getModelBuilder().createModel(context, contracts, true); + getModelBuilder().createOperation(model, TopiaTckLegacyEntityEnum.Pet, ReplicationOperationPhase.before, null); + } + + @Test(expected = IllegalArgumentException.class) + public void testCreateOperation_noNode() throws Exception { + + model = getModelBuilder().createModel(context, contracts, true); + // le noeud Pet n'existe pas + getModelBuilder().addAfterOperation(model, TopiaTckLegacyEntityEnum.Pet, Duplicate.class); + } + + @Test(expected = IllegalArgumentException.class) + public void testCreateOperation_noOperation() throws Exception { + + model = getModelBuilder().createModel(context, contracts, true); + // le noeud Pet n'existe pas + getModelBuilder().addAfterOperation(model, TopiaTckLegacyEntityEnum.Pet, UnregistredOperation.class); + } + + @Test +// @Test(expected = UnsupportedOperationException.class) + public void testCreateSupportedBeforeOperation_Duplicate() throws Exception { + createSupportedBeforeOperation(TopiaTckLegacyEntityEnum.Person, person, Duplicate.class); + } + +// @Test(expected = UnsupportedOperationException.class) +// public void testCreateUnsupportedBeforeOperation_AttachAssociation() throws Exception { +// createUnsupportedBeforeOperation(TopiaTckItEntityEnum.Person, person, AttachAssociation.class); +// } + + @Test +// @Test(expected = UnsupportedOperationException.class) + public void testCreateSupportedBeforeOperation_DetachAssociation() throws Exception { + createSupportedBeforeOperation(TopiaTckLegacyEntityEnum.Person, person, DettachAssociation.class); + } + + @Test +// @Test(expected = UnsupportedOperationException.class) + public void testCreateSupportedAfterOperation_Duplicate() throws Exception { + createSupportedAfterOperation(TopiaTckLegacyEntityEnum.Person, person, Duplicate.class); + } + +// @Test(expected = UnsupportedOperationException.class) +// public void testCreateSupportedAfterOperation_AttachAssociation() throws Exception { +// createUnsupportedAfterOperation(TopiaTckItEntityEnum.Person, person, AttachAssociation.class); +// } + + @Test +// @Test(expected = UnsupportedOperationException.class) + public void testCreateSupportedAfterOperation_DetachAssociation() throws Exception { + createSupportedAfterOperation(TopiaTckLegacyEntityEnum.Person, person, DettachAssociation.class); + } + +// @Test(expected = UnsupportedOperationException.class) +// public void testCreateUnsupportedBeforeOperation_UncreatableOperation() throws Exception { +// createUnsupportedBeforeOperation(TopiaTckItEntityEnum.Person, person, UncreatableOperation.class); +// } + +// @Test(expected = UnsupportedOperationException.class) +// public void testCreateUnsupportedAfterOperation_UncreatableOperation() throws Exception { +// createUnsupportedAfterOperation(TopiaTckItEntityEnum.Person, person, UncreatableOperation.class); +// } + + @Test + public void testCreateOperation() throws Exception { + + model = getModelBuilder().createModel(context, contracts, true, pet.getTopiaId()); + getModelBuilder().addBeforeOperation(model, TopiaTckLegacyEntityEnum.Pet, FakeOperation.class, "before"); + getModelBuilder().addAfterOperation(model, TopiaTckLegacyEntityEnum.Race, FakeOperation.class, "after"); + } + + @Test(expected = NullPointerException.class) + public void testDoReplicate_nullModel() throws Exception { + + service.doReplicate(null, null); + } + + @Test(expected = NullPointerException.class) + public void testDoReplicate_nullDstCtxt() throws Exception { + + model = getModelBuilder().createModel(context, contracts, true); + service.doReplicate(model, null); + } + + @Override + protected TopiaEntityEnum[] getContracts() { + return contracts; + } + + @Override + protected Log getLog() { + return log; + } + + @Override + protected TopiaContext createDb2(String name) throws Exception { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void testDetectTypes() throws Exception { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void testDetectAssociations() throws Exception { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void testDetectDirectDependencies() throws Exception { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void testDetectShell() throws Exception { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void testDetectDependencies() throws Exception { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void testDetectObjectsToDettach() throws Exception { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void testDetectOperations() throws Exception { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void testDoReplicate() throws Exception { + throw new UnsupportedOperationException("Not supported yet."); + } +} + + Property changes on: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/TopiaReplicationOperationTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/TopiaReplicationServiceImplAllTest.java (from rev 2523, trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplAllTest.java) =================================================================== --- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/TopiaReplicationServiceImplAllTest.java (rev 0) +++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/TopiaReplicationServiceImplAllTest.java 2012-05-24 07:53:22 UTC (rev 2524) @@ -0,0 +1,199 @@ +/* + * #%L + * ToPIA :: Service Replication + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package org.nuiton.topia.tck.replication; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Before; +import org.junit.Test; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.TopiaEntityEnum; +import org.nuiton.topia.tck.legacy.entities.Person; +import org.nuiton.topia.tck.legacy.entities.Pet; +import org.nuiton.topia.tck.legacy.entities.Race; + +import static org.nuiton.topia.tck.legacy.TopiaTckLegacyDAOHelper.TopiaTckLegacyEntityEnum; + +/** + * TopiaReplicationServiceImplTest on model TopiaTest + * <p/> + * Created: 07 jun. 09 17:14:22 + * + * @author tchemit <chemit@codelutin.com> + * @since 2.2.0 + */ +public class TopiaReplicationServiceImplAllTest extends AbstractTopiaReplicationServiceTest { + + /** Logger */ + private static final Log log = + LogFactory.getLog(TopiaReplicationServiceImplTest.class); + + protected static final TopiaEntityEnum[] contracts = { + TopiaTckLegacyEntityEnum.Person, + TopiaTckLegacyEntityEnum.Pet, + TopiaTckLegacyEntityEnum.Race + }; + + protected Person person, person2; + + protected Pet pet, pet2, pet3; + + protected Race race, race2, race3; + + @Before + @Override + public void setUp() throws Exception { + + super.setUp(); + + // get data + + ReplicationModelFixtures fixtures = db.getFixtures(); + + person = fixtures.getPerson(ctxt); + person2 = fixtures.getPerson2(ctxt); + pet = fixtures.getPet(ctxt); + pet2 = fixtures.getPet2(ctxt); + pet3 = fixtures.getPet3(ctxt); + race = fixtures.getRace(ctxt); + race2 = fixtures.getRace2(ctxt); + race3 = fixtures.getRace3(ctxt); + } + + @Test + @Override + public void testDetectTypes() throws Exception { + + detectTypes(race, Race.class); + detectTypes(pet, Pet.class, Person.class, Race.class); + detectTypes(person, Pet.class, Person.class, Race.class); + + detectTypes(pet2, Pet.class); + detectTypes(person2, Person.class); + detectTypes(race2, Race.class); + + detectTypes(race3, Race.class); + detectTypes(pet3, Pet.class, Race.class); + } + + @Test + @Override + public void testGetOperation() throws Exception { + } + + @Test + @Override + public void testDetectAssociations() throws Exception { + + detectAssociations(person, TopiaTckLegacyEntityEnum.Person, Person.PROPERTY_PET); + detectAssociations(race); + detectAssociations(pet); + + detectAssociations(person2); + detectAssociations(race2); + detectAssociations(pet2); + + } + + @Test + @Override + public void testDetectDirectDependencies() throws Exception { + + detectDirectDependencies(person); + detectDirectDependencies(race); + detectDirectDependencies(pet, TopiaTckLegacyEntityEnum.Pet, Pet.PROPERTY_PERSON, TopiaTckLegacyEntityEnum.Pet, Pet.PROPERTY_RACE); + + detectDirectDependencies(person2); + detectDirectDependencies(race2); + detectDirectDependencies(pet2); + } + + @Test + @Override + public void testDetectShell() throws Exception { + + detectShell(person, TopiaTckLegacyEntityEnum.Pet, TopiaTckLegacyEntityEnum.Race); + detectShell(race); + detectShell(pet, TopiaTckLegacyEntityEnum.Person, TopiaTckLegacyEntityEnum.Race); + detectShell(person2, TopiaTckLegacyEntityEnum.Pet, TopiaTckLegacyEntityEnum.Race); + detectShell(race2); + detectShell(pet2, TopiaTckLegacyEntityEnum.Person, TopiaTckLegacyEntityEnum.Race); + } + + @Test + @Override + public void testDetectDependencies() throws Exception { + + detectDependencies(null, + new TopiaTckLegacyEntityEnum[]{TopiaTckLegacyEntityEnum.Race}, new TopiaTckLegacyEntityEnum[]{TopiaTckLegacyEntityEnum.Person}, new TopiaTckLegacyEntityEnum[]{TopiaTckLegacyEntityEnum.Pet}); + } + + @Test + @Override + public void testDetectObjectsToDettach() throws Exception { + + detectObjectsToDettach(null, TopiaTckLegacyEntityEnum.Person, new String[]{Person.PROPERTY_PET}); + } + + @Test + @Override + public void testDetectOperations() throws Exception { + + detectOperations(null); + } + + @Test + @Override + public void testDoReplicate() throws Exception { + + doReplicateAll(); + + } + + @Override + protected TopiaEntityEnum[] getContracts() { + return contracts; + } + + @Override + protected Log getLog() { + return log; + } + + @Override + protected void createModel(TopiaEntity entity) throws TopiaException { + model = getModelBuilder().createModelForAll(getContracts()); + } + + @Override + protected void prepareModel(String... ids) throws TopiaException { + model = service.prepareForAll(getContracts()); + } + +} + + Property changes on: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/TopiaReplicationServiceImplAllTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/TopiaReplicationServiceImplTest.java (from rev 2523, trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplTest.java) =================================================================== --- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/TopiaReplicationServiceImplTest.java (rev 0) +++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/TopiaReplicationServiceImplTest.java 2012-05-24 07:53:22 UTC (rev 2524) @@ -0,0 +1,367 @@ +/* + * #%L + * ToPIA :: Service Replication + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package org.nuiton.topia.tck.replication; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Before; +import org.junit.Test; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaContextImplementor; +import org.nuiton.topia.persistence.TopiaEntityEnum; +import org.nuiton.topia.persistence.util.TopiaEntityIdsMap; +import org.nuiton.topia.replication.model.ReplicationModel; +import org.nuiton.topia.replication.operation.DettachAssociation; +import org.nuiton.topia.replication.operation.Duplicate; +import org.nuiton.topia.tck.legacy.entities.Person; +import org.nuiton.topia.tck.legacy.entities.Pet; +import org.nuiton.topia.tck.legacy.entities.Race; +import org.nuiton.topia.tck.replication.operation.FakeOperation; +import org.nuiton.topia.tck.replication.operation.UncreatableOperation; +import org.nuiton.topia.tck.replication.operation.UnregistredOperation; + +import static org.nuiton.topia.tck.legacy.TopiaTckLegacyDAOHelper.TopiaTckLegacyEntityEnum; + +/** + * TopiaReplicationServiceImplTest on model TopiaTest + * <p/> + * Created: 07 jun. 09 17:14:22 + * + * @author tchemit <chemit@codelutin.com> + * @since 2.2.0 + */ +public class TopiaReplicationServiceImplTest extends AbstractTopiaReplicationServiceTest { + + /** Logger */ + private static final Log log = + LogFactory.getLog(TopiaReplicationServiceImplTest.class); + + protected static final TopiaEntityEnum[] contracts = {TopiaTckLegacyEntityEnum.Person, TopiaTckLegacyEntityEnum.Pet, TopiaTckLegacyEntityEnum.Race}; + + protected Person person, person2; + + protected Pet pet, pet2, pet3; + + protected Race race, race2, race3; + + @Before + @Override + public void setUp() throws Exception { + + super.setUp(); + + ReplicationModelFixtures fixtures = db.getFixtures(); + + person = fixtures.getPerson(ctxt); + person2 = fixtures.getPerson2(ctxt); + pet = fixtures.getPet(ctxt); + pet2 = fixtures.getPet2(ctxt); + pet3 = fixtures.getPet3(ctxt); + race = fixtures.getRace(ctxt); + race2 = fixtures.getRace2(ctxt); + race3 = fixtures.getRace3(ctxt); + } + + @Test + @Override + public void testDetectTypes() throws Exception { + + detectTypes(race, Race.class); + detectTypes(pet, Pet.class, Person.class, Race.class); + detectTypes(person, Pet.class, Person.class, Race.class); + + detectTypes(pet2, Pet.class); + detectTypes(person2, Person.class); + detectTypes(race2, Race.class); + + detectTypes(race3, Race.class); + detectTypes(pet3, Pet.class, Race.class); + } + + @Test + @Override + public void testGetOperation() throws Exception { + + getOperation(UnregistredOperation.class, false); + getOperation(UncreatableOperation.class, true); + getOperation(FakeOperation.class, true); + getOperation(Duplicate.class, true); + getOperation(DettachAssociation.class, true); + } + + @Test + @Override + public void testDetectAssociations() throws Exception { + + detectAssociations(person, TopiaTckLegacyEntityEnum.Person, Person.PROPERTY_PET); + detectAssociations(race); + detectAssociations(pet); + + detectAssociations(person2); + detectAssociations(race2); + detectAssociations(pet2); + } + + @Test + @Override + public void testDetectDirectDependencies() throws Exception { + + detectDirectDependencies(person); + detectDirectDependencies(race); + detectDirectDependencies(pet, TopiaTckLegacyEntityEnum.Pet, Pet.PROPERTY_PERSON, TopiaTckLegacyEntityEnum.Pet, Pet.PROPERTY_RACE); + + detectDirectDependencies(person2); + detectDirectDependencies(race2); + detectDirectDependencies(pet2); + } + + @Test + @Override + public void testDetectShell() throws Exception { + + detectShell(person, TopiaTckLegacyEntityEnum.Pet, TopiaTckLegacyEntityEnum.Race); + detectShell(race); + detectShell(pet, TopiaTckLegacyEntityEnum.Person, TopiaTckLegacyEntityEnum.Race); + detectShell(person2); + detectShell(race2); + detectShell(pet2); + } + + @Test + @Override + public void testDetectDependencies() throws Exception { + + detectDependencies(person, new TopiaTckLegacyEntityEnum[]{TopiaTckLegacyEntityEnum.Race}, new TopiaTckLegacyEntityEnum[]{TopiaTckLegacyEntityEnum.Person}, new TopiaTckLegacyEntityEnum[]{TopiaTckLegacyEntityEnum.Pet}); + detectDependencies(race, new TopiaTckLegacyEntityEnum[]{TopiaTckLegacyEntityEnum.Race}); + detectDependencies(pet, new TopiaTckLegacyEntityEnum[]{TopiaTckLegacyEntityEnum.Race}, new TopiaTckLegacyEntityEnum[]{TopiaTckLegacyEntityEnum.Person}, new TopiaTckLegacyEntityEnum[]{TopiaTckLegacyEntityEnum.Pet}); + + detectDependencies(person2, new TopiaTckLegacyEntityEnum[]{TopiaTckLegacyEntityEnum.Person}); + detectDependencies(race2, new TopiaTckLegacyEntityEnum[]{TopiaTckLegacyEntityEnum.Race}); + detectDependencies(pet2, new TopiaTckLegacyEntityEnum[]{TopiaTckLegacyEntityEnum.Pet}); + } + + @Test + @Override + public void testDetectObjectsToDettach() throws Exception { + + detectObjectsToDettach(person, TopiaTckLegacyEntityEnum.Person, new String[]{Person.PROPERTY_PET}); + detectObjectsToDettach(race); + detectObjectsToDettach(pet, TopiaTckLegacyEntityEnum.Person, new String[]{Person.PROPERTY_PET}); + + detectObjectsToDettach(person2); + detectObjectsToDettach(race2); + detectObjectsToDettach(pet2); + + detectObjectsToDettach(race3); + detectObjectsToDettach(pet3); + } + + @Test + @Override + public void testDetectOperations() throws Exception { + + //TODO Make some real test on detected operations... + + detectOperations(person); + detectOperations(pet); + detectOperations(race); + + detectOperations(person2); + detectOperations(pet2); + detectOperations(race2); + + detectOperations(race3); + detectOperations(pet3); + } + + @Test + @Override + public void testDoReplicate() throws Exception { + + doReplicate(TopiaTckLegacyEntityEnum.Person, person); + doReplicate(TopiaTckLegacyEntityEnum.Person, person2); + doReplicate(TopiaTckLegacyEntityEnum.Person, person, person2); + + doReplicate(TopiaTckLegacyEntityEnum.Pet, pet); + doReplicate(TopiaTckLegacyEntityEnum.Pet, pet2); + doReplicate(TopiaTckLegacyEntityEnum.Pet, pet, pet2, pet3); + doReplicate(TopiaTckLegacyEntityEnum.Pet, person2, pet3); + + doReplicate(TopiaTckLegacyEntityEnum.Race, race); + doReplicate(TopiaTckLegacyEntityEnum.Race, race2); + doReplicate(TopiaTckLegacyEntityEnum.Race, race, race2); + + } + + /** + * Cette methode montre pourquoi la simple replication ne peut pas + * fonctionne :) + * <p/> + * Le replicateur ne deplique pas dans le bon ordre et on a donc des + * violations de clef etrangeres... + * + * @throws Exception pour toute erreur + */ + @Test(expected = TopiaException.class) + public void testSimpleReplicateFailed() throws Exception { + + TopiaContext dstRootCtxt = createDb2("testSimpleReplicateFailed"); + + //model = service.prepare(contracts, pet.getTopiaId()); + + TopiaContext srcCtxt = ctxt.beginTransaction(); + dstCtxt = (TopiaContextImplementor) dstRootCtxt.beginTransaction(); + + try { + + srcCtxt.replicateEntity(dstCtxt, pet); + + dstCtxt.commitTransaction(); + + } finally { + srcCtxt.rollbackTransaction(); + srcCtxt.closeContext(); + dstCtxt.closeContext(); + } + } + + /** + * Cette methode montre comment manuellement on peut effectuer la + * replication (en dettachant les dependances qui forment des cycles) + * <p/> + * La methode utilisee ici peut ne pas fonctionner : si une clef metier est + * posee sur une dependance alors cela ne fonctionne pas. + * + * @throws Exception pour toute erreur + */ + @Test + public void testSimpleReplicateNotSure() throws Exception { + + TopiaContext dstRootCtxt = createDb2("testSimpleReplicateNotSure"); + + //model = service.prepare(contracts, pet.getTopiaId()); + + TopiaContext srcCtxt = ctxt; + dstCtxt = (TopiaContextImplementor) dstRootCtxt.beginTransaction(); + + try { + + + srcCtxt.replicateEntity(dstCtxt, race); + + // on dettache l'entite qui pose probleme + + pet.setPerson(null); + srcCtxt.replicateEntity(dstCtxt, pet); + srcCtxt.rollbackTransaction(); + + srcCtxt.replicateEntity(dstCtxt, person); + + dstCtxt.commitTransaction(); + ((Pet) dstCtxt.findByTopiaId(pet.getTopiaId())).setPerson((Person) dstCtxt.findByTopiaId(person.getTopiaId())); + dstCtxt.commitTransaction(); + + srcCtxt.rollbackTransaction(); + person = db.getFixtures().getPerson(srcCtxt); + + assertEntityEquals(person, dstCtxt.findByTopiaId(person.getTopiaId()), null); + } finally { + srcCtxt.rollbackTransaction(); + //srcCtxt.closeContext(); + dstCtxt.closeContext(); + } + } + + /** + * Cette methode montre comment manuellement on peut effectuer la + * replication (en dettachant les associations qui forment des cycles) + * <p/> + * La methode utilisee ici fonctionne mieux que la precedante : il parrait + * dificille de pose une une clef metier sur une association :). + * <p/> + * On remarque que l'on dettache l'assocation qui forme un cycle et que l'on + * est pas obligee de la reattachee car elle est bi-directionnelle. + * <p/> + * On doit optimiser l'algorithme dans la methode {@link + * ReplicationModel#adjustOperations(TopiaEntityIdsMap)}. + * + * @throws Exception pour toute erreur + */ + @Test + public void testSimpleReplicateSure() throws Exception { + + TopiaContext dstRootCtxt = createDb2("testSimpleReplicateSure"); + + //model = service.prepare(contracts, pet.getTopiaId()); + + TopiaContext srcCtxt = ctxt; + dstCtxt = (TopiaContextImplementor) dstRootCtxt.beginTransaction(); + + try { + + srcCtxt.replicateEntity(dstCtxt, race); + // on dettache l'association qui pose probleme + person.setPet(null); + srcCtxt.replicateEntity(dstCtxt, person); + + srcCtxt.replicateEntity(dstCtxt, pet); + srcCtxt.rollbackTransaction(); + dstCtxt.commitTransaction(); + + //((Person) dstCtxt.findByTopiaId(person.getTopiaId())).addPet(((Pet) dstCtxt.findByTopiaId(pet.getTopiaId()))); + //dstCtxt.commitTransaction(); + + srcCtxt.rollbackTransaction(); + + srcCtxt.closeContext(); + dstCtxt.closeContext(); + + ctxt = db.beginTransaction(); + dstCtxt = (TopiaContextImplementor) dstRootCtxt.beginTransaction(); + + person = db.getFixtures().getPerson(ctxt); + + assertEntityEquals(person, dstCtxt.findByTopiaId(person.getTopiaId()), null); + + } finally { + dstCtxt.closeContext(); + } + } + + @Override + protected TopiaEntityEnum[] getContracts() { + return contracts; + } + + @Override + protected Log getLog() { + return log; + } + +} + + Property changes on: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/TopiaReplicationServiceImplTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/operation/FakeOperation.java (from rev 2523, trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/FakeOperation.java) =================================================================== --- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/operation/FakeOperation.java (rev 0) +++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/operation/FakeOperation.java 2012-05-24 07:53:22 UTC (rev 2524) @@ -0,0 +1,57 @@ +/* + * #%L + * ToPIA :: Service Replication + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package org.nuiton.topia.tck.replication.operation; + +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaContextImplementor; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.replication.TopiaReplicationContext; +import org.nuiton.topia.replication.TopiaReplicationOperation; +import org.nuiton.topia.replication.model.ReplicationOperationDef; + +import java.util.List; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 2.2.0 + */ +public class FakeOperation implements TopiaReplicationOperation { + + public static final Class<?>[] PARAMETERS_CLASSES = + new Class<?>[]{String.class}; + + @Override + public void run(TopiaReplicationContext replicationContext, + ReplicationOperationDef operationDef, + TopiaContextImplementor srcCtxt, + TopiaContextImplementor dstCtxt, + List<? extends TopiaEntity> nodeEntities + ) + throws TopiaException { + + } + +} Property changes on: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/operation/FakeOperation.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/operation/UncreatableOperation.java (from rev 2523, trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/UncreatableOperation.java) =================================================================== --- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/operation/UncreatableOperation.java (rev 0) +++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/operation/UncreatableOperation.java 2012-05-24 07:53:22 UTC (rev 2524) @@ -0,0 +1,53 @@ +/* + * #%L + * ToPIA :: Service Replication + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package org.nuiton.topia.tck.replication.operation; + +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaContextImplementor; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.replication.TopiaReplicationContext; +import org.nuiton.topia.replication.TopiaReplicationOperation; +import org.nuiton.topia.replication.model.ReplicationOperationDef; + +import java.util.List; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 2.2.0 + */ +public class UncreatableOperation implements TopiaReplicationOperation { + + @Override + public void run(TopiaReplicationContext replicationContext, + ReplicationOperationDef operationDef, + TopiaContextImplementor srcCtxt, + TopiaContextImplementor dstCtxt, + List<? extends TopiaEntity> nodeEntities + ) + throws TopiaException { + } + +} Property changes on: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/operation/UncreatableOperation.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/operation/UnregistredOperation.java (from rev 2523, trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/UnregistredOperation.java) =================================================================== --- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/operation/UnregistredOperation.java (rev 0) +++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/operation/UnregistredOperation.java 2012-05-24 07:53:22 UTC (rev 2524) @@ -0,0 +1,54 @@ +/* + * #%L + * ToPIA :: Service Replication + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package org.nuiton.topia.tck.replication.operation; + +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaContextImplementor; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.replication.TopiaReplicationContext; +import org.nuiton.topia.replication.TopiaReplicationOperation; +import org.nuiton.topia.replication.model.ReplicationOperationDef; + +import java.util.List; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 2.2.0 + */ +public class UnregistredOperation implements TopiaReplicationOperation { + + @Override + public void run( + TopiaReplicationContext replicationContext, + ReplicationOperationDef operationDef, + TopiaContextImplementor srcCtxt, + TopiaContextImplementor dstCtxt, + List<? extends TopiaEntity> nodeEntities + ) + throws TopiaException { + } + +} Property changes on: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/operation/UnregistredOperation.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/topia-persistence-tck/src/test/resources/META-INF/services/org.nuiton.topia.replication.TopiaReplicationOperation (from rev 2523, trunk/topia-service-replication/src/test/resources/META-INF/services/org.nuiton.topia.replication.TopiaReplicationOperation) =================================================================== --- trunk/topia-persistence-tck/src/test/resources/META-INF/services/org.nuiton.topia.replication.TopiaReplicationOperation (rev 0) +++ trunk/topia-persistence-tck/src/test/resources/META-INF/services/org.nuiton.topia.replication.TopiaReplicationOperation 2012-05-24 07:53:22 UTC (rev 2524) @@ -0,0 +1,6 @@ +# +# la liste des operations disponibles pour le moteur de replication +# voir la classe org.nuiton.topia.replication.TopiaReplicationServiceImpl +# +org.nuiton.topia.replication.operation.FakeOperation +org.nuiton.topia.replication.operation.UncreatableOperation \ No newline at end of file Property changes on: trunk/topia-persistence-tck/src/test/resources/META-INF/services/org.nuiton.topia.replication.TopiaReplicationOperation ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/mappings/TMSVersionDAO.java =================================================================== --- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/mappings/TMSVersionDAO.java 2012-05-23 18:34:02 UTC (rev 2523) +++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/mappings/TMSVersionDAO.java 2012-05-24 07:53:22 UTC (rev 2524) @@ -40,6 +40,7 @@ import org.nuiton.util.Version; import org.nuiton.util.VersionUtil; +import javax.persistence.EntityManager; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -64,7 +65,7 @@ public static TMSVersion get(TopiaContext tx) throws TopiaException { try { - Session session = ((TopiaContextImplementor) tx).getEntityManager(); + EntityManager session = ((TopiaContextImplementor) tx).getEntityManager(); Criteria criteria = session.createCriteria(TMSVersion.class); List<?> list = criteria.list(); TMSVersion result = list.isEmpty() ? null : (TMSVersion) list.get(0); @@ -91,11 +92,11 @@ public static TMSVersion create(TopiaContext tx, String version) throws TopiaException { try { - Session session = ((TopiaContextImplementor) tx).getEntityManager(); + EntityManager session = ((TopiaContextImplementor) tx).getEntityManager(); TMSVersion result = TMSVersion.valueOf(version); // save entity - session.save(result); + session.persist(result); return result; } catch (HibernateException e) { throw new TopiaException("Could not create version " + version, e); @@ -104,8 +105,8 @@ public static void update(TopiaContext tx, TMSVersion version) throws TopiaException { try { - Session session = ((TopiaContextImplementor) tx).getEntityManager(); - session.saveOrUpdate(version); + EntityManager session = ((TopiaContextImplementor) tx).getEntityManager(); + session.merge(version); tx.commitTransaction(); } catch (HibernateException e) { throw new TopiaException("Could not update version " + version, e); @@ -114,11 +115,11 @@ public static void deleteAll(TopiaContext tx) throws TopiaException { try { - Session session = ((TopiaContextImplementor) tx).getEntityManager(); + EntityManager session = ((TopiaContextImplementor) tx).getEntityManager(); Criteria criteria = session.createCriteria(TMSVersion.class); List<?> list = criteria.list(); for (Object o : list) { - session.delete(o); + session.remove(o); } } catch (HibernateException e) { throw new TopiaException("Could not delete all versions", e); Modified: trunk/topia-service-replication/pom.xml =================================================================== --- trunk/topia-service-replication/pom.xml 2012-05-23 18:34:02 UTC (rev 2523) +++ trunk/topia-service-replication/pom.xml 2012-05-24 07:53:22 UTC (rev 2524) @@ -27,10 +27,6 @@ <modelVersion>4.0.0</modelVersion> - <!-- ************************************************************* --> - <!-- *** POM Relationships *************************************** --> - <!-- ************************************************************* --> - <parent> <groupId>org.nuiton</groupId> <artifactId>topia</artifactId> @@ -40,6 +36,9 @@ <groupId>org.nuiton.topia</groupId> <artifactId>topia-service-replication</artifactId> + <name>ToPIA :: Service Replication</name> + <description>Hibernate based replication service</description> + <dependencies> <!-- Sibling dependencies --> @@ -51,27 +50,6 @@ </dependency> <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>topia-persistence</artifactId> - <version>${project.version}</version> - <scope>test</scope> - <classifier>tests</classifier> - </dependency> - - <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>topia-persistence-tck</artifactId> - <version>${project.version}</version> - </dependency> - - <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>topia-persistence-hibernate</artifactId> - <version>${project.version}</version> - <scope>test</scope> - </dependency> - - <dependency> <groupId>org.nuiton.i18n</groupId> <artifactId>nuiton-i18n</artifactId> </dependency> @@ -91,19 +69,7 @@ <artifactId>hibernate-core</artifactId> </dependency> - <!-- Depencies for test--> <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> - </dependency> - - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-lang3</artifactId> - <scope>test</scope> - </dependency> - - <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </dependency> @@ -115,95 +81,14 @@ </dependencies> - <!-- ************************************************************* --> - <!-- *** Project Information ************************************* --> - <!-- ************************************************************* --> - - <name>ToPIA :: Service Replication</name> - <description>Hibernate based replication service</description> - - <!-- ************************************************************* --> - <!-- *** Build Settings ****************************************** --> - <!-- ************************************************************* --> - - <packaging>jar</packaging> - <build> <plugins> - <!--plugin> - <groupId>org.nuiton.i18n</groupId> - <artifactId>maven-i18n-plugin</artifactId> - <executions> - <execution> - <goals> - <goal>parserJava</goal> - <goal>gen</goal> - </goals> - </execution> - </executions> - </plugin--> - <plugin> - <artifactId>maven-jar-plugin</artifactId> - <executions> - <execution> - <id>attach-test</id> - <goals> - <goal>test-jar</goal> - </goals> - </execution> - </executions> - </plugin> </plugins> </build> - <!-- ************************************************************* --> - <!-- *** Build Environment ************************************** --> - <!-- ************************************************************* --> <profiles> - <!-- perform only on a release stage when using the maven-release-plugin --> - <profile> - <id>release-profile</id> - <activation> - <property> - <name>performRelease</name> - <value>true</value> - </property> - </activation> - <build> - <plugins> - - <!-- always compute tests source jar --> - <plugin> - <artifactId>maven-source-plugin</artifactId> - <executions> - <execution> - <id>attach-test-sources</id> - <goals> - <goal>test-jar</goal> - </goals> - </execution> - </executions> - </plugin> - - <!-- always compute tests source jar --> - <plugin> - <artifactId>maven-javadoc-plugin</artifactId> - <executions> - <execution> - <id>attach-test-javadoc</id> - <goals> - <goal>test-jar</goal> - </goals> - </execution> - </executions> - </plugin> - - </plugins> - </build> - </profile> - <!-- reporting at release time --> <profile> <id>reporting</id> Modified: trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationModelBuilder.java =================================================================== --- trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationModelBuilder.java 2012-05-23 18:34:02 UTC (rev 2523) +++ trunk/topia-service-replication/src/main/java/org/nuiton/topia/replication/TopiaReplicationModelBuilder.java 2012-05-24 07:53:22 UTC (rev 2524) @@ -255,9 +255,9 @@ return model; } - protected Set<Class<? extends TopiaEntity>> detectTypes(TopiaContext context, - TopiaEntityEnum[] contracts, - String... ids) throws TopiaException { + public Set<Class<? extends TopiaEntity>> detectTypes(TopiaContext context, + TopiaEntityEnum[] contracts, + String... ids) throws TopiaException { TopiaContext ctxt = context.beginTransaction(); try { Deleted: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/AbstractTopiaReplicationServiceTest.java =================================================================== --- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/AbstractTopiaReplicationServiceTest.java 2012-05-23 18:34:02 UTC (rev 2523) +++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/AbstractTopiaReplicationServiceTest.java 2012-05-24 07:53:22 UTC (rev 2524) @@ -1,658 +0,0 @@ -/* - * #%L - * ToPIA :: Service Replication - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.topia.replication; - -import org.apache.commons.logging.Log; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.nuiton.i18n.I18n; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.framework.TopiaContextImplementor; -import org.nuiton.topia.framework.TopiaUtil; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.TopiaEntityEnum; -import org.nuiton.topia.persistence.util.EntityOperator; -import org.nuiton.topia.persistence.util.EntityOperatorStore; -import org.nuiton.topia.persistence.util.TopiaEntityHelper; -import org.nuiton.topia.replication.model.ReplicationModel; -import org.nuiton.topia.replication.model.ReplicationNode; -import org.nuiton.topia.replication.model.ReplicationOperationDef; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Set; - -/** - * TopiaReplicationServiceImplTest. - * <p/> - * Created: 07 jun. 09 17:14:22 - * - * @author tchemit <chemit@codelutin.com> - * @version $Id$ - * @since 2.2.0 - */ -public abstract class AbstractTopiaReplicationServiceTest extends Assert { - - protected TopiaContext context; - - protected TopiaContext ctxt; - - protected TopiaContextImplementor dstCtxt; - - protected TopiaReplicationService service; - - protected ReplicationModel model; - -// static protected boolean init; - -// static private Long testsTimeStamp; - -// static private File testsBasedir; - -// static private final String TEST_BASEDIR = "target%1$ssurefire-tests%1$s%2$td_%2$tm_%2$tY%1$s%2$tH_%2$tM_%2$tS"; - - @Rule - public final TopiaDatabaseLegacy db = new TopiaDatabaseLegacy("-source"); - - protected TopiaDatabaseLegacy db2; - - @BeforeClass - public static void before() { - I18n.setDefaultLocale(Locale.FRANCE); - } - - public void setUp() throws Exception { - - context = db.getRootCtxt(); - - db.createDb(); - - ctxt = db.beginTransaction(); - - service = db.getReplicationService(); - } - - public void tearDown() throws Exception { - service = null; - context = null; - ctxt = null; - dstCtxt = null; - model = null; - if (db2 != null) { - db2.finished(db2.getDescription()); - } - - } - - protected TopiaReplicationModelBuilder getModelBuilder() { - return service.getModelBuilder(); - } - - protected TopiaContext createDb2(String name) throws Exception { - - db2 = new TopiaDatabaseLegacy(name + "-target"); - - // creates new db - db2.starting(db.getDescription()); - - return db2.getRootCtxt(); - } - - protected TopiaContext createReplicateDb(Object contract) throws Exception { - TopiaContext rootCtxt = createDb2(contract.toString() + dbCounter++); - return rootCtxt; - } - - protected abstract TopiaEntityEnum[] getContracts(); - - protected abstract Log getLog(); - - /** - * Test of detectTypes method, of class ReplicationServiceImplementor. - * - * @throws Exception if any error - */ - public void testDetectTypes() throws Exception { - } - - /** - * Test of getOperation method, of class ReplicationServiceImplementor. - * - * @throws Exception if any error - */ - public void testGetOperation() throws Exception { - } - - /** - * Test of detectAssociations method, of class ReplicationModel. - * - * @throws Exception if any error - */ - public void testDetectAssociations() throws Exception { - } - - /** - * Test of detectDirectDependencies method, of class ReplicationModel. - * - * @throws Exception if any error - */ - public void testDetectDirectDependencies() throws Exception { - } - - /** - * Test of detectShell method, of class ReplicationModel. - * - * @throws Exception if any error - */ - public void testDetectShell() throws Exception { - } - - /** - * Test of detectDependencies method, of class ReplicationModel. - * - * @throws Exception if any error - */ - public void testDetectDependencies() throws Exception { - } - - /** - * Test of detectObjectsToDettach method, of class ReplicationModel. - * - * @throws Exception if any error - */ - public void testDetectObjectsToDettach() throws Exception { - } - - /** - * Test of detectOperations method, of class ReplicationModel. - * - * @throws Exception if any error - */ - public void testDetectOperations() throws Exception { - } - - /** - * Test of doReplicate method, of class ReplicationService. - * - * @throws Exception if any error - */ - public void testDoReplicate() throws Exception { - } - - protected void detectTypes(TopiaEntity entity, Object... expectedCouple) throws TopiaException { - - Set<?> detectTypes; - - detectTypes = service.getModelBuilder().detectTypes(context, getContracts(), entity.getTopiaId()); - assertEquals("expected types : " + - Arrays.toString(expectedCouple) + - " but was " + detectTypes, - expectedCouple.length, detectTypes.size()); - for (Object o : expectedCouple) { - assertTrue(detectTypes.contains(o)); - } - } - - protected void getOperation(Class<? extends TopiaReplicationOperation> operationClass, boolean shouldExist) throws TopiaException { - TopiaReplicationOperation operation = getModelBuilder().getOperationProvider().getOperation(operationClass); - assertEquals(shouldExist, operation != null); - } - - protected void detectAssociations(TopiaEntity entity, - Object... expectedCouple) - throws TopiaException { - - createModel(entity); - model.detectAssociations(); - - assertEquals(0, expectedCouple.length % 2); - - for (int i = 0, j = expectedCouple.length / 2; i < j; i++) { - TopiaEntityEnum src = (TopiaEntityEnum) expectedCouple[2 * i]; - String name = (String) expectedCouple[2 * i + 1]; - ReplicationNode nodeSrc = model.getNode(src); - assertNotNull("association " + name + " not found", nodeSrc); - assertTrue(nodeSrc.hasAssociation()); - assertTrue(nodeSrc.getAssociations().containsKey(name)); - } - } - - protected void detectDirectDependencies(TopiaEntity entity, - Object... expectedCouple) - throws TopiaException { - - createModel(entity); - model.detectDirectDependencies(); - - assertEquals(0, expectedCouple.length % 2); - - for (int i = 0, j = expectedCouple.length / 2; i < j; i++) { - TopiaEntityEnum src = (TopiaEntityEnum) expectedCouple[2 * i]; - String name = (String) expectedCouple[2 * i + 1]; - ReplicationNode nodeSrc = model.getNode(src); - assertTrue(nodeSrc + " should have dependency but was not!", nodeSrc.hasDependency()); - assertTrue(nodeSrc + " should contain dependency " + name + "but was not! (" + nodeSrc.getDependencies() + ")", nodeSrc.getDependencies().containsKey(name)); - } - } - - protected void detectShell(TopiaEntity entity, - TopiaEntityEnum... expected) throws - TopiaException { - Set<ReplicationNode> shell; - - createModel(entity); - model.detectAssociations(); - model.detectDirectDependencies(); - model.detectShell(); - - TopiaEntityEnum c = TopiaEntityHelper.getEntityEnum( - entity.getClass(), getContracts()); - assertNotNull(c); - shell = model.getNode(c).getShell(); - assertEquals( - "expected shell : " + Arrays.toString(expected) + ", but was " + - shell, expected.length, shell.size()); - - for (TopiaEntityEnum type : expected) { - ReplicationNode node = model.getNode(type); - assertTrue(shell.contains(node)); - assertEquals(type, node.getContract()); - } - } - - protected void detectDependencies( - TopiaEntity entity, - TopiaEntityEnum[]... expected) throws TopiaException { - - createModel(entity); - model.detectAssociations(); - model.detectDirectDependencies(); - model.detectShell(); - model.detectDependencies(); - List<ReplicationNode> dependencies = model.getOrder(); - - int i = 0; - for (ReplicationNode level : dependencies) { - getLog().info("level " + level + " = " + level); - } - -// assertEquals("expected " + expected.length + " levels but had " + dependencies.size(), expected.length, dependencies.size()); -// -// Iterator<List<ReplicationNode>> order = dependencies.iterator(); -// if (entity != null) { -// getLog().info("for " + entity.getTopiaId()); -// } -// int index = 0; -// for (TopiaEntityEnum[] expectedLevel : expected) { -// -// List<ReplicationNode> next = order.next(); -// getLog().info("level " + (index++) + " : " + next); -// for (TopiaEntityEnum ee : expectedLevel) { -// ReplicationNode expectedNode = model.getNode(ee); -// -// assertTrue("should have contains node " + expectedNode, next.contains(expectedNode)); -// } -// -// } - } - - protected void detectObjectsToDettach(TopiaEntity entity, Object... expected) throws TopiaException { - - assertEquals(0, expected.length % 2); - - createModel(entity); - model.detectAssociations(); - model.detectDirectDependencies(); - model.detectShell(); - model.detectDependencies(); - model.detectObjectsToDettach(); - Set<ReplicationNode> nodes = new HashSet<ReplicationNode>(); - - for (int i = 0, j = expected.length / 2; i < j; i++) { - TopiaEntityEnum e = (TopiaEntityEnum) expected[2 * i]; - ReplicationNode node = model.getNode(e); - String[] ids = (String[]) expected[2 * i + 1]; - assertEquals(ids.length > 0, node.hasAssociationsToDettach()); - for (String id : ids) { - assertTrue(node.getAssociationsToDettach().contains(id)); - } - nodes.add(node); - } - - for (ReplicationNode node : model.getNodes()) { - if (!nodes.contains(node)) { - // on verifie bien qu'il n' y a pas d'associations dettachee - assertFalse(node.hasAssociationsToDettach()); - } - } - - } - - protected void detectOperations(TopiaEntity entity, Object... expected) throws TopiaException { - - assertEquals(0, expected.length % 2); - - if (entity == null) { - prepareModel(); - } else { - prepareModel(entity.getTopiaId()); - } -// createModel(entity); -// model.detectAssociations(); -// model.detectDirectDependencies(); -// model.detectShell(); -// model.detectDependencies(); -// model.detectObjectsToDettach(); -// model.detectOperations(); - - if (getLog().isInfoEnabled()) { - getLog().info("=========================================================================="); - if (entity == null) { - - getLog().info("resume of operations for all "); - } else { - getLog().info("resume of operations for entity " + entity.getTopiaId()); - } - - for (ReplicationNode node : model.getOrder()) { - ReplicationOperationDef[] operations = node.getOperations(); - for (ReplicationOperationDef op : operations) { - getLog().info("[" + node + "] : operation " + op); - } - } - getLog().info("=========================================================================="); - } - } - - private static int dbCounter; - - protected void doReplicate(TopiaEntityEnum contract, - TopiaEntity... entity) throws Exception { - - TopiaContext rootCtxt = createReplicateDb("doReplicate_" + contract); - - List<String> ids = TopiaUtil.getTopiaIdList(Arrays.asList(entity)); - getLog().info("entity " + ids); - - prepareModel(ids.toArray(new String[ids.size()])); - - dstCtxt = (TopiaContextImplementor) rootCtxt; - - service.doReplicate(model, dstCtxt); - - //dstCtxt.closeContext(); - - if (entity.length == 0) { - - return; - } - dstCtxt = (TopiaContextImplementor) rootCtxt.beginTransaction(); - - for (TopiaEntity e : entity) { - TopiaEntity actual = dstCtxt.findByTopiaId(e.getTopiaId()); - assertNotNull(actual); - assertEquals(e, actual); - } - - dstCtxt.closeContext(); - - dstCtxt = (TopiaContextImplementor) rootCtxt; - } - - protected void doReplicateAll() throws Exception { - - TopiaContext rootCtxt = createReplicateDb("doReplicateAll"); - - prepareModelAll(); - - dstCtxt = (TopiaContextImplementor) rootCtxt; - - service.doReplicate(model, dstCtxt); - - TopiaContextImplementor ctxt2 = (TopiaContextImplementor) ctxt; - dstCtxt = (TopiaContextImplementor) rootCtxt.beginTransaction(); - - assertDbEquals(model.getContracts(), (TopiaContextImplementor) ctxt, ctxt2); - - dstCtxt.closeContext(); - - dstCtxt = (TopiaContextImplementor) rootCtxt; - } - - protected void doReplicateWithComputedOrder(TopiaEntity... entity) throws Exception { - - TopiaContext rootCtxt = createReplicateDb("doReplicateWithComputedOrder"); - - List<String> ids = TopiaUtil.getTopiaIdList(Arrays.asList(entity)); - - prepareModelWithComputedOrder(ids.toArray(new String[ids.size()])); - - dstCtxt = (TopiaContextImplementor) rootCtxt; - - service.doReplicate(model, dstCtxt); - - getLog().info("replication is done for " + Arrays.toString(entity) + ", will verify data..."); - - TopiaContextImplementor ctxt2 = (TopiaContextImplementor) ctxt; - dstCtxt = (TopiaContextImplementor) rootCtxt.beginTransaction(); - - assertDbEquals(model.getContracts(), (TopiaContextImplementor) ctxt, ctxt2); - - dstCtxt.closeContext(); - - dstCtxt = (TopiaContextImplementor) rootCtxt; - } - - protected void assertDbEquals(TopiaEntityEnum[] contracts, - TopiaContextImplementor ctxt, - TopiaContextImplementor ctxt2) throws TopiaException { - Set<String> ids = new HashSet<String>(); - - if (getLog().isInfoEnabled()) { - getLog().info("will verify db for contracts " + Arrays.toString(contracts)); - } - for (TopiaEntityEnum c : contracts) { - if (getLog().isDebugEnabled()) { - getLog().debug("verify for contract " + c); - } - TopiaDAO<? extends TopiaEntity> daoSrc = ctxt.getDAO(c.getContract()); - TopiaDAO<? extends TopiaEntity> daoDst = ctxt2.getDAO(c.getContract()); - long nbSrc = daoSrc.count(); - long nbDst = daoDst.count(); - assertEquals("le nombres d'entites de type " + c + " devrait etre " + nbSrc + " mais est " + nbDst, nbSrc, nbDst); - List<String> idsSrc = daoSrc.findAllIds(); - List<String> idsDst = daoDst.findAllIds(); - Collections.sort(idsSrc); - Collections.sort(idsDst); - assertEquals(idsSrc, idsDst); - for (String id : idsSrc) { - if (getLog().isDebugEnabled()) { - getLog().debug("verify for entity " + id); - } - TopiaEntity eSrc = daoSrc.findByTopiaId(id); - TopiaEntity eDst = daoDst.findByTopiaId(id); - assertEquals(eSrc, eDst); - assertEntityEquals(eSrc, eDst, ids); - } - } - } - - protected void assertEntityEquals(TopiaEntity expected, - TopiaEntity actual, - Set<String> treated) { - if (treated == null) { - treated = new HashSet<String>(); - } - if (treated.contains(actual.getTopiaId())) { - return; - } - if (getLog().isDebugEnabled()) { - getLog().debug(expected); - } - assertEquals(actual.getTopiaId(), expected.getTopiaId()); - treated.add(actual.getTopiaId()); - if (getLog().isDebugEnabled()) { - getLog().debug("expected : " + expected + " / actual " + actual); - } - TopiaEntityEnum contract = TopiaEntityHelper.getEntityEnum(expected.getClass(), getContracts()); - if (contract == null) { - // this type of entity in not dealed here... - getLog().debug("untested property type " + expected.getClass()); - return; - } - Assert.assertNotNull( - "contract not found for " + expected.getClass() + " in " + - Arrays.toString(getContracts()), contract); - EntityOperator<TopiaEntity> operator = EntityOperatorStore.getOperator(contract); - List<String> associationProperties = operator.getAssociationProperties(); - for (String name : associationProperties) { - if (getLog().isDebugEnabled()) { - getLog().debug("association " + name); - } - if (operator.isChildEmpty(name, expected)) { - assertTrue("l'association " + name + " devrait etre vide mais possede " + operator.sizeChild(name, actual) + " entrees", operator.isChildEmpty(name, actual)); - } else { - assertFalse("l'association " + name + " devrait posseder " + operator.isChildEmpty(name, expected) + " mais est vide", operator.isChildEmpty(name, actual)); - - } - assertEquals(operator.isChildEmpty(name, actual), operator.isChildEmpty(name, expected)); - - Class<?> type = operator.getAssociationPropertyType(name); - Collection<?> src = (Collection<?>) operator.get(name, expected); - Collection<?> dst = (Collection<?>) operator.get(name, actual); -// assertEquals(src, dst); - Iterator<?> itrSrc = src.iterator(); - Iterator<?> itrDst = dst.iterator(); - while (itrSrc.hasNext()) { - if (TopiaEntity.class.isAssignableFrom(type)) { - assertEntityEquals((TopiaEntity) itrSrc.next(), (TopiaEntity) itrDst.next(), treated); - } else { - assertEquals(itrSrc.next(), itrDst.next()); - } - } - } - - for (String name : operator.getProperties()) { - if (getLog().isDebugEnabled()) { - getLog().debug("dependency " + name); - } - if (associationProperties.contains(name)) { - // deja traite au dessus - continue; - } - Class<?> type = operator.getPropertyType(name); - Object src = operator.get(name, expected); - Object dst = operator.get(name, actual); - assertFalse(src == null && dst != null); - assertFalse(src != null && dst == null); - if (src == null) { - continue; - } - if (TopiaEntity.class.isAssignableFrom(type)) { - assertEntityEquals((TopiaEntity) src, (TopiaEntity) dst, treated); - } else { - assertEquals(src, dst); - } - } - } - - protected void createSupportedBeforeOperation(TopiaEntityEnum contract, - TopiaEntity entity, - Class<? extends TopiaReplicationOperation> operationClass, - Object... parameters) throws Exception { - - getLog().info("entity " + entity.getTopiaId()); - prepareModel(entity.getTopiaId()); - - getModelBuilder().addBeforeOperation(model, contract, operationClass, parameters); - // on doit avoir le droit de creer cette operation - Assert.assertTrue(true); - } - - protected void createSupportedAfterOperation( - TopiaEntityEnum contract, - TopiaEntity entity, - Class<? extends TopiaReplicationOperation> operationClass, - Object... parameters) throws Exception { - - getLog().info("entity " + entity.getTopiaId()); - prepareModel(entity.getTopiaId()); -// model = service.createModel(getContracts()); -// model.detectDirectDependencies(); - getModelBuilder().addAfterOperation(model, contract, operationClass, parameters); - // on doit avoir le droit de creer cette operation - Assert.assertTrue(true); - } - -// protected Long getTestsTimeStamp() { -// if (testsTimeStamp == null) { -// testsTimeStamp = System.currentTimeMillis(); -// getLog().info("tests timestamp : " + testsTimeStamp); -// } -// return testsTimeStamp; -// } - -// protected File getTestDir(Class<?> testClass) { -// if (testsBasedir == null) { -// String tmp = System.getProperty("basedir"); -// if (tmp == null) { -// tmp = new File("").getAbsolutePath(); -// } -// String name = String.format(TEST_BASEDIR, File.separator, new Date(getTestsTimeStamp())); -// testsBasedir = new File(new File(tmp), name); -// getLog().info("tests basedir : " + testsBasedir); -// } -// return new File(testsBasedir, testClass.getSimpleName()); -// } - - protected void createModel(TopiaEntity entity) throws TopiaException { - model = getModelBuilder().createModel(context, - getContracts(), - true, - entity.getTopiaId() - ); - } - - protected void prepareModel(String... ids) throws TopiaException { - model = service.prepare(getContracts(), true, ids); - } - - protected void prepareModelAll() throws TopiaException { - model = service.prepareForAll(getContracts()); - } - - protected void prepareModelWithComputedOrder(String... ids) throws TopiaException { - model = service.prepare(getContracts(), false, ids); - } -} Deleted: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/ModelFixture.java =================================================================== --- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/ModelFixture.java 2012-05-23 18:34:02 UTC (rev 2523) +++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/ModelFixture.java 2012-05-24 07:53:22 UTC (rev 2524) @@ -1,113 +0,0 @@ -package org.nuiton.topia.replication; - -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.framework.TopiaContextImplementor; -import org.nuiton.topia.tck.legacy.TopiaTckLegacyDAOHelper; -import org.nuiton.topia.tck.legacy.entities.Person; -import org.nuiton.topia.tck.legacy.entities.PersonDAO; -import org.nuiton.topia.tck.legacy.entities.Pet; -import org.nuiton.topia.tck.legacy.entities.PetDAO; -import org.nuiton.topia.tck.legacy.entities.Race; -import org.nuiton.topia.tck.legacy.entities.RaceDAO; - -/** - * Fixtures to test replication serivce. - * - * @author tchemit <chemit@codelutin.com> - * @since 3.0 - */ -public class ModelFixture { - - public static final String PERSON_NAME = "pudding master"; - - public static final String PERSON2_NAME = "pudding II master"; - - public static final String RACE_NAME = "race I"; - - public static final String RACE2_NAME = "race II"; - - public static final String PET_NAME = "pudding"; - - public static final String PET2_NAME = "pudding II"; - - public static final String RACE3_NAME = "race III"; - - public static final String PET3_NAME = "pudding III"; - - public void createDb(TopiaContext context) throws TopiaException { - - TopiaContextImplementor tx = - (TopiaContextImplementor) context.beginTransaction(); - - try { - PersonDAO personDAO = TopiaTckLegacyDAOHelper.getPersonDAO(tx); - RaceDAO raceDAO = TopiaTckLegacyDAOHelper.getRaceDAO(tx); - PetDAO petDAO = TopiaTckLegacyDAOHelper.getPetDAO(tx); - - Person person = personDAO.create(Person.PROPERTY_NAME, PERSON_NAME); - Race race = raceDAO.create(Race.PROPERTY_NAME, RACE_NAME); - petDAO.create(Pet.PROPERTY_NAME, PET_NAME, Pet.PROPERTY_PERSON, person, Pet.PROPERTY_RACE, race); - - personDAO.create(Person.PROPERTY_NAME, PERSON2_NAME); - petDAO.create(Pet.PROPERTY_NAME, PET2_NAME); - raceDAO.create(Race.PROPERTY_NAME, RACE2_NAME); - - Race race3 = raceDAO.create(Race.PROPERTY_NAME, RACE3_NAME); - petDAO.create(Pet.PROPERTY_NAME, PET3_NAME, Pet.PROPERTY_RACE, race3); - - tx.commitTransaction(); - } finally { - tx.closeContext(); - } - } - - public Person getPerson(TopiaContext tx) throws TopiaException { - PersonDAO personDAO = TopiaTckLegacyDAOHelper.getPersonDAO(tx); - Person result = personDAO.findByName(PERSON_NAME); - return result; - } - - public Person getPerson2(TopiaContext tx) throws TopiaException { - PersonDAO personDAO = TopiaTckLegacyDAOHelper.getPersonDAO(tx); - Person result = personDAO.findByName(PERSON2_NAME); - return result; - } - - public Race getRace(TopiaContext tx) throws TopiaException { - RaceDAO raceDAO = TopiaTckLegacyDAOHelper.getRaceDAO(tx); - Race race = raceDAO.findByName(RACE_NAME); - return race; - } - - public Race getRace2(TopiaContext tx) throws TopiaException { - RaceDAO raceDAO = TopiaTckLegacyDAOHelper.getRaceDAO(tx); - Race race = raceDAO.findByName(RACE2_NAME); - return race; - } - - public Race getRace3(TopiaContext tx) throws TopiaException { - RaceDAO raceDAO = TopiaTckLegacyDAOHelper.getRaceDAO(tx); - Race race = raceDAO.findByName(RACE3_NAME); - return race; - } - - public Pet getPet(TopiaContext tx) throws TopiaException { - PetDAO petDAO = TopiaTckLegacyDAOHelper.getPetDAO(tx); - Pet pet = petDAO.findByName(PET_NAME); - return pet; - } - - public Pet getPet2(TopiaContext tx) throws TopiaException { - PetDAO petDAO = TopiaTckLegacyDAOHelper.getPetDAO(tx); - Pet pet = petDAO.findByName(PET2_NAME); - return pet; - } - - public Pet getPet3(TopiaContext tx) throws TopiaException { - PetDAO petDAO = TopiaTckLegacyDAOHelper.getPetDAO(tx); - Pet pet = petDAO.findByName(PET3_NAME); - return pet; - } - -} Deleted: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaDatabaseLegacy.java =================================================================== --- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaDatabaseLegacy.java 2012-05-23 18:34:02 UTC (rev 2523) +++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaDatabaseLegacy.java 2012-05-24 07:53:22 UTC (rev 2524) @@ -1,60 +0,0 @@ -package org.nuiton.topia.replication; - -import org.junit.runner.Description; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.tck.TopiaDatabase; -import org.nuiton.topia.tck.legacy.TopiaTckLegacyDAOHelper; - -/** - * Concrete topia database for {@code it} model. - * - * @author tchemit <chemit@codelutin.com> - * @since 3.0 - */ -public class TopiaDatabaseLegacy extends TopiaDatabase { - - private ModelFixture fixtures; - - private TopiaReplicationService replicationService; - - public TopiaDatabaseLegacy(String classifier) { - super("/TopiaContext-legacy.properties", classifier); - } - - @Override - protected Class<? extends TopiaEntity>[] getImplementationClasses() { - return TopiaTckLegacyDAOHelper.getImplementationClasses(); - } - - public ModelFixture getFixtures() { - if (fixtures == null) { - fixtures = new ModelFixture(); - } - return fixtures; - } - - public TopiaReplicationService getReplicationService() throws TopiaException { - if (replicationService == null) { - replicationService = - getRootCtxt().getService(TopiaReplicationService.class); - } - return replicationService; - } - - public void createDb() throws TopiaException { - - getFixtures().createDb(getRootCtxt()); - - } - - @Override - public void starting(Description description) { - super.starting(description); - } - - @Override - public void finished(Description description) { - super.finished(description); - } -} Deleted: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationOperationTest.java =================================================================== --- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationOperationTest.java 2012-05-23 18:34:02 UTC (rev 2523) +++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationOperationTest.java 2012-05-24 07:53:22 UTC (rev 2524) @@ -1,281 +0,0 @@ -/* - * #%L - * ToPIA :: Service Replication - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.topia.replication; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.Before; -import org.junit.Test; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.persistence.TopiaEntityEnum; -import org.nuiton.topia.replication.model.ReplicationOperationPhase; -import org.nuiton.topia.replication.operation.DettachAssociation; -import org.nuiton.topia.replication.operation.Duplicate; -import org.nuiton.topia.replication.operation.FakeOperation; -import org.nuiton.topia.replication.operation.UncreatableOperation; -import org.nuiton.topia.replication.operation.UnregistredOperation; -import org.nuiton.topia.tck.legacy.entities.Person; -import org.nuiton.topia.tck.legacy.entities.Pet; -import org.nuiton.topia.tck.legacy.entities.Race; - -import java.io.File; - -import static org.nuiton.topia.tck.legacy.TopiaTckLegacyDAOHelper.TopiaTckLegacyEntityEnum; - -/** - * TopiaReplicationServiceImplTest on model TopiaTest - * <p/> - * Created: 07 jun. 09 17:14:22 - * - * @author tchemit <chemit@codelutin.com> - * @since 2.2.0 - */ -public class TopiaReplicationOperationTest extends AbstractTopiaReplicationServiceTest { - - /** Logger */ - private static final Log log = - LogFactory.getLog(TopiaReplicationOperationTest.class); - - protected static final TopiaEntityEnum[] contracts = { - TopiaTckLegacyEntityEnum.Person, - TopiaTckLegacyEntityEnum.Pet, - TopiaTckLegacyEntityEnum.Race - }; - -// protected static final String entitiesList = -// PersonImpl.class.getName() + "," + -// PetImpl.class.getName() + "," + -// RaceImpl.class.getName(); - - static protected Person person, person2; - - static protected Pet pet, pet2; - - static protected Race race, race2; - - protected static File tesDir; - - @Before - @Override - public void setUp() throws Exception { - - super.setUp(); - - ModelFixture fixtures = db.getFixtures(); - - person = fixtures.getPerson(ctxt); - person2 = fixtures.getPerson2(ctxt); - pet = fixtures.getPet(ctxt); - pet2 = fixtures.getPet2(ctxt); - race = fixtures.getRace(ctxt); - race2 = fixtures.getRace2(ctxt); - - } - - @Test(expected = NullPointerException.class) - public void testGetOperation_nullOperationClass() throws Exception { - getModelBuilder().getOperationProvider().getOperation((Class<? extends TopiaReplicationOperation>) null); - } - - protected TopiaReplicationModelBuilder getModelBuilder() { - return service.getModelBuilder(); - } - - @Test - @Override - public void testGetOperation() throws Exception { - - getOperation(UnregistredOperation.class, false); - getOperation(UncreatableOperation.class, true); - getOperation(FakeOperation.class, true); - getOperation(Duplicate.class, true); - getOperation(DettachAssociation.class, true); - } - - @Test(expected = NullPointerException.class) - public void testCreateOperation_nullModel() throws Exception { - getModelBuilder().createOperation(null, null, null, null); - } - - @Test(expected = NullPointerException.class) - public void testCreateOperation_nullType() throws Exception { - - model = getModelBuilder().createModel(context, contracts, true); - getModelBuilder().createOperation(model, null, null, null); - } - - @Test(expected = NullPointerException.class) - public void testCreateOperation_nullPhase() throws Exception { - - model = getModelBuilder().createModel(context, contracts, true); - getModelBuilder().createOperation(model, TopiaTckLegacyEntityEnum.Pet, null, null); - } - - @Test(expected = NullPointerException.class) - public void testCreateOperation_nullOperationClass() throws Exception { - - model = getModelBuilder().createModel(context, contracts, true); - getModelBuilder().createOperation(model, TopiaTckLegacyEntityEnum.Pet, ReplicationOperationPhase.before, null); - } - - @Test(expected = IllegalArgumentException.class) - public void testCreateOperation_noNode() throws Exception { - - model = getModelBuilder().createModel(context, contracts, true); - // le noeud Pet n'existe pas - getModelBuilder().addAfterOperation(model, TopiaTckLegacyEntityEnum.Pet, Duplicate.class); - } - - @Test(expected = IllegalArgumentException.class) - public void testCreateOperation_noOperation() throws Exception { - - model = getModelBuilder().createModel(context, contracts, true); - // le noeud Pet n'existe pas - getModelBuilder().addAfterOperation(model, TopiaTckLegacyEntityEnum.Pet, UnregistredOperation.class); - } - - @Test -// @Test(expected = UnsupportedOperationException.class) - public void testCreateSupportedBeforeOperation_Duplicate() throws Exception { - createSupportedBeforeOperation(TopiaTckLegacyEntityEnum.Person, person, Duplicate.class); - } - -// @Test(expected = UnsupportedOperationException.class) -// public void testCreateUnsupportedBeforeOperation_AttachAssociation() throws Exception { -// createUnsupportedBeforeOperation(TopiaTckItEntityEnum.Person, person, AttachAssociation.class); -// } - - @Test -// @Test(expected = UnsupportedOperationException.class) - public void testCreateSupportedBeforeOperation_DetachAssociation() throws Exception { - createSupportedBeforeOperation(TopiaTckLegacyEntityEnum.Person, person, DettachAssociation.class); - } - - @Test -// @Test(expected = UnsupportedOperationException.class) - public void testCreateSupportedAfterOperation_Duplicate() throws Exception { - createSupportedAfterOperation(TopiaTckLegacyEntityEnum.Person, person, Duplicate.class); - } - -// @Test(expected = UnsupportedOperationException.class) -// public void testCreateSupportedAfterOperation_AttachAssociation() throws Exception { -// createUnsupportedAfterOperation(TopiaTckItEntityEnum.Person, person, AttachAssociation.class); -// } - - @Test -// @Test(expected = UnsupportedOperationException.class) - public void testCreateSupportedAfterOperation_DetachAssociation() throws Exception { - createSupportedAfterOperation(TopiaTckLegacyEntityEnum.Person, person, DettachAssociation.class); - } - -// @Test(expected = UnsupportedOperationException.class) -// public void testCreateUnsupportedBeforeOperation_UncreatableOperation() throws Exception { -// createUnsupportedBeforeOperation(TopiaTckItEntityEnum.Person, person, UncreatableOperation.class); -// } - -// @Test(expected = UnsupportedOperationException.class) -// public void testCreateUnsupportedAfterOperation_UncreatableOperation() throws Exception { -// createUnsupportedAfterOperation(TopiaTckItEntityEnum.Person, person, UncreatableOperation.class); -// } - - @Test - public void testCreateOperation() throws Exception { - - model = getModelBuilder().createModel(context, contracts, true, pet.getTopiaId()); - getModelBuilder().addBeforeOperation(model, TopiaTckLegacyEntityEnum.Pet, FakeOperation.class, "before"); - getModelBuilder().addAfterOperation(model, TopiaTckLegacyEntityEnum.Race, FakeOperation.class, "after"); - } - - @Test(expected = NullPointerException.class) - public void testDoReplicate_nullModel() throws Exception { - - service.doReplicate(null, null); - } - - @Test(expected = NullPointerException.class) - public void testDoReplicate_nullDstCtxt() throws Exception { - - model = getModelBuilder().createModel(context, contracts, true); - service.doReplicate(model, null); - } - - @Override - protected TopiaEntityEnum[] getContracts() { - return contracts; - } - - @Override - protected Log getLog() { - return log; - } - - @Override - protected TopiaContext createDb2(String name) throws Exception { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public void testDetectTypes() throws Exception { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public void testDetectAssociations() throws Exception { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public void testDetectDirectDependencies() throws Exception { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public void testDetectShell() throws Exception { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public void testDetectDependencies() throws Exception { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public void testDetectObjectsToDettach() throws Exception { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public void testDetectOperations() throws Exception { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public void testDoReplicate() throws Exception { - throw new UnsupportedOperationException("Not supported yet."); - } -} - - Deleted: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplAllTest.java =================================================================== --- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplAllTest.java 2012-05-23 18:34:02 UTC (rev 2523) +++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplAllTest.java 2012-05-24 07:53:22 UTC (rev 2524) @@ -1,199 +0,0 @@ -/* - * #%L - * ToPIA :: Service Replication - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.topia.replication; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.Before; -import org.junit.Test; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.TopiaEntityEnum; -import org.nuiton.topia.tck.legacy.entities.Person; -import org.nuiton.topia.tck.legacy.entities.Pet; -import org.nuiton.topia.tck.legacy.entities.Race; - -import static org.nuiton.topia.tck.legacy.TopiaTckLegacyDAOHelper.TopiaTckLegacyEntityEnum; - -/** - * TopiaReplicationServiceImplTest on model TopiaTest - * <p/> - * Created: 07 jun. 09 17:14:22 - * - * @author tchemit <chemit@codelutin.com> - * @since 2.2.0 - */ -public class TopiaReplicationServiceImplAllTest extends AbstractTopiaReplicationServiceTest { - - /** Logger */ - private static final Log log = - LogFactory.getLog(TopiaReplicationServiceImplTest.class); - - protected static final TopiaEntityEnum[] contracts = { - TopiaTckLegacyEntityEnum.Person, - TopiaTckLegacyEntityEnum.Pet, - TopiaTckLegacyEntityEnum.Race - }; - - protected Person person, person2; - - protected Pet pet, pet2, pet3; - - protected Race race, race2, race3; - - @Before - @Override - public void setUp() throws Exception { - - super.setUp(); - - // get data - - ModelFixture fixtures = db.getFixtures(); - - person = fixtures.getPerson(ctxt); - person2 = fixtures.getPerson2(ctxt); - pet = fixtures.getPet(ctxt); - pet2 = fixtures.getPet2(ctxt); - pet3 = fixtures.getPet3(ctxt); - race = fixtures.getRace(ctxt); - race2 = fixtures.getRace2(ctxt); - race3 = fixtures.getRace3(ctxt); - } - - @Test - @Override - public void testDetectTypes() throws Exception { - - detectTypes(race, Race.class); - detectTypes(pet, Pet.class, Person.class, Race.class); - detectTypes(person, Pet.class, Person.class, Race.class); - - detectTypes(pet2, Pet.class); - detectTypes(person2, Person.class); - detectTypes(race2, Race.class); - - detectTypes(race3, Race.class); - detectTypes(pet3, Pet.class, Race.class); - } - - @Test - @Override - public void testGetOperation() throws Exception { - } - - @Test - @Override - public void testDetectAssociations() throws Exception { - - detectAssociations(person, TopiaTckLegacyEntityEnum.Person, Person.PROPERTY_PET); - detectAssociations(race); - detectAssociations(pet); - - detectAssociations(person2); - detectAssociations(race2); - detectAssociations(pet2); - - } - - @Test - @Override - public void testDetectDirectDependencies() throws Exception { - - detectDirectDependencies(person); - detectDirectDependencies(race); - detectDirectDependencies(pet, TopiaTckLegacyEntityEnum.Pet, Pet.PROPERTY_PERSON, TopiaTckLegacyEntityEnum.Pet, Pet.PROPERTY_RACE); - - detectDirectDependencies(person2); - detectDirectDependencies(race2); - detectDirectDependencies(pet2); - } - - @Test - @Override - public void testDetectShell() throws Exception { - - detectShell(person, TopiaTckLegacyEntityEnum.Pet, TopiaTckLegacyEntityEnum.Race); - detectShell(race); - detectShell(pet, TopiaTckLegacyEntityEnum.Person, TopiaTckLegacyEntityEnum.Race); - detectShell(person2, TopiaTckLegacyEntityEnum.Pet, TopiaTckLegacyEntityEnum.Race); - detectShell(race2); - detectShell(pet2, TopiaTckLegacyEntityEnum.Person, TopiaTckLegacyEntityEnum.Race); - } - - @Test - @Override - public void testDetectDependencies() throws Exception { - - detectDependencies(null, - new TopiaTckLegacyEntityEnum[]{TopiaTckLegacyEntityEnum.Race}, new TopiaTckLegacyEntityEnum[]{TopiaTckLegacyEntityEnum.Person}, new TopiaTckLegacyEntityEnum[]{TopiaTckLegacyEntityEnum.Pet}); - } - - @Test - @Override - public void testDetectObjectsToDettach() throws Exception { - - detectObjectsToDettach(null, TopiaTckLegacyEntityEnum.Person, new String[]{Person.PROPERTY_PET}); - } - - @Test - @Override - public void testDetectOperations() throws Exception { - - detectOperations(null); - } - - @Test - @Override - public void testDoReplicate() throws Exception { - - doReplicateAll(); - - } - - @Override - protected TopiaEntityEnum[] getContracts() { - return contracts; - } - - @Override - protected Log getLog() { - return log; - } - - @Override - protected void createModel(TopiaEntity entity) throws TopiaException { - model = getModelBuilder().createModelForAll(getContracts()); - } - - @Override - protected void prepareModel(String... ids) throws TopiaException { - model = service.prepareForAll(getContracts()); - } - -} - - Deleted: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplTest.java =================================================================== --- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplTest.java 2012-05-23 18:34:02 UTC (rev 2523) +++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplTest.java 2012-05-24 07:53:22 UTC (rev 2524) @@ -1,367 +0,0 @@ -/* - * #%L - * ToPIA :: Service Replication - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.topia.replication; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.Before; -import org.junit.Test; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.framework.TopiaContextImplementor; -import org.nuiton.topia.persistence.TopiaEntityEnum; -import org.nuiton.topia.persistence.util.TopiaEntityIdsMap; -import org.nuiton.topia.replication.model.ReplicationModel; -import org.nuiton.topia.replication.operation.DettachAssociation; -import org.nuiton.topia.replication.operation.Duplicate; -import org.nuiton.topia.replication.operation.FakeOperation; -import org.nuiton.topia.replication.operation.UncreatableOperation; -import org.nuiton.topia.replication.operation.UnregistredOperation; -import org.nuiton.topia.tck.legacy.entities.Person; -import org.nuiton.topia.tck.legacy.entities.Pet; -import org.nuiton.topia.tck.legacy.entities.Race; - -import static org.nuiton.topia.tck.legacy.TopiaTckLegacyDAOHelper.TopiaTckLegacyEntityEnum; - -/** - * TopiaReplicationServiceImplTest on model TopiaTest - * <p/> - * Created: 07 jun. 09 17:14:22 - * - * @author tchemit <chemit@codelutin.com> - * @since 2.2.0 - */ -public class TopiaReplicationServiceImplTest extends AbstractTopiaReplicationServiceTest { - - /** Logger */ - private static final Log log = - LogFactory.getLog(TopiaReplicationServiceImplTest.class); - - protected static final TopiaEntityEnum[] contracts = {TopiaTckLegacyEntityEnum.Person, TopiaTckLegacyEntityEnum.Pet, TopiaTckLegacyEntityEnum.Race}; - - protected Person person, person2; - - protected Pet pet, pet2, pet3; - - protected Race race, race2, race3; - - @Before - @Override - public void setUp() throws Exception { - - super.setUp(); - - ModelFixture fixtures = db.getFixtures(); - - person = fixtures.getPerson(ctxt); - person2 = fixtures.getPerson2(ctxt); - pet = fixtures.getPet(ctxt); - pet2 = fixtures.getPet2(ctxt); - pet3 = fixtures.getPet3(ctxt); - race = fixtures.getRace(ctxt); - race2 = fixtures.getRace2(ctxt); - race3 = fixtures.getRace3(ctxt); - } - - @Test - @Override - public void testDetectTypes() throws Exception { - - detectTypes(race, Race.class); - detectTypes(pet, Pet.class, Person.class, Race.class); - detectTypes(person, Pet.class, Person.class, Race.class); - - detectTypes(pet2, Pet.class); - detectTypes(person2, Person.class); - detectTypes(race2, Race.class); - - detectTypes(race3, Race.class); - detectTypes(pet3, Pet.class, Race.class); - } - - @Test - @Override - public void testGetOperation() throws Exception { - - getOperation(UnregistredOperation.class, false); - getOperation(UncreatableOperation.class, true); - getOperation(FakeOperation.class, true); - getOperation(Duplicate.class, true); - getOperation(DettachAssociation.class, true); - } - - @Test - @Override - public void testDetectAssociations() throws Exception { - - detectAssociations(person, TopiaTckLegacyEntityEnum.Person, Person.PROPERTY_PET); - detectAssociations(race); - detectAssociations(pet); - - detectAssociations(person2); - detectAssociations(race2); - detectAssociations(pet2); - } - - @Test - @Override - public void testDetectDirectDependencies() throws Exception { - - detectDirectDependencies(person); - detectDirectDependencies(race); - detectDirectDependencies(pet, TopiaTckLegacyEntityEnum.Pet, Pet.PROPERTY_PERSON, TopiaTckLegacyEntityEnum.Pet, Pet.PROPERTY_RACE); - - detectDirectDependencies(person2); - detectDirectDependencies(race2); - detectDirectDependencies(pet2); - } - - @Test - @Override - public void testDetectShell() throws Exception { - - detectShell(person, TopiaTckLegacyEntityEnum.Pet, TopiaTckLegacyEntityEnum.Race); - detectShell(race); - detectShell(pet, TopiaTckLegacyEntityEnum.Person, TopiaTckLegacyEntityEnum.Race); - detectShell(person2); - detectShell(race2); - detectShell(pet2); - } - - @Test - @Override - public void testDetectDependencies() throws Exception { - - detectDependencies(person, new TopiaTckLegacyEntityEnum[]{TopiaTckLegacyEntityEnum.Race}, new TopiaTckLegacyEntityEnum[]{TopiaTckLegacyEntityEnum.Person}, new TopiaTckLegacyEntityEnum[]{TopiaTckLegacyEntityEnum.Pet}); - detectDependencies(race, new TopiaTckLegacyEntityEnum[]{TopiaTckLegacyEntityEnum.Race}); - detectDependencies(pet, new TopiaTckLegacyEntityEnum[]{TopiaTckLegacyEntityEnum.Race}, new TopiaTckLegacyEntityEnum[]{TopiaTckLegacyEntityEnum.Person}, new TopiaTckLegacyEntityEnum[]{TopiaTckLegacyEntityEnum.Pet}); - - detectDependencies(person2, new TopiaTckLegacyEntityEnum[]{TopiaTckLegacyEntityEnum.Person}); - detectDependencies(race2, new TopiaTckLegacyEntityEnum[]{TopiaTckLegacyEntityEnum.Race}); - detectDependencies(pet2, new TopiaTckLegacyEntityEnum[]{TopiaTckLegacyEntityEnum.Pet}); - } - - @Test - @Override - public void testDetectObjectsToDettach() throws Exception { - - detectObjectsToDettach(person, TopiaTckLegacyEntityEnum.Person, new String[]{Person.PROPERTY_PET}); - detectObjectsToDettach(race); - detectObjectsToDettach(pet, TopiaTckLegacyEntityEnum.Person, new String[]{Person.PROPERTY_PET}); - - detectObjectsToDettach(person2); - detectObjectsToDettach(race2); - detectObjectsToDettach(pet2); - - detectObjectsToDettach(race3); - detectObjectsToDettach(pet3); - } - - @Test - @Override - public void testDetectOperations() throws Exception { - - //TODO Make some real test on detected operations... - - detectOperations(person); - detectOperations(pet); - detectOperations(race); - - detectOperations(person2); - detectOperations(pet2); - detectOperations(race2); - - detectOperations(race3); - detectOperations(pet3); - } - - @Test - @Override - public void testDoReplicate() throws Exception { - - doReplicate(TopiaTckLegacyEntityEnum.Person, person); - doReplicate(TopiaTckLegacyEntityEnum.Person, person2); - doReplicate(TopiaTckLegacyEntityEnum.Person, person, person2); - - doReplicate(TopiaTckLegacyEntityEnum.Pet, pet); - doReplicate(TopiaTckLegacyEntityEnum.Pet, pet2); - doReplicate(TopiaTckLegacyEntityEnum.Pet, pet, pet2, pet3); - doReplicate(TopiaTckLegacyEntityEnum.Pet, person2, pet3); - - doReplicate(TopiaTckLegacyEntityEnum.Race, race); - doReplicate(TopiaTckLegacyEntityEnum.Race, race2); - doReplicate(TopiaTckLegacyEntityEnum.Race, race, race2); - - } - - /** - * Cette methode montre pourquoi la simple replication ne peut pas - * fonctionne :) - * <p/> - * Le replicateur ne deplique pas dans le bon ordre et on a donc des - * violations de clef etrangeres... - * - * @throws Exception pour toute erreur - */ - @Test(expected = TopiaException.class) - public void testSimpleReplicateFailed() throws Exception { - - TopiaContext dstRootCtxt = createDb2("testSimpleReplicateFailed"); - - //model = service.prepare(contracts, pet.getTopiaId()); - - TopiaContext srcCtxt = ctxt.beginTransaction(); - dstCtxt = (TopiaContextImplementor) dstRootCtxt.beginTransaction(); - - try { - - srcCtxt.replicateEntity(dstCtxt, pet); - - dstCtxt.commitTransaction(); - - } finally { - srcCtxt.rollbackTransaction(); - srcCtxt.closeContext(); - dstCtxt.closeContext(); - } - } - - /** - * Cette methode montre comment manuellement on peut effectuer la - * replication (en dettachant les dependances qui forment des cycles) - * <p/> - * La methode utilisee ici peut ne pas fonctionner : si une clef metier est - * posee sur une dependance alors cela ne fonctionne pas. - * - * @throws Exception pour toute erreur - */ - @Test - public void testSimpleReplicateNotSure() throws Exception { - - TopiaContext dstRootCtxt = createDb2("testSimpleReplicateNotSure"); - - //model = service.prepare(contracts, pet.getTopiaId()); - - TopiaContext srcCtxt = ctxt; - dstCtxt = (TopiaContextImplementor) dstRootCtxt.beginTransaction(); - - try { - - - srcCtxt.replicateEntity(dstCtxt, race); - - // on dettache l'entite qui pose probleme - - pet.setPerson(null); - srcCtxt.replicateEntity(dstCtxt, pet); - srcCtxt.rollbackTransaction(); - - srcCtxt.replicateEntity(dstCtxt, person); - - dstCtxt.commitTransaction(); - ((Pet) dstCtxt.findByTopiaId(pet.getTopiaId())).setPerson((Person) dstCtxt.findByTopiaId(person.getTopiaId())); - dstCtxt.commitTransaction(); - - srcCtxt.rollbackTransaction(); - person = db.getFixtures().getPerson(srcCtxt); - - assertEntityEquals(person, dstCtxt.findByTopiaId(person.getTopiaId()), null); - } finally { - srcCtxt.rollbackTransaction(); - //srcCtxt.closeContext(); - dstCtxt.closeContext(); - } - } - - /** - * Cette methode montre comment manuellement on peut effectuer la - * replication (en dettachant les associations qui forment des cycles) - * <p/> - * La methode utilisee ici fonctionne mieux que la precedante : il parrait - * dificille de pose une une clef metier sur une association :). - * <p/> - * On remarque que l'on dettache l'assocation qui forme un cycle et que l'on - * est pas obligee de la reattachee car elle est bi-directionnelle. - * <p/> - * On doit optimiser l'algorithme dans la methode {@link - * ReplicationModel#adjustOperations(TopiaEntityIdsMap)}. - * - * @throws Exception pour toute erreur - */ - @Test - public void testSimpleReplicateSure() throws Exception { - - TopiaContext dstRootCtxt = createDb2("testSimpleReplicateSure"); - - //model = service.prepare(contracts, pet.getTopiaId()); - - TopiaContext srcCtxt = ctxt; - dstCtxt = (TopiaContextImplementor) dstRootCtxt.beginTransaction(); - - try { - - srcCtxt.replicateEntity(dstCtxt, race); - // on dettache l'association qui pose probleme - person.setPet(null); - srcCtxt.replicateEntity(dstCtxt, person); - - srcCtxt.replicateEntity(dstCtxt, pet); - srcCtxt.rollbackTransaction(); - dstCtxt.commitTransaction(); - - //((Person) dstCtxt.findByTopiaId(person.getTopiaId())).addPet(((Pet) dstCtxt.findByTopiaId(pet.getTopiaId()))); - //dstCtxt.commitTransaction(); - - srcCtxt.rollbackTransaction(); - - srcCtxt.closeContext(); - dstCtxt.closeContext(); - - ctxt = db.beginTransaction(); - dstCtxt = (TopiaContextImplementor) dstRootCtxt.beginTransaction(); - - person = db.getFixtures().getPerson(ctxt); - - assertEntityEquals(person, dstCtxt.findByTopiaId(person.getTopiaId()), null); - - } finally { - dstCtxt.closeContext(); - } - } - - @Override - protected TopiaEntityEnum[] getContracts() { - return contracts; - } - - @Override - protected Log getLog() { - return log; - } - -} - - Deleted: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/FakeOperation.java =================================================================== --- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/FakeOperation.java 2012-05-23 18:34:02 UTC (rev 2523) +++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/FakeOperation.java 2012-05-24 07:53:22 UTC (rev 2524) @@ -1,57 +0,0 @@ -/* - * #%L - * ToPIA :: Service Replication - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.topia.replication.operation; - -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.framework.TopiaContextImplementor; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.replication.TopiaReplicationContext; -import org.nuiton.topia.replication.TopiaReplicationOperation; -import org.nuiton.topia.replication.model.ReplicationOperationDef; - -import java.util.List; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 2.2.0 - */ -public class FakeOperation implements TopiaReplicationOperation { - - public static final Class<?>[] PARAMETERS_CLASSES = - new Class<?>[]{String.class}; - - @Override - public void run(TopiaReplicationContext replicationContext, - ReplicationOperationDef operationDef, - TopiaContextImplementor srcCtxt, - TopiaContextImplementor dstCtxt, - List<? extends TopiaEntity> nodeEntities - ) - throws TopiaException { - - } - -} Deleted: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/UncreatableOperation.java =================================================================== --- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/UncreatableOperation.java 2012-05-23 18:34:02 UTC (rev 2523) +++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/UncreatableOperation.java 2012-05-24 07:53:22 UTC (rev 2524) @@ -1,53 +0,0 @@ -/* - * #%L - * ToPIA :: Service Replication - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.topia.replication.operation; - -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.framework.TopiaContextImplementor; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.replication.TopiaReplicationContext; -import org.nuiton.topia.replication.TopiaReplicationOperation; -import org.nuiton.topia.replication.model.ReplicationOperationDef; - -import java.util.List; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 2.2.0 - */ -public class UncreatableOperation implements TopiaReplicationOperation { - - @Override - public void run(TopiaReplicationContext replicationContext, - ReplicationOperationDef operationDef, - TopiaContextImplementor srcCtxt, - TopiaContextImplementor dstCtxt, - List<? extends TopiaEntity> nodeEntities - ) - throws TopiaException { - } - -} Deleted: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/UnregistredOperation.java =================================================================== --- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/UnregistredOperation.java 2012-05-23 18:34:02 UTC (rev 2523) +++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/operation/UnregistredOperation.java 2012-05-24 07:53:22 UTC (rev 2524) @@ -1,54 +0,0 @@ -/* - * #%L - * ToPIA :: Service Replication - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.topia.replication.operation; - -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.framework.TopiaContextImplementor; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.replication.TopiaReplicationContext; -import org.nuiton.topia.replication.TopiaReplicationOperation; -import org.nuiton.topia.replication.model.ReplicationOperationDef; - -import java.util.List; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 2.2.0 - */ -public class UnregistredOperation implements TopiaReplicationOperation { - - @Override - public void run( - TopiaReplicationContext replicationContext, - ReplicationOperationDef operationDef, - TopiaContextImplementor srcCtxt, - TopiaContextImplementor dstCtxt, - List<? extends TopiaEntity> nodeEntities - ) - throws TopiaException { - } - -} Deleted: trunk/topia-service-replication/src/test/resources/META-INF/services/org.nuiton.topia.replication.TopiaReplicationOperation =================================================================== --- trunk/topia-service-replication/src/test/resources/META-INF/services/org.nuiton.topia.replication.TopiaReplicationOperation 2012-05-23 18:34:02 UTC (rev 2523) +++ trunk/topia-service-replication/src/test/resources/META-INF/services/org.nuiton.topia.replication.TopiaReplicationOperation 2012-05-24 07:53:22 UTC (rev 2524) @@ -1,6 +0,0 @@ -# -# la liste des operations disponibles pour le moteur de replication -# voir la classe org.nuiton.topia.replication.TopiaReplicationServiceImpl -# -org.nuiton.topia.replication.operation.FakeOperation -org.nuiton.topia.replication.operation.UncreatableOperation \ No newline at end of file Deleted: trunk/topia-service-replication/src/test/resources/TopiaContext-legacy.properties =================================================================== --- trunk/topia-service-replication/src/test/resources/TopiaContext-legacy.properties 2012-05-23 18:34:02 UTC (rev 2523) +++ trunk/topia-service-replication/src/test/resources/TopiaContext-legacy.properties 2012-05-24 07:53:22 UTC (rev 2524) @@ -1,15 +0,0 @@ -# Proprietes par defaut pour une base de donnees de type H2 et le model legacy -hibernate.hbm2ddl.auto=update -hibernate.show_sql=false - -hibernate.dialect=org.hibernate.dialect.H2Dialect - -topia.use.hibernate.mapping.files=false -topia.connection.username=sa -topia.connection.password=sa -topia.connection.driver_class=org.h2.Driver - -#Not necessary, but useful -hibernate.connection.provider_class=org.nuiton.topia.framework.TopiaHibernateConnectionProvider - -topia.service.replication=org.nuiton.topia.replication.TopiaReplicationServiceImpl \ No newline at end of file
participants (1)
-
tchemit@users.nuiton.org