Topia-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
May 2012
- 4 participants
- 135 discussions
r2530 - in trunk: topia-persistence/src/main/java/org/nuiton/topia/generator topia-persistence-tck/src/main/xmi
by tchemit@users.nuiton.org 25 May '12
by tchemit@users.nuiton.org 25 May '12
25 May '12
Author: tchemit
Date: 2012-05-25 15:38:08 +0200 (Fri, 25 May 2012)
New Revision: 2530
Url: http://nuiton.org/repositories/revision/topia/2530
Log:
refs #2089: Use JPA (orm) mappings
add new tests for unique and not-null
improve TopiaGeneratorUtil (add missing methods for boolean tag-values)
Modified:
trunk/topia-persistence-tck/src/main/xmi/topia-tck-mapping.zargo
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityJPAMappingGenerator.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaTagValues.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityJPAMappingGenerator.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityJPAMappingGenerator.java 2012-05-25 12:40:12 UTC (rev 2529)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityJPAMappingGenerator.java 2012-05-25 13:38:08 UTC (rev 2530)
@@ -1,8 +1,11 @@
package org.nuiton.topia.generator;
+import com.google.common.base.Function;
import com.google.common.base.Strings;
import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Iterables;
import com.google.common.collect.LinkedHashMultimap;
+import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import org.apache.commons.collections.CollectionUtils;
@@ -184,7 +187,7 @@
splitAttributes(input, attributes);
// get all unique constraints to add
- Multimap<String, String> uniqueContraints = getUniqueConstraints(
+ List<String[]> uniqueContraints = getUniqueConstraints(
input, attributes, embeddableAttributes);
/*{<?xml version="1.0" encoding="UTF-8"?>
@@ -240,17 +243,11 @@
/*{<%=flushTag(TAG_TABLE, uniqueContraints.isEmpty(), xmlAttributes)%>
}*/
if (!uniqueContraints.isEmpty()) {
- for (String uniqueContraintName : uniqueContraints.keySet()) {
- addAttribute(xmlAttributes, ATTRIBUTE_NAME, uniqueContraintName);
-/*{<%=flushTag(TAG_UNIQUE_CONTRAINT, xmlAttributes)%>
+ for (String uniqueContraint : uniqueContraints) {
+/*{<%=flushTag(TAG_UNIQUE_CONTRAINT)%>
+<%=flushTag(TAG_COLUMN_NAME, uniqueContraint)%><%=closeStrictTag(TAG_COLUMN_NAME)%>
+<%=closeTag(TAG_UNIQUE_CONTRAINT)%>
}*/
- for (String uniqueContraint :
- uniqueContraints.get(uniqueContraintName)) {
-/*{<%=flushTag(TAG_COLUMN_NAME, uniqueContraint)%>
-}*/
- }
-/*{<%=closeTag(TAG_UNIQUE_CONTRAINT)%>
-}*/
}
/*{<%=closeTag(TAG_TABLE)%>
}*/
@@ -260,7 +257,7 @@
// TODO AThimel 22/05/2012 Is the strategy choosable ?
// TODO AThimel 22/05/2012 May only be specified on parent entities ?
- addAttribute(xmlAttributes, ATTRIBUTE_STRATEGY, InheritanceType.TABLE_PER_CLASS.name());
+ addAttribute(xmlAttributes, ATTRIBUTE_STRATEGY, InheritanceType.TABLE_PER_CLASS);
/*{<%=flushTag(TAG_INHERITANCE, true, xmlAttributes)%>
}*/
@@ -627,6 +624,10 @@
}*/
// add join-column
addAttribute(columnAttributes, ATTRIBUTE_NAME, reverseAttrDBName);
+ // unique stereotype
+ if (TopiaGeneratorUtil.hasUniqueStereotype(attr)) {
+ addAttribute(columnAttributes, ATTRIBUTE_UNIQUE, true);
+ }
/*{<%=flushTag(TAG_JOIN_COLUMN, true, columnAttributes)%>
}*/
// add a reverse-join-column
@@ -717,8 +718,8 @@
}
private void generateOneToManyAttribute(Writer output,
- ObjectModelClass input,
- ObjectModelAttribute attr) throws IOException {
+ ObjectModelClass input,
+ ObjectModelAttribute attr) throws IOException {
Map<String, String> xmlAttributes = Maps.newTreeMap();
boolean needsIndex = TopiaGeneratorUtil.hasIndexedStereotype(attr);
@@ -745,6 +746,10 @@
addAttribute(columnAttributes, ATTRIBUTE_NAME, reverseAttrDBName);
+ // unique stereotype
+ if (TopiaGeneratorUtil.hasUniqueStereotype(attr)) {
+ addAttribute(columnAttributes, ATTRIBUTE_UNIQUE, true);
+ }
/*{<%=flushTag(TAG_ONE_TO_MANY, xmlAttributes)%>
}*/
@@ -945,7 +950,9 @@
return result;
}
-
+ /**
+ * Different types of relations.
+ */
public enum PROPERTY_TYPE {
BASIC,
MANY_TO_ONE,
@@ -998,13 +1005,43 @@
return result;
}
- private Multimap<String, String> getUniqueConstraints(ObjectModelClass input,
- List<ObjectModelAttribute> attributes,
- Multimap<String, ObjectModelAttribute> embeddableAttributes) {
- Multimap<String, String> result = ArrayListMultimap.create();
+ private List<String[]> getUniqueConstraints(ObjectModelClass input,
+ List<ObjectModelAttribute> attributes,
+ Multimap<String, ObjectModelAttribute> embeddableAttributes) {
+ List< String[]> result = Lists.newArrayList();
+
+ // only generate unique constraints for embeddable entities since for
+ // other stuff this is already done with a unique attribute
+
+// Multimap<PROPERTY_TYPE, ObjectModelAttribute> attributesByType =
+// splitAttributesByType(attributes);
+//
+// Collection<ObjectModelAttribute> basicAttributes =
+// attributesByType.get(PROPERTY_TYPE.BASIC);
+// for (ObjectModelAttribute attribute : basicAttributes) {
+//
+// if (TopiaGeneratorUtil.hasUniqueStereotype(attribute)) {
+// String dbName = TopiaGeneratorUtil.getDbName(attribute);
+// result.add(dbName);
+// }
+// }
+
+ for (String s : embeddableAttributes.keySet()) {
+ Collection<ObjectModelAttribute> attrs = embeddableAttributes.get(s);
+ Iterable<String> dbNames = Iterables.transform(attrs, ATTRIBUTE_TO_DB_NAME);
+ String[] strings = Iterables.toArray(dbNames, String.class);
+ result.add(strings);
+ }
return result;
}
+ public static final Function<ObjectModelAttribute, String> ATTRIBUTE_TO_DB_NAME = new Function<ObjectModelAttribute, String>() {
+ @Override
+ public String apply(ObjectModelAttribute input) {
+ return TopiaGeneratorUtil.getDbName(input);
+ }
+ };
+
protected String getName(ObjectModelAttribute attr) {
return getName(attr, false);
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java 2012-05-25 12:40:12 UTC (rev 2529)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java 2012-05-25 13:38:08 UTC (rev 2530)
@@ -48,7 +48,6 @@
import org.nuiton.eugene.models.object.ObjectModelParameter;
import org.nuiton.topia.persistence.TopiaDAOImpl;
-import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -58,7 +57,6 @@
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
-import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -375,8 +373,8 @@
* Les naturalId {@link #isNaturalId} sont not null par défaut
*
* @param attribute l'attribut à tester
- * @return {@code true} si l'attribut doit être non null,
- * par défaut pour les naturalId, {@code false} sinon..
+ * @return {@code true} si l'attribut doit être non null, {@code false}
+ * sinon.
* @since 2.6.9
*/
public static boolean isNotNull(ObjectModelAttribute attribute) {
@@ -646,7 +644,7 @@
return Set.class.getName();
}
if (JavaGeneratorUtil.hasIndexedStereotype(attr) || attr.isOrdered() ||
- StringUtils.isNotBlank(getOrderByTagValue(attr))) {
+ StringUtils.isNotBlank(getOrderByTagValue(attr))) {
return List.class.getName();
}
return Collection.class.getName();
@@ -1050,7 +1048,7 @@
public static boolean isSetNeeded(Collection<ObjectModelOperation> operations) {
return isImportNeeded(operations,
- Set.class.getSimpleName());
+ Set.class.getSimpleName());
}
/**
@@ -1348,6 +1346,31 @@
}
/**
+ * Detecte si un attribut est déclaré comme inverse d'une relation.
+ * <p/>
+ *
+ * @param attribute l'attribut à tester
+ * @return {@code true} si le tag value a ete positionne sur l'attribut
+ * via le tag {@link TopiaTagValues#TAG_INVERSE}, {@code false}
+ * sinon.
+ * @since 3.0
+ */
+ public static boolean isInverse(ObjectModelAttribute attribute) {
+ String value = getInverseTagValue(attribute);
+ if (StringUtils.isEmpty(value)) {
+ // valeur null, donc par default pas inverse
+ return false;
+ }
+ try {
+ return Boolean.valueOf(value.trim());
+ } catch (Exception e) {
+ // on a pas reussi a convertir en boolean.
+ //todo peut-être declancher une exception ?
+ return false;
+ }
+ }
+
+ /**
* Obtain the value of the {@link TopiaTagValues#TAG_LAZY}
* tag value on the given attribute.
* <p/>
@@ -1363,6 +1386,31 @@
}
/**
+ * Detecte si un attribut est déclaré comme lazy d'une relation.
+ * <p/>
+ *
+ * @param attribute l'attribut à tester
+ * @return {@code true} si le tag value a ete positionne sur l'attribut
+ * via le tag {@link TopiaTagValues#TAG_LAZY}, {@code false}
+ * sinon.
+ * @since 3.0
+ */
+ public static boolean isLazy(ObjectModelAttribute attribute) {
+ String value = getLazyTagValue(attribute);
+ if (StringUtils.isEmpty(value)) {
+ // valeur null, donc par default pas de lazy
+ return false;
+ }
+ try {
+ return Boolean.valueOf(value.trim());
+ } catch (Exception e) {
+ // on a pas reussi a convertir en boolean.
+ //todo peut-être declancher une exception ?
+ return false;
+ }
+ }
+
+ /**
* Obtain the value of the {@link TopiaTagValues#TAG_FETCH}
* tag value on the given attribute.
* <p/>
@@ -1378,6 +1426,31 @@
}
/**
+ * Detecte si un attribut est déclaré comme lazy d'une relation.
+ * <p/>
+ *
+ * @param attribute l'attribut à tester
+ * @return {@code true} si le tag value a ete positionne sur l'attribut
+ * via le tag {@link TopiaTagValues#TAG_FETCH}, {@code false}
+ * sinon.
+ * @since 3.0
+ */
+ public static boolean isFetch(ObjectModelAttribute attribute) {
+ String value = getFetchTagValue(attribute);
+ if (StringUtils.isEmpty(value)) {
+ // valeur null, donc par default pas de fetch
+ return false;
+ }
+ try {
+ return Boolean.valueOf(value.trim());
+ } catch (Exception e) {
+ // on a pas reussi a convertir en boolean.
+ //todo peut-être declancher une exception ?
+ return false;
+ }
+ }
+
+ /**
* Obtain the value of the {@link TopiaTagValues#TAG_ORDER_BY}
* tag value on the given attribute.
* <p/>
@@ -1686,7 +1759,7 @@
* given attribute.
*
* @param attribute attribute to test
- * @param model model to test
+ * @param model model to test
* @return none empty value of the found tag value or {@code null} if not found nor empty.
* @see TopiaTagValues#TAG_INDEX_FOREIGN_KEYS
* @since 2.6.5
@@ -1733,28 +1806,28 @@
public static final Predicate<ObjectModelAttribute> IS_ATTRIBUTE_COMPOSITE = new Predicate<ObjectModelAttribute>() {
@Override
- public boolean apply( ObjectModelAttribute input) {
+ public boolean apply(ObjectModelAttribute input) {
return input.isComposite();
}
};
public static final Predicate<ObjectModelAttribute> IS_ATTRIBUTE_AGGREGATE = new Predicate<ObjectModelAttribute>() {
@Override
- public boolean apply( ObjectModelAttribute input) {
+ public boolean apply(ObjectModelAttribute input) {
return input.isAggregate();
}
};
- public static final Predicate<ObjectModelAttribute> IS_ATTRIBUTE_REFERENCE_CLASSIFIER= new Predicate<ObjectModelAttribute>() {
+ public static final Predicate<ObjectModelAttribute> IS_ATTRIBUTE_REFERENCE_CLASSIFIER = new Predicate<ObjectModelAttribute>() {
@Override
- public boolean apply( ObjectModelAttribute input) {
+ public boolean apply(ObjectModelAttribute input) {
return input.referenceClassifier();
}
};
- public static final Predicate<ObjectModelAttribute> IS_ATTRIBUTE_HAS_ASSOCIATION_CLASS= new Predicate<ObjectModelAttribute>() {
+ public static final Predicate<ObjectModelAttribute> IS_ATTRIBUTE_HAS_ASSOCIATION_CLASS = new Predicate<ObjectModelAttribute>() {
@Override
- public boolean apply( ObjectModelAttribute input) {
+ public boolean apply(ObjectModelAttribute input) {
return input.hasAssociationClass();
}
};
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaTagValues.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaTagValues.java 2012-05-25 12:40:12 UTC (rev 2529)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaTagValues.java 2012-05-25 13:38:08 UTC (rev 2530)
@@ -35,6 +35,8 @@
import org.nuiton.topia.persistence.TopiaEntityContextable;
import org.nuiton.topia.persistence.TopiaEntityEnum;
+import java.util.Collection;
+
import static org.nuiton.eugene.ModelPropertiesUtil.TagValueDefinition;
/**
@@ -148,6 +150,7 @@
* l'ordre alphabétique.
*
* @see TopiaGeneratorUtil#getInverseTagValue(ObjectModelAttribute)
+ * @see TopiaGeneratorUtil#isInverse(ObjectModelAttribute)
* @since 2.5
*/
@TagValueDefinition(target = {ObjectModelAttribute.class},
@@ -158,6 +161,7 @@
* Tag pour spécifier la caractère lazy d'une association multiple.
*
* @see TopiaGeneratorUtil#getLazyTagValue(ObjectModelAttribute)
+ * @see TopiaGeneratorUtil#isLazy(ObjectModelAttribute)
* @since 2.5
*/
@TagValueDefinition(target = {ObjectModelAttribute.class},
@@ -168,6 +172,7 @@
* Tag pour spécifier la caractère fetch d'une association multiple.
*
* @see TopiaGeneratorUtil#getFetchTagValue(ObjectModelAttribute)
+ * @see TopiaGeneratorUtil#isFetch(ObjectModelAttribute)
* @since 2.5
*/
@TagValueDefinition(target = {ObjectModelAttribute.class},
@@ -188,6 +193,7 @@
* Tag pour spécifier la caractère not-null d'un attribut.
*
* @see TopiaGeneratorUtil#getNotNullTagValue(ObjectModelAttribute)
+ * @see TopiaGeneratorUtil#isNotNull(ObjectModelAttribute)
* @since 2.5
*/
@TagValueDefinition(target = {ObjectModelAttribute.class},
Modified: trunk/topia-persistence-tck/src/main/xmi/topia-tck-mapping.zargo
===================================================================
(Binary files differ)
1
0
r2529 - in trunk/topia-persistence/src/main/java/org/nuiton/topia: . framework
by athimel@users.nuiton.org 25 May '12
by athimel@users.nuiton.org 25 May '12
25 May '12
Author: athimel
Date: 2012-05-25 14:40:12 +0200 (Fri, 25 May 2012)
New Revision: 2529
Url: http://nuiton.org/repositories/revision/topia/2529
Log:
Javadoc and reorganize TopiaContext
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2012-05-25 08:18:33 UTC (rev 2528)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2012-05-25 12:40:12 UTC (rev 2529)
@@ -42,18 +42,27 @@
import java.io.Reader;
import java.io.Writer;
import java.util.List;
+import java.util.Properties;
/**
- * TODO-FD20100507 : Need javadoc + translate the one on methods.
+ * The TopiaContext is the most important class of ToPIA. It contains all the
+ * methods to manipulate data : transaction management, entities querying, event
+ * firing, schema management, services management, ...
* <p/>
+ * To get an instance of TopiaContext, see {@link
+ * TopiaContextFactory#getContext(Properties)}
+ * <p/>
* Created: 3 janv. 2006 21:18:34
*
* @author poussin <poussin(a)codelutin.com>
* @author tchemit <tchemit(a)codelutin.com>
* @version $Id$
+ * @see TopiaContextFactory#getContext(Properties)
*/
public interface TopiaContext {
+ /* -------------------- TRANSACTION MANAGEMENT --------------------------*/
+
/**
* Returns a new context containing its own transaction.
*
@@ -94,7 +103,9 @@
*/
boolean isClosed();
+ /* ------------------------ EVENT FIRING --------------------------*/
+
/* TopiaEntityListener */
/**
@@ -131,7 +142,7 @@
* the context
*
* @param entityClass the listened TopiaEntity's class
- * @param listener the listener instance to unregister
+ * @param listener the listener instance to unregister
*/
void removeTopiaEntityListener(
Class<? extends TopiaEntity> entityClass,
@@ -155,7 +166,7 @@
* operation on the entity.
*
* @param entityClass the TopiaEntity's class to listen
- * @param vetoable the vetoable instance to register
+ * @param vetoable the vetoable instance to register
*/
void addTopiaEntityVetoable(
Class<? extends TopiaEntity> entityClass,
@@ -174,13 +185,32 @@
* the context
*
* @param entityClass the listened TopiaEntity's class
- * @param vetoable the vetoable instance to unregister
+ * @param vetoable the vetoable instance to unregister
*/
void removeTopiaEntityVetoable(
Class<? extends TopiaEntity> entityClass,
TopiaEntityVetoable vetoable);
+ /* TopiaEntitiesVetoable */
+
+ /**
+ * Register to the context a TopiaEntitiesVetoable about any TopiaEntity.
+ * <code>vetoable</code> instance will be notified BEFORE any entity load
+ *
+ * @param vetoable the vetoable instance to register
+ */
+ void addTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable);
+
+ /**
+ * Unregister the given TopiaEntitiesVetoable about any TopiaEntity from the
+ * context
+ *
+ * @param vetoable the vetoable instance to unregister
+ */
+ void removeTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable);
+
+
/* TopiaTransactionListener */
/**
@@ -200,6 +230,7 @@
*/
void removeTopiaTransactionListener(TopiaTransactionListener listener);
+
/* TopiaTransactionVetoable */
/**
@@ -283,80 +314,9 @@
@Deprecated
void removeTopiaContextListener(TopiaContextListener listener);
+ /* -------------------- GLOBAL OPERATIONS ON ENTITIES --------------------*/
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- /* TopiaEntitiesVetoable */
-
- void addTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable);
-
- void removeTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable);
-
/**
- * Return true if specific service is available.
- *
- * @param <E> type of service
- * @param interfaceService fqn of the service
- * @return the service
- */
- <E extends TopiaService> boolean serviceEnabled(
- Class<E> interfaceService);
-
- /**
- * Return the service. This service must be valid with a public static final
- * SERVICE_NAME property.
- *
- * @param <E> type of service that extends {@link TopiaService}
- * @param interfaceService class of the service
- * @return the service instance
- * @throws TopiaNotFoundException if service can't be retrieved
- */
- <E extends TopiaService> E getService(Class<E> interfaceService)
- throws TopiaNotFoundException;
-
- /**
- * Detect if the table is created on storage for a given persistent class.
- *
- * @param clazz the researched class
- * @return true if the table exists on storage
- * @throws TopiaException if the context is not initialized
- */
- boolean isSchemaExist(Class<?> clazz) throws TopiaException;
-
- /**
- * Permet de créer le schema de la base de données.
- *
- * @throws TopiaException if any exception
- */
- void createSchema() throws TopiaException;
-
- /**
- * Permet d'afficher les requêtes SQL de création de base.
- *
- * @throws TopiaException if any exception
- */
- void showCreateSchema() throws TopiaException;
-
- /**
- * Permet de mettre à jour le schema de la base de données.
- *
- * @throws TopiaException if any exception
- */
- void updateSchema() throws TopiaException;
-
- /**
* Retrieve {@link TopiaEntity} using its unique {@code id}.
*
* @param topiaId unique identifier of the entity in all the application.
@@ -379,10 +339,10 @@
List findByQuery(TopiaQuery query) throws TopiaException;
/**
- * Instantiate a new TopiaQuery.
+ * Instantiate a new TopiaQuery typed for the given entity's class
*
- * @param entityClass main entity class for the Query
- * @param alias alias of the entity in the Query
+ * @param entityClass main entity class for the Query
+ * @param alias alias of the entity in the Query
* @return a new TopiaQuery
* @see TopiaQuery
* @deprecated since TopiaQuery is deprecated in 3.0.
@@ -391,77 +351,147 @@
TopiaQuery createQuery(Class<?> entityClass, String alias);
/**
- * Permet de faire une requete HQL hibernate directement sur la base.
- *
+ * Allow to do some JPA-QL query
+ * <p/>
* WARNING : Depending on the registered service, this method may not
* support something else than queries on TopiaEntity
*
- * @param hql la requete a faire
- * @param args les arguments de la requete
- * @return La liste des resultats
- * @throws TopiaException si une erreur survient durant la requete
+ * @param jpaql the JPA-QL query to execute
+ * @param paramNamesAndValues an array of query parameters based on
+ * [key,value,key,value,...]
+ * @return The result list
+ * @throws TopiaException for any error during querying
*/
- List find(String hql, Object... args) throws TopiaException;
+ List find(String jpaql, Object... paramNamesAndValues)
+ throws TopiaException;
/**
- * Permet de faire une requete HQL hibernate directement sur la base en
- * precisant la fenetre des elements a remonter avec les parametres {@code
- * startIndex} et {@code endIndex}.
- *
+ * Allow to do some JPA-QL query using the given bounds.
+ * <p/>
+ * No lower bound : <code>startIndex</code> = 0.<br/>
+ * No upper bound : <code>endIndex</code> = -1.
+ * <p/>
* WARNING : Depending on the registered service, this method may not
* support something else than queries on TopiaEntity
*
- * @param hql la requete a faire
- * @param startIndex la position du premier element a remonter
- * @param endIndex la position du dernier element a remonter
- * @param args les arguments de la requete
- * @return La liste des resultats
- * @throws TopiaException si une erreur survient durant la requete
+ * @param jpaql the JPA-QL query to execute
+ * @param startIndex first element position
+ * @param endIndex last element position
+ * @param paramNamesAndValues an array of query parameters based on
+ * [key,value,key,value,...]
+ * @return The result list
+ * @throws TopiaException for any error during querying
*/
- List find(String hql, int startIndex, int endIndex, Object... args)
+ List find(String jpaql, int startIndex, int endIndex,
+ Object... paramNamesAndValues)
throws TopiaException;
/**
- * Execute HQL operation on data (Update, Delete).
+ * Execute JPA-QL operation on data (Update, Delete).
*
- * @param hql la requete a faire
- * @param args les arguments de la requete
+ * @param jpaql the JPA-QL query to execute
+ * @param paramNamesAndValues an array of query parameters based on
+ * [key,value,key,value,...]
* @return The number of entities updated or deleted.
* @throws TopiaException if any exception
*/
- int execute(String hql, Object... args) throws TopiaException;
+ int execute(String jpaql, Object... paramNamesAndValues) throws TopiaException;
/**
- * Permet d'ajouter dans le TopiaContext une TopiaEntity créé par un autre
- * context.
+ * Add into this TopiaContext an entity created by another TopiaContext
*
- * @param e l'entity a ajouter
+ * @param e the entity to add
* @throws TopiaException if any exception
*/
void add(TopiaEntity e) throws TopiaException;
/**
- * Permet d'importer des données en XML.
+ * Execute a given sql code inside this transaction.
*
- * @param xml le flux XML
- * @throws TopiaException si une erreur survient durant l'import
+ * @param sqlScript the sql script to execute
+ * @throws TopiaException if any problem occurred while executing the sql script.
+ */
+ void executeSQL(String sqlScript) throws TopiaException;
+
+ /* -------------------- SCHEMA MANAGMENT -----------------------------*/
+
+ /**
+ * Detect if the table is created on storage for a given persistent class.
+ *
+ * @param clazz the researched class
+ * @return true if the table exists on storage
+ * @throws TopiaException if the context is not initialized
+ */
+ boolean isSchemaExist(Class<?> clazz) throws TopiaException;
+
+ /**
+ * Triggers database schema creation
+ *
+ * @throws TopiaException if any exception
+ */
+ void createSchema() throws TopiaException;
+
+ /**
+ * Displays the SQL queries that would be used for a schema creation
+ *
+ * @throws TopiaException if any exception
+ */
+ void showCreateSchema() throws TopiaException;
+
+ /**
+ * Triggers database schema update
+ *
+ * @throws TopiaException if any exception
+ */
+ void updateSchema() throws TopiaException;
+
+ /* -------------------- SERVICES MANAGMENT -------------------------------*/
+
+ /**
+ * Return the service. This service must be valid with a public static final
+ * SERVICE_NAME property.
+ *
+ * @param <E> type of service that extends {@link TopiaService}
+ * @param serviceInterface class of the service
+ * @return the service instance
+ * @throws TopiaNotFoundException if service can't be retrieved
+ */
+ <E extends TopiaService> E getService(Class<E> serviceInterface)
+ throws TopiaNotFoundException;
+
+ /**
+ * Return true if specific service is available.
+ *
+ * @param <E> type of service
+ * @param serviceInterface fqn of the service
+ * @return the service
+ */
+ <E extends TopiaService> boolean serviceEnabled(
+ Class<E> serviceInterface);
+
+ /* ------------------ IMPORT / EXPORT / REPLICATION ---------------------*/
+
+ /**
+ * Make entities import from an XML stream
+ *
+ * @param xml the XML stream
+ * @throws TopiaException if any problem occurred during import
* @deprecated nobody uses it, will be removed in future versions
*/
@Deprecated
void importXML(Reader xml) throws TopiaException;
/**
- * Permet d'exporter certaines données en XML.
+ * Export entities to XML
* <p/>
- * <b>Note:</b> Si le parametre <code>entityAndCondition</code> est vide,
- * alors on duplique toutes les entités de la base.
+ * <b>Note:</b> If the <code>entityAndCondition</code> parameter is empty,
+ * all the database will be exported
*
- * @param xml le flux XML dans lequel il faut ecrire
- * @param entityAndCondition paramètre qui vont par deux, qui represente la
- * classe de l'entity a exporter et la condition
- * where que doit respecter l'objet pour etre
- * exporter (entityClass, condition)
- * @throws TopiaException si une erreur survient durant l'export
+ * @param xml the XML writer to write into
+ * @param entityAndCondition [key;value;...] parameter which key is the
+ * entity class to export, and value the "where"
+ * condition to use when querying entities
+ * @throws TopiaException if any problem occurred during export
* @deprecated nobody uses it, will be removed in future versions
*/
@Deprecated
@@ -469,68 +499,60 @@
throws TopiaException;
/**
- * Permet de dupliquer de ce context vers un context d'une autre base des
- * données sans modification des entites.
+ * Makes a replication of some entities from this context to the given
+ * context without any entity modification.
* <p/>
- * <b>Note:</b> Si le parametre <code>entityAndCondition</code> est vide,
- * alors on duplique toutes les entités de la base.
+ * <b>Note:</b> If the <code>entityAndCondition</code> parameter is empty,
+ * all the database will be replicated
* <p/>
- * <b>Note 2:</b> Il se peut que la replication simple ne soit pas
- * suffisante (par example si l'on veut repliquer q'une partie d'une
- * entité), on utilisera donc la seconde méthode {@link
+ * <b>Note 2:</b> The simple replication may not be sufficent. You may want
+ * to replicate only a part of some entities : use the method {@link
* #replicateEntities(TopiaContext, List)}.
*
- * @param dstCtxt le context de la base destination
- * @param entityAndCondition paramètre qui vont par deux, qui represente la
- * classe de l'entity a exporter et la condition
- * where que doit respecter l'objet pour etre
- * exporter (entityClass, condition)
- * @throws TopiaException si une erreur pendant la duplication
- * @throws IllegalArgumentException si l'un des context n'est pas ouvert, ou
- * si on essaye de dupliquer dans la même
- * base.
+ * @param destinationContext the destination context
+ * @param entityAndCondition [key;value;...] parameter which key is the
+ * entity class to replicate, and value the
+ * "where" condition to use when querying entities
+ * @throws TopiaException if any problem occurred during replicate
+ * @throws IllegalArgumentException if one of the context is closed or if
+ * trying to replicate within the same
+ * database
*/
- void replicate(TopiaContext dstCtxt, Object... entityAndCondition)
+ void replicate(TopiaContext destinationContext, Object... entityAndCondition)
throws TopiaException, IllegalArgumentException;
/**
- * Permet de dupliquer une entité du type donné vers un autre context.
+ * Replicate a given entity from this context to the given context.
*
- * @param dstCtxt le context de la base destination
- * @param entity l'entité à répliquer
- * @param <T> le type des entités à répliquer
- * @throws TopiaException si une erreur pendant la duplication
- * @throws IllegalArgumentException si l'un des context n'est pas ouvert, ou
- * si on essaye de dupliquer dans la même
- * base.
+ * @param destinationContext the destination context
+ * @param entity the entity instance to replicate
+ * @param <T> type of the entity to replicate
+ * @throws TopiaException if any problem occurred during replicate
+ * @throws IllegalArgumentException if one of the context is closed or if
+ * trying to replicate within the same
+ * database
*/
- <T extends TopiaEntity> void replicateEntity(TopiaContext dstCtxt, T entity)
+ <T extends TopiaEntity> void replicateEntity(
+ TopiaContext destinationContext, T entity)
throws TopiaException, IllegalArgumentException;
/**
- * Permet de dupliquer les entités du type donné vers un autre context.
+ * Makes a replication of some entities from this context to the given
+ * context without any entity modification.
*
- * @param dstCtxt le context de la base destination
- * @param entities les entités à répliquer
- * @param <T> le type des entités à répliquer
- * @throws TopiaException si une erreur pendant la duplication
- * @throws IllegalArgumentException si l'un des context n'est pas ouvert, ou
- * si on essaye de dupliquer dans la même
- * base.
+ * @param destinationContext the destination context
+ * @param entities the list of entities instance to replicate
+ * @param <T> type of the entities to replicate
+ * @throws TopiaException if any problem occurred during replicate
+ * @throws IllegalArgumentException if one of the context is closed or if
+ * trying to replicate within the same
+ * database
*/
- <T extends TopiaEntity> void replicateEntities(TopiaContext dstCtxt,
- List<T> entities)
+ <T extends TopiaEntity> void replicateEntities(
+ TopiaContext destinationContext, List<T> entities)
throws TopiaException, IllegalArgumentException;
/**
- * Execute a given sql code inside this transaction.
- *
- * @param sqlScript the sql script to execute
- * @throws TopiaException if any problem occurs while executing the sql script.
- */
- void executeSQL(String sqlScript) throws TopiaException;
-
- /**
* Sauve la base de données dans un format natif a la base, la
* representation n'est pas portable d'une base a l'autre. Cette methode ne
* doit être utilisé que pour un stockage temporaire utile à une
@@ -539,20 +561,20 @@
* @param file le nom du fichier ou stocker les informations
* @param compress si vrai compress le fichier avec gzip
* @throws TopiaException if any exception
+ * @see TopiaH2Util#backup(File, boolean)
* @deprecated use database specific class : {@link TopiaH2Util}
- * @see TopiaH2Util#backup(File, boolean)
*/
@Deprecated
void backup(File file, boolean compress) throws TopiaException;
/**
- * l'inverse de la methode {@link #backup(File,boolean)}.
+ * l'inverse de la methode {@link #backup(File, boolean)}.
*
* @param file le fichier ou prendre les informations, il peut-etre
* compressé avec gzip ou non.
* @throws TopiaException if any exception
+ * @see TopiaH2Util#restore(File)
* @deprecated use database specific class : {@link TopiaH2Util}
- * @see TopiaH2Util#restore(File)
*/
@Deprecated
void restore(File file) throws TopiaException;
@@ -565,8 +587,8 @@
* supprimé (ex: h2) ou sera fait sur la base
* (postgresql)
* @throws TopiaException if any exception
+ * @see TopiaH2Util#clear(boolean)
* @deprecated use database specific class : {@link TopiaH2Util}
- * @see TopiaH2Util#clear(boolean)
*/
@Deprecated
void clear(boolean dropDatabase) throws TopiaException;
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2012-05-25 08:18:33 UTC (rev 2528)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2012-05-25 12:40:12 UTC (rev 2529)
@@ -708,7 +708,7 @@
return firesSupport;
}
- /* Listeners adders */
+ /* TopiaEntityListener */
@Override
public void addTopiaEntityListener(TopiaEntityListener listener) {
@@ -723,68 +723,62 @@
}
@Override
- public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
- getFiresSupport().addTopiaEntityVetoable(TopiaEntity.class, vetoable);
+ public void removeTopiaEntityListener(TopiaEntityListener listener) {
+ getFiresSupport().removeTopiaEntityListener(TopiaEntity.class,
+ listener);
}
@Override
- public void addTopiaEntityVetoable(
+ public void removeTopiaEntityListener(
Class<? extends TopiaEntity> entityClass,
- TopiaEntityVetoable vetoable) {
- getFiresSupport().addTopiaEntityVetoable(entityClass, vetoable);
+ TopiaEntityListener listener) {
+ getFiresSupport().removeTopiaEntityListener(entityClass, listener);
}
- @Override
- public void addTopiaTransactionListener(TopiaTransactionListener listener) {
- getFiresSupport().addTopiaTransactionListener(listener);
- }
+ /* TopiaEntityVetoable */
@Override
- public void addTopiaTransactionVetoable(TopiaTransactionVetoable vetoable) {
- getFiresSupport().addTopiaTransactionVetoable(vetoable);
+ public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
+ getFiresSupport().addTopiaEntityVetoable(TopiaEntity.class, vetoable);
}
@Override
- public void addPropertyChangeListener(PropertyChangeListener listener) {
- getFiresSupport().addPropertyChangeListener(listener);
+ public void addTopiaEntityVetoable(
+ Class<? extends TopiaEntity> entityClass,
+ TopiaEntityVetoable vetoable) {
+ getFiresSupport().addTopiaEntityVetoable(entityClass, vetoable);
}
@Override
- public void addTopiaSchemaListener(TopiaSchemaListener listener) {
- getFiresSupport().addTopiaContextListener(listener);
+ public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
+ getFiresSupport().removeTopiaEntityVetoable(TopiaEntity.class,
+ vetoable);
}
@Override
- public void addTopiaContextListener(TopiaContextListener listener) {
- addTopiaSchemaListener(listener);
+ public void removeTopiaEntityVetoable(
+ Class<? extends TopiaEntity> entityClass,
+ TopiaEntityVetoable vetoable) {
+ getFiresSupport().removeTopiaEntityVetoable(entityClass, vetoable);
}
- /* Listeners removers */
+ /* TopiaEntitiesVetoable */
@Override
- public void removeTopiaEntityListener(TopiaEntityListener listener) {
- getFiresSupport().removeTopiaEntityListener(TopiaEntity.class,
- listener);
+ public void addTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable) {
+ getFiresSupport().addTopiaEntitiesVetoable(vetoable);
}
@Override
- public void removeTopiaEntityListener(
- Class<? extends TopiaEntity> entityClass,
- TopiaEntityListener listener) {
- getFiresSupport().removeTopiaEntityListener(entityClass, listener);
+ public void removeTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable) {
+ getFiresSupport().removeTopiaEntitiesVetoable(vetoable);
}
- @Override
- public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable) {
- getFiresSupport().removeTopiaEntityVetoable(TopiaEntity.class,
- vetoable);
- }
+ /* TopiaTransactionListener */
@Override
- public void removeTopiaEntityVetoable(
- Class<? extends TopiaEntity> entityClass,
- TopiaEntityVetoable vetoable) {
- getFiresSupport().removeTopiaEntityVetoable(entityClass, vetoable);
+ public void addTopiaTransactionListener(TopiaTransactionListener listener) {
+ getFiresSupport().addTopiaTransactionListener(listener);
}
@Override
@@ -793,20 +787,36 @@
getFiresSupport().removeTopiaTransactionListener(listener);
}
+ /* TopiaTransactionVetoable */
+
@Override
+ public void addTopiaTransactionVetoable(TopiaTransactionVetoable vetoable) {
+ getFiresSupport().addTopiaTransactionVetoable(vetoable);
+ }
+
+ @Override
public void removeTopiaTransactionVetoable(
TopiaTransactionVetoable vetoable) {
getFiresSupport().removeTopiaTransactionVetoable(vetoable);
}
+ /* PropertyChangeListener */
+
@Override
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ getFiresSupport().addPropertyChangeListener(listener);
+ }
+
+ @Override
public void removePropertyChangeListener(PropertyChangeListener listener) {
getFiresSupport().removePropertyChangeListener(listener);
}
+ /* TopiaSchemaListener */
+
@Override
- public void removeTopiaContextListener(TopiaContextListener listener) {
- removeTopiaSchemaListener(listener);
+ public void addTopiaSchemaListener(TopiaSchemaListener listener) {
+ getFiresSupport().addTopiaContextListener(listener);
}
@Override
@@ -814,18 +824,20 @@
getFiresSupport().removeTopiaContextListener(listener);
}
+ /* TopiaContextListener */
+
@Override
- public void addTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable) {
- getFiresSupport().addTopiaEntitiesVetoable(vetoable);
+ public void addTopiaContextListener(TopiaContextListener listener) {
+ addTopiaSchemaListener(listener);
}
@Override
- public void removeTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable) {
- getFiresSupport().removeTopiaEntitiesVetoable(vetoable);
+ public void removeTopiaContextListener(TopiaContextListener listener) {
+ removeTopiaSchemaListener(listener);
}
- /* -------------------- GLOBAL OPERATIONS ON SCHEMA ----------------------*/
+ /* -------------------- GLOBAL OPERATIONS ON ENTITIES --------------------*/
@Override
public TopiaEntity findByTopiaId(String id) throws TopiaException {
@@ -848,8 +860,8 @@
}
@Override
- public List<?> find(String hql, Object... args) throws TopiaException {
- List<?> result = find(hql, 0, -1, args);
+ public List<?> find(String jpaql, Object... paramNamesAndValues) throws TopiaException {
+ List<?> result = find(jpaql, 0, -1, paramNamesAndValues);
return result;
}
@@ -862,15 +874,15 @@
}
@Override
- public List<?> find(String hql, int startIndex, int endIndex, Object... args)
+ public List<?> find(String jpaql, int startIndex, int endIndex, Object... paramNamesAndValues)
throws TopiaException {
checkClosed("find");
try {
- Query query = getEntityManager().createQuery(hql);
- for (int j = 0; j < args.length; j += 2) {
- String name = (String) args[j];
- Object value = transformArrayToCollection(args[j + 1]);
+ Query query = getEntityManager().createQuery(jpaql);
+ for (int j = 0; j < paramNamesAndValues.length; j += 2) {
+ String name = (String) paramNamesAndValues[j];
+ Object value = transformArrayToCollection(paramNamesAndValues[j + 1]);
query.setParameter(name, value);
}
query.setFirstResult(startIndex);
@@ -887,28 +899,20 @@
} catch (PersistenceException eee) {
String message = String.format(
"An error occurred (%s) during a query operation : %s",
- eee.getMessage(), hql);
+ eee.getMessage(), jpaql);
throw new TopiaException(message, eee);
}
}
- /**
- * Execute HQL operation on data (Update, Delete)
- *
- * @param hql HQL query
- * @param args arguments for query
- * @return The number of entities updated or deleted.
- * @throws TopiaException
- */
@Override
- public int execute(String hql, Object... args) throws TopiaException {
+ public int execute(String jpaql, Object... paramNamesAndValues) throws TopiaException {
checkClosed("execute");
try {
- Query query = getEntityManager().createQuery(hql);
- for (int j = 0; j < args.length; j += 2) {
- String name = (String) args[j];
- Object value = transformArrayToCollection(args[j + 1]);
+ Query query = getEntityManager().createQuery(jpaql);
+ for (int j = 0; j < paramNamesAndValues.length; j += 2) {
+ String name = (String) paramNamesAndValues[j];
+ Object value = transformArrayToCollection(paramNamesAndValues[j + 1]);
query.setParameter(name, value);
}
int result = query.executeUpdate();
@@ -916,7 +920,7 @@
} catch (PersistenceException eee) {
String message = String.format(
"An error occurred (%s) during a query operation : %s",
- eee.getMessage(), hql);
+ eee.getMessage(), jpaql);
throw new TopiaException(message, eee);
}
}
@@ -928,6 +932,7 @@
String id = e.getTopiaId();
Class<TopiaEntity> entityClass = TopiaIdUtil.getClassName(id);
TopiaDAO<TopiaEntity> dao = getDAO(entityClass);
+
dao.update(e);
}
@@ -1140,15 +1145,15 @@
@Override
public <E extends TopiaService> boolean serviceEnabled(
- Class<E> interfaceService) {
+ Class<E> serviceInterface) {
boolean result = false;
try {
- String name = getServiceName(interfaceService);
+ String name = getServiceName(serviceInterface);
result = isServiceEnabled(name);
} catch (Exception eee) {
String message = String.format(
"The service named '%s' could not be found for following reason : %s",
- interfaceService, getProperExceptionMessage(eee));
+ serviceInterface, getProperExceptionMessage(eee));
if (log.isDebugEnabled()) {
log.debug(message, eee);
} else if (log.isWarnEnabled()) {
1
0
r2528 - in trunk/topia-persistence-tck/src: main/java/org/nuiton/topia/tck main/xmi test/java/org/nuiton/topia/tck
by tchemit@users.nuiton.org 25 May '12
by tchemit@users.nuiton.org 25 May '12
25 May '12
Author: tchemit
Date: 2012-05-25 10:18:33 +0200 (Fri, 25 May 2012)
New Revision: 2528
Url: http://nuiton.org/repositories/revision/topia/2528
Log:
- remove TopiadataBase to test scope
- model for mapping test11 (unique stuff)
Added:
trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/TopiaDatabase.java
Removed:
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaDatabase.java
Modified:
trunk/topia-persistence-tck/src/main/xmi/topia-tck-mapping.zargo
Deleted: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaDatabase.java
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaDatabase.java 2012-05-24 08:19:19 UTC (rev 2527)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaDatabase.java 2012-05-25 08:18:33 UTC (rev 2528)
@@ -1,239 +0,0 @@
-/*
- * #%L
- * ToPIA :: Persistence
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2012 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.topia.tck;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.junit.rules.TestWatcher;
-import org.junit.runner.Description;
-import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.TopiaContextFactory;
-import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.persistence.TopiaEntity;
-
-import java.io.File;
-import java.io.InputStream;
-import java.util.Properties;
-
-/**
- * Put this class as a Rule in test to obtain a new isolated db for each test.
- * <p/>
- * Here is a simple example of usage :
- * <pre>
- * public class MyTest {
- *
- * \@Rule
- * public final TopiaDatabase db = new TopiaDatabase();
- *
- * \@Test
- * public void testMethod() throws TopiaException {
- *
- * TopiaContext tx = db.beginTransaction();
- * ...
- * }
- * </pre>
- * The db created will be unique for each test method (and for each build also).
- * <p/>
- * You don't need to close any transaction, it will be done for you and the end
- * of each method test.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.6.8
- */
-public abstract class TopiaDatabase extends TestWatcher {
-
- /** Logger. */
- private static final Log log = LogFactory.getLog(TopiaDatabase.class);
-
- /** A time-stamp, allow to make multiple build and keep the tests data. */
- public static final String TIMESTAMP = String.valueOf(System.nanoTime());
-
- private File testBasedir;
-
- private Properties dbConfiguration;
-
- private TopiaContext rootCtxt;
-
- private Description description;
-
- private final String configurationPath;
-
- private final String classifier;
-
- protected TopiaDatabase(String configurationPath, String classifier) {
- this.configurationPath = configurationPath;
- this.classifier = classifier;
- }
-
- public TopiaDatabase(String configurationPath) {
- this(configurationPath, "");
- }
-
- /**
- * Obtain all types persisted in this db.
- *
- * @return all persisted types in this db.
- * @since 3.0
- */
- protected abstract Class<? extends TopiaEntity>[] getImplementationClasses();
-
- @Override
- protected void starting(Description description) {
-
- this.description=description;
-
- // get test directory
- testBasedir = getTestSpecificDirectory(
- description.getTestClass(),
- description.getMethodName(),
- classifier);
-
- if (log.isDebugEnabled()) {
- log.debug("testBasedir = " + testBasedir);
- }
-
- // create the root context
- try {
-
- dbConfiguration = new Properties();
- InputStream stream =
- getClass().getResourceAsStream(configurationPath);
-
- try {
- dbConfiguration.load(stream);
- } finally {
- stream.close();
- }
- dbConfiguration.setProperty(
- TopiaContextFactory.CONFIG_PERSISTENCE_CLASSES,
- getImplementationClassesAsString());
-
- // make sure we always use a different directory
-
- String dbPath = new File(testBasedir, "db").getAbsolutePath();
-
- String jdbcUrl = "jdbc:h2:file:" + dbPath;
-
- if (log.isInfoEnabled()) {
- log.info("Use " + jdbcUrl);
- }
-
- dbConfiguration.setProperty(
- TopiaContextFactory.CONFIG_URL, jdbcUrl);
-
- onDbConfigurationCreate(dbConfiguration, testBasedir, dbPath);
-
- rootCtxt = TopiaContextFactory.getContext(dbConfiguration);
- } catch (Exception e) {
- throw new IllegalStateException(
- "Could not start db at " + testBasedir, e);
- }
- }
-
- @Override
- public void finished(Description description) {
-
- if (rootCtxt != null && !rootCtxt.isClosed()) {
- try {
- rootCtxt.closeContext();
- } catch (TopiaException e) {
- if (log.isErrorEnabled()) {
- log.error("Could not close topia root context", e);
- }
- }
- }
- rootCtxt = null;
- dbConfiguration = null;
- }
-
- public File getTestBasedir() {
- return testBasedir;
- }
-
- public TopiaContext getRootCtxt() {
- return rootCtxt;
- }
-
- public Properties getDbConfiguration() {
- return dbConfiguration;
- }
-
- public TopiaContext beginTransaction() throws TopiaException {
- return rootCtxt.beginTransaction();
- }
-
- public Description getDescription() {
- return description;
- }
-
- protected void onDbConfigurationCreate(Properties configuration,
- File testDir,
- String dbPath) {
-
- }
-
- protected final String getImplementationClassesAsString() {
- StringBuilder buffer = new StringBuilder();
- for (Class<? extends TopiaEntity> aClass : getImplementationClasses()) {
- buffer.append(',').append(aClass.getName());
- }
- return buffer.substring(1);
- }
-
- public static File getTestSpecificDirectory(Class<?> testClassName,
- String methodName) {
- return getTestSpecificDirectory(testClassName, methodName, "");
- }
-
- public static File getTestSpecificDirectory(Class<?> testClassName,
- String methodName,
- String classifier) {
- // Trying to look for the temporary folder to store data for the test
- String tempDirPath = System.getProperty("java.io.tmpdir");
- if (tempDirPath == null) {
- // can this really occur ?
- tempDirPath = "";
- if (log.isWarnEnabled()) {
- log.warn("'\"java.io.tmpdir\" not defined");
- }
- }
- File tempDirFile = new File(tempDirPath);
-
- // create the directory to store database data
- String dataBasePath = testClassName.getName()
- + File.separator // a directory with the test class name
- + methodName; // a sub-directory with the method name
-
- if (StringUtils.isNotBlank(classifier)) {
- dataBasePath += classifier;
- }
- dataBasePath += '_'
- + TIMESTAMP; // and a timestamp
- File databaseFile = new File(tempDirFile, dataBasePath);
- return databaseFile;
- }
-}
-
Modified: trunk/topia-persistence-tck/src/main/xmi/topia-tck-mapping.zargo
===================================================================
(Binary files differ)
Copied: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/TopiaDatabase.java (from rev 2527, trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaDatabase.java)
===================================================================
--- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/TopiaDatabase.java (rev 0)
+++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/TopiaDatabase.java 2012-05-25 08:18:33 UTC (rev 2528)
@@ -0,0 +1,239 @@
+/*
+ * #%L
+ * ToPIA :: Persistence
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.topia.tck;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.rules.TestWatcher;
+import org.junit.runner.Description;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaContextFactory;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.persistence.TopiaEntity;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.Properties;
+
+/**
+ * Put this class as a Rule in test to obtain a new isolated db for each test.
+ * <p/>
+ * Here is a simple example of usage :
+ * <pre>
+ * public class MyTest {
+ *
+ * \@Rule
+ * public final TopiaDatabase db = new TopiaDatabase();
+ *
+ * \@Test
+ * public void testMethod() throws TopiaException {
+ *
+ * TopiaContext tx = db.beginTransaction();
+ * ...
+ * }
+ * </pre>
+ * The db created will be unique for each test method (and for each build also).
+ * <p/>
+ * You don't need to close any transaction, it will be done for you and the end
+ * of each method test.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.6.8
+ */
+public abstract class TopiaDatabase extends TestWatcher {
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(TopiaDatabase.class);
+
+ /** A time-stamp, allow to make multiple build and keep the tests data. */
+ public static final String TIMESTAMP = String.valueOf(System.nanoTime());
+
+ private File testBasedir;
+
+ private Properties dbConfiguration;
+
+ private TopiaContext rootCtxt;
+
+ private Description description;
+
+ private final String configurationPath;
+
+ private final String classifier;
+
+ protected TopiaDatabase(String configurationPath, String classifier) {
+ this.configurationPath = configurationPath;
+ this.classifier = classifier;
+ }
+
+ public TopiaDatabase(String configurationPath) {
+ this(configurationPath, "");
+ }
+
+ /**
+ * Obtain all types persisted in this db.
+ *
+ * @return all persisted types in this db.
+ * @since 3.0
+ */
+ protected abstract Class<? extends TopiaEntity>[] getImplementationClasses();
+
+ @Override
+ protected void starting(Description description) {
+
+ this.description=description;
+
+ // get test directory
+ testBasedir = getTestSpecificDirectory(
+ description.getTestClass(),
+ description.getMethodName(),
+ classifier);
+
+ if (log.isDebugEnabled()) {
+ log.debug("testBasedir = " + testBasedir);
+ }
+
+ // create the root context
+ try {
+
+ dbConfiguration = new Properties();
+ InputStream stream =
+ getClass().getResourceAsStream(configurationPath);
+
+ try {
+ dbConfiguration.load(stream);
+ } finally {
+ stream.close();
+ }
+ dbConfiguration.setProperty(
+ TopiaContextFactory.CONFIG_PERSISTENCE_CLASSES,
+ getImplementationClassesAsString());
+
+ // make sure we always use a different directory
+
+ String dbPath = new File(testBasedir, "db").getAbsolutePath();
+
+ String jdbcUrl = "jdbc:h2:file:" + dbPath;
+
+ if (log.isInfoEnabled()) {
+ log.info("Use " + jdbcUrl);
+ }
+
+ dbConfiguration.setProperty(
+ TopiaContextFactory.CONFIG_URL, jdbcUrl);
+
+ onDbConfigurationCreate(dbConfiguration, testBasedir, dbPath);
+
+ rootCtxt = TopiaContextFactory.getContext(dbConfiguration);
+ } catch (Exception e) {
+ throw new IllegalStateException(
+ "Could not start db at " + testBasedir, e);
+ }
+ }
+
+ @Override
+ public void finished(Description description) {
+
+ if (rootCtxt != null && !rootCtxt.isClosed()) {
+ try {
+ rootCtxt.closeContext();
+ } catch (TopiaException e) {
+ if (log.isErrorEnabled()) {
+ log.error("Could not close topia root context", e);
+ }
+ }
+ }
+ rootCtxt = null;
+ dbConfiguration = null;
+ }
+
+ public File getTestBasedir() {
+ return testBasedir;
+ }
+
+ public TopiaContext getRootCtxt() {
+ return rootCtxt;
+ }
+
+ public Properties getDbConfiguration() {
+ return dbConfiguration;
+ }
+
+ public TopiaContext beginTransaction() throws TopiaException {
+ return rootCtxt.beginTransaction();
+ }
+
+ public Description getDescription() {
+ return description;
+ }
+
+ protected void onDbConfigurationCreate(Properties configuration,
+ File testDir,
+ String dbPath) {
+
+ }
+
+ protected final String getImplementationClassesAsString() {
+ StringBuilder buffer = new StringBuilder();
+ for (Class<? extends TopiaEntity> aClass : getImplementationClasses()) {
+ buffer.append(',').append(aClass.getName());
+ }
+ return buffer.substring(1);
+ }
+
+ public static File getTestSpecificDirectory(Class<?> testClassName,
+ String methodName) {
+ return getTestSpecificDirectory(testClassName, methodName, "");
+ }
+
+ public static File getTestSpecificDirectory(Class<?> testClassName,
+ String methodName,
+ String classifier) {
+ // Trying to look for the temporary folder to store data for the test
+ String tempDirPath = System.getProperty("java.io.tmpdir");
+ if (tempDirPath == null) {
+ // can this really occur ?
+ tempDirPath = "";
+ if (log.isWarnEnabled()) {
+ log.warn("'\"java.io.tmpdir\" not defined");
+ }
+ }
+ File tempDirFile = new File(tempDirPath);
+
+ // create the directory to store database data
+ String dataBasePath = testClassName.getName()
+ + File.separator // a directory with the test class name
+ + methodName; // a sub-directory with the method name
+
+ if (StringUtils.isNotBlank(classifier)) {
+ dataBasePath += classifier;
+ }
+ dataBasePath += '_'
+ + TIMESTAMP; // and a timestamp
+ File databaseFile = new File(tempDirFile, dataBasePath);
+ return databaseFile;
+ }
+}
+
Property changes on: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/TopiaDatabase.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
1
0
r2527 - trunk/topia-persistence-tck/src/main/resources/META-INF/services
by tchemit@users.nuiton.org 24 May '12
by tchemit@users.nuiton.org 24 May '12
24 May '12
Author: tchemit
Date: 2012-05-24 10:19:19 +0200 (Thu, 24 May 2012)
New Revision: 2527
Url: http://nuiton.org/repositories/revision/topia/2527
Log:
fix test operation fqns
Modified:
trunk/topia-persistence-tck/src/main/resources/META-INF/services/org.nuiton.topia.replication.TopiaReplicationOperation
Modified: trunk/topia-persistence-tck/src/main/resources/META-INF/services/org.nuiton.topia.replication.TopiaReplicationOperation
===================================================================
--- trunk/topia-persistence-tck/src/main/resources/META-INF/services/org.nuiton.topia.replication.TopiaReplicationOperation 2012-05-24 08:00:59 UTC (rev 2526)
+++ trunk/topia-persistence-tck/src/main/resources/META-INF/services/org.nuiton.topia.replication.TopiaReplicationOperation 2012-05-24 08:19:19 UTC (rev 2527)
@@ -2,5 +2,5 @@
# 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
+org.nuiton.topia.tck.replication.operation.FakeOperation
+org.nuiton.topia.tck.replication.operation.UncreatableOperation
\ No newline at end of file
1
0
r2526 - trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication
by tchemit@users.nuiton.org 24 May '12
by tchemit@users.nuiton.org 24 May '12
24 May '12
Author: tchemit
Date: 2012-05-24 10:00:59 +0200 (Thu, 24 May 2012)
New Revision: 2526
Url: http://nuiton.org/repositories/revision/topia/2526
Log:
move replication test in tck
Removed:
trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/operation/
1
0
Author: tchemit
Date: 2012-05-24 10:00:35 +0200 (Thu, 24 May 2012)
New Revision: 2525
Url: http://nuiton.org/repositories/revision/topia/2525
Log:
move replication test in tck
Added:
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/replication/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/replication/operation/
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/replication/operation/FakeOperation.java
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/replication/operation/UncreatableOperation.java
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/replication/operation/UnregistredOperation.java
trunk/topia-persistence-tck/src/main/resources/META-INF/
trunk/topia-persistence-tck/src/main/resources/META-INF/services/
trunk/topia-persistence-tck/src/main/resources/META-INF/services/org.nuiton.topia.replication.TopiaReplicationOperation
Removed:
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
Modified:
trunk/topia-persistence-hibernate/pom.xml
Modified: trunk/topia-persistence-hibernate/pom.xml
===================================================================
--- trunk/topia-persistence-hibernate/pom.xml 2012-05-24 07:53:22 UTC (rev 2524)
+++ trunk/topia-persistence-hibernate/pom.xml 2012-05-24 08:00:35 UTC (rev 2525)
@@ -36,6 +36,13 @@
</dependency>
<dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>topia-service-replication</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
@@ -69,8 +76,6 @@
<scope>test</scope>
</dependency>
-
-
</dependencies>
<build>
Copied: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/replication/operation/FakeOperation.java (from rev 2524, trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/operation/FakeOperation.java)
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/replication/operation/FakeOperation.java (rev 0)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/replication/operation/FakeOperation.java 2012-05-24 08:00:35 UTC (rev 2525)
@@ -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(a)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/main/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/main/java/org/nuiton/topia/tck/replication/operation/UncreatableOperation.java (from rev 2524, trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/operation/UncreatableOperation.java)
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/replication/operation/UncreatableOperation.java (rev 0)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/replication/operation/UncreatableOperation.java 2012-05-24 08:00:35 UTC (rev 2525)
@@ -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(a)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/main/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/main/java/org/nuiton/topia/tck/replication/operation/UnregistredOperation.java (from rev 2524, trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/operation/UnregistredOperation.java)
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/replication/operation/UnregistredOperation.java (rev 0)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/replication/operation/UnregistredOperation.java 2012-05-24 08:00:35 UTC (rev 2525)
@@ -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(a)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/main/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/main/resources/META-INF/services/org.nuiton.topia.replication.TopiaReplicationOperation (from rev 2524, trunk/topia-persistence-tck/src/test/resources/META-INF/services/org.nuiton.topia.replication.TopiaReplicationOperation)
===================================================================
--- trunk/topia-persistence-tck/src/main/resources/META-INF/services/org.nuiton.topia.replication.TopiaReplicationOperation (rev 0)
+++ trunk/topia-persistence-tck/src/main/resources/META-INF/services/org.nuiton.topia.replication.TopiaReplicationOperation 2012-05-24 08:00:35 UTC (rev 2525)
@@ -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/main/resources/META-INF/services/org.nuiton.topia.replication.TopiaReplicationOperation
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: 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/FakeOperation.java 2012-05-24 07:53:22 UTC (rev 2524)
+++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/operation/FakeOperation.java 2012-05-24 08:00:35 UTC (rev 2525)
@@ -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.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(a)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-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/UncreatableOperation.java 2012-05-24 07:53:22 UTC (rev 2524)
+++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/operation/UncreatableOperation.java 2012-05-24 08:00:35 UTC (rev 2525)
@@ -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.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(a)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-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/operation/UnregistredOperation.java
===================================================================
--- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/operation/UnregistredOperation.java 2012-05-24 07:53:22 UTC (rev 2524)
+++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/replication/operation/UnregistredOperation.java 2012-05-24 08:00:35 UTC (rev 2525)
@@ -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.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(a)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-persistence-tck/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 2012-05-24 07:53:22 UTC (rev 2524)
+++ trunk/topia-persistence-tck/src/test/resources/META-INF/services/org.nuiton.topia.replication.TopiaReplicationOperation 2012-05-24 08:00:35 UTC (rev 2525)
@@ -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
1
0
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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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
1
0
r2523 - in trunk/topia-service-replication: . src/test/java/org/nuiton/topia/replication src/test/resources
by tchemit@users.nuiton.org 23 May '12
by tchemit@users.nuiton.org 23 May '12
23 May '12
Author: tchemit
Date: 2012-05-23 20:34:02 +0200 (Wed, 23 May 2012)
New Revision: 2523
Url: http://nuiton.org/repositories/revision/topia/2523
Log:
service replication build and tests are ok for it :)
Added:
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/resources/TopiaContext-legacy.properties
Modified:
trunk/topia-service-replication/pom.xml
trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/AbstractTopiaReplicationServiceTest.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
Modified: trunk/topia-service-replication/pom.xml
===================================================================
--- trunk/topia-service-replication/pom.xml 2012-05-23 18:32:37 UTC (rev 2522)
+++ trunk/topia-service-replication/pom.xml 2012-05-23 18:34:02 UTC (rev 2523)
@@ -59,6 +59,19 @@
</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>
Modified: 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:32:37 UTC (rev 2522)
+++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/AbstractTopiaReplicationServiceTest.java 2012-05-23 18:34:02 UTC (rev 2523)
@@ -27,6 +27,8 @@
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;
@@ -42,11 +44,9 @@
import org.nuiton.topia.replication.model.ReplicationNode;
import org.nuiton.topia.replication.model.ReplicationOperationDef;
-import java.io.File;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -64,9 +64,9 @@
*/
public abstract class AbstractTopiaReplicationServiceTest extends Assert {
- static protected TopiaContext context;
+ protected TopiaContext context;
- static protected TopiaContext ctxt;
+ protected TopiaContext ctxt;
protected TopiaContextImplementor dstCtxt;
@@ -74,64 +74,61 @@
protected ReplicationModel model;
- static protected boolean init;
+// static protected boolean init;
- static private Long testsTimeStamp;
+// static private Long testsTimeStamp;
- static private File testsBasedir;
+// 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";
+// 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";
- public static void after() throws Exception {
- if (context != null && !context.isClosed()) {
- try {
- context.closeContext();
- } catch (TopiaException e) {
- // cela peut arriver si on demande la fermeture dans un thread
- // ailleurs...
- }
- }
- init = false;
+ @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 {
- if (!init) {
+ context = db.getRootCtxt();
- I18n.setDefaultLocale(Locale.FRANCE);
+ db.createDb();
- try {
- context = createDb("source");
- } catch (Exception e) {
- getLog().error("could not create db source.", e);
- throw e;
- }
- init = true;
- }
+ ctxt = db.beginTransaction();
- ctxt = context.beginTransaction();
-
- service = context.getService(TopiaReplicationService.class);
+ service = db.getReplicationService();
}
public void tearDown() throws Exception {
- if (ctxt != null) {
- ctxt.rollbackTransaction();
- ctxt.closeContext();
- ctxt = null;
- }
service = null;
+ context = null;
+ ctxt = null;
+ dstCtxt = null;
+ model = null;
+ if (db2 != null) {
+ db2.finished(db2.getDescription());
+ }
+
}
-
protected TopiaReplicationModelBuilder getModelBuilder() {
return service.getModelBuilder();
}
- protected abstract TopiaContext createDb2(String name) throws Exception;
+ protected TopiaContext createDb2(String name) throws Exception {
- protected abstract TopiaContext createDb(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;
@@ -141,10 +138,6 @@
protected abstract Log getLog();
- protected <E extends TopiaEntity> E update(E e) throws TopiaException {
- return (E) ctxt.findByTopiaId(e.getTopiaId());
- }
-
/**
* Test of detectTypes method, of class ReplicationServiceImplementor.
*
@@ -291,8 +284,7 @@
"expected shell : " + Arrays.toString(expected) + ", but was " +
shell, expected.length, shell.size());
- for (int i = 0, j = expected.length; i < j; i++) {
- TopiaEntityEnum type = expected[i];
+ for (TopiaEntityEnum type : expected) {
ReplicationNode node = model.getNode(type);
assertTrue(shell.contains(node));
assertEquals(type, node.getContract());
@@ -596,9 +588,9 @@
}
protected void createSupportedBeforeOperation(TopiaEntityEnum contract,
- TopiaEntity entity,
- Class<? extends TopiaReplicationOperation> operationClass,
- Object... parameters) throws Exception {
+ TopiaEntity entity,
+ Class<? extends TopiaReplicationOperation> operationClass,
+ Object... parameters) throws Exception {
getLog().info("entity " + entity.getTopiaId());
prepareModel(entity.getTopiaId());
@@ -623,26 +615,26 @@
Assert.assertTrue(true);
}
- protected Long getTestsTimeStamp() {
- if (testsTimeStamp == null) {
- testsTimeStamp = System.currentTimeMillis();
- getLog().info("tests timestamp : " + testsTimeStamp);
- }
- return testsTimeStamp;
- }
+// 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 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,
Added: 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 (rev 0)
+++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/ModelFixture.java 2012-05-23 18:34:02 UTC (rev 2523)
@@ -0,0 +1,113 @@
+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(a)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;
+ }
+
+}
Copied: trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaDatabaseLegacy.java (from rev 2518, trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/legacy/TopiaDatabaseLegacy.java)
===================================================================
--- trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaDatabaseLegacy.java (rev 0)
+++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaDatabaseLegacy.java 2012-05-23 18:34:02 UTC (rev 2523)
@@ -0,0 +1,60 @@
+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(a)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);
+ }
+}
Modified: 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:32:37 UTC (rev 2522)
+++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationOperationTest.java 2012-05-23 18:34:02 UTC (rev 2523)
@@ -27,16 +27,9 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.junit.After;
-import org.junit.AfterClass;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
-import org.nuiton.topia.TestHelper;
import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.TopiaContextFactory;
-import org.nuiton.topia.TopiaTestDAOHelper.TopiaTckItEntityEnum;
-import org.nuiton.topia.framework.TopiaContextImplementor;
import org.nuiton.topia.persistence.TopiaEntityEnum;
import org.nuiton.topia.replication.model.ReplicationOperationPhase;
import org.nuiton.topia.replication.operation.DettachAssociation;
@@ -44,17 +37,14 @@
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.test.entities.Person;
-import org.nuiton.topia.test.entities.PersonImpl;
-import org.nuiton.topia.test.entities.Pet;
-import org.nuiton.topia.test.entities.PetImpl;
-import org.nuiton.topia.test.entities.Race;
-import org.nuiton.topia.test.entities.RaceImpl;
+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 java.io.IOException;
-import java.util.Properties;
+import static org.nuiton.topia.tck.legacy.TopiaTckLegacyDAOHelper.TopiaTckLegacyEntityEnum;
+
/**
* TopiaReplicationServiceImplTest on model TopiaTest
* <p/>
@@ -70,15 +60,15 @@
LogFactory.getLog(TopiaReplicationOperationTest.class);
protected static final TopiaEntityEnum[] contracts = {
- TopiaTckItEntityEnum.Person,
- TopiaTckItEntityEnum.Pet,
- TopiaTckItEntityEnum.Race
+ TopiaTckLegacyEntityEnum.Person,
+ TopiaTckLegacyEntityEnum.Pet,
+ TopiaTckLegacyEntityEnum.Race
};
- protected static final String entitiesList =
- PersonImpl.class.getName() + "," +
- PetImpl.class.getName() + "," +
- RaceImpl.class.getName();
+// protected static final String entitiesList =
+// PersonImpl.class.getName() + "," +
+// PetImpl.class.getName() + "," +
+// RaceImpl.class.getName();
static protected Person person, person2;
@@ -88,38 +78,21 @@
protected static File tesDir;
- @BeforeClass
- public static void beforeClass() throws IOException {
- tesDir = TestHelper.getTestBasedir(TopiaReplicationOperationTest.class);
-
- }
-
- @AfterClass
- public static void after() throws Exception {
- AbstractTopiaReplicationServiceTest.after();
- }
-
@Before
@Override
public void setUp() throws Exception {
super.setUp();
- person = update(person);
- person2 = update(person2);
- pet = update(pet);
- pet2 = update(pet2);
- race = update(race);
- race2 = update(race2);
- }
+ ModelFixture fixtures = db.getFixtures();
- @After
- @Override
- public void tearDown() throws Exception {
- super.tearDown();
- if (dstCtxt != null && !dstCtxt.isClosed()) {
- dstCtxt.closeContext();
- }
+ 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)
@@ -158,14 +131,14 @@
public void testCreateOperation_nullPhase() throws Exception {
model = getModelBuilder().createModel(context, contracts, true);
- getModelBuilder().createOperation(model, TopiaTckItEntityEnum.Pet, null, null);
+ 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, TopiaTckItEntityEnum.Pet, ReplicationOperationPhase.before, null);
+ getModelBuilder().createOperation(model, TopiaTckLegacyEntityEnum.Pet, ReplicationOperationPhase.before, null);
}
@Test(expected = IllegalArgumentException.class)
@@ -173,7 +146,7 @@
model = getModelBuilder().createModel(context, contracts, true);
// le noeud Pet n'existe pas
- getModelBuilder().addAfterOperation(model, TopiaTckItEntityEnum.Pet, Duplicate.class);
+ getModelBuilder().addAfterOperation(model, TopiaTckLegacyEntityEnum.Pet, Duplicate.class);
}
@Test(expected = IllegalArgumentException.class)
@@ -181,13 +154,13 @@
model = getModelBuilder().createModel(context, contracts, true);
// le noeud Pet n'existe pas
- getModelBuilder().addAfterOperation(model, TopiaTckItEntityEnum.Pet, UnregistredOperation.class);
+ getModelBuilder().addAfterOperation(model, TopiaTckLegacyEntityEnum.Pet, UnregistredOperation.class);
}
@Test
// @Test(expected = UnsupportedOperationException.class)
public void testCreateSupportedBeforeOperation_Duplicate() throws Exception {
- createSupportedBeforeOperation(TopiaTckItEntityEnum.Person, person, Duplicate.class);
+ createSupportedBeforeOperation(TopiaTckLegacyEntityEnum.Person, person, Duplicate.class);
}
// @Test(expected = UnsupportedOperationException.class)
@@ -198,13 +171,13 @@
@Test
// @Test(expected = UnsupportedOperationException.class)
public void testCreateSupportedBeforeOperation_DetachAssociation() throws Exception {
- createSupportedBeforeOperation(TopiaTckItEntityEnum.Person, person, DettachAssociation.class);
+ createSupportedBeforeOperation(TopiaTckLegacyEntityEnum.Person, person, DettachAssociation.class);
}
@Test
// @Test(expected = UnsupportedOperationException.class)
public void testCreateSupportedAfterOperation_Duplicate() throws Exception {
- createSupportedAfterOperation(TopiaTckItEntityEnum.Person, person, Duplicate.class);
+ createSupportedAfterOperation(TopiaTckLegacyEntityEnum.Person, person, Duplicate.class);
}
// @Test(expected = UnsupportedOperationException.class)
@@ -215,7 +188,7 @@
@Test
// @Test(expected = UnsupportedOperationException.class)
public void testCreateSupportedAfterOperation_DetachAssociation() throws Exception {
- createSupportedAfterOperation(TopiaTckItEntityEnum.Person, person, DettachAssociation.class);
+ createSupportedAfterOperation(TopiaTckLegacyEntityEnum.Person, person, DettachAssociation.class);
}
// @Test(expected = UnsupportedOperationException.class)
@@ -232,8 +205,8 @@
public void testCreateOperation() throws Exception {
model = getModelBuilder().createModel(context, contracts, true, pet.getTopiaId());
- getModelBuilder().addBeforeOperation(model, TopiaTckItEntityEnum.Pet, FakeOperation.class, "before");
- getModelBuilder().addAfterOperation(model, TopiaTckItEntityEnum.Race, FakeOperation.class, "after");
+ getModelBuilder().addBeforeOperation(model, TopiaTckLegacyEntityEnum.Pet, FakeOperation.class, "before");
+ getModelBuilder().addAfterOperation(model, TopiaTckLegacyEntityEnum.Race, FakeOperation.class, "after");
}
@Test(expected = NullPointerException.class)
@@ -250,31 +223,6 @@
}
@Override
- protected TopiaContext createDb(String name) throws Exception {
-
-// File localDB = new File(getTestDir(getClass()), "db_" + name);
-
- Properties config = getH2Properties(name);
-
- context = TopiaContextFactory.getContext(config);
-
- TopiaContextImplementor tx =
- (TopiaContextImplementor) context.beginTransaction();
-
- person = tx.getDAO(Person.class).create(Person.PROPERTY_NAME, "pudding master");
- race = tx.getDAO(Race.class).create(Race.PROPERTY_NAME, "race I");
- pet = tx.getDAO(Pet.class).create(Pet.PROPERTY_NAME, "pudding", Pet.PROPERTY_PERSON, person, Pet.PROPERTY_RACE, race);
-
- person2 = tx.getDAO(Person.class).create(Person.PROPERTY_NAME, "pudding II master");
- pet2 = tx.getDAO(Pet.class).create(Pet.PROPERTY_NAME, "pudding II");
- race2 = tx.getDAO(Race.class).create(Race.PROPERTY_NAME, "race II");
-
- tx.commitTransaction();
- tx.closeContext();
- return context;
- }
-
- @Override
protected TopiaEntityEnum[] getContracts() {
return contracts;
}
@@ -284,25 +232,6 @@
return log;
}
- protected Properties getH2Properties(String dbName) throws IOException {
-
- Properties config = TestHelper.initTopiaContextConfiguration(tesDir, dbName);
-
-// config.setProperty("hibernate.show_sql", "false");
-// config.setProperty("hibernate.hbm2ddl.auto", "create");
-
- config.setProperty("topia.persistence.classes", entitiesList);
-// config.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
-// config.setProperty("hibernate.connection.driver_class", "org.h2.Driver");
-// config.setProperty("hibernate.connection.url", "jdbc:h2:file:" + f.getAbsolutePath() + ";create=true");
-// config.setProperty("hibernate.connection.username", "sa");
-// config.setProperty("hibernate.connection.password", "");
-
- config.setProperty("topia.service.replication", TopiaReplicationServiceImpl.class.getName());
-
- return config;
- }
-
@Override
protected TopiaContext createDb2(String name) throws Exception {
throw new UnsupportedOperationException("Not supported yet.");
Modified: 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:32:37 UTC (rev 2522)
+++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplAllTest.java 2012-05-23 18:34:02 UTC (rev 2523)
@@ -27,29 +27,16 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.junit.After;
-import org.junit.AfterClass;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
-import org.nuiton.topia.TestHelper;
-import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.TopiaContextFactory;
import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.TopiaTestDAOHelper.TopiaTckItEntityEnum;
-import org.nuiton.topia.framework.TopiaContextImplementor;
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.topia.persistence.TopiaEntityEnum;
-import org.nuiton.topia.test.entities.Person;
-import org.nuiton.topia.test.entities.PersonImpl;
-import org.nuiton.topia.test.entities.Pet;
-import org.nuiton.topia.test.entities.PetImpl;
-import org.nuiton.topia.test.entities.Race;
-import org.nuiton.topia.test.entities.RaceImpl;
+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 java.io.IOException;
-import java.util.Properties;
+import static org.nuiton.topia.tck.legacy.TopiaTckLegacyDAOHelper.TopiaTckLegacyEntityEnum;
/**
* TopiaReplicationServiceImplTest on model TopiaTest
@@ -62,63 +49,41 @@
public class TopiaReplicationServiceImplAllTest extends AbstractTopiaReplicationServiceTest {
/** Logger */
- private static final Log log = LogFactory.getLog(TopiaReplicationServiceImplTest.class);
+ private static final Log log =
+ LogFactory.getLog(TopiaReplicationServiceImplTest.class);
protected static final TopiaEntityEnum[] contracts = {
- TopiaTckItEntityEnum.Person,
- TopiaTckItEntityEnum.Pet,
- TopiaTckItEntityEnum.Race
+ TopiaTckLegacyEntityEnum.Person,
+ TopiaTckLegacyEntityEnum.Pet,
+ TopiaTckLegacyEntityEnum.Race
};
- protected static final String entitiesList =
- PersonImpl.class.getName() + "," +
- PetImpl.class.getName() + "," +
- RaceImpl.class.getName();
+ protected Person person, person2;
- static protected Person person, person2;
+ protected Pet pet, pet2, pet3;
- static protected Pet pet, pet2, pet3;
+ protected Race race, race2, race3;
- static protected Race race, race2, race3;
-
- protected static File tesDir;
-
- @BeforeClass
- public static void beforeClass() throws IOException {
- tesDir = TestHelper.getTestBasedir(TopiaReplicationServiceImplAllTest.class);
- }
-
- @AfterClass
- public static void after() throws Exception {
- AbstractTopiaReplicationServiceTest.after();
- }
-
@Before
@Override
public void setUp() throws Exception {
super.setUp();
- person = update(person);
- person2 = update(person2);
- pet = update(pet);
- pet2 = update(pet2);
- race = update(race);
- race2 = update(race2);
- race3 = update(race3);
- }
+ // get data
- @After
- @Override
- public void tearDown() throws Exception {
- super.tearDown();
- if (dstCtxt != null && !dstCtxt.isClosed()) {
- dstCtxt.closeContext();
- }
+ 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);
}
-// @Ignore
-
@Test
@Override
public void testDetectTypes() throws Exception {
@@ -135,20 +100,16 @@
detectTypes(pet3, Pet.class, Race.class);
}
-// @Ignore
-
@Test
@Override
public void testGetOperation() throws Exception {
}
-// @Ignore
-
@Test
@Override
public void testDetectAssociations() throws Exception {
- detectAssociations(person, TopiaTckItEntityEnum.Person, Person.PROPERTY_PET);
+ detectAssociations(person, TopiaTckLegacyEntityEnum.Person, Person.PROPERTY_PET);
detectAssociations(race);
detectAssociations(pet);
@@ -158,56 +119,46 @@
}
-// @Ignore
-
@Test
@Override
public void testDetectDirectDependencies() throws Exception {
detectDirectDependencies(person);
detectDirectDependencies(race);
- detectDirectDependencies(pet, TopiaTckItEntityEnum.Pet, Pet.PROPERTY_PERSON, TopiaTckItEntityEnum.Pet, Pet.PROPERTY_RACE);
+ detectDirectDependencies(pet, TopiaTckLegacyEntityEnum.Pet, Pet.PROPERTY_PERSON, TopiaTckLegacyEntityEnum.Pet, Pet.PROPERTY_RACE);
detectDirectDependencies(person2);
detectDirectDependencies(race2);
detectDirectDependencies(pet2);
}
-// @Ignore
-
@Test
@Override
public void testDetectShell() throws Exception {
- detectShell(person, TopiaTckItEntityEnum.Pet, TopiaTckItEntityEnum.Race);
+ detectShell(person, TopiaTckLegacyEntityEnum.Pet, TopiaTckLegacyEntityEnum.Race);
detectShell(race);
- detectShell(pet, TopiaTckItEntityEnum.Person, TopiaTckItEntityEnum.Race);
- detectShell(person2, TopiaTckItEntityEnum.Pet, TopiaTckItEntityEnum.Race);
+ detectShell(pet, TopiaTckLegacyEntityEnum.Person, TopiaTckLegacyEntityEnum.Race);
+ detectShell(person2, TopiaTckLegacyEntityEnum.Pet, TopiaTckLegacyEntityEnum.Race);
detectShell(race2);
- detectShell(pet2, TopiaTckItEntityEnum.Person, TopiaTckItEntityEnum.Race);
+ detectShell(pet2, TopiaTckLegacyEntityEnum.Person, TopiaTckLegacyEntityEnum.Race);
}
-// @Ignore
-
@Test
@Override
public void testDetectDependencies() throws Exception {
detectDependencies(null,
- new TopiaTckItEntityEnum[]{TopiaTckItEntityEnum.Race}, new TopiaTckItEntityEnum[]{TopiaTckItEntityEnum.Person}, new TopiaTckItEntityEnum[]{TopiaTckItEntityEnum.Pet});
+ new TopiaTckLegacyEntityEnum[]{TopiaTckLegacyEntityEnum.Race}, new TopiaTckLegacyEntityEnum[]{TopiaTckLegacyEntityEnum.Person}, new TopiaTckLegacyEntityEnum[]{TopiaTckLegacyEntityEnum.Pet});
}
-// @Ignore
-
@Test
@Override
public void testDetectObjectsToDettach() throws Exception {
- detectObjectsToDettach(null, TopiaTckItEntityEnum.Person, new String[]{Person.PROPERTY_PET});
+ detectObjectsToDettach(null, TopiaTckLegacyEntityEnum.Person, new String[]{Person.PROPERTY_PET});
}
-// @Ignore
-
@Test
@Override
public void testDetectOperations() throws Exception {
@@ -215,8 +166,6 @@
detectOperations(null);
}
-// @Ignore
-
@Test
@Override
public void testDoReplicate() throws Exception {
@@ -226,43 +175,6 @@
}
@Override
- protected TopiaContext createDb(String name) throws Exception {
-
-// File localDB = new File(getTestDir(getClass()), "db_" + name);
-
- Properties config = getH2Properties(name);
-
- context = TopiaContextFactory.getContext(config);
-
- TopiaContextImplementor tx = (TopiaContextImplementor) context.beginTransaction();
-
- person = tx.getDAO(Person.class).create(Person.PROPERTY_NAME, "pudding master");
- race = tx.getDAO(Race.class).create(Race.PROPERTY_NAME, "race I");
- pet = tx.getDAO(Pet.class).create(Pet.PROPERTY_NAME, "pudding", Pet.PROPERTY_PERSON, person, Pet.PROPERTY_RACE, race);
-
- person2 = tx.getDAO(Person.class).create(Person.PROPERTY_NAME, "pudding II master");
- pet2 = tx.getDAO(Pet.class).create(Pet.PROPERTY_NAME, "pudding II");
- race2 = tx.getDAO(Race.class).create(Race.PROPERTY_NAME, "race II");
-
- race3 = tx.getDAO(Race.class).create(Race.PROPERTY_NAME, "race III");
- pet3 = tx.getDAO(Pet.class).create(Pet.PROPERTY_NAME, "pudding III", Pet.PROPERTY_RACE, race3);
-
- tx.commitTransaction();
- tx.closeContext();
- return context;
- }
-
- @Override
- protected TopiaContext createDb2(String name) throws Exception {
-
-// File localDB = new File(getTestDir(getClass()), "db_" + name);
-
- Properties config = getH2Properties(name);
-
- return TopiaContextFactory.getContext(config);
- }
-
- @Override
protected TopiaEntityEnum[] getContracts() {
return contracts;
}
@@ -272,26 +184,6 @@
return log;
}
- protected Properties getH2Properties(String dbName) throws IOException {
-
- Properties config = TestHelper.initTopiaContextConfiguration(tesDir, dbName);
-
-// config.setProperty("hibernate.show_sql", "false");
-// config.setProperty("hibernate.hbm2ddl.auto", "create");
-
- config.setProperty("topia.persistence.classes", entitiesList);
-// config.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
-// config.setProperty("hibernate.connection.driver_class", "org.h2.Driver");
-// config.setProperty("hibernate.connection.url", "jdbc:h2:file:" + f.getAbsolutePath() + ";create=true");
-// config.setProperty("hibernate.connection.username", "sa");
-// config.setProperty("hibernate.connection.password", "");
-
- config.setProperty(TopiaReplicationServiceImpl.TOPIA_SERVICE_NAME, TopiaReplicationServiceImpl.class.getName());
-
- return config;
- }
-
-
@Override
protected void createModel(TopiaEntity entity) throws TopiaException {
model = getModelBuilder().createModelForAll(getContracts());
Modified: 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:32:37 UTC (rev 2522)
+++ trunk/topia-service-replication/src/test/java/org/nuiton/topia/replication/TopiaReplicationServiceImplTest.java 2012-05-23 18:34:02 UTC (rev 2523)
@@ -27,16 +27,10 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.junit.After;
-import org.junit.AfterClass;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
-import org.nuiton.topia.TestHelper;
import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.TopiaContextFactory;
import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.TopiaTestDAOHelper.TopiaTckItEntityEnum;
import org.nuiton.topia.framework.TopiaContextImplementor;
import org.nuiton.topia.persistence.TopiaEntityEnum;
import org.nuiton.topia.persistence.util.TopiaEntityIdsMap;
@@ -46,16 +40,11 @@
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.test.entities.Person;
-import org.nuiton.topia.test.entities.PersonImpl;
-import org.nuiton.topia.test.entities.Pet;
-import org.nuiton.topia.test.entities.PetImpl;
-import org.nuiton.topia.test.entities.Race;
-import org.nuiton.topia.test.entities.RaceImpl;
+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 java.io.IOException;
-import java.util.Properties;
+import static org.nuiton.topia.tck.legacy.TopiaTckLegacyDAOHelper.TopiaTckLegacyEntityEnum;
/**
* TopiaReplicationServiceImplTest on model TopiaTest
@@ -71,51 +60,30 @@
private static final Log log =
LogFactory.getLog(TopiaReplicationServiceImplTest.class);
- protected static final TopiaEntityEnum[] contracts = {TopiaTckItEntityEnum.Person, TopiaTckItEntityEnum.Pet, TopiaTckItEntityEnum.Race};
+ 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();
+ protected Person person, person2;
- static protected Person person, person2;
+ protected Pet pet, pet2, pet3;
- static protected Pet pet, pet2, pet3;
+ protected Race race, race2, race3;
- static protected Race race, race2, race3;
-
- protected static File tesDir;
-
- @BeforeClass
- public static void beforeClass() throws IOException {
- tesDir = TestHelper.getTestBasedir(
- TopiaReplicationServiceImplTest.class);
- }
-
- @AfterClass
- public static void after() throws Exception {
- AbstractTopiaReplicationServiceTest.after();
- }
-
@Before
@Override
public void setUp() throws Exception {
super.setUp();
- person = update(person);
- person2 = update(person2);
- pet = update(pet);
- pet2 = update(pet2);
- race = update(race);
- race2 = update(race2);
- race3 = update(race3);
- }
+ ModelFixture fixtures = db.getFixtures();
- @After
- @Override
- public void tearDown() throws Exception {
- super.tearDown();
- if (dstCtxt != null && !dstCtxt.isClosed()) {
- dstCtxt.closeContext();
- }
+ 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
@@ -149,7 +117,7 @@
@Override
public void testDetectAssociations() throws Exception {
- detectAssociations(person, TopiaTckItEntityEnum.Person, Person.PROPERTY_PET);
+ detectAssociations(person, TopiaTckLegacyEntityEnum.Person, Person.PROPERTY_PET);
detectAssociations(race);
detectAssociations(pet);
@@ -164,7 +132,7 @@
detectDirectDependencies(person);
detectDirectDependencies(race);
- detectDirectDependencies(pet, TopiaTckItEntityEnum.Pet, Pet.PROPERTY_PERSON, TopiaTckItEntityEnum.Pet, Pet.PROPERTY_RACE);
+ detectDirectDependencies(pet, TopiaTckLegacyEntityEnum.Pet, Pet.PROPERTY_PERSON, TopiaTckLegacyEntityEnum.Pet, Pet.PROPERTY_RACE);
detectDirectDependencies(person2);
detectDirectDependencies(race2);
@@ -175,9 +143,9 @@
@Override
public void testDetectShell() throws Exception {
- detectShell(person, TopiaTckItEntityEnum.Pet, TopiaTckItEntityEnum.Race);
+ detectShell(person, TopiaTckLegacyEntityEnum.Pet, TopiaTckLegacyEntityEnum.Race);
detectShell(race);
- detectShell(pet, TopiaTckItEntityEnum.Person, TopiaTckItEntityEnum.Race);
+ detectShell(pet, TopiaTckLegacyEntityEnum.Person, TopiaTckLegacyEntityEnum.Race);
detectShell(person2);
detectShell(race2);
detectShell(pet2);
@@ -187,22 +155,22 @@
@Override
public void testDetectDependencies() throws Exception {
- detectDependencies(person, new TopiaTckItEntityEnum[]{TopiaTckItEntityEnum.Race}, new TopiaTckItEntityEnum[]{TopiaTckItEntityEnum.Person}, new TopiaTckItEntityEnum[]{TopiaTckItEntityEnum.Pet});
- detectDependencies(race, new TopiaTckItEntityEnum[]{TopiaTckItEntityEnum.Race});
- detectDependencies(pet, new TopiaTckItEntityEnum[]{TopiaTckItEntityEnum.Race}, new TopiaTckItEntityEnum[]{TopiaTckItEntityEnum.Person}, new TopiaTckItEntityEnum[]{TopiaTckItEntityEnum.Pet});
+ 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 TopiaTckItEntityEnum[]{TopiaTckItEntityEnum.Person});
- detectDependencies(race2, new TopiaTckItEntityEnum[]{TopiaTckItEntityEnum.Race});
- detectDependencies(pet2, new TopiaTckItEntityEnum[]{TopiaTckItEntityEnum.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, TopiaTckItEntityEnum.Person, new String[]{Person.PROPERTY_PET});
+ detectObjectsToDettach(person, TopiaTckLegacyEntityEnum.Person, new String[]{Person.PROPERTY_PET});
detectObjectsToDettach(race);
- detectObjectsToDettach(pet, TopiaTckItEntityEnum.Person, new String[]{Person.PROPERTY_PET});
+ detectObjectsToDettach(pet, TopiaTckLegacyEntityEnum.Person, new String[]{Person.PROPERTY_PET});
detectObjectsToDettach(person2);
detectObjectsToDettach(race2);
@@ -234,18 +202,18 @@
@Override
public void testDoReplicate() throws Exception {
- doReplicate(TopiaTckItEntityEnum.Person, person);
- doReplicate(TopiaTckItEntityEnum.Person, person2);
- doReplicate(TopiaTckItEntityEnum.Person, person, person2);
+ doReplicate(TopiaTckLegacyEntityEnum.Person, person);
+ doReplicate(TopiaTckLegacyEntityEnum.Person, person2);
+ doReplicate(TopiaTckLegacyEntityEnum.Person, person, person2);
- doReplicate(TopiaTckItEntityEnum.Pet, pet);
- doReplicate(TopiaTckItEntityEnum.Pet, pet2);
- doReplicate(TopiaTckItEntityEnum.Pet, pet, pet2, pet3);
- doReplicate(TopiaTckItEntityEnum.Pet, person2, pet3);
+ doReplicate(TopiaTckLegacyEntityEnum.Pet, pet);
+ doReplicate(TopiaTckLegacyEntityEnum.Pet, pet2);
+ doReplicate(TopiaTckLegacyEntityEnum.Pet, pet, pet2, pet3);
+ doReplicate(TopiaTckLegacyEntityEnum.Pet, person2, pet3);
- doReplicate(TopiaTckItEntityEnum.Race, race);
- doReplicate(TopiaTckItEntityEnum.Race, race2);
- doReplicate(TopiaTckItEntityEnum.Race, race, race2);
+ doReplicate(TopiaTckLegacyEntityEnum.Race, race);
+ doReplicate(TopiaTckLegacyEntityEnum.Race, race2);
+ doReplicate(TopiaTckLegacyEntityEnum.Race, race, race2);
}
@@ -318,7 +286,7 @@
dstCtxt.commitTransaction();
srcCtxt.rollbackTransaction();
- person = update(person);
+ person = db.getFixtures().getPerson(srcCtxt);
assertEntityEquals(person, dstCtxt.findByTopiaId(person.getTopiaId()), null);
} finally {
@@ -372,10 +340,10 @@
srcCtxt.closeContext();
dstCtxt.closeContext();
- ctxt = context.beginTransaction();
+ ctxt = db.beginTransaction();
dstCtxt = (TopiaContextImplementor) dstRootCtxt.beginTransaction();
- person = update(person);
+ person = db.getFixtures().getPerson(ctxt);
assertEntityEquals(person, dstCtxt.findByTopiaId(person.getTopiaId()), null);
@@ -385,45 +353,6 @@
}
@Override
- protected TopiaContext createDb(String name) throws Exception {
-
-// File localDB = new File(getTestDir(getClass()), "db_" + name);
-
- Properties config = getH2Properties(name);
-
- context = TopiaContextFactory.getContext(config);
-
- TopiaContextImplementor tx = (TopiaContextImplementor) context.beginTransaction();
-
- person = tx.getDAO(Person.class).create(Person.PROPERTY_NAME, "pudding master");
- race = tx.getDAO(Race.class).create(Race.PROPERTY_NAME, "race I");
- pet = tx.getDAO(Pet.class).create(Pet.PROPERTY_NAME, "pudding", Pet.PROPERTY_PERSON, person, Pet.PROPERTY_RACE, race);
-
- person2 = tx.getDAO(Person.class).create(Person.PROPERTY_NAME, "pudding II master");
- pet2 = tx.getDAO(Pet.class).create(Pet.PROPERTY_NAME, "pudding II");
- race2 = tx.getDAO(Race.class).create(Race.PROPERTY_NAME, "race II");
-
- race3 = tx.getDAO(Race.class).create(Race.PROPERTY_NAME, "race III");
- pet3 = tx.getDAO(Pet.class).create(Pet.PROPERTY_NAME, "pudding III", Pet.PROPERTY_RACE, race3);
-
- tx.commitTransaction();
- tx.closeContext();
- return context;
- }
-
- @Override
- protected TopiaContext createDb2(String name) throws Exception {
-
-// File localDB = new File(getTestDir(getClass()), "db_" + name);
-//
-// log.info("db dir :\n" + localDB.getAbsolutePath());
-
- Properties config = getH2Properties(name);
-
- return TopiaContextFactory.getContext(config);
- }
-
- @Override
protected TopiaEntityEnum[] getContracts() {
return contracts;
}
@@ -433,25 +362,6 @@
return log;
}
- protected Properties getH2Properties(String dbName) throws IOException {
-
-
- Properties config = TestHelper.initTopiaContextConfiguration(tesDir, dbName);
-
-// config.setProperty("hibernate.show_sql", "false");
-// config.setProperty("hibernate.hbm2ddl.auto", "create");
-
- config.setProperty("topia.persistence.classes", entitiesList);
-// config.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
-// config.setProperty("hibernate.connection.driver_class", "org.h2.Driver");
-// config.setProperty("hibernate.connection.url", "jdbc:h2:file:" + f.getAbsolutePath() + "/db;create=true");
-// config.setProperty("hibernate.connection.username", "sa");
-// config.setProperty("hibernate.connection.password", "");
-
- config.setProperty(TopiaReplicationServiceImpl.TOPIA_SERVICE_NAME, TopiaReplicationServiceImpl.class.getName());
-
- return config;
- }
}
Copied: trunk/topia-service-replication/src/test/resources/TopiaContext-legacy.properties (from rev 2518, trunk/topia-persistence-hibernate/src/test/resources/TopiaContext-legacy.properties)
===================================================================
--- trunk/topia-service-replication/src/test/resources/TopiaContext-legacy.properties (rev 0)
+++ trunk/topia-service-replication/src/test/resources/TopiaContext-legacy.properties 2012-05-23 18:34:02 UTC (rev 2523)
@@ -0,0 +1,15 @@
+# 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
1
0
r2522 - in trunk/topia-persistence-tck: . src/main/java/org/nuiton/topia/tck src/test/java/org/nuiton/topia/tck src/test/java/org/nuiton/topia/tck/it src/test/java/org/nuiton/topia/tck/legacy/framework
by tchemit@users.nuiton.org 23 May '12
by tchemit@users.nuiton.org 23 May '12
23 May '12
Author: tchemit
Date: 2012-05-23 20:32:37 +0200 (Wed, 23 May 2012)
New Revision: 2522
Url: http://nuiton.org/repositories/revision/topia/2522
Log:
improve TopiaDatabase = remove no more used test stuff
Added:
trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaDatabase.java
Removed:
trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/TestHelper.java
trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/TopiaDatabase.java
Modified:
trunk/topia-persistence-tck/pom.xml
trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/it/EnumTest.java
trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/legacy/framework/TopiaContextReplicateTest.java
Modified: trunk/topia-persistence-tck/pom.xml
===================================================================
--- trunk/topia-persistence-tck/pom.xml 2012-05-23 18:02:50 UTC (rev 2521)
+++ trunk/topia-persistence-tck/pom.xml 2012-05-23 18:32:37 UTC (rev 2522)
@@ -59,6 +59,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
+ <scope>compile</scope>
</dependency>
<dependency>
Copied: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaDatabase.java (from rev 2518, trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/TopiaDatabase.java)
===================================================================
--- trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaDatabase.java (rev 0)
+++ trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaDatabase.java 2012-05-23 18:32:37 UTC (rev 2522)
@@ -0,0 +1,239 @@
+/*
+ * #%L
+ * ToPIA :: Persistence
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.topia.tck;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.rules.TestWatcher;
+import org.junit.runner.Description;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaContextFactory;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.persistence.TopiaEntity;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.Properties;
+
+/**
+ * Put this class as a Rule in test to obtain a new isolated db for each test.
+ * <p/>
+ * Here is a simple example of usage :
+ * <pre>
+ * public class MyTest {
+ *
+ * \@Rule
+ * public final TopiaDatabase db = new TopiaDatabase();
+ *
+ * \@Test
+ * public void testMethod() throws TopiaException {
+ *
+ * TopiaContext tx = db.beginTransaction();
+ * ...
+ * }
+ * </pre>
+ * The db created will be unique for each test method (and for each build also).
+ * <p/>
+ * You don't need to close any transaction, it will be done for you and the end
+ * of each method test.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.6.8
+ */
+public abstract class TopiaDatabase extends TestWatcher {
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(TopiaDatabase.class);
+
+ /** A time-stamp, allow to make multiple build and keep the tests data. */
+ public static final String TIMESTAMP = String.valueOf(System.nanoTime());
+
+ private File testBasedir;
+
+ private Properties dbConfiguration;
+
+ private TopiaContext rootCtxt;
+
+ private Description description;
+
+ private final String configurationPath;
+
+ private final String classifier;
+
+ protected TopiaDatabase(String configurationPath, String classifier) {
+ this.configurationPath = configurationPath;
+ this.classifier = classifier;
+ }
+
+ public TopiaDatabase(String configurationPath) {
+ this(configurationPath, "");
+ }
+
+ /**
+ * Obtain all types persisted in this db.
+ *
+ * @return all persisted types in this db.
+ * @since 3.0
+ */
+ protected abstract Class<? extends TopiaEntity>[] getImplementationClasses();
+
+ @Override
+ protected void starting(Description description) {
+
+ this.description=description;
+
+ // get test directory
+ testBasedir = getTestSpecificDirectory(
+ description.getTestClass(),
+ description.getMethodName(),
+ classifier);
+
+ if (log.isDebugEnabled()) {
+ log.debug("testBasedir = " + testBasedir);
+ }
+
+ // create the root context
+ try {
+
+ dbConfiguration = new Properties();
+ InputStream stream =
+ getClass().getResourceAsStream(configurationPath);
+
+ try {
+ dbConfiguration.load(stream);
+ } finally {
+ stream.close();
+ }
+ dbConfiguration.setProperty(
+ TopiaContextFactory.CONFIG_PERSISTENCE_CLASSES,
+ getImplementationClassesAsString());
+
+ // make sure we always use a different directory
+
+ String dbPath = new File(testBasedir, "db").getAbsolutePath();
+
+ String jdbcUrl = "jdbc:h2:file:" + dbPath;
+
+ if (log.isInfoEnabled()) {
+ log.info("Use " + jdbcUrl);
+ }
+
+ dbConfiguration.setProperty(
+ TopiaContextFactory.CONFIG_URL, jdbcUrl);
+
+ onDbConfigurationCreate(dbConfiguration, testBasedir, dbPath);
+
+ rootCtxt = TopiaContextFactory.getContext(dbConfiguration);
+ } catch (Exception e) {
+ throw new IllegalStateException(
+ "Could not start db at " + testBasedir, e);
+ }
+ }
+
+ @Override
+ public void finished(Description description) {
+
+ if (rootCtxt != null && !rootCtxt.isClosed()) {
+ try {
+ rootCtxt.closeContext();
+ } catch (TopiaException e) {
+ if (log.isErrorEnabled()) {
+ log.error("Could not close topia root context", e);
+ }
+ }
+ }
+ rootCtxt = null;
+ dbConfiguration = null;
+ }
+
+ public File getTestBasedir() {
+ return testBasedir;
+ }
+
+ public TopiaContext getRootCtxt() {
+ return rootCtxt;
+ }
+
+ public Properties getDbConfiguration() {
+ return dbConfiguration;
+ }
+
+ public TopiaContext beginTransaction() throws TopiaException {
+ return rootCtxt.beginTransaction();
+ }
+
+ public Description getDescription() {
+ return description;
+ }
+
+ protected void onDbConfigurationCreate(Properties configuration,
+ File testDir,
+ String dbPath) {
+
+ }
+
+ protected final String getImplementationClassesAsString() {
+ StringBuilder buffer = new StringBuilder();
+ for (Class<? extends TopiaEntity> aClass : getImplementationClasses()) {
+ buffer.append(',').append(aClass.getName());
+ }
+ return buffer.substring(1);
+ }
+
+ public static File getTestSpecificDirectory(Class<?> testClassName,
+ String methodName) {
+ return getTestSpecificDirectory(testClassName, methodName, "");
+ }
+
+ public static File getTestSpecificDirectory(Class<?> testClassName,
+ String methodName,
+ String classifier) {
+ // Trying to look for the temporary folder to store data for the test
+ String tempDirPath = System.getProperty("java.io.tmpdir");
+ if (tempDirPath == null) {
+ // can this really occur ?
+ tempDirPath = "";
+ if (log.isWarnEnabled()) {
+ log.warn("'\"java.io.tmpdir\" not defined");
+ }
+ }
+ File tempDirFile = new File(tempDirPath);
+
+ // create the directory to store database data
+ String dataBasePath = testClassName.getName()
+ + File.separator // a directory with the test class name
+ + methodName; // a sub-directory with the method name
+
+ if (StringUtils.isNotBlank(classifier)) {
+ dataBasePath += classifier;
+ }
+ dataBasePath += '_'
+ + TIMESTAMP; // and a timestamp
+ File databaseFile = new File(tempDirFile, dataBasePath);
+ return databaseFile;
+ }
+}
+
Property changes on: trunk/topia-persistence-tck/src/main/java/org/nuiton/topia/tck/TopiaDatabase.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/TestHelper.java
===================================================================
--- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/TestHelper.java 2012-05-23 18:02:50 UTC (rev 2521)
+++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/TestHelper.java 2012-05-23 18:32:37 UTC (rev 2522)
@@ -1,161 +0,0 @@
-/*
- * #%L
- * ToPIA :: Persistence
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.topia.tck;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.junit.Ignore;
-import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.TopiaContextFactory;
-import org.nuiton.topia.TopiaNotFoundException;
-import org.nuiton.topia.tck.it.TopiaTckItDAOHelper;
-import org.nuiton.util.FileUtil;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
-
-/**
- * Helper for all topia tests.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.5
- */
-@Ignore
-// this is not a test :)
-public class TestHelper {
-
- private static final Log log = LogFactory.getLog(TestHelper.class);
-
- protected static File testBasedir;
-
- protected static File targetdir;
-
- protected static File dirDatabase;
-
- public static final String DEFAULT_CONFIGURATION_LOCATION = "/TopiaContextImpl.properties";
-
- public static File getTestWorkdir() {
- if (testBasedir == null) {
- String base = System.getProperty("java.io.tmpdir");
- if (base == null || base.isEmpty()) {
- base = new File("").getAbsolutePath();
- }
- testBasedir = new File(base);
- log.info("basedir for test " + testBasedir);
- }
- return testBasedir;
- }
-
- public static File getTestBasedir(Class<?> testClass) throws IOException {
- File dir = getTestWorkdir();
- File result = new File(dir, testClass.getName());
- if (result.exists()) {
-
- // when calling this method (always in a BeforeClass method), we wants
- // to clean the directory, this is a new build
- FileUtil.deleteRecursively(result);
- }
-
- // always create the directory
- FileUtil.createDirectoryIfNecessary(result);
- return result;
- }
-
- public static TopiaContext initTopiaContext(File testDirectory,
- String dbname)
- throws IOException, TopiaNotFoundException {
-
-
- TopiaContext topiaContext = initTopiaContext(
- testDirectory,
- DEFAULT_CONFIGURATION_LOCATION,
- dbname
- );
- return topiaContext;
- }
-
- public static TopiaContext initTopiaContext(File testDirectory,
- String dbPropertiesPath,
- String dbname)
- throws IOException, TopiaNotFoundException {
-
- Properties configuration = initTopiaContextConfiguration(
- testDirectory,
- dbPropertiesPath,
- dbname);
- return TopiaContextFactory.getContext(configuration);
- }
-
- public static Properties initTopiaContextConfiguration(File testDirectory,
- String dbPropertiesPath,
- String dbname)
- throws IOException {
-
- Properties configuration = loadHibernateConfiguration(dbPropertiesPath);
-
- // make sure we always use a different directory
-
- String dbPath = getDbName(testDirectory, dbname);
-
- if (log.isInfoEnabled()) {
- log.info("dbPath = " + dbPath);
- }
- configuration.setProperty(
- "topia.connection.url",
- "jdbc:h2:file:" + dbPath);
-
- return configuration;
- }
-
- public static Properties loadHibernateConfiguration(String dbPropertiesPath) throws IOException {
- InputStream stream = TestHelper.class.getResourceAsStream(dbPropertiesPath);
-
- Properties configuration = new Properties();
-
- configuration.load(stream);
- configuration.setProperty(
- TopiaContextFactory.CONFIG_PERSISTENCE_CLASSES,
- TopiaTckItDAOHelper.getImplementationClassesAsString());
- return configuration;
- }
-
- public static String getDbName(File testDirectory, String dbname) {
- return new File(testDirectory,
- dbname + '_' + System.nanoTime()).getAbsolutePath();
- }
-
- public static Properties initTopiaContextConfiguration(File testDirectory,
- String dbname)
- throws IOException {
-
- return initTopiaContextConfiguration(
- testDirectory,
- DEFAULT_CONFIGURATION_LOCATION,
- dbname
- );
- }
-}
Deleted: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/TopiaDatabase.java
===================================================================
--- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/TopiaDatabase.java 2012-05-23 18:02:50 UTC (rev 2521)
+++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/TopiaDatabase.java 2012-05-23 18:32:37 UTC (rev 2522)
@@ -1,215 +0,0 @@
-/*
- * #%L
- * ToPIA :: Persistence
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2012 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.topia.tck;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.junit.rules.TestWatcher;
-import org.junit.runner.Description;
-import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.TopiaContextFactory;
-import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.persistence.TopiaEntity;
-
-import java.io.File;
-import java.io.InputStream;
-import java.util.Properties;
-
-/**
- * Put this class as a Rule in test to obtain a new isolated db for each test.
- * <p/>
- * Here is a simple example of usage :
- * <pre>
- * public class MyTest {
- *
- * \@Rule
- * public final TopiaDatabase db = new TopiaDatabase();
- *
- * \@Test
- * public void testMethod() throws TopiaException {
- *
- * TopiaContext tx = db.beginTransaction();
- * ...
- * }
- * </pre>
- * The db created will be unique for each test method (and for each build also).
- * <p/>
- * You don't need to close any transaction, it will be done for you and the end
- * of each method test.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.6.8
- */
-public abstract class TopiaDatabase extends TestWatcher {
-
- /** Logger. */
- private static final Log log = LogFactory.getLog(TopiaDatabase.class);
-
- /** A time-stamp, allow to make multiple build and keep the tests data. */
- public static final String TIMESTAMP = String.valueOf(System.nanoTime());
-
- private File testBasedir;
-
- private Properties dbConfiguration;
-
- private TopiaContext rootCtxt;
-
- private final String configurationPath;
-
-// public TopiaDatabase() {
-// this(TestHelper.DEFAULT_CONFIGURATION_LOCATION);
-// }
-
- public TopiaDatabase(String configurationPath) {
- this.configurationPath = configurationPath;
- }
-
- /**
- * Obtain all types persisted in this db.
- *
- * @return all persisted types in this db.
- * @since 3.0
- */
- protected abstract Class<? extends TopiaEntity>[] getImplementationClasses();
-
- @Override
- protected void starting(Description description) {
-
- // get test directory
- testBasedir = getTestSpecificDirectory(
- description.getTestClass(),
- description.getMethodName());
-
- if (log.isDebugEnabled()) {
- log.debug("testBasedir = " + testBasedir);
- }
-
- // create the root context
- try {
-
- dbConfiguration = new Properties();
- InputStream stream =
- getClass().getResourceAsStream(configurationPath);
-
- try {
- dbConfiguration.load(stream);
- } finally {
- stream.close();
- }
- dbConfiguration.setProperty(
- TopiaContextFactory.CONFIG_PERSISTENCE_CLASSES,
- getImplementationClassesAsString());
-
- // make sure we always use a different directory
-
- String dbPath = new File(testBasedir, "db").getAbsolutePath();
-
- String jdbcUrl = "jdbc:h2:file:" + dbPath;
-
- if (log.isInfoEnabled()) {
- log.info("Use " + jdbcUrl);
- }
-
- dbConfiguration.setProperty(
- TopiaContextFactory.CONFIG_URL, jdbcUrl);
-
- onDbConfigurationCreate(dbConfiguration, testBasedir, dbPath);
-
- rootCtxt = TopiaContextFactory.getContext(dbConfiguration);
- } catch (Exception e) {
- throw new IllegalStateException(
- "Could not start db at " + testBasedir, e);
- }
- }
-
- @Override
- public void finished(Description description) {
-
- if (rootCtxt != null && !rootCtxt.isClosed()) {
- try {
- rootCtxt.closeContext();
- } catch (TopiaException e) {
- if (log.isErrorEnabled()) {
- log.error("Could not close topia root context", e);
- }
- }
- }
- rootCtxt = null;
- dbConfiguration = null;
- }
-
- public File getTestBasedir() {
- return testBasedir;
- }
-
- public TopiaContext getRootCtxt() {
- return rootCtxt;
- }
-
- public Properties getDbConfiguration() {
- return dbConfiguration;
- }
-
- public TopiaContext beginTransaction() throws TopiaException {
- return rootCtxt.beginTransaction();
- }
-
- protected void onDbConfigurationCreate(Properties configuration,
- File testDir,
- String dbPath) {
-
- }
-
- protected final String getImplementationClassesAsString() {
- StringBuilder buffer = new StringBuilder();
- for (Class<? extends TopiaEntity> aClass : getImplementationClasses()) {
- buffer.append(',').append(aClass.getName());
- }
- return buffer.substring(1);
- }
-
- public static File getTestSpecificDirectory(Class<?> testClassName, String methodName) {
- // Trying to look for the temporary folder to store data for the test
- String tempDirPath = System.getProperty("java.io.tmpdir");
- if (tempDirPath == null) {
- // can this really occur ?
- tempDirPath = "";
- if (log.isWarnEnabled()) {
- log.warn("'\"java.io.tmpdir\" not defined");
- }
- }
- File tempDirFile = new File(tempDirPath);
-
- // create the directory to store database data
- String dataBasePath = testClassName.getName()
- + File.separator // a directory with the test class name
- + methodName// a sub-directory with the method name
- + '_'
- + TIMESTAMP; // and a timestamp
- File databaseFile = new File(tempDirFile, dataBasePath);
- return databaseFile;
- }
-}
-
Modified: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/it/EnumTest.java
===================================================================
--- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/it/EnumTest.java 2012-05-23 18:02:50 UTC (rev 2521)
+++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/it/EnumTest.java 2012-05-23 18:32:37 UTC (rev 2522)
@@ -30,7 +30,6 @@
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.tck.TopiaDatabase;
import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.tck.it.TopiaTckItDAOHelper;
/**
* Test the support of possibility to have an attribute of type enumeration
Modified: trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/legacy/framework/TopiaContextReplicateTest.java
===================================================================
--- trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/legacy/framework/TopiaContextReplicateTest.java 2012-05-23 18:02:50 UTC (rev 2521)
+++ trunk/topia-persistence-tck/src/test/java/org/nuiton/topia/tck/legacy/framework/TopiaContextReplicateTest.java 2012-05-23 18:32:37 UTC (rev 2522)
@@ -74,25 +74,9 @@
@Test
public void replicateEntity() throws Exception {
-//
-// Properties configSource = TestHelper.initTopiaContextConfiguration(
-// testBasedir,
-// "/TopiaContextImpl.properties",
-// "replicateSource");
-//
-// Properties configTarget = TestHelper.initTopiaContextConfiguration(
-// testBasedir,
-// "/TopiaContextImpl.properties",
-// "replicateTarget");
-//
-
TopiaContext contextSource = dbSource.getRootCtxt();
TopiaContext contextTarget = dbTarget.getRootCtxt();
-// try {
-// contextSource = TopiaContextFactory.getContext(configSource);
-// contextTarget = TopiaContextFactory.getContext(configTarget);
-
TopiaContext txSource;
TopiaContext txTarget;
PersonDAO daoSource, daoTarget;
@@ -148,11 +132,5 @@
Assert.assertEquals(petTarget, personTarget.getPet().iterator().next());
-
-// } finally {
-// closeDb(contextSource);
-// closeDb(contextTarget);
-// }
-
}
}
1
0
r2521 - trunk/topia-persistence/src/main/java/org/nuiton/topia/generator
by tchemit@users.nuiton.org 23 May '12
by tchemit@users.nuiton.org 23 May '12
23 May '12
Author: tchemit
Date: 2012-05-23 20:02:50 +0200 (Wed, 23 May 2012)
New Revision: 2521
Url: http://nuiton.org/repositories/revision/topia/2521
Log:
refs #2089: Use JPA (orm) mappings (always generate column name in ManyToOne relation)
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityJPAMappingGenerator.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityJPAMappingGenerator.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityJPAMappingGenerator.java 2012-05-23 17:48:01 UTC (rev 2520)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityJPAMappingGenerator.java 2012-05-23 18:02:50 UTC (rev 2521)
@@ -508,9 +508,7 @@
addAttribute(columnAttributes, ATTRIBUTE_UNIQUE, true);
}
- if (!attrName.equals(attrColumn)) {
- addAttribute(columnAttributes, ATTRIBUTE_NAME, attrColumn);
- }
+ addAttribute(columnAttributes, ATTRIBUTE_NAME, attrColumn);
//NOTUSED addAttribute(columnAttributes, ATTRIBUTE_REFERENCE_COLUMN_NAME, TopiaEntity.TOPIA_ID);
addAttribute(xmlAttributes, ATTRIBUTE_TARGET_ENTITY, getType(attr));
1
0