|
From: <lh...@us...> - 2008-04-23 12:16:13
|
Revision: 29
http://tinytim.svn.sourceforge.net/tinytim/?rev=29&view=rev
Author: lheuer
Date: 2008-04-23 05:16:08 -0700 (Wed, 23 Apr 2008)
Log Message:
-----------
- Added moveable to move a Topic Maps construct to another
- Tests for item identifier constraints
- Enhanced TopicUtils
Modified Paths:
--------------
tinytim/trunk/src/main/java/org/tinytim/Construct.java
tinytim/trunk/src/main/java/org/tinytim/Event.java
tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java
tinytim/trunk/src/main/java/org/tinytim/OccurrenceImpl.java
tinytim/trunk/src/main/java/org/tinytim/ReificationUtils.java
tinytim/trunk/src/main/java/org/tinytim/Scoped.java
tinytim/trunk/src/main/java/org/tinytim/TopicImpl.java
tinytim/trunk/src/main/java/org/tinytim/TopicNameImpl.java
tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java
tinytim/trunk/src/main/java/org/tinytim/Typed.java
tinytim/trunk/src/main/java/org/tinytim/VariantImpl.java
tinytim/trunk/src/test/java/org/tinytim/TestReificationUtils.java
tinytim/trunk/src/test/java/org/tinytim/TestTopicMergeDetection.java
tinytim/trunk/src/test/java/org/tinytim/TestTopicUtils.java
Added Paths:
-----------
tinytim/trunk/src/main/java/org/tinytim/IMovable.java
tinytim/trunk/src/test/java/org/tinytim/TestItemIdentifierConstraint.java
Modified: tinytim/trunk/src/main/java/org/tinytim/Construct.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/Construct.java 2008-04-22 15:12:58 UTC (rev 28)
+++ tinytim/trunk/src/main/java/org/tinytim/Construct.java 2008-04-23 12:16:08 UTC (rev 29)
@@ -167,4 +167,18 @@
_iids = null;
}
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder(super.toString());
+ sb.append(" iids=[");
+ for (Locator sid: getItemIdentifiers()) {
+ sb.append(sid);
+ sb.append(',');
+ }
+ sb.append("]");
+ return sb.toString();
+ }
}
Modified: tinytim/trunk/src/main/java/org/tinytim/Event.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/Event.java 2008-04-22 15:12:58 UTC (rev 28)
+++ tinytim/trunk/src/main/java/org/tinytim/Event.java 2008-04-23 12:16:08 UTC (rev 29)
@@ -151,6 +151,10 @@
* Notification that the "resource" of an occurrence or variant should be
* set.
*/
- SET_LOCATOR; //TODO: Remove this once we have a TMDM-compatible version
+ SET_LOCATOR, //TODO: Remove this once we have a TMDM-compatible version
+ MOVE_OCCURRENCE,
+ MOVE_NAME,
+ MOVE_VARIANT
+
}
Added: tinytim/trunk/src/main/java/org/tinytim/IMovable.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/IMovable.java (rev 0)
+++ tinytim/trunk/src/main/java/org/tinytim/IMovable.java 2008-04-23 12:16:08 UTC (rev 29)
@@ -0,0 +1,41 @@
+/*
+ * This is tinyTiM, a tiny Topic Maps engine.
+ *
+ * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+package org.tinytim;
+
+/**
+ * Indicates that a Topic Maps construct is able to be detached from the
+ * current parent and attached to another parent.
+ *
+ * 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:$
+ */
+interface IMovable<T /* extends IConstruct */> {
+
+ /**
+ * Moves this Topic Maps construct to the new parent.
+ *
+ * @param newParent The parent to move this construct to.
+ */
+ public void moveTo(T newParent);
+
+}
Property changes on: tinytim/trunk/src/main/java/org/tinytim/IMovable.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date Id
Name: svn:eol-style
+ native
Modified: tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java 2008-04-22 15:12:58 UTC (rev 28)
+++ tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java 2008-04-23 12:16:08 UTC (rev 29)
@@ -84,6 +84,7 @@
/**
* @see #merge(Topic, Topic)
*/
+ @SuppressWarnings("unchecked")
private static void _merge(TopicImpl source, TopicImpl target) {
if (source == null || target == null) {
throw new IllegalArgumentException("Neither the source topic nor the target topic must be null");
@@ -130,8 +131,7 @@
removeConstruct((IConstruct)occ);
}
else {
- source.removeOccurrence(occ);
- target.addOccurrence(occ);
+ ((IMovable<Topic>) occ).moveTo(target);
}
}
sigs.clear();
@@ -146,8 +146,7 @@
removeConstruct((IConstruct) name);
}
else {
- source.removeName(name);
- target.addName(name);
+ ((IMovable<Topic>) name).moveTo(target);
}
}
sigs.clear();
@@ -210,6 +209,7 @@
* @param source The name to take the variants from.
* @param target The target to add the variants to.
*/
+ @SuppressWarnings("unchecked")
static void moveVariants(TopicNameImpl source, TopicNameImpl target) {
Map<String, Variant> sigs = ((TopicMapImpl) target.getTopicMap()).getCollectionFactory().<String, Variant>createMap();
for (Variant var: target.getVariants()) {
@@ -223,8 +223,7 @@
removeConstruct((IConstruct)var);
}
else {
- source.removeVariant(var);
- target.addVariant(var);
+ ((IMovable<TopicName>) var).moveTo(target);
}
}
}
Modified: tinytim/trunk/src/main/java/org/tinytim/OccurrenceImpl.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/OccurrenceImpl.java 2008-04-22 15:12:58 UTC (rev 28)
+++ tinytim/trunk/src/main/java/org/tinytim/OccurrenceImpl.java 2008-04-23 12:16:08 UTC (rev 29)
@@ -34,7 +34,7 @@
* @version $Rev$ - $Date$
*/
public final class OccurrenceImpl extends DatatypeAwareConstruct implements
- Occurrence, ITyped, IScoped {
+ Occurrence, ITyped, IScoped, IMovable<Topic> {
OccurrenceImpl(TopicMapImpl topicMap, Topic type, String value, Collection<Topic> scope) {
super(topicMap, type, value, scope);
@@ -52,6 +52,15 @@
}
/* (non-Javadoc)
+ * @see org.tinytim.IMovable#moveTo(java.lang.Object)
+ */
+ public void moveTo(Topic newParent) {
+ _fireEvent(Event.MOVE_OCCURRENCE, _parent, newParent);
+ ((TopicImpl) _parent).detachOccurrence(this);
+ ((TopicImpl) newParent).attachOccurrence(this);
+ }
+
+ /* (non-Javadoc)
* @see org.tmapi.core.TopicMapObject#remove()
*/
public void remove() throws TMAPIException {
Modified: tinytim/trunk/src/main/java/org/tinytim/ReificationUtils.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/ReificationUtils.java 2008-04-22 15:12:58 UTC (rev 28)
+++ tinytim/trunk/src/main/java/org/tinytim/ReificationUtils.java 2008-04-23 12:16:08 UTC (rev 29)
@@ -30,12 +30,10 @@
/**
* Functions to support the XTM 1.0 reification mechanism.
*
- * This class 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$
*/
-final class ReificationUtils {
+public final class ReificationUtils {
/**
* Returns all Topic Maps constructs which have an item identifier
Modified: tinytim/trunk/src/main/java/org/tinytim/Scoped.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/Scoped.java 2008-04-22 15:12:58 UTC (rev 28)
+++ tinytim/trunk/src/main/java/org/tinytim/Scoped.java 2008-04-23 12:16:08 UTC (rev 29)
@@ -97,7 +97,7 @@
}
/* (non-Javadoc)
- * @see org.tinytim.Construct#dispose()
+ * @see org.tinytim.Typed#dispose()
*/
@Override
protected void dispose() {
Modified: tinytim/trunk/src/main/java/org/tinytim/TopicImpl.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/TopicImpl.java 2008-04-22 15:12:58 UTC (rev 28)
+++ tinytim/trunk/src/main/java/org/tinytim/TopicImpl.java 2008-04-23 12:16:08 UTC (rev 29)
@@ -159,8 +159,7 @@
return;
}
_fireEvent(Event.ADD_OCCURRENCE, null, o);
- o._parent = this;
- _occs.add(o);
+ attachOccurrence(o);
}
/**
@@ -174,10 +173,19 @@
return;
}
_fireEvent(Event.REMOVE_OCCURRENCE, o, null);
- _occs.remove(o);
- o._parent = null;
+ detachOccurrence(o);
}
+ void attachOccurrence(OccurrenceImpl occ) {
+ occ._parent = this;
+ _occs.add(occ);
+ }
+
+ void detachOccurrence(OccurrenceImpl occ) {
+ _occs.remove(occ);
+ occ._parent = null;
+ }
+
/* (non-Javadoc)
* @see org.tmapi.core.Topic#getTopicNames()
*/
@@ -212,8 +220,7 @@
}
assert n._parent == null;
_fireEvent(Event.ADD_NAME, null, n);
- n._parent = this;
- _names.add(n);
+ attachName(n);
}
void removeName(TopicName name) {
@@ -222,10 +229,19 @@
return;
}
_fireEvent(Event.REMOVE_NAME, n, null);
- _names.remove(n);
- n._parent = null;
+ detachName(n);
}
+ void attachName(TopicNameImpl name) {
+ name._parent = this;
+ _names.add(name);
+ }
+
+ void detachName(TopicNameImpl name) {
+ _names.remove(name);
+ name._parent = null;
+ }
+
/* (non-Javadoc)
* @see org.tmapi.core.Topic#getReified()
*/
@@ -303,9 +319,12 @@
* @see org.tmapi.core.TopicMapObject#remove()
*/
public void remove() throws TopicInUseException {
- if (!TopicUtils.isRemovable(this)) {
- throw new TopicInUseException("The topic is used as type, player, reifier or theme");
+ if (!TopicUtils.isRemovable(this, false)) {
+ throw new TopicInUseException("The topic is used as type, player, or theme");
}
+ if (_reified != null) {
+ _reified.setReifier(null);
+ }
_tm.removeTopic(this);
_sids = null;
_slos = null;
@@ -317,4 +336,24 @@
super.dispose();
}
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder(super.toString());
+ sb.append(", sids=[");
+ for (Locator sid: getSubjectIdentifiers()) {
+ sb.append(sid);
+ sb.append(',');
+ }
+ sb.append("], slos=[");
+ for (Locator slo: getSubjectLocators()) {
+ sb.append(slo);
+ sb.append(',');
+ }
+ sb.append("]");
+ return sb.toString();
+ }
+
}
Modified: tinytim/trunk/src/main/java/org/tinytim/TopicNameImpl.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/TopicNameImpl.java 2008-04-22 15:12:58 UTC (rev 28)
+++ tinytim/trunk/src/main/java/org/tinytim/TopicNameImpl.java 2008-04-23 12:16:08 UTC (rev 29)
@@ -37,7 +37,8 @@
* @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
* @version $Rev$ - $Date$
*/
-public final class TopicNameImpl extends Scoped implements TopicName, ITyped, IScoped {
+public final class TopicNameImpl extends Scoped implements TopicName, ITyped,
+ IScoped, IMovable<Topic> {
private String _value;
private Set<Variant> _variants;
@@ -104,11 +105,7 @@
}
assert v._parent == null;
_fireEvent(Event.ADD_VARIANT, null, v);
- if (_variants == null) {
- _variants = _tm.getCollectionFactory().createSet();
- }
- v._parent = this;
- _variants.add(v);
+ attachVariant(v);
}
void removeVariant(Variant variant) {
@@ -117,10 +114,31 @@
return;
}
_fireEvent(Event.REMOVE_VARIANT, v, null);
- _variants.remove(v);
- v._parent = null;
+ detachVariant(v);
}
+ void attachVariant(VariantImpl variant) {
+ if (_variants == null) {
+ _variants = _tm.getCollectionFactory().createSet();
+ }
+ variant._parent = this;
+ _variants.add(variant);
+ }
+
+ void detachVariant(VariantImpl variant) {
+ _variants.remove(variant);
+ variant._parent = null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.IMovable#moveTo(java.lang.Object)
+ */
+ public void moveTo(Topic newParent) {
+ _fireEvent(Event.MOVE_NAME, _parent, newParent);
+ ((TopicImpl) _parent).detachName(this);
+ ((TopicImpl) newParent).attachName(this);
+ }
+
/* (non-Javadoc)
* @see org.tmapi.core.TopicMapObject#remove()
*/
Modified: tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java 2008-04-22 15:12:58 UTC (rev 28)
+++ tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java 2008-04-23 12:16:08 UTC (rev 29)
@@ -41,15 +41,36 @@
* Returns if the <code>topic</code> is removable.
*
* A topic is removable iff it plays no role, is not used as type of
+ * a typed Topic Maps construct, and is not not used as theme of a scoped
+ * Topic Maps construct.
+ *
+ * This functions returns the same result as
+ * <code>isRemovable(topic, false)</code>.
+ *
+ * @param topic The topic to check.
+ * @return <code>true</code> if the topic is removable, <code>false</code>
+ * otherwise.
+ */
+ public static boolean isRemovable(Topic topic) {
+ return isRemovable(topic, false);
+ }
+
+ /**
+ * Returns if the <code>topic</code> is removable.
+ *
+ * A topic is removable iff it plays no role, is not used as type of
* a typed Topic Maps construct, is not not used as theme of a scoped
- * Topic Maps construct and iff it is not used reifier.
+ * Topic Maps construct and iff it is not used reifier
+ * (if <code>includeReified</code> is <code>true</code>).
*
* @param topic The topic to check.
+ * @param includeReified Indicates if a reified Topic Maps construct (if any)
+ * is considered as dependency.
* @return <code>true</code> if the topic is removable, <code>false</code>
* otherwise.
*/
- public static boolean isRemovable(Topic topic) {
- if (((TopicImpl) topic)._reified != null) {
+ public static boolean isRemovable(Topic topic, boolean includeReified) {
+ if (includeReified && ((TopicImpl) topic)._reified != null) {
return false;
}
if (!topic.getRolesPlayed().isEmpty()) {
@@ -78,4 +99,5 @@
}
return removable;
}
+
}
Modified: tinytim/trunk/src/main/java/org/tinytim/Typed.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/Typed.java 2008-04-22 15:12:58 UTC (rev 28)
+++ tinytim/trunk/src/main/java/org/tinytim/Typed.java 2008-04-23 12:16:08 UTC (rev 29)
@@ -89,7 +89,7 @@
}
/* (non-Javadoc)
- * @see org.tinytim.Scoped#dispose()
+ * @see org.tinytim.Construct#dispose()
*/
@Override
protected void dispose() {
Modified: tinytim/trunk/src/main/java/org/tinytim/VariantImpl.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/VariantImpl.java 2008-04-22 15:12:58 UTC (rev 28)
+++ tinytim/trunk/src/main/java/org/tinytim/VariantImpl.java 2008-04-23 12:16:08 UTC (rev 29)
@@ -35,7 +35,7 @@
* @version $Rev$ - $Date$
*/
public final class VariantImpl extends DatatypeAwareConstruct implements
- Variant, IScoped {
+ Variant, IScoped, IMovable<TopicName> {
VariantImpl(TopicMapImpl topicMap, String value, Collection<Topic> scope) {
super(topicMap, null, value, scope);
@@ -53,6 +53,15 @@
}
/* (non-Javadoc)
+ * @see org.tinytim.IMovable#moveTo(java.lang.Object)
+ */
+ public void moveTo(TopicName newParent) {
+ _fireEvent(Event.MOVE_VARIANT, _parent, newParent);
+ ((TopicNameImpl) _parent).detachVariant(this);
+ ((TopicNameImpl) newParent).attachVariant(this);
+ }
+
+ /* (non-Javadoc)
* @see org.tmapi.core.Variant#remove()
*/
public void remove() throws TMAPIException {
Added: tinytim/trunk/src/test/java/org/tinytim/TestItemIdentifierConstraint.java
===================================================================
--- tinytim/trunk/src/test/java/org/tinytim/TestItemIdentifierConstraint.java (rev 0)
+++ tinytim/trunk/src/test/java/org/tinytim/TestItemIdentifierConstraint.java 2008-04-23 12:16:08 UTC (rev 29)
@@ -0,0 +1,155 @@
+/*
+ * This is tinyTiM, a tiny Topic Maps engine.
+ *
+ * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+package org.tinytim;
+
+import org.tmapi.core.Association;
+import org.tmapi.core.AssociationRole;
+import org.tmapi.core.DuplicateSourceLocatorException;
+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.TopicsMustMergeException;
+import org.tmapi.core.Variant;
+
+/**
+ * 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:$
+ */
+public class TestItemIdentifierConstraint extends TinyTimTestCase {
+
+ /**
+ * Tests against a topic map.
+ */
+ public void testTopicMap() throws Exception {
+ _testConstraint(_tm);
+ }
+
+ /**
+ * Tests againts a topic.
+ */
+ public void testTopic() throws Exception {
+ Topic topic = _tm.createTopic();
+ Locator iid = _tm.createLocator("http://sf.net/projects/tinytim");
+ topic.addSourceLocator(iid);
+ assertTrue(topic.getSourceLocators().contains(iid));
+ Topic topic2 = _tm.createTopic();
+ try {
+ topic2.addSourceLocator(iid);
+ }
+ catch (TopicsMustMergeException ex) {
+ // noop.
+ }
+ topic.removeSourceLocator(iid);
+ assertFalse(topic.getSourceLocators().contains(iid));
+ topic2.addSourceLocator(iid);
+ assertTrue(topic2.getSourceLocators().contains(iid));
+ topic2.removeSourceLocator(iid);
+ topic.addSourceLocator(iid);
+ assertTrue(topic.getSourceLocators().contains(iid));
+ assertFalse(topic2.getSourceLocators().contains(iid));
+ topic.remove();
+ topic2.addSourceLocator(iid);
+ assertTrue(topic2.getSourceLocators().contains(iid));
+ }
+
+ /**
+ * Tests against an association.
+ */
+ public void testAssociation() throws Exception {
+ _testConstraint(_tm.createAssociation());
+ }
+
+ /**
+ * Tests against a role.
+ */
+ public void testRole() throws Exception {
+ Association assoc = _tm.createAssociation();
+ AssociationRole role = assoc.createAssociationRole(_tm.createTopic(), _tm.createTopic());
+ _testConstraint(role);
+ }
+
+ /**
+ * Tests against an occurrence.
+ */
+ public void testOccurrence() throws Exception {
+ Topic topic = _tm.createTopic();
+ Occurrence occ = topic.createOccurrence("tinyTiM", null, null);
+ _testConstraint(occ);
+ }
+
+ /**
+ * Tests against a name.
+ */
+ public void testName() throws Exception {
+ Topic topic = _tm.createTopic();
+ TopicName name = topic.createTopicName("tinyTiM", null, null);
+ _testConstraint(name);
+ }
+
+ /**
+ * Tests against a variant.
+ */
+ public void testVariant() throws Exception {
+ Topic topic = _tm.createTopic();
+ TopicName name = topic.createTopicName("tinyTiM", null, null);
+ Variant variant = name.createVariant("tinyTiM", null);
+ _testConstraint(variant);
+ }
+
+ /**
+ * The item identifier constraint test.
+ *
+ * @param tmo The Topic Maps construct to test.
+ */
+ private void _testConstraint(TopicMapObject tmo) throws Exception {
+ assertTrue(tmo.getSourceLocators().isEmpty());
+ Locator iid = _tm.createLocator("http://sf.net/projects/tinytim");
+ tmo.addSourceLocator(iid);
+ assertTrue(tmo.getSourceLocators().contains(iid));
+ Association assoc = _tm.createAssociation();
+ try {
+ assoc.addSourceLocator(iid);
+ fail("Topic Maps constructs with the same item identifier are not allowed");
+ }
+ catch (DuplicateSourceLocatorException ex) {
+ // noop
+ }
+ tmo.removeSourceLocator(iid);
+ assertFalse(tmo.getSourceLocators().contains(iid));
+ assoc.addSourceLocator(iid);
+ assertTrue(assoc.getSourceLocators().contains(iid));
+ assoc.removeSourceLocator(iid);
+ assertFalse(assoc.getSourceLocators().contains(iid));
+ tmo.addSourceLocator(iid);
+ assertTrue(tmo.getSourceLocators().contains(iid));
+ if (!(tmo instanceof TopicMap)) {
+ // Removal should 'free' the item identifier
+ tmo.remove();
+ assoc.addSourceLocator(iid);
+ assertTrue(assoc.getSourceLocators().contains(iid));
+ }
+ }
+}
Property changes on: tinytim/trunk/src/test/java/org/tinytim/TestItemIdentifierConstraint.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date Id
Name: svn:eol-style
+ native
Modified: tinytim/trunk/src/test/java/org/tinytim/TestReificationUtils.java
===================================================================
--- tinytim/trunk/src/test/java/org/tinytim/TestReificationUtils.java 2008-04-22 15:12:58 UTC (rev 28)
+++ tinytim/trunk/src/test/java/org/tinytim/TestReificationUtils.java 2008-04-23 12:16:08 UTC (rev 29)
@@ -34,7 +34,7 @@
* Tests against the {@link ReificationUtils}.
*
* @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
- * @version $Rev:$ - $Date:$
+ * @version $Rev$ - $Date$
*/
public class TestReificationUtils extends TinyTimTestCase {
Modified: tinytim/trunk/src/test/java/org/tinytim/TestTopicMergeDetection.java
===================================================================
--- tinytim/trunk/src/test/java/org/tinytim/TestTopicMergeDetection.java 2008-04-22 15:12:58 UTC (rev 28)
+++ tinytim/trunk/src/test/java/org/tinytim/TestTopicMergeDetection.java 2008-04-23 12:16:08 UTC (rev 29)
@@ -99,9 +99,9 @@
}
/**
- * Tests if adding a subject identifier equals to an item identifier is detected.
+ * Tests if adding an item identifier equals to a subject identifier is detected.
*/
- public void testExistingSubjectIdentifierItemIdentifier() {
+ public void testExistingSubjectIdentifierAddItemIdentifier() {
Topic topic1 = _tm.createTopic();
Topic topic2 = _tm.createTopic();
Locator loc = _tm.createLocator("http://sf.net/projects/tinytim");
@@ -118,10 +118,10 @@
}
/**
- * Tests if adding a subject identifier equals to an item identifier
+ * Tests if adding an item identifier equals to a subject identifier
* on the SAME topic is accepted
*/
- public void testExistingSubjectIdentifierItemIdentifierLegal() {
+ public void testExistingSubjectIdentifierAddItemIdentifierLegal() {
Topic topic1 = _tm.createTopic();
Locator loc = _tm.createLocator("http://sf.net/projects/tinytim");
topic1.addSubjectIdentifier(loc);
@@ -138,4 +138,45 @@
assertEquals(topic1, _tm.getTopicBySubjectIdentifier(loc));
assertEquals(topic1, _tm.getObjectByItemIdentifier(loc));
}
+
+ /**
+ * Tests if adding a subject identifier equals to an item identifier is detected.
+ */
+ public void testExistingItemIdentifierAddSubjectIdentifier() {
+ Topic topic1 = _tm.createTopic();
+ Topic topic2 = _tm.createTopic();
+ Locator loc = _tm.createLocator("http://sf.net/projects/tinytim");
+ topic1.addSourceLocator(loc);
+ assertTrue(topic1.getSourceLocators().contains(loc));
+ assertEquals(topic1, _tm.getObjectByItemIdentifier(loc));
+ try {
+ topic2.addSubjectIdentifier(loc);
+ fail("A topic with an item identifier equals to the subject identifier '" + loc + "' exists.");
+ }
+ catch (TopicsMustMergeException ex) {
+ // noop.
+ }
+ }
+
+ /**
+ * Tests if adding a subject identifier equals to an item identifier
+ * on the SAME topic is accepted
+ */
+ public void testExistingItemIdentifierAddSubjectIdentifierLegal() {
+ Topic topic1 = _tm.createTopic();
+ Locator loc = _tm.createLocator("http://sf.net/projects/tinytim");
+ topic1.addSourceLocator(loc);
+ assertEquals(1, topic1.getSourceLocators().size());
+ assertEquals(0, topic1.getSubjectIdentifiers().size());
+ assertTrue(topic1.getSourceLocators().contains(loc));
+ assertEquals(topic1, _tm.getObjectByItemIdentifier(loc));
+ assertNull(_tm.getTopicBySubjectIdentifier(loc));
+ topic1.addSubjectIdentifier(loc);
+ assertEquals(1, topic1.getSubjectIdentifiers().size());
+ assertEquals(1, topic1.getSourceLocators().size());
+ assertTrue(topic1.getSubjectIdentifiers().contains(loc));
+ assertTrue(topic1.getSourceLocators().contains(loc));
+ assertEquals(topic1, _tm.getTopicBySubjectIdentifier(loc));
+ assertEquals(topic1, _tm.getObjectByItemIdentifier(loc));
+ }
}
Modified: tinytim/trunk/src/test/java/org/tinytim/TestTopicUtils.java
===================================================================
--- tinytim/trunk/src/test/java/org/tinytim/TestTopicUtils.java 2008-04-22 15:12:58 UTC (rev 28)
+++ tinytim/trunk/src/test/java/org/tinytim/TestTopicUtils.java 2008-04-23 12:16:08 UTC (rev 29)
@@ -56,7 +56,8 @@
assertTrue(TopicUtils.isRemovable(topic));
// Reifier
((IReifiable) assoc).setReifier(topic);
- assertFalse(TopicUtils.isRemovable(topic));
+ assertTrue(TopicUtils.isRemovable(topic));
+ assertFalse(TopicUtils.isRemovable(topic, true));
((IReifiable) assoc).setReifier(null);
assertTrue(TopicUtils.isRemovable(topic));
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|