|
From: <lh...@us...> - 2008-08-11 12:26:17
|
Revision: 113
http://tinytim.svn.sourceforge.net/tinytim/?rev=113&view=rev
Author: lheuer
Date: 2008-08-11 12:26:15 +0000 (Mon, 11 Aug 2008)
Log Message:
-----------
Updated test suite
Modified Paths:
--------------
tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java
tinytim/trunk/src/test/java/org/tinytim/core/TestDuplicateRemovalUtils.java
tinytim/trunk/src/test/java/org/tinytim/core/TestItemIdentifierConstraint.java
tinytim/trunk/src/test/java/org/tinytim/core/TestSignatureGenerator.java
tinytim/trunk/src/test/java/org/tinytim/core/TestTopicMapSystemFactoryImpl.java
tinytim/trunk/src/test/java/org/tinytim/core/TestTopicUtils.java
tinytim/trunk/src/test/java/org/tinytim/core/TinyTimTestCase.java
Added Paths:
-----------
tinytim/trunk/src/test/java/org/tinytim/core/TestScope.java
Modified: tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java
===================================================================
--- tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java 2008-08-11 12:21:38 UTC (rev 112)
+++ tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java 2008-08-11 12:26:15 UTC (rev 113)
@@ -39,6 +39,7 @@
TestSuite suite = new TestSuite();
suite.addTestSuite(TestDuplicateRemovalUtils.class);
suite.addTestSuite(TestIRI.class);
+ suite.addTestSuite(TestScope.class);
suite.addTestSuite(TestLiteral.class);
suite.addTestSuite(TestItemIdentifierConstraint.class);
suite.addTestSuite(TestSignatureGenerator.class);
Modified: tinytim/trunk/src/test/java/org/tinytim/core/TestDuplicateRemovalUtils.java
===================================================================
--- tinytim/trunk/src/test/java/org/tinytim/core/TestDuplicateRemovalUtils.java 2008-08-11 12:21:38 UTC (rev 112)
+++ tinytim/trunk/src/test/java/org/tinytim/core/TestDuplicateRemovalUtils.java 2008-08-11 12:26:15 UTC (rev 113)
@@ -34,8 +34,8 @@
public class TestDuplicateRemovalUtils extends TinyTimTestCase {
public void testTopicRemoveNames() {
- Topic topic = _tm.createTopic();
- Topic nameType = _tm.createTopic();
+ Topic topic = createTopic();
+ Topic nameType = createTopic();
Name name1 = topic.createName(nameType, "tinyTiM");
Name name2 = topic.createName(nameType, "tinyTiM");
assertEquals(nameType, name1.getType());
@@ -52,12 +52,12 @@
}
public void testTopicRemoveNames2() {
- Topic topic = _tm.createTopic();
- Topic nameType = _tm.createTopic();
+ Topic topic = createTopic();
+ Topic nameType = createTopic();
Name name1 = topic.createName(nameType, "tinyTiM");
Name name2 = topic.createName(nameType, "tinyTiM");
- Locator iid1 = _tm.createLocator("http://example.org/iid-1");
- Locator iid2 = _tm.createLocator("http://example.org/iid-2");
+ Locator iid1 = createLocator("http://example.org/iid-1");
+ Locator iid2 = createLocator("http://example.org/iid-2");
name1.addItemIdentifier(iid1);
name2.addItemIdentifier(iid2);
assertEquals(2, topic.getNames().size());
@@ -73,10 +73,10 @@
}
public void testTopicRemoveNames3() {
- Topic topic = _tm.createTopic();
- Topic theme1 = _tm.createTopic();
- Topic theme2 = _tm.createTopic();
- Topic nameType = _tm.createTopic();
+ Topic topic = createTopic();
+ Topic theme1 = createTopic();
+ Topic theme2 = createTopic();
+ Topic nameType = createTopic();
Name name1 = topic.createName(nameType, "tinyTiM", theme1, theme2);
Name name2 = topic.createName(nameType, "tinyTiM", theme2, theme1);
assertEquals(2, name1.getScope().size());
@@ -91,9 +91,9 @@
}
public void testRemoveRoles() {
- Association assoc = _tm.createAssociation(_tm.createTopic());
- Topic type = _tm.createTopic();
- Topic player = _tm.createTopic();
+ Association assoc = createAssociation();
+ Topic type = createTopic();
+ Topic player = createTopic();
assoc.createRole(type, player);
assoc.createRole(type, player);
assertEquals(2, player.getRolesPlayed().size());
Modified: tinytim/trunk/src/test/java/org/tinytim/core/TestItemIdentifierConstraint.java
===================================================================
--- tinytim/trunk/src/test/java/org/tinytim/core/TestItemIdentifierConstraint.java 2008-08-11 12:21:38 UTC (rev 112)
+++ tinytim/trunk/src/test/java/org/tinytim/core/TestItemIdentifierConstraint.java 2008-08-11 12:26:15 UTC (rev 113)
@@ -24,12 +24,8 @@
import org.tmapi.core.Construct;
import org.tmapi.core.IdentityConstraintException;
import org.tmapi.core.Locator;
-import org.tmapi.core.Name;
-import org.tmapi.core.Occurrence;
-import org.tmapi.core.Role;
import org.tmapi.core.Topic;
import org.tmapi.core.TopicMap;
-import org.tmapi.core.Variant;
/**
* Tests if the TMDM item identifier constraint is respected.
@@ -40,6 +36,40 @@
public class TestItemIdentifierConstraint extends TinyTimTestCase {
/**
+ * The item identifier constraint test.
+ *
+ * @param tmo The Topic Maps construct to test.
+ */
+ private void _testConstraint(Construct tmo) throws Exception {
+ assertTrue(tmo.getItemIdentifiers().isEmpty());
+ Locator iid = createLocator("http://sf.net/projects/tinytim");
+ Locator iid2 = createLocator("http://sf.net/projects/tinytim2");
+ Association assoc = createAssociation();
+ assoc.addItemIdentifier(iid);
+ assertFalse(tmo.getItemIdentifiers().contains(iid));
+ try {
+ tmo.addItemIdentifier(iid);
+ fail("Topic Maps constructs with the same item identifier are not allowed");
+ }
+ catch (IdentityConstraintException ex) {
+ // noop
+ }
+ tmo.addItemIdentifier(iid2);
+ assertTrue(tmo.getItemIdentifiers().contains(iid2));
+ tmo.removeItemIdentifier(iid2);
+ assoc.removeItemIdentifier(iid);
+ assertFalse(assoc.getItemIdentifiers().contains(iid));
+ tmo.addItemIdentifier(iid);
+ assertTrue(tmo.getItemIdentifiers().contains(iid));
+ if (!(tmo instanceof TopicMap)) {
+ // Removal should 'free' the item identifier
+ tmo.remove();
+ assoc.addItemIdentifier(iid);
+ assertTrue(assoc.getItemIdentifiers().contains(iid));
+ }
+ }
+
+ /**
* Tests against a topic map.
*/
public void testTopicMap() throws Exception {
@@ -50,11 +80,11 @@
* Tests againts a topic.
*/
public void testTopic() throws Exception {
- Topic topic = _tm.createTopic();
- Locator iid = _tm.createLocator("http://sf.net/projects/tinytim");
+ Topic topic = createTopic();
+ Locator iid = createLocator("http://sf.net/projects/tinytim");
topic.addItemIdentifier(iid);
assertTrue(topic.getItemIdentifiers().contains(iid));
- Topic topic2 = _tm.createTopic();
+ Topic topic2 = createTopic();
try {
topic2.addItemIdentifier(iid);
}
@@ -78,77 +108,35 @@
* Tests against an association.
*/
public void testAssociation() throws Exception {
- _testConstraint(_tm.createAssociation(_tm.createTopic()));
+ _testConstraint(createAssociation());
}
/**
* Tests against a role.
*/
public void testRole() throws Exception {
- Association assoc = _tm.createAssociation(_tm.createTopic());
- Role role = assoc.createRole(_tm.createTopic(), _tm.createTopic());
- _testConstraint(role);
+ _testConstraint(createRole());
}
/**
* Tests against an occurrence.
*/
public void testOccurrence() throws Exception {
- Topic topic = _tm.createTopic();
- Occurrence occ = topic.createOccurrence(_tm.createTopic(), "tinyTiM");
- _testConstraint(occ);
+ _testConstraint(createOccurrence());
}
/**
* Tests against a name.
*/
public void testName() throws Exception {
- Topic topic = _tm.createTopic();
- Name name = topic.createName("tinyTiM");
- _testConstraint(name);
+ _testConstraint(createName());
}
/**
* Tests against a variant.
*/
public void testVariant() throws Exception {
- Topic topic = _tm.createTopic();
- Name name = topic.createName("tinyTiM");
- Variant variant = name.createVariant("tinyTiM", _tm.createTopic());
- _testConstraint(variant);
+ _testConstraint(createVariant());
}
- /**
- * The item identifier constraint test.
- *
- * @param tmo The Topic Maps construct to test.
- */
- private void _testConstraint(Construct tmo) throws Exception {
- assertTrue(tmo.getItemIdentifiers().isEmpty());
- Locator iid = _tm.createLocator("http://sf.net/projects/tinytim");
- tmo.addItemIdentifier(iid);
- assertTrue(tmo.getItemIdentifiers().contains(iid));
- Association assoc = _tm.createAssociation(_tm.createTopic());
- try {
- assoc.addItemIdentifier(iid);
- fail("Topic Maps constructs with the same item identifier are not allowed");
- }
- catch (IdentityConstraintException ex) {
- // noop
- }
- tmo.removeItemIdentifier(iid);
- assertFalse(tmo.getItemIdentifiers().contains(iid));
- assoc.addItemIdentifier(iid);
- assertTrue(assoc.getItemIdentifiers().contains(iid));
- assoc.removeItemIdentifier(iid);
- assertFalse(assoc.getItemIdentifiers().contains(iid));
- tmo.addItemIdentifier(iid);
- assertTrue(tmo.getItemIdentifiers().contains(iid));
- if (!(tmo instanceof TopicMap)) {
- // Removal should 'free' the item identifier
- tmo.remove();
- assoc.addItemIdentifier(iid);
- assertTrue(assoc.getItemIdentifiers().contains(iid));
- }
- }
}
Added: tinytim/trunk/src/test/java/org/tinytim/core/TestScope.java
===================================================================
--- tinytim/trunk/src/test/java/org/tinytim/core/TestScope.java (rev 0)
+++ tinytim/trunk/src/test/java/org/tinytim/core/TestScope.java 2008-08-11 12:26:15 UTC (rev 113)
@@ -0,0 +1,48 @@
+/*
+ * 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.core;
+
+import java.util.Arrays;
+
+import org.tmapi.core.Topic;
+
+/**
+ *
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public class TestScope extends TinyTimTestCase {
+
+ public void testUnconstrained() {
+ assertTrue(Scope.UCS.isUnconstrained());
+ assertEquals(0, Scope.UCS.size());
+ }
+
+ public void testEquals() {
+ Topic theme1 = createTopic();
+ Topic theme2 = createTopic();
+ IScope scope1 = Scope.create(Arrays.asList(theme1, theme2));
+ assertEquals(2, scope1.size());
+ IScope scope2 = Scope.create(Arrays.asList(theme2, theme1));
+ assertSame(scope1, scope2);
+ }
+}
Property changes on: tinytim/trunk/src/test/java/org/tinytim/core/TestScope.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
Modified: tinytim/trunk/src/test/java/org/tinytim/core/TestSignatureGenerator.java
===================================================================
--- tinytim/trunk/src/test/java/org/tinytim/core/TestSignatureGenerator.java 2008-08-11 12:21:38 UTC (rev 112)
+++ tinytim/trunk/src/test/java/org/tinytim/core/TestSignatureGenerator.java 2008-08-11 12:26:15 UTC (rev 113)
@@ -40,7 +40,7 @@
* signature.
*/
public void testAssociationBasic() {
- Topic type = _tm.createTopic();
+ Topic type = createTopic();
Association assoc = _tm.createAssociation(type);
Association assoc2 = _tm.createAssociation(type);
assertFalse(assoc.getId().equals(assoc2.getId()));
@@ -53,8 +53,8 @@
* signature.
*/
public void testOccurrenceBasic() {
- Topic topic = _tm.createTopic();
- Topic type = _tm.createTopic();
+ Topic topic = createTopic();
+ Topic type = createTopic();
Occurrence occ = topic.createOccurrence(type, "tinyTiM");
Occurrence occ2 = topic.createOccurrence(type, "tinyTiM");
assertFalse(occ.getId().equals(occ2.getId()));
@@ -76,7 +76,7 @@
* signature.
*/
public void testNameBasic() {
- Topic topic = _tm.createTopic();
+ Topic topic = createTopic();
Name name = topic.createName("tinyTiM");
Name name2 = topic.createName("tinyTiM");
assertFalse(name.getId().equals(name2.getId()));
@@ -116,8 +116,8 @@
* Tests if associations with the same type return the same signature.
*/
public void testAssociationTyped() {
- Topic type1 = _tm.createTopic();
- Topic type2 = _tm.createTopic();
+ Topic type1 = createTopic();
+ Topic type2 = createTopic();
Association assoc = _tm.createAssociation(type1);
int sigBefore = SignatureGenerator.generateSignature(assoc);
assoc.setType(type2);
@@ -130,9 +130,9 @@
}
public void testRoles() {
- Association assoc = _tm.createAssociation(_tm.createTopic());
- Topic type = _tm.createTopic();
- Topic player = _tm.createTopic();
+ Association assoc = _tm.createAssociation(createTopic());
+ Topic type = createTopic();
+ Topic player = createTopic();
Role role1 = assoc.createRole(type, player);
Role role2 = assoc.createRole(type, player);
assertEquals(2, player.getRolesPlayed().size());
Modified: tinytim/trunk/src/test/java/org/tinytim/core/TestTopicMapSystemFactoryImpl.java
===================================================================
--- tinytim/trunk/src/test/java/org/tinytim/core/TestTopicMapSystemFactoryImpl.java 2008-08-11 12:21:38 UTC (rev 112)
+++ tinytim/trunk/src/test/java/org/tinytim/core/TestTopicMapSystemFactoryImpl.java 2008-08-11 12:26:15 UTC (rev 113)
@@ -20,13 +20,6 @@
*/
package org.tinytim.core;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.tinytim.utils.ICollectionFactory;
-import org.tinytim.utils.Property;
import org.tinytim.utils.Feature;
import org.tmapi.core.FeatureNotRecognizedException;
import org.tmapi.core.FeatureNotSupportedException;
@@ -110,81 +103,4 @@
}
}
- /**
- * Tests if the collection factory property is set.
- *
- * @throws Exception
- */
- public void testCollectionFactoryProperty() throws Exception {
- boolean troveAvailable = false;
- try {
- Class.forName("gnu.trove.THashSet");
- troveAvailable = true;
- }
- catch (Exception ex) {
- // noop.
- }
- if (troveAvailable) {
- assertEquals("org.tinytim.core.TroveCollectionFactory", _sysFactory.getProperty(Property.COLLECTION_FACTORY));
- }
- else {
- assertEquals("org.tinytim.core.JavaCollectionFactory", _sysFactory.getProperty(Property.COLLECTION_FACTORY));
- assertTrue(((TopicMapSystemImpl) _sysFactory.newTopicMapSystem()).getCollectionFactory() instanceof JavaCollectionFactory);
- }
- }
-
- /**
- * Tests if the TopicMapSystemFactory creates automatically a default
- * CollectionFactory iff the class name in the property is invaild /
- * not resolvable.
- *
- * @throws Exception
- */
- public void testCollectionFactoryFallback() throws Exception {
- _sysFactory.setProperty(Property.COLLECTION_FACTORY, "a.non.existent.CollectionFactory");
- TopicMapSystemImpl sys = (TopicMapSystemImpl) _sysFactory.newTopicMapSystem();
- assertTrue(sys.getCollectionFactory() instanceof JavaCollectionFactory);
- }
-
- /**
- * Sets the setting of a custom {@link ICollectionFactory}.
- *
- * @throws Exception
- */
- public void testCustomCollectionFactory() throws Exception {
- _sysFactory.setProperty(Property.COLLECTION_FACTORY, MyCollectionFactory.class.getName());
- TopicMapSystemImpl sys = (TopicMapSystemImpl) _sysFactory.newTopicMapSystem();
- assertTrue(sys.getCollectionFactory() instanceof MyCollectionFactory);
- }
-
- /**
- * {@link ICollectionFactory} implementation that uses the Java collections.
- */
- public static final class MyCollectionFactory implements ICollectionFactory {
- public <K, V> Map<K, V> createMap() {
- return new HashMap<K, V>();
- }
- public <K, V> Map<K, V> createMap(int size) {
- return createMap();
- }
- public <E> Set<E> createSet(int size) {
- return createSet();
- }
- public <E> Set<E> createSet() {
- return new HashSet<E>();
- }
- public <K, V> Map<K, V> createIdentityMap() {
- return createMap();
- }
- public <K, V> Map<K, V> createIdentityMap(int size) {
- return createMap(size);
- }
- public <E> Set<E> createIdentitySet() {
- return createSet();
- }
- public <E> Set<E> createIdentitySet(int size) {
- return createSet(size);
- }
-
- }
}
Modified: tinytim/trunk/src/test/java/org/tinytim/core/TestTopicUtils.java
===================================================================
--- tinytim/trunk/src/test/java/org/tinytim/core/TestTopicUtils.java 2008-08-11 12:21:38 UTC (rev 112)
+++ tinytim/trunk/src/test/java/org/tinytim/core/TestTopicUtils.java 2008-08-11 12:26:15 UTC (rev 113)
@@ -36,16 +36,16 @@
* Tests if a topic is considered as 'removable'.
*/
public void testRemovable() {
- Topic topic = _tm.createTopic();
+ Topic topic = createTopic();
assertTrue(TopicUtils.isRemovable(topic));
Association assoc = _tm.createAssociation(topic);
assertFalse(TopicUtils.isRemovable(topic));
- assoc.setType(_tm.createTopic());
+ assoc.setType(createTopic());
assertTrue(TopicUtils.isRemovable(topic));
// Role played
- Role role = assoc.createRole(_tm.createTopic(), topic);
+ Role role = assoc.createRole(createTopic(), topic);
assertFalse(TopicUtils.isRemovable(topic));
- role.setPlayer(_tm.createTopic());
+ role.setPlayer(createTopic());
assertTrue(TopicUtils.isRemovable(topic));
// Theme
assoc.addTheme(topic);
Modified: tinytim/trunk/src/test/java/org/tinytim/core/TinyTimTestCase.java
===================================================================
--- tinytim/trunk/src/test/java/org/tinytim/core/TinyTimTestCase.java 2008-08-11 12:21:38 UTC (rev 112)
+++ tinytim/trunk/src/test/java/org/tinytim/core/TinyTimTestCase.java 2008-08-11 12:26:15 UTC (rev 113)
@@ -29,6 +29,7 @@
import org.tmapi.core.Occurrence;
import org.tmapi.core.Role;
import org.tmapi.core.Topic;
+import org.tmapi.core.TopicMapSystem;
import org.tmapi.core.Variant;
import junit.framework.TestCase;
@@ -48,9 +49,17 @@
protected static final String _IRI = "http://www.semagia.com/tinyTiM/testTopicMap/";
protected Locator _base;
protected TopicMapImpl _tm;
- protected TopicMapSystemImpl _sys;
+ protected TopicMapSystem _sys;
protected TopicMapSystemFactoryImpl _sysFactory;
+ public TinyTimTestCase() {
+ super();
+ }
+
+ public TinyTimTestCase(String name) {
+ super(name);
+ }
+
/**
* Returns additional / non-default properties which should be set
* to configure the {@link org.tmapi.core.TopicMapSystemFactory}.
@@ -118,6 +127,10 @@
return createName().createVariant("Variant", createTopic());
}
+ protected Locator createLocator(final String reference) {
+ return _sys.createLocator(reference);
+ }
+
/* (non-Javadoc)
* @see junit.framework.TestCase#setUp()
*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|