|
From: <lh...@us...> - 2008-08-07 15:08:25
|
Revision: 107
http://tinytim.svn.sourceforge.net/tinytim/?rev=107&view=rev
Author: lheuer
Date: 2008-08-07 15:08:28 +0000 (Thu, 07 Aug 2008)
Log Message:
-----------
- Imported new test suite
Added Paths:
-----------
tinytim/trunk/src/test/java/org/tinytim/core/
tinytim/trunk/src/test/java/org/tinytim/core/AbstractTMAPITestSuite.java
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/TestIRI.java
tinytim/trunk/src/test/java/org/tinytim/core/TestItemIdentifierConstraint.java
tinytim/trunk/src/test/java/org/tinytim/core/TestLiteral.java
tinytim/trunk/src/test/java/org/tinytim/core/TestSignatureGenerator.java
tinytim/trunk/src/test/java/org/tinytim/core/TestTMAPICore.java
tinytim/trunk/src/test/java/org/tinytim/core/TestTMAPIIndex.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: tinytim/trunk/src/test/java/org/tinytim/core/AbstractTMAPITestSuite.java
===================================================================
--- tinytim/trunk/src/test/java/org/tinytim/core/AbstractTMAPITestSuite.java (rev 0)
+++ tinytim/trunk/src/test/java/org/tinytim/core/AbstractTMAPITestSuite.java 2008-08-07 15:08:28 UTC (rev 107)
@@ -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.core;
+
+import junit.framework.TestSuite;
+
+/**
+ * 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 abstract class AbstractTMAPITestSuite extends TestSuite {
+
+ static {
+ System.setProperty("org.tmapi.core.TopicMapSystemFactory", "org.tinytim.core.TopicMapSystemFactoryImpl");
+ }
+}
Property changes on: tinytim/trunk/src/test/java/org/tinytim/core/AbstractTMAPITestSuite.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
Added: tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java
===================================================================
--- tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java (rev 0)
+++ tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java 2008-08-07 15:08:28 UTC (rev 107)
@@ -0,0 +1,51 @@
+/*
+ * 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 junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Runs all tests.
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev$ - $Date$
+ */
+public class AllTests extends TestSuite {
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(suite());
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
+ suite.addTestSuite(TestDuplicateRemovalUtils.class);
+ suite.addTestSuite(TestIRI.class);
+ suite.addTestSuite(TestLiteral.class);
+ suite.addTestSuite(TestItemIdentifierConstraint.class);
+ suite.addTestSuite(TestSignatureGenerator.class);
+ suite.addTest(TestTMAPICore.suite());
+ suite.addTest(TestTMAPIIndex.suite());
+ suite.addTestSuite(TestTopicMapSystemFactoryImpl.class);
+ suite.addTestSuite(TestTopicUtils.class);
+ return suite;
+ }
+}
Property changes on: tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
Added: tinytim/trunk/src/test/java/org/tinytim/core/TestDuplicateRemovalUtils.java
===================================================================
--- tinytim/trunk/src/test/java/org/tinytim/core/TestDuplicateRemovalUtils.java (rev 0)
+++ tinytim/trunk/src/test/java/org/tinytim/core/TestDuplicateRemovalUtils.java 2008-08-07 15:08:28 UTC (rev 107)
@@ -0,0 +1,105 @@
+/*
+ * 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 org.tmapi.core.Association;
+import org.tmapi.core.Locator;
+import org.tmapi.core.Name;
+import org.tmapi.core.Topic;
+
+/**
+ * Tests against the {@link DuplicateRemovalUtils}.
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev$ - $Date$
+ */
+public class TestDuplicateRemovalUtils extends TinyTimTestCase {
+
+ public void testTopicRemoveNames() {
+ Topic topic = _tm.createTopic();
+ Topic nameType = _tm.createTopic();
+ Name name1 = topic.createName(nameType, "tinyTiM");
+ Name name2 = topic.createName(nameType, "tinyTiM");
+ assertEquals(nameType, name1.getType());
+ assertTrue(name1.getScope().isEmpty());
+ assertEquals(nameType, name2.getType());
+ assertTrue(name2.getScope().isEmpty());
+ assertEquals(2, topic.getNames().size());
+ DuplicateRemovalUtils.removeDuplicates(topic);
+ assertEquals(1, topic.getNames().size());
+ Name name = (Name) topic.getNames().iterator().next();
+ assertEquals("tinyTiM", name.getValue());
+ assertEquals(nameType, name.getType());
+ assertTrue(name.getScope().isEmpty());
+ }
+
+ public void testTopicRemoveNames2() {
+ Topic topic = _tm.createTopic();
+ Topic nameType = _tm.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");
+ name1.addItemIdentifier(iid1);
+ name2.addItemIdentifier(iid2);
+ assertEquals(2, topic.getNames().size());
+ DuplicateRemovalUtils.removeDuplicates(topic);
+ assertEquals(1, topic.getNames().size());
+ Name name = (Name) topic.getNames().iterator().next();
+ assertEquals("tinyTiM", name.getValue());
+ assertEquals(nameType, name.getType());
+ assertTrue(name.getScope().isEmpty());
+ assertEquals(2, name.getItemIdentifiers().size());
+ assertTrue(name.getItemIdentifiers().contains(iid1));
+ assertTrue(name.getItemIdentifiers().contains(iid2));
+ }
+
+ public void testTopicRemoveNames3() {
+ Topic topic = _tm.createTopic();
+ Topic theme1 = _tm.createTopic();
+ Topic theme2 = _tm.createTopic();
+ Topic nameType = _tm.createTopic();
+ Name name1 = topic.createName(nameType, "tinyTiM", theme1, theme2);
+ Name name2 = topic.createName(nameType, "tinyTiM", theme2, theme1);
+ assertEquals(2, name1.getScope().size());
+ assertEquals(2, name2.getScope().size());
+ assertEquals(2, topic.getNames().size());
+ DuplicateRemovalUtils.removeDuplicates(topic);
+ assertEquals(1, topic.getNames().size());
+ Name name = (Name) topic.getNames().iterator().next();
+ assertEquals("tinyTiM", name.getValue());
+ assertEquals(nameType, name.getType());
+ assertEquals(2, name.getScope().size());
+ }
+
+ public void testRemoveRoles() {
+ Association assoc = _tm.createAssociation(_tm.createTopic());
+ Topic type = _tm.createTopic();
+ Topic player = _tm.createTopic();
+ assoc.createRole(type, player);
+ assoc.createRole(type, player);
+ assertEquals(2, player.getRolesPlayed().size());
+ assertEquals(2, assoc.getRoles().size());
+ DuplicateRemovalUtils.removeDuplicates(assoc);
+ assertEquals(1, player.getRolesPlayed().size());
+ assertEquals(1, assoc.getRoles().size());
+ }
+}
Property changes on: tinytim/trunk/src/test/java/org/tinytim/core/TestDuplicateRemovalUtils.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
Added: tinytim/trunk/src/test/java/org/tinytim/core/TestIRI.java
===================================================================
--- tinytim/trunk/src/test/java/org/tinytim/core/TestIRI.java (rev 0)
+++ tinytim/trunk/src/test/java/org/tinytim/core/TestIRI.java 2008-08-07 15:08:28 UTC (rev 107)
@@ -0,0 +1,51 @@
+/*
+ * 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 org.tmapi.core.Locator;
+
+/**
+ * Tests against the locator implementation.
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public class TestIRI extends TinyTimTestCase {
+
+ public void testNormalization() {
+ Locator loc = _tm.createLocator("http://www.example.org/test+me/");
+ assertEquals("http://www.example.org/test me/", loc.getReference());
+ assertEquals("http://www.example.org/test%20me/", loc.toExternalForm());
+ Locator loc2 = loc.resolve("./too");
+ assertEquals("http://www.example.org/test me/too", loc2.getReference());
+ assertEquals("http://www.example.org/test%20me/too", loc2.toExternalForm());
+ Locator loc3 = _tm.createLocator("http://www.example.org/test me/");
+ assertEquals("http://www.example.org/test me/", loc3.getReference());
+ assertEquals("http://www.example.org/test%20me/", loc3.toExternalForm());
+ }
+
+ //TODO!
+// public void testLowerCaseScheme() {
+// Locator loc = _tm.createLocator("HTTP://www.example.org/test+me/");
+// assertEquals("http://www.example.org/test me/", loc.getReference());
+// assertEquals("http://www.example.org/test%20me/", loc.toExternalForm());
+// }
+}
Property changes on: tinytim/trunk/src/test/java/org/tinytim/core/TestIRI.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
Added: tinytim/trunk/src/test/java/org/tinytim/core/TestItemIdentifierConstraint.java
===================================================================
--- tinytim/trunk/src/test/java/org/tinytim/core/TestItemIdentifierConstraint.java (rev 0)
+++ tinytim/trunk/src/test/java/org/tinytim/core/TestItemIdentifierConstraint.java 2008-08-07 15:08:28 UTC (rev 107)
@@ -0,0 +1,154 @@
+/*
+ * 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 org.tmapi.core.Association;
+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.
+ *
+ * @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.addItemIdentifier(iid);
+ assertTrue(topic.getItemIdentifiers().contains(iid));
+ Topic topic2 = _tm.createTopic();
+ try {
+ topic2.addItemIdentifier(iid);
+ }
+ catch (IdentityConstraintException ex) {
+ // noop.
+ }
+ topic.removeItemIdentifier(iid);
+ assertFalse(topic.getItemIdentifiers().contains(iid));
+ topic2.addItemIdentifier(iid);
+ assertTrue(topic2.getItemIdentifiers().contains(iid));
+ topic2.removeItemIdentifier(iid);
+ topic.addItemIdentifier(iid);
+ assertTrue(topic.getItemIdentifiers().contains(iid));
+ assertFalse(topic2.getItemIdentifiers().contains(iid));
+ topic.remove();
+ topic2.addItemIdentifier(iid);
+ assertTrue(topic2.getItemIdentifiers().contains(iid));
+ }
+
+ /**
+ * Tests against an association.
+ */
+ public void testAssociation() throws Exception {
+ _testConstraint(_tm.createAssociation(_tm.createTopic()));
+ }
+
+ /**
+ * 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);
+ }
+
+ /**
+ * Tests against an occurrence.
+ */
+ public void testOccurrence() throws Exception {
+ Topic topic = _tm.createTopic();
+ Occurrence occ = topic.createOccurrence(_tm.createTopic(), "tinyTiM");
+ _testConstraint(occ);
+ }
+
+ /**
+ * Tests against a name.
+ */
+ public void testName() throws Exception {
+ Topic topic = _tm.createTopic();
+ Name name = topic.createName("tinyTiM");
+ _testConstraint(name);
+ }
+
+ /**
+ * 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);
+ }
+
+ /**
+ * 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));
+ }
+ }
+}
Property changes on: tinytim/trunk/src/test/java/org/tinytim/core/TestItemIdentifierConstraint.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
Added: tinytim/trunk/src/test/java/org/tinytim/core/TestLiteral.java
===================================================================
--- tinytim/trunk/src/test/java/org/tinytim/core/TestLiteral.java (rev 0)
+++ tinytim/trunk/src/test/java/org/tinytim/core/TestLiteral.java 2008-08-07 15:08:28 UTC (rev 107)
@@ -0,0 +1,75 @@
+/*
+ * 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 org.tinytim.voc.XSD;
+import org.tmapi.core.Locator;
+
+/**
+ *
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public class TestLiteral extends TinyTimTestCase {
+
+ public void testStringEquality() {
+ final String value = "tinyTiM";
+ ILiteral lit1 = Literal.create(value);
+ ILiteral lit2 = Literal.create(value);
+ assertSame(lit1, lit2);
+ }
+
+ public void testStringEquality2() {
+ final String value = "tinyTiM";
+ ILiteral lit1 = Literal.create(value);
+ ILiteral lit2 = Literal.create(value, XSD.STRING);
+ assertSame(lit1, lit2);
+ }
+
+ public void testStringEquality3() {
+ final String value = "tinyTiM";
+ ILiteral lit1 = Literal.create(value, XSD.STRING);
+ ILiteral lit2 = Literal.create(value);
+ assertSame(lit1, lit2);
+ }
+
+ public void testIRIEquality() {
+ final Locator value = _sys.createLocator("http://www.semagia.com/");
+ ILiteral lit1 = Literal.create(value);
+ ILiteral lit2 = Literal.create(value);
+ assertSame(lit1, lit2);
+ }
+
+ public void testIRIEquality2() {
+ final Locator value = _sys.createLocator("http://www.semagia.com/");
+ ILiteral lit1 = Literal.create(value);
+ ILiteral lit2 = Literal.create(value.getReference(), XSD.ANY_URI);
+ assertSame(lit1, lit2);
+ }
+
+ public void testIRIEquality3() {
+ final Locator value = _sys.createLocator("http://www.semagia.com/");
+ ILiteral lit1 = Literal.create(value.getReference(), XSD.ANY_URI);
+ ILiteral lit2 = Literal.create(value);
+ assertSame(lit1, lit2);
+ }
+}
Property changes on: tinytim/trunk/src/test/java/org/tinytim/core/TestLiteral.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
Added: tinytim/trunk/src/test/java/org/tinytim/core/TestSignatureGenerator.java
===================================================================
--- tinytim/trunk/src/test/java/org/tinytim/core/TestSignatureGenerator.java (rev 0)
+++ tinytim/trunk/src/test/java/org/tinytim/core/TestSignatureGenerator.java 2008-08-07 15:08:28 UTC (rev 107)
@@ -0,0 +1,118 @@
+/*
+ * 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 org.tmapi.core.Association;
+import org.tmapi.core.Name;
+import org.tmapi.core.Occurrence;
+import org.tmapi.core.Role;
+import org.tmapi.core.Topic;
+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() {
+ Topic type = _tm.createTopic();
+ Association assoc = _tm.createAssociation(type);
+ Association assoc2 = _tm.createAssociation(type);
+ assertFalse(assoc.getId().equals(assoc2.getId()));
+ String sig = SignatureGenerator.generateSignature(assoc);
+ assertEquals(sig, SignatureGenerator.generateSignature(assoc2));
+ }
+
+ /**
+ * Tests if an occurrence with no initialized properties returns the same
+ * signature.
+ */
+ public void testOccurrenceBasic() {
+ Topic topic = _tm.createTopic();
+ Topic type = _tm.createTopic();
+ Occurrence occ = topic.createOccurrence(type, "tinyTiM");
+ Occurrence occ2 = topic.createOccurrence(type, "tinyTiM");
+ assertFalse(occ.getId().equals(occ2.getId()));
+ 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();
+ Name name = topic.createName("tinyTiM");
+ Name name2 = topic.createName("tinyTiM");
+ assertFalse(name.getId().equals(name2.getId()));
+ 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();
+ Name name = topic.createName("tinyTiM");
+ Variant variant = name.createVariant("tiny Topic Maps", _tm.createTopic());
+ String sig = SignatureGenerator.generateSignature(variant);
+ assertEquals(sig, SignatureGenerator.generateSignature(variant));
+ }
+
+ /**
+ * Tests if associations with the same type return the same signature.
+ */
+ public void testAssociationTyped() {
+ Topic type1 = _tm.createTopic();
+ Topic type2 = _tm.createTopic();
+ Association assoc = _tm.createAssociation(type1);
+ String sigBefore = SignatureGenerator.generateSignature(assoc);
+ assoc.setType(type2);
+ String sigAfter = SignatureGenerator.generateSignature(assoc);
+ assertFalse(sigBefore.equals(sigAfter));
+ Association assoc2 = _tm.createAssociation(type1);
+ assertEquals(sigBefore, SignatureGenerator.generateSignature(assoc2));
+ assoc2.setType(type2);
+ assertEquals(sigAfter, SignatureGenerator.generateSignature(assoc2));
+ }
+
+ public void testRoles() {
+ Association assoc = _tm.createAssociation(_tm.createTopic());
+ Topic type = _tm.createTopic();
+ Topic player = _tm.createTopic();
+ Role role1 = assoc.createRole(type, player);
+ Role role2 = assoc.createRole(type, player);
+ assertEquals(2, player.getRolesPlayed().size());
+ assertEquals(2, assoc.getRoles().size());
+ String sig = SignatureGenerator.generateSignature(role1);
+ assertEquals(sig, SignatureGenerator.generateSignature(role2));
+ }
+}
Property changes on: tinytim/trunk/src/test/java/org/tinytim/core/TestSignatureGenerator.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
Added: tinytim/trunk/src/test/java/org/tinytim/core/TestTMAPICore.java
===================================================================
--- tinytim/trunk/src/test/java/org/tinytim/core/TestTMAPICore.java (rev 0)
+++ tinytim/trunk/src/test/java/org/tinytim/core/TestTMAPICore.java 2008-08-07 15:08:28 UTC (rev 107)
@@ -0,0 +1,42 @@
+/*
+ * 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 org.tmapi.core.AllCoreTests;
+
+import junit.framework.Test;
+
+/**
+ * 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 AbstractTMAPITestSuite {
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(suite());
+ }
+
+ public static Test suite() {
+ return AllCoreTests.suite();
+ }
+}
Property changes on: tinytim/trunk/src/test/java/org/tinytim/core/TestTMAPICore.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
Added: tinytim/trunk/src/test/java/org/tinytim/core/TestTMAPIIndex.java
===================================================================
--- tinytim/trunk/src/test/java/org/tinytim/core/TestTMAPIIndex.java (rev 0)
+++ tinytim/trunk/src/test/java/org/tinytim/core/TestTMAPIIndex.java 2008-08-07 15:08:28 UTC (rev 107)
@@ -0,0 +1,42 @@
+/*
+ * 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 org.tmapi.index.AllIndexTests;
+
+import junit.framework.Test;
+
+/**
+ * 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 AbstractTMAPITestSuite {
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(suite());
+ }
+
+ public static Test suite() {
+ return AllIndexTests.suite();
+ }
+}
Property changes on: tinytim/trunk/src/test/java/org/tinytim/core/TestTMAPIIndex.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
Added: tinytim/trunk/src/test/java/org/tinytim/core/TestTopicMapSystemFactoryImpl.java
===================================================================
--- tinytim/trunk/src/test/java/org/tinytim/core/TestTopicMapSystemFactoryImpl.java (rev 0)
+++ tinytim/trunk/src/test/java/org/tinytim/core/TestTopicMapSystemFactoryImpl.java 2008-08-07 15:08:28 UTC (rev 107)
@@ -0,0 +1,190 @@
+/*
+ * 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.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;
+
+/**
+ * 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(Feature.NOTATION_URI));
+ assertTrue(_sysFactory.getFeature(Feature.XTM_1_1));
+ assertFalse(_sysFactory.getFeature(Feature.XTM_1_0));
+ assertFalse(_sysFactory.getFeature(Feature.READ_ONLY));
+ assertFalse(_sysFactory.getFeature(Feature.AUTOMERGE));
+ assertFalse(_sysFactory.getFeature(Feature.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(Feature.NOTATION_URI, true);
+ _setFeatureToUnacceptedValue(Feature.NOTATION_URI, false);
+ _setFeatureToAcceptedValue(Feature.XTM_1_0, false);
+ _setFeatureToUnacceptedValue(Feature.XTM_1_0, true);
+ _setFeatureToAcceptedValue(Feature.XTM_1_1, true);
+ _setFeatureToUnacceptedValue(Feature.XTM_1_1, false);
+ _setFeatureToAcceptedValue(Feature.READ_ONLY, false);
+ _setFeatureToUnacceptedValue(Feature.READ_ONLY, true);
+ _setFeatureToAcceptedValue(Feature.AUTOMERGE, false);
+ _setFeatureToUnacceptedValue(Feature.AUTOMERGE, true);
+ _setFeatureToAcceptedValue(Feature.TNC, false);
+ _setFeatureToUnacceptedValue(Feature.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.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);
+ }
+
+ }
+}
Property changes on: tinytim/trunk/src/test/java/org/tinytim/core/TestTopicMapSystemFactoryImpl.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
Added: tinytim/trunk/src/test/java/org/tinytim/core/TestTopicUtils.java
===================================================================
--- tinytim/trunk/src/test/java/org/tinytim/core/TestTopicUtils.java (rev 0)
+++ tinytim/trunk/src/test/java/org/tinytim/core/TestTopicUtils.java 2008-08-07 15:08:28 UTC (rev 107)
@@ -0,0 +1,64 @@
+/*
+ * 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 org.tmapi.core.Association;
+import org.tmapi.core.Role;
+import org.tmapi.core.Topic;
+
+/**
+ * Tests against the {@link TopicUtils}.
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev$ - $Date$
+ */
+public class TestTopicUtils extends TinyTimTestCase {
+
+ /**
+ * Tests if a topic is considered as 'removable'.
+ */
+ public void testRemovable() {
+ Topic topic = _tm.createTopic();
+ assertTrue(TopicUtils.isRemovable(topic));
+ Association assoc = _tm.createAssociation(topic);
+ assertFalse(TopicUtils.isRemovable(topic));
+ assoc.setType(_tm.createTopic());
+ assertTrue(TopicUtils.isRemovable(topic));
+ // Role played
+ Role role = assoc.createRole(_tm.createTopic(), topic);
+ assertFalse(TopicUtils.isRemovable(topic));
+ role.setPlayer(_tm.createTopic());
+ assertTrue(TopicUtils.isRemovable(topic));
+ // Theme
+ assoc.addTheme(topic);
+ assertFalse(TopicUtils.isRemovable(topic));
+ assoc.removeTheme(topic);
+ assertTrue(TopicUtils.isRemovable(topic));
+ // Reifier
+ assoc.setReifier(topic);
+ assertTrue(TopicUtils.isRemovable(topic));
+ assertFalse(TopicUtils.isRemovable(topic, true));
+ assoc.setReifier(null);
+ assertTrue(TopicUtils.isRemovable(topic));
+ assertTrue(TopicUtils.isRemovable(topic, true));
+ }
+
+}
Property changes on: tinytim/trunk/src/test/java/org/tinytim/core/TestTopicUtils.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
Added: tinytim/trunk/src/test/java/org/tinytim/core/TinyTimTestCase.java
===================================================================
--- tinytim/trunk/src/test/java/org/tinytim/core/TinyTimTestCase.java (rev 0)
+++ tinytim/trunk/src/test/java/org/tinytim/core/TinyTimTestCase.java 2008-08-07 15:08:28 UTC (rev 107)
@@ -0,0 +1,90 @@
+/*
+ * 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.Enumeration;
+import java.util.Properties;
+
+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;
+
+ /**
+ * Returns additional / non-default properties which should be set
+ * to configure the {@link org.tmapi.core.TopicMapSystemFactory}.
+ *
+ * @return Properties instance or <code>null</code> if no properties !=
+ * default properties should be set.
+ */
+ protected Properties getAdditionalProperties() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ _sysFactory = new TopicMapSystemFactoryImpl();
+ Properties properties = getAdditionalProperties();
+ if (properties != null) {
+ for (Enumeration<?> e = properties.propertyNames(); e.hasMoreElements();) {
+ String name = (String) e.nextElement();
+ _sysFactory.setProperty(name, properties.getProperty(name));
+ }
+ }
+ _sys = (TopicMapSystemImpl) _sysFactory.newTopicMapSystem();
+ _base = _sys.createLocator(_IRI);
+ _tm = (TopicMapImpl) _sys.createTopicMap(_base);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ _sysFactory = null;
+ _sys = null;
+ _tm = null;
+ _base = null;
+ }
+
+}
Property changes on: tinytim/trunk/src/test/java/org/tinytim/core/TinyTimTestCase.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|