|
From: <lh...@us...> - 2008-04-20 12:06:28
|
Revision: 11
http://tinytim.svn.sourceforge.net/tinytim/?rev=11&view=rev
Author: lheuer
Date: 2008-04-20 05:06:28 -0700 (Sun, 20 Apr 2008)
Log Message:
-----------
Initial test case import
Added Paths:
-----------
tinytim/trunk/test/
tinytim/trunk/test/java/
tinytim/trunk/test/java/org/
tinytim/trunk/test/java/org/tinytim/
tinytim/trunk/test/java/org/tinytim/TMAPITestCase.java
tinytim/trunk/test/java/org/tinytim/TestReifiable.java
tinytim/trunk/test/java/org/tinytim/TestScoped.java
tinytim/trunk/test/java/org/tinytim/TestSignatureGenerator.java
tinytim/trunk/test/java/org/tinytim/TestTMAPICore.java
tinytim/trunk/test/java/org/tinytim/TestTMAPIIndex.java
tinytim/trunk/test/java/org/tinytim/TestTopicMapSystemFactoryImpl.java
tinytim/trunk/test/java/org/tinytim/TestTopicMerge.java
tinytim/trunk/test/java/org/tinytim/TestTopicMergeDetection.java
tinytim/trunk/test/java/org/tinytim/TestTyped.java
tinytim/trunk/test/java/org/tinytim/TinyTimTestCase.java
Added: tinytim/trunk/test/java/org/tinytim/TMAPITestCase.java
===================================================================
--- tinytim/trunk/test/java/org/tinytim/TMAPITestCase.java (rev 0)
+++ tinytim/trunk/test/java/org/tinytim/TMAPITestCase.java 2008-04-20 12:06:28 UTC (rev 11)
@@ -0,0 +1,36 @@
+/*
+ * 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 junit.framework.TestCase;
+
+/**
+ * Base class for all TMAPI-related test cases.
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public class TMAPITestCase extends TestCase {
+
+ static {
+ System.setProperty("org.tmapi.core.TopicMapSystemFactory", "org.tinytim.TopicMapSystemFactoryImpl");
+ }
+}
Property changes on: tinytim/trunk/test/java/org/tinytim/TMAPITestCase.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date Id
Name: svn:eol-style
+ native
Added: tinytim/trunk/test/java/org/tinytim/TestReifiable.java
===================================================================
--- tinytim/trunk/test/java/org/tinytim/TestReifiable.java (rev 0)
+++ tinytim/trunk/test/java/org/tinytim/TestReifiable.java 2008-04-20 12:06:28 UTC (rev 11)
@@ -0,0 +1,151 @@
+/*
+ * 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.ModelConstraintException;
+import org.tmapi.core.Occurrence;
+import org.tmapi.core.Topic;
+import org.tmapi.core.TopicMap;
+import org.tmapi.core.TopicName;
+import org.tmapi.core.Variant;
+
+/**
+ * Tests against the {@link org.tinytim.IReifiable} interface.
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public class TestReifiable extends TinyTimTestCase {
+
+ /**
+ * Tests if a Topic Maps construct is an instance of IReifiable.
+ */
+ public void testInstanceOf() {
+ assertTrue(((TopicMap)_tm) instanceof IReifiable);
+ Topic topic = _tm.createTopic();
+ assertFalse(topic instanceof IReifiable);
+ Association assoc = _tm.createAssociation();
+ assertTrue(assoc instanceof IReifiable);
+ AssociationRole role = assoc.createAssociationRole(_tm.createTopic(), _tm.createTopic());
+ assertTrue(role instanceof IReifiable);
+ Occurrence occ = topic.createOccurrence("tinyTiM", null, null);
+ assertTrue(occ instanceof IReifiable);
+ TopicName name = topic.createTopicName("tinyTiM", null);
+ assertTrue(name instanceof IReifiable);
+ Variant variant = name.createVariant("tinyTiM", null);
+ assertTrue(variant instanceof IReifiable);
+ }
+
+ /**
+ * Tests setting and getting the reifier of a topic map.
+ */
+ public void testTopicMap() {
+ _testSetGet((IReifiable)_tm);
+ }
+
+ /**
+ * Tests setting and getting the reifier of an association.
+ */
+ public void testAssociation() {
+ _testSetGet((IReifiable)_tm.createAssociation());
+ }
+
+ /**
+ * Tests setting and getting the reifier of a role.
+ */
+ public void testRole() {
+ Association assoc = _tm.createAssociation();
+ AssociationRole role = assoc.createAssociationRole(_tm.createTopic(), _tm.createTopic());
+ _testSetGet((IReifiable)role);
+ }
+
+ /**
+ * Tests setting and getting the reifier of an occurrence.
+ */
+ public void testOccurrence() {
+ Topic topic = _tm.createTopic();
+ Occurrence occ = topic.createOccurrence("tinyTiM", null, null);
+ _testSetGet((IReifiable)occ);
+ }
+
+ /**
+ * Tests setting and getting the reifier of a name.
+ */
+ public void testName() {
+ Topic topic = _tm.createTopic();
+ TopicName name = topic.createTopicName("tinyTiM", null, null);
+ _testSetGet((IReifiable)name);
+ }
+
+ /**
+ * Tests setting and getting the reifier of a variant.
+ */
+ public void testVariant() {
+ Topic topic = _tm.createTopic();
+ TopicName name = topic.createTopicName("tinyTiM", null, null);
+ Variant variant = name.createVariant("tinyTiM", null);
+ _testSetGet((IReifiable)variant);
+ }
+
+ /**
+ * Tests setting and getting the reifier of a reifiable Topic Maps construct.
+ *
+ * @param reifiable The Topic Maps construct to test.
+ */
+ private void _testSetGet(IReifiable reifiable) {
+ assertNull(reifiable.getReifier());
+ TopicImpl reifier = (TopicImpl) _tm.createTopic();
+ assertEquals(0, reifier.getReified().size());
+ reifiable.setReifier(reifier);
+ assertEquals(reifier, reifiable.getReifier());
+ assertEquals(reifiable, reifier._reified);
+ assertEquals(1, reifier.getReified().size());
+ assertTrue(reifier.getReified().contains(reifiable));
+ reifiable.setReifier(null);
+ assertNull(reifiable.getReifier());
+ assertNull(reifier._reified);
+ 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);
+ try {
+ reifiable.setReifier(reifier2);
+ fail("Expected an exception. The reifier reifies another Topic Maps construct");
+ }
+ catch (ModelConstraintException ex) {
+ // noop.
+ }
+ assoc.setReifier(null);
+ assertNull(assoc.getReifier());
+ assertNull(reifier2._reified);
+ reifiable.setReifier(reifier);
+ assertEquals(reifier, reifiable.getReifier());
+ assertEquals(reifiable, reifier._reified);
+ reifiable.setReifier(reifier2);
+ assertEquals(reifier2, reifiable.getReifier());
+ assertEquals(reifiable, reifier2._reified);
+ }
+}
Property changes on: tinytim/trunk/test/java/org/tinytim/TestReifiable.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date Id
Name: svn:eol-style
+ native
Added: tinytim/trunk/test/java/org/tinytim/TestScoped.java
===================================================================
--- tinytim/trunk/test/java/org/tinytim/TestScoped.java (rev 0)
+++ tinytim/trunk/test/java/org/tinytim/TestScoped.java 2008-04-20 12:06:28 UTC (rev 11)
@@ -0,0 +1,119 @@
+/*
+ * 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.Occurrence;
+import org.tmapi.core.Topic;
+import org.tmapi.core.TopicMap;
+import org.tmapi.core.TopicName;
+import org.tmapi.core.Variant;
+
+/**
+ * Tests against the {@link org.tinytim.IScoped} interface.
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public class TestScoped extends TinyTimTestCase {
+
+ /**
+ * Tests if a Topic Maps construct is an instance of IScoped.
+ */
+ public void testInstanceOf() {
+ assertFalse(((TopicMap)_tm) instanceof IScoped);
+ Topic topic = _tm.createTopic();
+ assertFalse(topic instanceof IScoped);
+ Association assoc = _tm.createAssociation();
+ assertTrue(assoc instanceof IScoped);
+ AssociationRole role = assoc.createAssociationRole(_tm.createTopic(), _tm.createTopic());
+ assertFalse(role instanceof IScoped);
+ Occurrence occ = topic.createOccurrence("tinyTiM", null, null);
+ assertTrue(occ instanceof IScoped);
+ TopicName name = topic.createTopicName("tinyTiM", null);
+ assertTrue(name instanceof IScoped);
+ Variant variant = name.createVariant("tinyTiM", null);
+ assertTrue(variant instanceof IScoped);
+ }
+
+ /**
+ * Tests against an association.
+ */
+ public void testAssociation() {
+ Association assoc = _tm.createAssociation();
+ _testScoped((IScoped) assoc);
+ }
+
+ /**
+ * Tests against an occurrence.
+ */
+ public void testOccurrence() {
+ Topic topic = _tm.createTopic();
+ Occurrence occ = topic.createOccurrence("tinyTiM", null, null);
+ _testScoped((IScoped) occ);
+ }
+
+ /**
+ * Tests against a name.
+ */
+ public void testName() {
+ Topic topic = _tm.createTopic();
+ TopicName name = topic.createTopicName("tinyTiM", null, null);
+ _testScoped((IScoped) name);
+ }
+
+ /**
+ * Tests against a variant.
+ */
+ public void testVariant() {
+ Topic topic = _tm.createTopic();
+ TopicName name = topic.createTopicName("tinyTiM", null, null);
+ Variant variant = name.createVariant("tinyTiM", null);
+ _testScoped((IScoped) variant);
+ }
+
+ /**
+ * Tests adding / removing themes.
+ *
+ * @param scoped The scoped Topic Maps construct to test.
+ */
+ private void _testScoped(IScoped scoped) {
+ //TODO: This may fail in the future for variants
+ assertEquals(0, scoped.getScope().size());
+ Topic theme1 = _tm.createTopic();
+ scoped.addTheme(theme1);
+ assertEquals(1, scoped.getScope().size());
+ assertTrue(scoped.getScope().contains(theme1));
+ Topic theme2 = _tm.createTopic();
+ assertFalse(scoped.getScope().contains(theme2));
+ scoped.addTheme(theme2);
+ assertEquals(2, scoped.getScope().size());
+ assertTrue(scoped.getScope().contains(theme1));
+ assertTrue(scoped.getScope().contains(theme2));
+ scoped.removeTheme(theme2);
+ assertEquals(1, scoped.getScope().size());
+ assertTrue(scoped.getScope().contains(theme1));
+ assertFalse(scoped.getScope().contains(theme2));
+ scoped.removeTheme(theme1);
+ assertEquals(0, scoped.getScope().size());
+ }
+}
Property changes on: tinytim/trunk/test/java/org/tinytim/TestScoped.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date Id
Name: svn:eol-style
+ native
Added: tinytim/trunk/test/java/org/tinytim/TestSignatureGenerator.java
===================================================================
--- tinytim/trunk/test/java/org/tinytim/TestSignatureGenerator.java (rev 0)
+++ tinytim/trunk/test/java/org/tinytim/TestSignatureGenerator.java 2008-04-20 12:06:28 UTC (rev 11)
@@ -0,0 +1,117 @@
+/*
+ * 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.tinytim.SignatureGenerator;
+import org.tmapi.core.Association;
+import org.tmapi.core.AssociationRole;
+import org.tmapi.core.Occurrence;
+import org.tmapi.core.Topic;
+import org.tmapi.core.TopicName;
+import org.tmapi.core.Variant;
+
+/**
+ * Tests against the {@link org.tinytim.SignatureGenerator}.
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public class TestSignatureGenerator extends TinyTimTestCase {
+
+ /**
+ * Tests if an association with no initialized properties returns the same
+ * signature.
+ */
+ public void testAssociationBasic() {
+ Association assoc = _tm.createAssociation();
+ Association assoc2 = _tm.createAssociation();
+ assertFalse(assoc.getObjectId().equals(assoc2.getObjectId()));
+ String sig = SignatureGenerator.generateSignature(assoc);
+ assertEquals(sig, SignatureGenerator.generateSignature(assoc2));
+ }
+
+ /**
+ * Tests if a role with no initialized properties returns the same
+ * signature.
+ */
+ public void testRoleBasic() {
+ Association assoc = _tm.createAssociation();
+ AssociationRole role = assoc.createAssociationRole(null, null);
+ AssociationRole role2 = assoc.createAssociationRole(null, null);
+ assertFalse(role.getObjectId().equals(role2.getObjectId()));
+ String sig = SignatureGenerator.generateSignature(role);
+ assertEquals(sig, SignatureGenerator.generateSignature(role2));
+ }
+
+ /**
+ * Tests if an occurrence with no initialized properties returns the same
+ * signature.
+ */
+ public void testOccurrenceBasic() {
+ Topic topic = _tm.createTopic();
+ Occurrence occ = topic.createOccurrence((String) null, null, null);
+ Occurrence occ2 = topic.createOccurrence((String) null, null, null);
+ assertFalse(occ.getObjectId().equals(occ2.getObjectId()));
+ String sig = SignatureGenerator.generateSignature(occ);
+ assertEquals(sig, SignatureGenerator.generateSignature(occ2));
+ }
+
+ /**
+ * Tests if a name with no initialized properties returns the same
+ * signature.
+ */
+ public void testNameBasic() {
+ Topic topic = _tm.createTopic();
+ TopicName name = topic.createTopicName(null, null);
+ TopicName name2 = topic.createTopicName(null, null);
+ assertFalse(name.getObjectId().equals(name2.getObjectId()));
+ String sig = SignatureGenerator.generateSignature(name);
+ assertEquals(sig, SignatureGenerator.generateSignature(name2));
+ }
+
+ /**
+ * Tests if a variant with no initialized properties returns the same
+ * signature.
+ */
+ public void testVariantBasic() {
+ Topic topic = _tm.createTopic();
+ TopicName name = topic.createTopicName("tinyTiM", null);
+ Variant variant = name.createVariant("tiny Topic Maps", null);
+ String sig = SignatureGenerator.generateSignature(variant);
+ assertEquals(sig, SignatureGenerator.generateSignature(variant));
+ }
+
+ /**
+ * Tests if associations with the same type return the same signature.
+ */
+ public void testAssociationTyped() {
+ Association assoc = _tm.createAssociation();
+ String sigBefore = SignatureGenerator.generateSignature(assoc);
+ Topic type = _tm.createTopic();
+ assoc.setType(type);
+ String sigAfter = SignatureGenerator.generateSignature(assoc);
+ assertFalse(sigBefore.equals(sigAfter));
+ Association assoc2 = _tm.createAssociation();
+ assertEquals(sigBefore, SignatureGenerator.generateSignature(assoc2));
+ assoc2.setType(type);
+ assertEquals(sigAfter, SignatureGenerator.generateSignature(assoc2));
+ }
+}
Property changes on: tinytim/trunk/test/java/org/tinytim/TestSignatureGenerator.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date Id
Name: svn:eol-style
+ native
Added: tinytim/trunk/test/java/org/tinytim/TestTMAPICore.java
===================================================================
--- tinytim/trunk/test/java/org/tinytim/TestTMAPICore.java (rev 0)
+++ tinytim/trunk/test/java/org/tinytim/TestTMAPICore.java 2008-04-20 12:06:28 UTC (rev 11)
@@ -0,0 +1,45 @@
+/*
+ * 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.test.AllTMAPITests;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Runs the TMAPI core test suite against tinyTiM.
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public class TestTMAPICore extends TMAPITestCase {
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(suite());
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
+ suite.addTest(AllTMAPITests.suite());
+ return suite;
+ }
+}
Property changes on: tinytim/trunk/test/java/org/tinytim/TestTMAPICore.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date Id
Name: svn:eol-style
+ native
Added: tinytim/trunk/test/java/org/tinytim/TestTMAPIIndex.java
===================================================================
--- tinytim/trunk/test/java/org/tinytim/TestTMAPIIndex.java (rev 0)
+++ tinytim/trunk/test/java/org/tinytim/TestTMAPIIndex.java 2008-04-20 12:06:28 UTC (rev 11)
@@ -0,0 +1,45 @@
+/*
+ * 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.index.core.test.AllTMAPIIndexTests;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Runs the TMAPI index test suite against tinyTiM.
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public class TestTMAPIIndex extends TMAPITestCase {
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(suite());
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
+ suite.addTest(AllTMAPIIndexTests.suite());
+ return suite;
+ }
+}
Property changes on: tinytim/trunk/test/java/org/tinytim/TestTMAPIIndex.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date Id
Name: svn:eol-style
+ native
Added: tinytim/trunk/test/java/org/tinytim/TestTopicMapSystemFactoryImpl.java
===================================================================
--- tinytim/trunk/test/java/org/tinytim/TestTopicMapSystemFactoryImpl.java (rev 0)
+++ tinytim/trunk/test/java/org/tinytim/TestTopicMapSystemFactoryImpl.java 2008-04-20 12:06:28 UTC (rev 11)
@@ -0,0 +1,179 @@
+/*
+ * 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 java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.tinytim.ICollectionFactory;
+import org.tinytim.JavaCollectionFactory;
+import org.tinytim.Property;
+import org.tinytim.TMAPIFeature;
+import org.tinytim.TopicMapSystemImpl;
+import org.tmapi.core.FeatureNotRecognizedException;
+import org.tmapi.core.FeatureNotSupportedException;
+
+/**
+ * Tests against the {@link org.tinytim.TopicMapSystemFactoryImpl}.
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public class TestTopicMapSystemFactoryImpl extends TinyTimTestCase {
+
+ /**
+ * Tests the default feature values.
+ *
+ * @throws Exception
+ */
+ public void testDefaultFeatureValues() throws Exception {
+ assertTrue(_sysFactory.getFeature(TMAPIFeature.NOTATION_URI));
+ assertTrue(_sysFactory.getFeature(TMAPIFeature.XTM_1_1));
+ assertFalse(_sysFactory.getFeature(TMAPIFeature.XTM_1_0));
+ assertFalse(_sysFactory.getFeature(TMAPIFeature.READ_ONLY));
+ assertFalse(_sysFactory.getFeature(TMAPIFeature.AUTOMERGE));
+ assertFalse(_sysFactory.getFeature(TMAPIFeature.TNC));
+ }
+
+
+ private void _setFeatureToAcceptedValue(String featureName, boolean value) throws Exception {
+ try {
+ _sysFactory.setFeature(featureName, value);
+ }
+ catch (FeatureNotSupportedException ex) {
+ fail("Unexpected exception while setting '" + featureName + "' to '" + value + "'");
+ }
+ }
+
+ private void _setFeatureToUnacceptedValue(String featureName, boolean value) throws Exception {
+ try {
+ _sysFactory.setFeature(featureName, value);
+ fail("Expected exception while setting '" + featureName + "' to '" + value + "'");
+ }
+ catch (FeatureNotSupportedException ex) {
+ // noop.
+ }
+ }
+
+ /**
+ * Tests if enabling / disabling of various features delivers the expected
+ * results.
+ *
+ * @throws Exception
+ */
+ public void testSetFeatureValues() throws Exception {
+ _setFeatureToAcceptedValue(TMAPIFeature.NOTATION_URI, true);
+ _setFeatureToUnacceptedValue(TMAPIFeature.NOTATION_URI, false);
+ _setFeatureToAcceptedValue(TMAPIFeature.XTM_1_0, false);
+ _setFeatureToUnacceptedValue(TMAPIFeature.XTM_1_0, true);
+ _setFeatureToAcceptedValue(TMAPIFeature.XTM_1_1, true);
+ _setFeatureToUnacceptedValue(TMAPIFeature.XTM_1_1, false);
+ _setFeatureToAcceptedValue(TMAPIFeature.READ_ONLY, false);
+ _setFeatureToUnacceptedValue(TMAPIFeature.READ_ONLY, true);
+ _setFeatureToAcceptedValue(TMAPIFeature.AUTOMERGE, false);
+ _setFeatureToUnacceptedValue(TMAPIFeature.AUTOMERGE, true);
+ _setFeatureToAcceptedValue(TMAPIFeature.TNC, false);
+ _setFeatureToUnacceptedValue(TMAPIFeature.TNC, true);
+ }
+
+ /**
+ * Tests if an unknown feature throws the expected exception.
+ *
+ * @throws Exception
+ */
+ public void testUnrecognizedFeature() throws Exception {
+ try {
+ String unknownFeatureName = "http://www.semagia.com/tinyTiM/unknownTMAPIFeature";
+ _sysFactory.setFeature(unknownFeatureName, true);
+ fail("Expected an exception while setting a unknown feature");
+ }
+ catch (FeatureNotRecognizedException ex) {
+ // noop.
+ }
+ }
+
+ /**
+ * 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.TroveCollectionFactory", _sysFactory.getProperty(Property.COLLECTION_FACTORY));
+ }
+ else {
+ assertEquals("org.tinytim.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>();
+ }
+ }
+}
Property changes on: tinytim/trunk/test/java/org/tinytim/TestTopicMapSystemFactoryImpl.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date Id
Name: svn:eol-style
+ native
Added: tinytim/trunk/test/java/org/tinytim/TestTopicMerge.java
===================================================================
--- tinytim/trunk/test/java/org/tinytim/TestTopicMerge.java (rev 0)
+++ tinytim/trunk/test/java/org/tinytim/TestTopicMerge.java 2008-04-20 12:06:28 UTC (rev 11)
@@ -0,0 +1,159 @@
+/*
+ * 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.Locator;
+import org.tmapi.core.ModelConstraintException;
+import org.tmapi.core.Topic;
+import org.tmapi.core.TopicName;
+
+/**
+ * Tests merging of topics.
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public class TestTopicMerge extends TinyTimTestCase {
+
+ /**
+ * If topics reify different Topic Maps constructs they cannot be merged.
+ */
+ public void testReifiedClash() {
+ Topic topic1 = _tm.createTopic();
+ Topic topic2 = _tm.createTopic();
+ Association assoc1 = _tm.createAssociation();
+ Association assoc2 = _tm.createAssociation();
+ Topic type1 = _tm.createTopic();
+ Topic type2 = _tm.createTopic();
+ assoc1.setType(type1);
+ assoc2.setType(type2);
+ ((IReifiable) assoc1).setReifier(topic1);
+ ((IReifiable) assoc2).setReifier(topic2);
+ assertEquals(type1, assoc1.getType());
+ assertEquals(type2, assoc2.getType());
+ assertEquals(topic1, assoc1.getReifier());
+ assertEquals(topic2, assoc2.getReifier());
+ try {
+ topic1.mergeIn(topic2);
+ fail("The topics reify different Topic Maps constructs and cannot be merged");
+ }
+ catch (ModelConstraintException ex) {
+ // noop.
+ }
+ }
+
+ /**
+ * Tests if a topic overtakes all roles played of the other topic.
+ */
+ public void testRolePlaying() {
+ Topic topic1 = _tm.createTopic();
+ Topic topic2 = _tm.createTopic();
+ Association assoc = _tm.createAssociation();
+ assoc.setType(_tm.createTopic());
+ AssociationRole role = assoc.createAssociationRole(topic2, _tm.createTopic());
+ assertEquals(4, _tm.getTopics().size());
+ assertFalse(topic1.getRolesPlayed().contains(role));
+ assertTrue(topic2.getRolesPlayed().contains(role));
+ topic1.mergeIn(topic2);
+ assertEquals(3, _tm.getTopics().size());
+ assertTrue(topic1.getRolesPlayed().contains(role));
+ }
+
+ /**
+ * Tests if the subject identifiers are overtaken.
+ */
+ public void testIdentitySubjectIdentifier() {
+ Topic topic1 = _tm.createTopic();
+ Topic topic2 = _tm.createTopic();
+ Locator sid1 = _tm.createLocator("http://psi.exmaple.org/sid-1");
+ Locator sid2 = _tm.createLocator("http://psi.exmaple.org/sid-2");
+ topic1.addSubjectIdentifier(sid1);
+ topic2.addSubjectIdentifier(sid2);
+ assertTrue(topic1.getSubjectIdentifiers().contains(sid1));
+ assertFalse(topic1.getSubjectIdentifiers().contains(sid2));
+ assertFalse(topic2.getSubjectIdentifiers().contains(sid1));
+ assertTrue(topic2.getSubjectIdentifiers().contains(sid2));
+ topic1.mergeIn(topic2);
+ assertEquals(2, topic1.getSubjectIdentifiers().size());
+ assertTrue(topic1.getSubjectIdentifiers().contains(sid1));
+ assertTrue(topic1.getSubjectIdentifiers().contains(sid2));
+ }
+
+ /**
+ * Tests if the subject locator are overtaken.
+ */
+ public void testIdentitySubjectLocator() {
+ Topic topic1 = _tm.createTopic();
+ Topic topic2 = _tm.createTopic();
+ Locator slo1 = _tm.createLocator("http://tinytim.sf.net");
+ Locator slo2 = _tm.createLocator("http://tinytim.sourceforge.net");
+ topic1.addSubjectLocator(slo1);
+ topic2.addSubjectLocator(slo2);
+ assertTrue(topic1.getSubjectLocators().contains(slo1));
+ assertFalse(topic1.getSubjectLocators().contains(slo2));
+ assertFalse(topic2.getSubjectLocators().contains(slo1));
+ assertTrue(topic2.getSubjectLocators().contains(slo2));
+ topic1.mergeIn(topic2);
+ assertEquals(2, topic1.getSubjectLocators().size());
+ assertTrue(topic1.getSubjectLocators().contains(slo1));
+ assertTrue(topic1.getSubjectLocators().contains(slo2));
+ }
+
+ /**
+ * Tests if the item identifiers are overtaken.
+ */
+ public void testIdentityItemIdentifier() {
+ Topic topic1 = _tm.createTopic();
+ Topic topic2 = _tm.createTopic();
+ Locator iid1 = _tm.createLocator("http://tinytim.sf.net/test#1");
+ Locator iid2 = _tm.createLocator("http://tinytim.sf.net/test#2");
+ topic1.addSourceLocator(iid1);
+ topic2.addSourceLocator(iid2);
+ assertTrue(topic1.getSourceLocators().contains(iid1));
+ assertFalse(topic1.getSourceLocators().contains(iid2));
+ assertFalse(topic2.getSourceLocators().contains(iid1));
+ assertTrue(topic2.getSourceLocators().contains(iid2));
+ topic1.mergeIn(topic2);
+ assertEquals(2, topic1.getSourceLocators().size());
+ assertTrue(topic1.getSourceLocators().contains(iid1));
+ assertTrue(topic1.getSourceLocators().contains(iid2));
+ }
+
+ /**
+ * Tests if merging detects duplicate names.
+ */
+ public void testDuplicateSuppressionName() {
+ Topic topic1 = _tm.createTopic();
+ Topic topic2 = _tm.createTopic();
+ TopicName name1 = topic1.createTopicName("tinyTiM", null, null);
+ TopicName name2 = topic2.createTopicName("tinyTiM", null, null);
+ TopicName name3 = topic2.createTopicName("tiny Topic Maps engine", null, null);
+ assertEquals(1, topic1.getTopicNames().size());
+ assertTrue(topic1.getTopicNames().contains(name1));
+ assertEquals(2, topic2.getTopicNames().size());
+ assertTrue(topic2.getTopicNames().contains(name2));
+ assertTrue(topic2.getTopicNames().contains(name3));
+ topic1.mergeIn(topic2);
+ assertEquals(2, topic1.getTopicNames().size());
+ }
+}
Property changes on: tinytim/trunk/test/java/org/tinytim/TestTopicMerge.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date Id
Name: svn:eol-style
+ native
Added: tinytim/trunk/test/java/org/tinytim/TestTopicMergeDetection.java
===================================================================
--- tinytim/trunk/test/java/org/tinytim/TestTopicMergeDetection.java (rev 0)
+++ tinytim/trunk/test/java/org/tinytim/TestTopicMergeDetection.java 2008-04-20 12:06:28 UTC (rev 11)
@@ -0,0 +1,141 @@
+/*
+ * 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.Locator;
+import org.tmapi.core.Topic;
+import org.tmapi.core.TopicsMustMergeException;
+
+/**
+ * Tests if merging situations are detected.
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public class TestTopicMergeDetection extends TinyTimTestCase {
+
+ /**
+ * Tests if adding a duplicate subject identifier is detected.
+ */
+ public void testExistingSubjectIdentifier() {
+ Topic topic1 = _tm.createTopic();
+ Topic topic2 = _tm.createTopic();
+ Locator loc = _tm.createLocator("http://sf.net/projects/tinytim");
+ topic1.addSubjectIdentifier(loc);
+ assertTrue(topic1.getSubjectIdentifiers().contains(loc));
+ assertEquals(topic1, _tm.getTopicBySubjectIdentifier(loc));
+ try {
+ topic2.addSubjectIdentifier(loc);
+ fail("The duplicate subject identifier '" + loc + "' is not detected");
+ }
+ catch (TopicsMustMergeException ex) {
+ // noop.
+ }
+ }
+
+ /**
+ * Tests if adding a duplicate subject identifier on the SAME topic is ignored.
+ */
+ public void testExistingSubjectIdentifierLegal() {
+ Topic topic1 = _tm.createTopic();
+ Locator loc = _tm.createLocator("http://sf.net/projects/tinytim");
+ topic1.addSubjectIdentifier(loc);
+ assertEquals(1, topic1.getSubjectIdentifiers().size());
+ assertTrue(topic1.getSubjectIdentifiers().contains(loc));
+ assertEquals(topic1, _tm.getTopicBySubjectIdentifier(loc));
+ topic1.addSubjectIdentifier(loc);
+ assertEquals(1, topic1.getSubjectIdentifiers().size());
+ }
+
+ /**
+ * Tests if adding a duplicate subject locator is detected.
+ */
+ public void testExistingSubjectLocator() {
+ Topic topic1 = _tm.createTopic();
+ Topic topic2 = _tm.createTopic();
+ Locator loc = _tm.createLocator("http://sf.net/projects/tinytim");
+ topic1.addSubjectLocator(loc);
+ assertTrue(topic1.getSubjectLocators().contains(loc));
+ assertEquals(topic1, _tm.getTopicBySubjectLocator(loc));
+ try {
+ topic2.addSubjectLocator(loc);
+ fail("The duplicate subject locator '" + loc + "' is not detected");
+ }
+ catch (TopicsMustMergeException ex) {
+ // noop.
+ }
+ }
+
+ /**
+ * Tests if adding a duplicate subject locator at the SAME topic is ignored.
+ */
+ public void testExistingSubjectLocatorLegal() {
+ Topic topic1 = _tm.createTopic();
+ Locator loc = _tm.createLocator("http://sf.net/projects/tinytim");
+ topic1.addSubjectLocator(loc);
+ assertEquals(1, topic1.getSubjectLocators().size());
+ assertTrue(topic1.getSubjectLocators().contains(loc));
+ assertEquals(topic1, _tm.getTopicBySubjectLocator(loc));
+ topic1.addSubjectLocator(loc);
+ assertEquals(1, topic1.getSubjectLocators().size());
+ }
+
+ /**
+ * Tests if adding a subject identifier equals to an item identifier is detected.
+ */
+ public void testExistingSubjectIdentifierItemIdentifier() {
+ Topic topic1 = _tm.createTopic();
+ Topic topic2 = _tm.createTopic();
+ Locator loc = _tm.createLocator("http://sf.net/projects/tinytim");
+ topic1.addSubjectIdentifier(loc);
+ assertTrue(topic1.getSubjectIdentifiers().contains(loc));
+ assertEquals(topic1, _tm.getTopicBySubjectIdentifier(loc));
+ try {
+ topic2.addSourceLocator(loc);
+ fail("A topic with a subject identifier equals to the item 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 testExistingSubjectIdentifierItemIdentifierLegal() {
+ Topic topic1 = _tm.createTopic();
+ Locator loc = _tm.createLocator("http://sf.net/projects/tinytim");
+ topic1.addSubjectIdentifier(loc);
+ assertEquals(1, topic1.getSubjectIdentifiers().size());
+ assertEquals(0, topic1.getSourceLocators().size());
+ assertTrue(topic1.getSubjectIdentifiers().contains(loc));
+ assertEquals(topic1, _tm.getTopicBySubjectIdentifier(loc));
+ assertNull(_tm.getObjectByItemIdentifier(loc));
+ topic1.addSourceLocator(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));
+ }
+}
Property changes on: tinytim/trunk/test/java/org/tinytim/TestTopicMergeDetection.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date Id
Name: svn:eol-style
+ native
Added: tinytim/trunk/test/java/org/tinytim/TestTyped.java
===================================================================
--- tinytim/trunk/test/java/org/tinytim/TestTyped.java (rev 0)
+++ tinytim/trunk/test/java/org/tinytim/TestTyped.java 2008-04-20 12:06:28 UTC (rev 11)
@@ -0,0 +1,111 @@
+/*
+ * 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.Occurrence;
+import org.tmapi.core.Topic;
+import org.tmapi.core.TopicMap;
+import org.tmapi.core.TopicName;
+import org.tmapi.core.Variant;
+
+/**
+ * Tests against the {@link org.tinytim.ITyped} interface.
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public class TestTyped extends TinyTimTestCase {
+
+ /**
+ * Tests if a Topic Maps construct is an instance of ITyped.
+ */
+ public void testInstanceOf() {
+ assertFalse(((TopicMap)_tm) instanceof ITyped);
+ Topic topic = _tm.createTopic();
+ assertFalse(topic instanceof ITyped);
+ Association assoc = _tm.createAssociation();
+ assertTrue(assoc instanceof ITyped);
+ AssociationRole role = assoc.createAssociationRole(_tm.createTopic(), _tm.createTopic());
+ assertTrue(role instanceof ITyped);
+ Occurrence occ = topic.createOccurrence("tinyTiM", null, null);
+ assertTrue(occ instanceof ITyped);
+ TopicName name = topic.createTopicName("tinyTiM", null);
+ assertTrue(name instanceof ITyped);
+ Variant variant = name.createVariant("tinyTiM", null);
+ assertFalse(variant instanceof ITyped);
+ }
+
+ /**
+ * Tests setting and getting the type of an association.
+ */
+ public void testAssociation() {
+ _testSetGet((ITyped)_tm.createAssociation());
+ }
+
+ /**
+ * Tests setting and getting the type of a role.
+ */
+ public void testRole() {
+ Association assoc = _tm.createAssociation();
+ AssociationRole role = assoc.createAssociationRole(_tm.createTopic(), _tm.createTopic());
+ _testSetGet((ITyped)role);
+ }
+
+ /**
+ * Tests setting and getting the type of an occurrence.
+ */
+ public void testOccurrence() {
+ Topic topic = _tm.createTopic();
+ Occurrence occ = topic.createOccurrence("tinyTiM", null, null);
+ _testSetGet((ITyped)occ);
+ }
+
+ /**
+ * Tests setting and getting the type of a name.
+ */
+ public void testName() {
+ Topic topic = _tm.createTopic();
+ TopicName name = topic.createTopicName("tinyTiM", null, null);
+ _testSetGet((ITyped)name);
+ }
+
+ /**
+ * Tests setting and getting the type of a typed Topic Maps construct.
+ *
+ * @param typed The Topic Maps construct to test.
+ */
+ private void _testSetGet(ITyped typed) {
+ Topic type = _tm.createTopic();
+ Topic type2 = _tm.createTopic();
+ assertFalse(type.equals(typed.getType()));
+ assertFalse(type2.equals(typed.getType()));
+ typed.setType(type);
+ assertTrue(type.equals(typed.getType()));
+ assertFalse(type2.equals(typed.getType()));
+ typed.setType(type2);
+ assertFalse(type.equals(typed.getType()));
+ assertTrue(type2.equals(typed.getType()));
+ typed.setType(null);
+ assertNull(typed.getType());
+ }
+}
Property changes on: tinytim/trunk/test/java/org/tinytim/TestTyped.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date Id
Name: svn:eol-style
+ native
Added: tinytim/trunk/test/java/org/tinytim/TinyTimTestCase.java
===================================================================
--- tinytim/trunk/test/java/org/tinytim/TinyTimTestCase.java (rev 0)
+++ tinytim/trunk/test/java/org/tinytim/TinyTimTestCase.java 2008-04-20 12:06:28 UTC (rev 11)
@@ -0,0 +1,71 @@
+/*
+ * 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.tinytim.TopicMapImpl;
+import org.tinytim.TopicMapSystemFactoryImpl;
+import org.tinytim.TopicMapSystemImpl;
+import org.tmapi.core.Locator;
+
+import junit.framework.TestCase;
+
+/**
+ * Base class of all tinyTiM-specific test cases.
+ *
+ * This class sets up a default {@link org.tinytim.TopicMapSystemFactoryImpl},
+ * a {@link org.tinytim.TopicMapSystemImpl}, and a
+ * {@link org.tinytim.TopicMapImpl}.
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public class TinyTimTestCase extends TestCase {
+
+ protected static final String _IRI = "http://www.semagia.com/tinyTiM/testTopicMap/";
+ protected Locator _base;
+ protected TopicMapImpl _tm;
+ protected TopicMapSystemImpl _sys;
+ protected TopicMapSystemFactoryImpl _sysFactory;
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ _sysFactory = new TopicMapSystemFactoryImpl();
+ _sys = (TopicMapSystemImpl) _sysFactory.newTopicMapSystem();
+ _tm = (TopicMapImpl) _sys.createTopicMap(_IRI);
+ _base = _tm.getBaseLocator();
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ _sysFactory = null;
+ _sys = null;
+ _tm = null;
+ }
+
+}
Property changes on: tinytim/trunk/test/java/org/tinytim/TinyTimTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date Id
Name: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|