|
From: <lh...@us...> - 2008-04-24 12:13:25
|
Revision: 35
http://tinytim.svn.sourceforge.net/tinytim/?rev=35&view=rev
Author: lheuer
Date: 2008-04-24 05:04:37 -0700 (Thu, 24 Apr 2008)
Log Message:
-----------
- More tests
- CopyUtils finished (needs testing, though)
- Added getReifiedConstruct() to the TopicImpl to avoid direct access to that field in most cases
Modified Paths:
--------------
tinytim/trunk/src/main/java/org/tinytim/CopyUtils.java
tinytim/trunk/src/main/java/org/tinytim/IMovable.java
tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java
tinytim/trunk/src/main/java/org/tinytim/TopicImpl.java
tinytim/trunk/src/main/java/org/tinytim/TopicMapImpl.java
tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndex.java
tinytim/trunk/src/main/java/org/tinytim/index/tmapi/OccurrencesIndexImpl.java
tinytim/trunk/src/main/java/org/tinytim/index/tmapi/TopicNamesIndexImpl.java
tinytim/trunk/src/main/resources/META-INF/services/org.tmapi.core.TopicMapSystemFactory
tinytim/trunk/src/test/java/org/tinytim/TestItemIdentifierConstraint.java
tinytim/trunk/src/test/java/org/tinytim/TestReifiable.java
tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java
Modified: tinytim/trunk/src/main/java/org/tinytim/CopyUtils.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/CopyUtils.java 2008-04-23 17:55:30 UTC (rev 34)
+++ tinytim/trunk/src/main/java/org/tinytim/CopyUtils.java 2008-04-24 12:04:37 UTC (rev 35)
@@ -22,12 +22,17 @@
import java.util.Iterator;
import java.util.Map;
+import java.util.Set;
+import org.tmapi.core.Association;
+import org.tmapi.core.AssociationRole;
import org.tmapi.core.Locator;
import org.tmapi.core.Occurrence;
import org.tmapi.core.Topic;
import org.tmapi.core.TopicMap;
import org.tmapi.core.TopicMapObject;
+import org.tmapi.core.TopicName;
+import org.tmapi.core.Variant;
/**
* This class provides methods to copy Topic Maps constructs from one
@@ -107,8 +112,17 @@
_copyTypes(topic, targetTopic, mergeMap);
_copyCharacteristics(topic, (TopicImpl)targetTopic, mergeMap);
}
+ _copyAssociations(source, target, mergeMap);
}
+ /**
+ * Copies the <code>topic</code> to the <code>target</code> topic map.
+ *
+ * @param topic The topic to copy.
+ * @param target The target topic map.
+ * @param mergeMap The map which holds the merge mappings.
+ * @return The newly created topic in the target topic map.
+ */
private static Topic _copyTopic(Topic topic, TopicMap target,
Map<Topic, Topic> mergeMap) {
Topic targetTopic = target.createTopic();
@@ -118,6 +132,13 @@
return targetTopic;
}
+ /**
+ * Copies the identities (item identifiers, subject identifiers and subject
+ * locators) from the <code>source/code> to the <code>targetTopic</code>.
+ *
+ * @param topic The topic to take the identities from.
+ * @param targetTopic The topic which gets the identities.
+ */
@SuppressWarnings("unchecked")
private static void _copyIdentities(Topic topic, Topic targetTopic) {
for(Iterator<Locator> iter = topic.getSubjectIdentifiers().iterator(); iter.hasNext();) {
@@ -129,6 +150,13 @@
_copyItemIdentifiers((IConstruct)topic, (IConstruct)targetTopic);
}
+ /**
+ * Copies the types from the <code>topic</code> to the <code>targetTopic</code>.
+ *
+ * @param topic The topic to take the types from.
+ * @param targetTopic The topic which receives the types.
+ * @param mergeMap The map which holds the merge mappings.
+ */
@SuppressWarnings("unchecked")
private static void _copyTypes(Topic topic, Topic targetTopic,
Map<Topic, Topic> mergeMap) {
@@ -142,20 +170,206 @@
}
}
+ /**
+ * Copies the occurrences and names from <code>topic</code> to the
+ * <code>targetTopic</code>.
+ *
+ * @param topic The topic to take the characteristics from.
+ * @param targetTopic The target topic which gets the charateristics.
+ * @param mergeMap The map which holds the merge mappings.
+ */
private static void _copyCharacteristics(Topic topic, TopicImpl targetTopic,
Map<Topic, Topic> mergeMap) {
Map<String, IReifiable> sigs = ((TopicMapImpl) targetTopic.getTopicMap()).getCollectionFactory().<String, IReifiable>createMap();
for (Occurrence occ: targetTopic.getOccurrences()) {
sigs.put(SignatureGenerator.generateSignature(occ), (IReifiable)occ);
}
+ IReifiable existing = null;
+ for (Occurrence occ: ((TopicImpl) topic).getOccurrences()) {
+ Occurrence targetOcc = targetTopic.createOccurrence((String)null, null, null);
+ _copyType((ITyped)occ, (ITyped)targetOcc, mergeMap);
+ _copyScope((IScoped)occ, (IScoped)targetOcc, mergeMap);
+ if (occ.getValue() != null) {
+ targetOcc.setValue(occ.getValue());
+ }
+ else if (occ.getResource() != null) {
+ targetOcc.setResource(occ.getResource());
+ }
+ existing = sigs.get(SignatureGenerator.generateSignature(targetOcc));
+ if (existing != null) {
+ MergeUtils.removeConstruct((IConstruct) targetOcc);
+ targetOcc = (Occurrence)existing;
+ }
+ _copyReifier((IReifiable) occ, (IReifiable) targetOcc, mergeMap);
+ _copyItemIdentifiers((IConstruct) occ, (IConstruct) targetOcc);
+ }
+ sigs.clear();
+ for (TopicName name: targetTopic.getTopicNames()) {
+ sigs.put(SignatureGenerator.generateSignature(name), (IReifiable)name);
+ }
+ for (TopicName name: ((TopicImpl) topic).getTopicNames()) {
+ TopicName targetName = targetTopic.createTopicName(name.getValue(), null);
+ _copyType((ITyped) name, (ITyped) targetName, mergeMap);
+ _copyScope((IScoped) name, (IScoped) targetName, mergeMap);
+ existing = sigs.get(SignatureGenerator.generateSignature(targetName));
+ if (existing != null) {
+ MergeUtils.removeConstruct((IConstruct)targetName);
+ targetName = (TopicName) existing;
+ }
+ _copyReifier((IReifiable) name, (IReifiable) targetName, mergeMap);
+ _copyItemIdentifiers((IConstruct) name, (IConstruct) targetName);
+ _copyVariants(name, targetName, mergeMap);
+ }
}
+ /**
+ * Copies the variants from <code>source</code> to the <code>target</code>.
+ *
+ * @param source The name to take the variants from.
+ * @param target The target name which receives the variants.
+ * @param mergeMap The map which holds the merge mappings.
+ */
+ private static void _copyVariants(TopicName source, TopicName target,
+ Map<Topic, Topic> mergeMap) {
+ Map<String, Variant> sigs = ((TopicMapImpl) target.getTopicMap()).getCollectionFactory().createMap();
+ for (Variant variant: ((TopicNameImpl) target).getVariants()) {
+ sigs.put(SignatureGenerator.generateSignature(variant), variant);
+ }
+ Variant existing = null;
+ for (Variant variant: ((TopicNameImpl) source).getVariants()) {
+ Variant targetVar = target.createVariant((String) null, null);
+ _copyScope((IScoped) variant, (IScoped) targetVar, mergeMap);
+ if (variant.getValue() != null) {
+ targetVar.setValue(variant.getValue());
+ }
+ else if (variant.getResource() != null) {
+ targetVar.setResource(variant.getResource());
+ }
+ existing = sigs.get(SignatureGenerator.generateSignature(targetVar));
+ if (existing != null) {
+ MergeUtils.removeConstruct((IConstruct) targetVar);
+ targetVar = existing;
+ }
+ _copyReifier((IReifiable) variant, (IReifiable) targetVar, mergeMap);
+ _copyItemIdentifiers((IConstruct) variant, (IConstruct) targetVar);
+ }
+ }
+
+ /**
+ * Copies the reifier of <code>source</code> (if any) to the <code>target</code>.
+ *
+ * @param source The reifiable Topic Maps construct to take the reifier from.
+ * @param target The target Topic Maps construct.
+ * @param mergeMap The map which holds the merge mappings.
+ */
+ private static void _copyReifier(IReifiable source, IReifiable target,
+ Map<Topic, Topic> mergeMap) {
+ Topic sourceReifier = source.getReifier();
+ if (sourceReifier == null) {
+ return;
+ }
+ Topic reifier = mergeMap.containsKey(sourceReifier) ? mergeMap.get(sourceReifier)
+ : _copyTopic(sourceReifier, target.getTopicMap(), mergeMap);
+ target.setReifier(reifier);
+ }
+
+ /**
+ * Copies the type of the <code>source</code> (if any) to the <code>target</code>.
+ *
+ * @param source The Topic Maps construct to take the type from.
+ * @param target The Topic Maps construct which receives the type.
+ * @param mergeMap The map which holds the merge mappings.
+ */
+ private static void _copyType(ITyped source, ITyped target,
+ Map<Topic, Topic> mergeMap) {
+ Topic sourceType = source.getType();
+ if (sourceType == null) {
+ return;
+ }
+ Topic type = mergeMap.containsKey(sourceType) ? mergeMap.get(sourceType)
+ : _copyTopic(sourceType, target.getTopicMap(), mergeMap);
+ target.setType(type);
+ }
+
+ /**
+ * Copies all themes from the <code>source</code> scoped Topic Maps construct
+ * to the <code>target</code>.
+ *
+ * @param source The source to take the scope from.
+ * @param target The target which receives the scope.
+ * @param mergeMap The map which holds the merge mappings.
+ */
+ private static void _copyScope(IScoped source, IScoped target,
+ Map<Topic, Topic> mergeMap) {
+ Topic theme = null;
+ for (Topic sourceTheme: source.getScope()) {
+ theme = mergeMap.containsKey(sourceTheme) ? mergeMap.get(sourceTheme)
+ : _copyTopic(sourceTheme, target.getTopicMap(), mergeMap);
+ target.addTheme(theme);
+ }
+ }
+
+ /**
+ * Copies the item identifiers from <code>source</code> to <code>target</code>.
+ *
+ * @param source The source Topic Maps construct.
+ * @param target The target Topic Maps construct.
+ */
private static void _copyItemIdentifiers(IConstruct source, IConstruct target) {
for(Locator iid: source.getItemIdentifiers()) {
target.addSourceLocator(iid);
}
}
+ /**
+ * Copies the associations from the <code>source</code> topic map to the
+ * <code>target</code> topic map.
+ *
+ * @param source The topic map to take the associations from.
+ * @param target The topic map which receives the associations.
+ * @param mergeMap The map which holds the merge mappings.
+ */
+ @SuppressWarnings("unchecked")
+ private static void _copyAssociations(TopicMapImpl source,
+ TopicMapImpl target, Map<Topic, Topic> mergeMap) {
+ Set<Association> assocs = target.getAssociations();
+ Map<String, Association> sigs = target.getCollectionFactory().createMap(assocs.size());
+ for (Association assoc: assocs) {
+ sigs.put(SignatureGenerator.generateSignature(assoc), assoc);
+ }
+ Association existing = null;
+ for (Association assoc: source.getAssociations()) {
+ Association targetAssoc = target.createAssociation();
+ _copyType((ITyped) assoc, (ITyped) targetAssoc, mergeMap);
+ _copyScope((IScoped) assoc, (IScoped) targetAssoc, mergeMap);
+ for (Iterator<AssociationRole> iter = assoc.getAssociationRoles().iterator(); iter.hasNext();) {
+ AssociationRole role = iter.next();
+ AssociationRole targetRole = targetAssoc.createAssociationRole(role.getPlayer(), role.getType());
+ _copyItemIdentifiers((IConstruct)role, (IConstruct)targetRole);
+ _copyReifier((IReifiable) role, (IReifiable) targetRole, mergeMap);
+ }
+ existing = sigs.get(SignatureGenerator.generateSignature(targetAssoc));
+ if (existing != null) {
+ MergeUtils.moveRoleCharacteristics(targetAssoc, existing);
+ MergeUtils.removeConstruct((IConstruct) targetAssoc);
+ targetAssoc = existing;
+ }
+ _copyReifier((IReifiable) assoc, (IReifiable) targetAssoc, mergeMap);
+ _copyItemIdentifiers((IConstruct) assoc, (IConstruct) targetAssoc);
+ }
+ }
+
+ /**
+ * Adds a mapping from <code>source</code> to <code>target</code> into the
+ * <code>mergeMap</code>.
+ *
+ * If <code>source</code> has already a mapping to another target topic,
+ * <code>target</code> is merged with the existing target topic.
+ *
+ * @param source The source topic.
+ * @param target The target topic.
+ * @param mergeMap The map which holds the merge mappings.
+ */
private static void _addMerge(Topic source, Topic target, Map<Topic, Topic> mergeMap) {
Topic prevTarget = mergeMap.get(source);
if (prevTarget != null) {
Modified: tinytim/trunk/src/main/java/org/tinytim/IMovable.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/IMovable.java 2008-04-23 17:55:30 UTC (rev 34)
+++ tinytim/trunk/src/main/java/org/tinytim/IMovable.java 2008-04-24 12:04:37 UTC (rev 35)
@@ -27,7 +27,7 @@
* This interface is not meant to be used outside of the tinyTiM package.
*
* @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
- * @version $Rev:$ - $Date:$
+ * @version $Rev$ - $Date$
*/
interface IMovable<T /* extends IConstruct */> {
Modified: tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java 2008-04-23 17:55:30 UTC (rev 34)
+++ tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java 2008-04-24 12:04:37 UTC (rev 35)
@@ -95,10 +95,10 @@
if (source.getTopicMap() != target.getTopicMap()) {
throw new IllegalArgumentException("The topics must belong to the same topic map");
}
- IReifiable sourceReifiable = source._reified;
- if (sourceReifiable != null && target._reified != null) {
+ IReifiable sourceReifiable = source.getReifiedConstruct();
+ if (sourceReifiable != null && target.getReifiedConstruct() != null) {
// This should be enforced by the model
- assert sourceReifiable != target._reified;
+ assert sourceReifiable != target.getReifiedConstruct();
throw new ModelConstraintException(target, "The topics cannot be merged. They reify different Topic Maps constructs");
}
_moveItemIdentifiers((IConstruct)source, (IConstruct)target);
@@ -160,7 +160,7 @@
existing = sigs.get(SignatureGenerator.generateSignature(parent));
if (existing != null) {
handleExistingConstruct((IReifiable)parent, existing);
- _moveRoleCharacteristics(parent, (Association)existing);
+ moveRoleCharacteristics(parent, (Association)existing);
removeConstruct((IConstruct)parent);
}
}
@@ -191,7 +191,7 @@
* @param target The association which takes the role characteristics.
*/
@SuppressWarnings("unchecked")
- private static void _moveRoleCharacteristics(Association source, Association target) {
+ static void moveRoleCharacteristics(Association source, Association target) {
Map<String, AssociationRole> sigs = ((TopicMapImpl) target.getTopicMap()).getCollectionFactory().<String, AssociationRole>createMap();
for (AssociationRole role: ((AssociationImpl)target).getAssociationRoles()) {
sigs.put(SignatureGenerator.generateSignature(role), role);
@@ -304,6 +304,14 @@
}
}
+ /**
+ * Replaces the <code>oldTheme</code> with the <code>newTheme</code> in each
+ * scoped Topic Maps construct.
+ *
+ * @param scopedCollection A collection of scoped Topic Maps constructs.
+ * @param oldTheme The old theme.
+ * @param newTheme The theme that is used as replacement for <code>oldTheme</code>.
+ */
private static void _replaceTopicAsTheme(Collection<? extends IScoped> scopedCollection,
Topic oldTheme, Topic newTheme) {
for (IScoped scoped: scopedCollection) {
Modified: tinytim/trunk/src/main/java/org/tinytim/TopicImpl.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/TopicImpl.java 2008-04-23 17:55:30 UTC (rev 34)
+++ tinytim/trunk/src/main/java/org/tinytim/TopicImpl.java 2008-04-24 12:04:37 UTC (rev 35)
@@ -242,6 +242,17 @@
name._parent = null;
}
+ /**
+ * Returns the Topic Maps construct that is reified by
+ * this topic.
+ *
+ * @return The reified construct or <code>null</code> if this
+ * topic reifies nothing.
+ */
+ public IReifiable getReifiedConstruct() {
+ return _reified;
+ }
+
/* (non-Javadoc)
* @see org.tmapi.core.Topic#getReified()
*/
Modified: tinytim/trunk/src/main/java/org/tinytim/TopicMapImpl.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/TopicMapImpl.java 2008-04-23 17:55:30 UTC (rev 34)
+++ tinytim/trunk/src/main/java/org/tinytim/TopicMapImpl.java 2008-04-24 12:04:37 UTC (rev 35)
@@ -49,7 +49,7 @@
* {@link org.tmapi.core.TopicMap} implementation.
*
* @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
- * @version $Rev:$ - $Date:$
+ * @version $Rev$ - $Date$
*/
public final class TopicMapImpl extends Construct implements TopicMap,
IReifiable, IEventHandler, IEventPublisher {
Modified: tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndex.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndex.java 2008-04-23 17:55:30 UTC (rev 34)
+++ tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndex.java 2008-04-24 12:04:37 UTC (rev 35)
@@ -197,7 +197,6 @@
private final class AddScopedHandler extends _EvtHandler {
@SuppressWarnings("unchecked")
- @Override
public void handleEvent(Event evt, IConstruct sender, Object oldValue,
Object newValue) {
ScopedObject scoped = (ScopedObject) newValue;
@@ -228,7 +227,6 @@
private final class RemoveScopedHandler extends _EvtHandler {
@SuppressWarnings("unchecked")
- @Override
public void handleEvent(Event evt, IConstruct sender, Object oldValue,
Object newValue) {
ScopedObject scoped = (ScopedObject) oldValue;
Modified: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/OccurrencesIndexImpl.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/index/tmapi/OccurrencesIndexImpl.java 2008-04-23 17:55:30 UTC (rev 34)
+++ tinytim/trunk/src/main/java/org/tinytim/index/tmapi/OccurrencesIndexImpl.java 2008-04-24 12:04:37 UTC (rev 35)
@@ -64,7 +64,6 @@
/* (non-Javadoc)
* @see org.tmapi.index.core.OccurrencesIndex#getOccurrenceTypes()
*/
- @Override
public Collection<Topic> getOccurrenceTypes() {
return _getTypeInstanceIndex().getOccurrenceTypes();
}
@@ -72,7 +71,6 @@
/* (non-Javadoc)
* @see org.tmapi.index.core.OccurrencesIndex#getOccurrencesByType(org.tmapi.core.Topic)
*/
- @Override
public Collection<OccurrenceImpl> getOccurrencesByType(Topic type) {
return _getTypeInstanceIndex().getOccurrences(type);
}
@@ -80,7 +78,6 @@
/* (non-Javadoc)
* @see org.tmapi.index.core.OccurrencesIndex#getOccurrencesByResource(org.tmapi.core.Locator)
*/
- @Override
public Collection<Occurrence> getOccurrencesByResource(Locator value) {
List<Occurrence> occs = _loc2Occs.get(value);
return occs == null ? Collections.<Occurrence>emptySet()
@@ -90,7 +87,6 @@
/* (non-Javadoc)
* @see org.tmapi.index.core.OccurrencesIndex#getOccurrencesByValue(java.lang.String)
*/
- @Override
public Collection<Occurrence> getOccurrencesByValue(String value) {
List<Occurrence> occs = _value2Occs.get(value);
return occs == null ? Collections.<Occurrence>emptySet()
@@ -100,7 +96,6 @@
/* (non-Javadoc)
* @see org.tmapi.index.Index#getFlags()
*/
- @Override
public IndexFlags getFlags() throws TMAPIIndexException {
return IndexFlagsImpl.NOT_AUTOUPDATED;
}
@@ -109,7 +104,6 @@
* @see org.tmapi.index.Index#reindex()
*/
@SuppressWarnings("unchecked")
- @Override
public void reindex() throws TMAPIIndexException {
_value2Occs.clear();
_loc2Occs.clear();
Modified: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/TopicNamesIndexImpl.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/index/tmapi/TopicNamesIndexImpl.java 2008-04-23 17:55:30 UTC (rev 34)
+++ tinytim/trunk/src/main/java/org/tinytim/index/tmapi/TopicNamesIndexImpl.java 2008-04-24 12:04:37 UTC (rev 35)
@@ -61,7 +61,6 @@
/* (non-Javadoc)
* @see org.tmapi.index.core.TopicNamesIndex#getTopicNameTypes()
*/
- @Override
public Collection<Topic> getTopicNameTypes() {
return _getTypeInstanceIndex().getNameTypes();
}
@@ -69,7 +68,6 @@
/* (non-Javadoc)
* @see org.tmapi.index.core.TopicNamesIndex#getTopicNamesByType(org.tmapi.core.Topic)
*/
- @Override
public Collection<TopicNameImpl> getTopicNamesByType(Topic type) {
return _getTypeInstanceIndex().getNames(type);
}
@@ -77,7 +75,6 @@
/* (non-Javadoc)
* @see org.tmapi.index.core.TopicNamesIndex#getTopicNamesByValue(java.lang.String)
*/
- @Override
public Collection<TopicName> getTopicNamesByValue(String value) {
List<TopicName> names = _value2Names.get(value);
return names == null ? Collections.<TopicName>emptySet()
@@ -87,7 +84,6 @@
/* (non-Javadoc)
* @see org.tmapi.index.Index#getFlags()
*/
- @Override
public IndexFlags getFlags() throws TMAPIIndexException {
return IndexFlagsImpl.NOT_AUTOUPDATED;
}
@@ -96,7 +92,6 @@
* @see org.tmapi.index.Index#reindex()
*/
@SuppressWarnings("unchecked")
- @Override
public void reindex() throws TMAPIIndexException {
_value2Names.clear();
for (Topic topic: _weakTopicMap.get().getTopics()) {
Modified: tinytim/trunk/src/main/resources/META-INF/services/org.tmapi.core.TopicMapSystemFactory
===================================================================
--- tinytim/trunk/src/main/resources/META-INF/services/org.tmapi.core.TopicMapSystemFactory 2008-04-23 17:55:30 UTC (rev 34)
+++ tinytim/trunk/src/main/resources/META-INF/services/org.tmapi.core.TopicMapSystemFactory 2008-04-24 12:04:37 UTC (rev 35)
@@ -1 +1 @@
-org.tinytim.TopicMapSystemFactoryImpl
\ No newline at end of file
+org.tinytim.TopicMapSystemFactoryImpl
Modified: tinytim/trunk/src/test/java/org/tinytim/TestItemIdentifierConstraint.java
===================================================================
--- tinytim/trunk/src/test/java/org/tinytim/TestItemIdentifierConstraint.java 2008-04-23 17:55:30 UTC (rev 34)
+++ tinytim/trunk/src/test/java/org/tinytim/TestItemIdentifierConstraint.java 2008-04-24 12:04:37 UTC (rev 35)
@@ -36,7 +36,7 @@
* Tests if the TMDM item identifier constraint is respected.
*
* @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
- * @version $Rev:$ - $Date:$
+ * @version $Rev$ - $Date$
*/
public class TestItemIdentifierConstraint extends TinyTimTestCase {
Modified: tinytim/trunk/src/test/java/org/tinytim/TestReifiable.java
===================================================================
--- tinytim/trunk/src/test/java/org/tinytim/TestReifiable.java 2008-04-23 17:55:30 UTC (rev 34)
+++ tinytim/trunk/src/test/java/org/tinytim/TestReifiable.java 2008-04-24 12:04:37 UTC (rev 35)
@@ -130,19 +130,19 @@
assertEquals(0, reifier.getReified().size());
reifiable.setReifier(reifier);
assertEquals(reifier, reifiable.getReifier());
- assertEquals(reifiable, reifier._reified);
+ assertEquals(reifiable, reifier.getReifiedConstruct());
assertEquals(1, reifier.getReified().size());
assertTrue(reifier.getReified().contains(reifiable));
reifiable.setReifier(null);
assertNull(reifiable.getReifier());
- assertNull(reifier._reified);
+ assertNull(reifier.getReifiedConstruct());
assertEquals(0, reifier.getReified().size());
TopicImpl reifier2 = (TopicImpl) _tm.createTopic();
IReifiable assoc = (IReifiable) _tm.createAssociation();
assoc.setReifier(reifier2);
assertEquals(reifier2, assoc.getReifier());
- assertEquals(assoc, reifier2._reified);
+ assertEquals(assoc, reifier2.getReifiedConstruct());
try {
reifiable.setReifier(reifier2);
fail("Expected an exception. The reifier reifies another Topic Maps construct");
@@ -152,12 +152,12 @@
}
assoc.setReifier(null);
assertNull(assoc.getReifier());
- assertNull(reifier2._reified);
+ assertNull(reifier2.getReifiedConstruct());
reifiable.setReifier(reifier);
assertEquals(reifier, reifiable.getReifier());
- assertEquals(reifiable, reifier._reified);
+ assertEquals(reifiable, reifier.getReifiedConstruct());
reifiable.setReifier(reifier2);
assertEquals(reifier2, reifiable.getReifier());
- assertEquals(reifiable, reifier2._reified);
+ assertEquals(reifiable, reifier2.getReifiedConstruct());
}
}
Modified: tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java
===================================================================
--- tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java 2008-04-23 17:55:30 UTC (rev 34)
+++ tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java 2008-04-24 12:04:37 UTC (rev 35)
@@ -154,6 +154,86 @@
}
/**
+ * Tests if merging detects duplicates and that the reifier is kept.
+ */
+ public void testDuplicateDetectionReifier() {
+ Topic topic1 = _tm.createTopic();
+ Topic topic2 = _tm.createTopic();
+ Topic reifier = _tm.createTopic();
+ TopicName name1 = topic1.createTopicName("tinyTiM", null, null);
+ TopicName name2 = topic2.createTopicName("tinyTiM", null, null);
+ assertEquals(3, _tm.getTopics().size());
+ ((IReifiable) name1).setReifier(reifier);
+ assertEquals(reifier, name1.getReifier());
+ assertEquals(1, topic1.getTopicNames().size());
+ assertTrue(topic1.getTopicNames().contains(name1));
+ assertEquals(1, topic2.getTopicNames().size());
+ assertTrue(topic2.getTopicNames().contains(name2));
+ topic1.mergeIn(topic2);
+ assertEquals(2, _tm.getTopics().size());
+ assertEquals(1, topic1.getTopicNames().size());
+ TopicName name = (TopicName) topic1.getTopicNames().iterator().next();
+ assertEquals(reifier, name.getReifier());
+ }
+
+ /**
+ * Tests if merging detects duplicates and merges the reifiers of the
+ * duplicates.
+ */
+ public void testDuplicateDetectionReifierMerge() {
+ Topic topic1 = _tm.createTopic();
+ Topic topic2 = _tm.createTopic();
+ Topic reifier1 = _tm.createTopic();
+ Topic reifier2 = _tm.createTopic();
+ TopicName name1 = topic1.createTopicName("tinyTiM", null, null);
+ TopicName name2 = topic2.createTopicName("tinyTiM", null, null);
+ assertEquals(4, _tm.getTopics().size());
+ ((IReifiable) name1).setReifier(reifier1);
+ ((IReifiable) name2).setReifier(reifier2);
+ assertEquals(reifier1, name1.getReifier());
+ assertEquals(reifier2, name2.getReifier());
+ assertEquals(1, topic1.getTopicNames().size());
+ assertTrue(topic1.getTopicNames().contains(name1));
+ assertEquals(1, topic2.getTopicNames().size());
+ assertTrue(topic2.getTopicNames().contains(name2));
+ topic1.mergeIn(topic2);
+ assertEquals(2, _tm.getTopics().size());
+ assertEquals(1, topic1.getTopicNames().size());
+ TopicName name = (TopicName) topic1.getTopicNames().iterator().next();
+ Topic reifier = null;
+ for (Topic topic: _tm.getTopics()) {
+ if (!topic.equals(topic1)) {
+ reifier = topic;
+ }
+ }
+ assertEquals(reifier, name.getReifier());
+ }
+
+ /**
+ * Tests if merging detects duplicate associations.
+ */
+ public void testDuplicateSuppressionAssociation() {
+ Topic topic1 = _tm.createTopic();
+ Topic topic2 = _tm.createTopic();
+ Topic roleType = _tm.createTopic();
+ Association assoc1 = _tm.createAssociation();
+ Association assoc2 = _tm.createAssociation();
+ AssociationRole role1 = assoc1.createAssociationRole(topic1, roleType);
+ AssociationRole role2 = assoc2.createAssociationRole(topic2, roleType);
+ assertEquals(3, _tm.getTopics().size());
+ assertEquals(2, _tm.getAssociations().size());
+ assertTrue(topic1.getRolesPlayed().contains(role1));
+ assertTrue(topic2.getRolesPlayed().contains(role2));
+ assertEquals(1, topic1.getRolesPlayed().size());
+ assertEquals(1, topic2.getRolesPlayed().size());
+ topic1.mergeIn(topic2);
+ assertEquals(2, _tm.getTopics().size());
+ assertEquals(1, _tm.getAssociations().size());
+ AssociationRole role = (AssociationRole) topic1.getRolesPlayed().iterator().next();
+ assertEquals(roleType, role.getType());
+ }
+
+ /**
* Tests if merging detects duplicate names.
*/
public void testDuplicateSuppressionName() {
@@ -196,6 +276,34 @@
}
/**
+ * Tests if merging detects duplicate names and sets the item
+ * identifier to the union of both names.
+ */
+ public void testDuplicateSuppressionNameMoveItemIdentifiers() {
+ Topic topic1 = _tm.createTopic();
+ Topic topic2 = _tm.createTopic();
+ Locator iid1 = _tm.createLocator("http://example.org/iid-1");
+ Locator iid2 = _tm.createLocator("http://example.org/iid-2");
+ TopicName name1 = topic1.createTopicName("tinyTiM", null, null);
+ TopicName name2 = topic2.createTopicName("tinyTiM", null, null);
+ name1.addSourceLocator(iid1);
+ name2.addSourceLocator(iid2);
+ assertTrue(name1.getSourceLocators().contains(iid1));
+ assertTrue(name2.getSourceLocators().contains(iid2));
+ assertEquals(1, topic1.getTopicNames().size());
+ assertTrue(topic1.getTopicNames().contains(name1));
+ assertEquals(1, topic2.getTopicNames().size());
+ assertTrue(topic2.getTopicNames().contains(name2));
+ topic1.mergeIn(topic2);
+ assertEquals(1, topic1.getTopicNames().size());
+ TopicName name = (TopicName) topic1.getTopicNames().iterator().next();
+ assertEquals(2, name.getSourceLocators().size());
+ assertTrue(name.getSourceLocators().contains(iid1));
+ assertTrue(name.getSourceLocators().contains(iid2));
+ assertEquals("tinyTiM", name.getValue());
+ }
+
+ /**
* Tests if merging detects duplicate occurrences.
*/
public void testDuplicateSuppressionOccurrence() {
@@ -214,10 +322,10 @@
}
/**
- * Tests if merging detects duplicate occurrences and moves the
- * item identifiers.
+ * Tests if merging detects duplicate occurrences and sets the item
+ * identifier to the union of both occurrences.
*/
- public void testDuplicateSuppressionOccurrenceItemIdentifiers() {
+ public void testDuplicateSuppressionOccurrenceMoveItemIdentifiers() {
Topic topic1 = _tm.createTopic();
Topic topic2 = _tm.createTopic();
Locator iid1 = _tm.createLocator("http://example.org/iid-1");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|