|
From: <tma...@li...> - 2008-08-05 11:26:47
|
Revision: 53
http://tmapi.svn.sourceforge.net/tmapi/?rev=53&view=rev
Author: lheuer
Date: 2008-08-05 11:26:51 +0000 (Tue, 05 Aug 2008)
Log Message:
-----------
- More .core tests
- Initial .index tests
Modified Paths:
--------------
trunk/src/test/java/org/tmapi/core/AllCoreTests.java
trunk/src/test/java/org/tmapi/core/TMAPITestCase.java
trunk/src/test/java/org/tmapi/core/TestAssociation.java
trunk/src/test/java/org/tmapi/core/TestConstruct.java
trunk/src/test/java/org/tmapi/core/TestDatatypeAware.java
trunk/src/test/java/org/tmapi/core/TestLocator.java
trunk/src/test/java/org/tmapi/core/TestName.java
trunk/src/test/java/org/tmapi/core/TestOccurrence.java
trunk/src/test/java/org/tmapi/core/TestReified.java
trunk/src/test/java/org/tmapi/core/TestRole.java
trunk/src/test/java/org/tmapi/core/TestScoped.java
trunk/src/test/java/org/tmapi/core/TestTopic.java
trunk/src/test/java/org/tmapi/core/TestTopicMap.java
trunk/src/test/java/org/tmapi/core/TestTopicMapMerge.java
trunk/src/test/java/org/tmapi/core/TestTopicMapSystem.java
trunk/src/test/java/org/tmapi/core/TestTopicMerge.java
trunk/src/test/java/org/tmapi/core/TestTopicMergeDetection.java
trunk/src/test/java/org/tmapi/core/TestTyped.java
trunk/src/test/java/org/tmapi/core/TestVariant.java
Added Paths:
-----------
trunk/src/test/java/org/tmapi/index/AllIndexTests.java
trunk/src/test/java/org/tmapi/index/TestLiteralIndex.java
trunk/src/test/java/org/tmapi/index/TestScopedIndex.java
trunk/src/test/java/org/tmapi/index/TestTypeInstanceIndex.java
Modified: trunk/src/test/java/org/tmapi/core/AllCoreTests.java
===================================================================
--- trunk/src/test/java/org/tmapi/core/AllCoreTests.java 2008-08-05 11:25:24 UTC (rev 52)
+++ trunk/src/test/java/org/tmapi/core/AllCoreTests.java 2008-08-05 11:26:51 UTC (rev 53)
@@ -1,7 +1,5 @@
/*
- * TMAPI 2.0
- *
- * Version 2.0 of the Topic Maps API (TMAPI), created collectively by
+ * The Topic Maps API (TMAPI) was created collectively by
* the membership of the tmapi-discuss mailing list
* <http://lists.sourceforge.net/mailman/listinfo/tmapi-discuss>,
* is hereby released into the public domain; and comes with
Modified: trunk/src/test/java/org/tmapi/core/TMAPITestCase.java
===================================================================
--- trunk/src/test/java/org/tmapi/core/TMAPITestCase.java 2008-08-05 11:25:24 UTC (rev 52)
+++ trunk/src/test/java/org/tmapi/core/TMAPITestCase.java 2008-08-05 11:26:51 UTC (rev 53)
@@ -1,7 +1,5 @@
/*
- * TMAPI 2.0
- *
- * Version 2.0 of the Topic Maps API (TMAPI), created collectively by
+ * The Topic Maps API (TMAPI) was created collectively by
* the membership of the tmapi-discuss mailing list
* <http://lists.sourceforge.net/mailman/listinfo/tmapi-discuss>,
* is hereby released into the public domain; and comes with
Modified: trunk/src/test/java/org/tmapi/core/TestAssociation.java
===================================================================
--- trunk/src/test/java/org/tmapi/core/TestAssociation.java 2008-08-05 11:25:24 UTC (rev 52)
+++ trunk/src/test/java/org/tmapi/core/TestAssociation.java 2008-08-05 11:26:51 UTC (rev 53)
@@ -1,7 +1,5 @@
/*
- * TMAPI 2.0
- *
- * Version 2.0 of the Topic Maps API (TMAPI), created collectively by
+ * The Topic Maps API (TMAPI) was created collectively by
* the membership of the tmapi-discuss mailing list
* <http://lists.sourceforge.net/mailman/listinfo/tmapi-discuss>,
* is hereby released into the public domain; and comes with
@@ -46,4 +44,114 @@
assertTrue("Expected association set size to decrement for topic map.",
parent.getAssociations().isEmpty());
}
+
+ public void testRoleCreation() {
+ final Association assoc = createAssociation();
+ assertTrue("Expected no roles in a newly created association",
+ assoc.getRoles().isEmpty());
+ final Topic roleType = createTopic();
+ final Topic player = createTopic();
+ assertEquals(0, player.getRolesPlayed().size());
+ final Role role = assoc.createRole(roleType, player);
+ assertEquals("Unexpected role type", roleType, role.getType());
+ assertEquals("Unexpected role player", player, role.getPlayer());
+ assertEquals(1, player.getRolesPlayed().size());
+ assertTrue(player.getRolesPlayed().contains(role));
+ }
+
+ public void testRoleTypes() {
+ final Association assoc = createAssociation();
+ final Topic type1 = createTopic();
+ final Topic type2 = createTopic();
+ assertTrue(assoc.getRoleTypes().isEmpty());
+ final Role role1 = assoc.createRole(type1, createTopic());
+ assertEquals(1, assoc.getRoleTypes().size());
+ assertTrue(assoc.getRoleTypes().contains(type1));
+ final Role role2 = assoc.createRole(type2, createTopic());
+ assertEquals(2, assoc.getRoleTypes().size());
+ assertTrue(assoc.getRoleTypes().contains(type1));
+ assertTrue(assoc.getRoleTypes().contains(type2));
+ final Role role3 = assoc.createRole(type2, createTopic());
+ assertEquals(2, assoc.getRoleTypes().size());
+ assertTrue(assoc.getRoleTypes().contains(type1));
+ assertTrue(assoc.getRoleTypes().contains(type2));
+ role3.remove();
+ assertEquals(2, assoc.getRoleTypes().size());
+ assertTrue(assoc.getRoleTypes().contains(type1));
+ assertTrue(assoc.getRoleTypes().contains(type2));
+ role2.remove();
+ assertEquals(1, assoc.getRoleTypes().size());
+ assertTrue(assoc.getRoleTypes().contains(type1));
+ assertFalse(assoc.getRoleTypes().contains(type2));
+ role1.remove();
+ assertEquals(0, assoc.getRoleTypes().size());
+ }
+
+ public void testRoleFilter() {
+ final Association assoc = createAssociation();
+ final Topic type1 = createTopic();
+ final Topic type2 = createTopic();
+ final Topic unusedType = createTopic();
+ assertTrue(assoc.getRoles(type1).isEmpty());
+ assertTrue(assoc.getRoles(type2).isEmpty());
+ assertTrue(assoc.getRoles(unusedType).isEmpty());
+ final Role role1 = assoc.createRole(type1, createTopic());
+ assertEquals(1, assoc.getRoles(type1).size());
+ assertTrue(assoc.getRoles(type1).contains(role1));
+ assertTrue(assoc.getRoles(type2).isEmpty());
+ assertTrue(assoc.getRoles(unusedType).isEmpty());
+ final Role role2 = assoc.createRole(type2, createTopic());
+ assertEquals(1, assoc.getRoles(type2).size());
+ assertTrue(assoc.getRoles(type2).contains(role2));
+ final Role role3 = assoc.createRole(type2, createTopic());
+ assertEquals(2, assoc.getRoles(type2).size());
+ assertTrue(assoc.getRoles(type2).contains(role2));
+ assertTrue(assoc.getRoles(type2).contains(role3));
+ assertTrue(assoc.getRoles(unusedType).isEmpty());
+ role3.remove();
+ assertEquals(1, assoc.getRoles(type2).size());
+ assertTrue(assoc.getRoles(type2).contains(role2));
+ role2.remove();
+ assertEquals(0, assoc.getRoles(type2).size());
+ role1.remove();
+ assertEquals(0, assoc.getRoles(type1).size());
+ assertEquals(0, assoc.getRoles(unusedType).size());
+ }
+
+ public void testRoleFilterIllegal() {
+ final Association assoc = createAssociation();
+ try {
+ assoc.getRoles(null);
+ fail("getRoles(null) is illegal");
+ }
+ catch (Exception ex) {
+ // noop.
+ }
+ }
+
+ public void testRoleCreationInvalidPlayer() {
+ final Association assoc = createAssociation();
+ assertTrue("Expected no roles in a newly created association",
+ assoc.getRoles().isEmpty());
+ try {
+ assoc.createRole(createTopic(), null);
+ fail("Role creation where player is null shouldn't be allowed");
+ }
+ catch (Exception ex) {
+ // noop.
+ }
+ }
+
+ public void testRoleCreationInvalidType() {
+ final Association assoc = createAssociation();
+ assertTrue("Expected no roles in a newly created association",
+ assoc.getRoles().isEmpty());
+ try {
+ assoc.createRole(null, createTopic());
+ fail("Role creation where type is null shouldn't be allowed");
+ }
+ catch (Exception ex) {
+ // noop.
+ }
+ }
}
Modified: trunk/src/test/java/org/tmapi/core/TestConstruct.java
===================================================================
--- trunk/src/test/java/org/tmapi/core/TestConstruct.java 2008-08-05 11:25:24 UTC (rev 52)
+++ trunk/src/test/java/org/tmapi/core/TestConstruct.java 2008-08-05 11:26:51 UTC (rev 53)
@@ -1,7 +1,5 @@
/*
- * TMAPI 2.0
- *
- * Version 2.0 of the Topic Maps API (TMAPI), created collectively by
+ * The Topic Maps API (TMAPI) was created collectively by
* the membership of the tmapi-discuss mailing list
* <http://lists.sourceforge.net/mailman/listinfo/tmapi-discuss>,
* is hereby released into the public domain; and comes with
Modified: trunk/src/test/java/org/tmapi/core/TestDatatypeAware.java
===================================================================
--- trunk/src/test/java/org/tmapi/core/TestDatatypeAware.java 2008-08-05 11:25:24 UTC (rev 52)
+++ trunk/src/test/java/org/tmapi/core/TestDatatypeAware.java 2008-08-05 11:26:51 UTC (rev 53)
@@ -1,7 +1,5 @@
/*
- * TMAPI 2.0
- *
- * Version 2.0 of the Topic Maps API (TMAPI), created collectively by
+ * The Topic Maps API (TMAPI) was created collectively by
* the membership of the tmapi-discuss mailing list
* <http://lists.sourceforge.net/mailman/listinfo/tmapi-discuss>,
* is hereby released into the public domain; and comes with
Modified: trunk/src/test/java/org/tmapi/core/TestLocator.java
===================================================================
--- trunk/src/test/java/org/tmapi/core/TestLocator.java 2008-08-05 11:25:24 UTC (rev 52)
+++ trunk/src/test/java/org/tmapi/core/TestLocator.java 2008-08-05 11:26:51 UTC (rev 53)
@@ -1,7 +1,5 @@
/*
- * TMAPI 2.0
- *
- * Version 2.0 of the Topic Maps API (TMAPI), created collectively by
+ * The Topic Maps API (TMAPI) was created collectively by
* the membership of the tmapi-discuss mailing list
* <http://lists.sourceforge.net/mailman/listinfo/tmapi-discuss>,
* is hereby released into the public domain; and comes with
Modified: trunk/src/test/java/org/tmapi/core/TestName.java
===================================================================
--- trunk/src/test/java/org/tmapi/core/TestName.java 2008-08-05 11:25:24 UTC (rev 52)
+++ trunk/src/test/java/org/tmapi/core/TestName.java 2008-08-05 11:26:51 UTC (rev 53)
@@ -1,7 +1,5 @@
/*
- * TMAPI 2.0
- *
- * Version 2.0 of the Topic Maps API (TMAPI), created collectively by
+ * The Topic Maps API (TMAPI) was created collectively by
* the membership of the tmapi-discuss mailing list
* <http://lists.sourceforge.net/mailman/listinfo/tmapi-discuss>,
* is hereby released into the public domain; and comes with
@@ -148,4 +146,15 @@
}
}
+
+ public void testVariantCreationIllegalNullScope() {
+ final Name name = createName();
+ try {
+ name.createVariant("Variant", (Topic[])null);
+ fail("Creation of a variant with a null scope is not allowed");
+ }
+ catch (Exception ex) {
+
+ }
+ }
}
Modified: trunk/src/test/java/org/tmapi/core/TestOccurrence.java
===================================================================
--- trunk/src/test/java/org/tmapi/core/TestOccurrence.java 2008-08-05 11:25:24 UTC (rev 52)
+++ trunk/src/test/java/org/tmapi/core/TestOccurrence.java 2008-08-05 11:26:51 UTC (rev 53)
@@ -1,7 +1,5 @@
/*
- * TMAPI 2.0
- *
- * Version 2.0 of the Topic Maps API (TMAPI), created collectively by
+ * The Topic Maps API (TMAPI) was created collectively by
* the membership of the tmapi-discuss mailing list
* <http://lists.sourceforge.net/mailman/listinfo/tmapi-discuss>,
* is hereby released into the public domain; and comes with
@@ -53,4 +51,5 @@
assertTrue("Expected occurrence set size to decrement for topic.",
parent.getOccurrences().isEmpty());
}
+
}
Modified: trunk/src/test/java/org/tmapi/core/TestReified.java
===================================================================
--- trunk/src/test/java/org/tmapi/core/TestReified.java 2008-08-05 11:25:24 UTC (rev 52)
+++ trunk/src/test/java/org/tmapi/core/TestReified.java 2008-08-05 11:26:51 UTC (rev 53)
@@ -1,7 +1,5 @@
/*
- * TMAPI 2.0
- *
- * Version 2.0 of the Topic Maps API (TMAPI), created collectively by
+ * The Topic Maps API (TMAPI) was created collectively by
* the membership of the tmapi-discuss mailing list
* <http://lists.sourceforge.net/mailman/listinfo/tmapi-discuss>,
* is hereby released into the public domain; and comes with
Modified: trunk/src/test/java/org/tmapi/core/TestRole.java
===================================================================
--- trunk/src/test/java/org/tmapi/core/TestRole.java 2008-08-05 11:25:24 UTC (rev 52)
+++ trunk/src/test/java/org/tmapi/core/TestRole.java 2008-08-05 11:26:51 UTC (rev 53)
@@ -1,7 +1,5 @@
/*
- * TMAPI 2.0
- *
- * Version 2.0 of the Topic Maps API (TMAPI), created collectively by
+ * The Topic Maps API (TMAPI) was created collectively by
* the membership of the tmapi-discuss mailing list
* <http://lists.sourceforge.net/mailman/listinfo/tmapi-discuss>,
* is hereby released into the public domain; and comes with
@@ -46,37 +44,6 @@
parent.getRoles().isEmpty());
}
- public void testRoleCreation() {
- final Association assoc = createAssociation();
- assertTrue("Expected no roles in a newly created association",
- assoc.getRoles().isEmpty());
- final Topic roleType = createTopic();
- final Topic player = createTopic();
- final Role role = assoc.createRole(roleType, player);
- assertEquals("Unexpected role type", roleType, role.getType());
- assertEquals("Unexpected role player", player, role.getPlayer());
- }
-
- public void testRoleCreationInvalid() {
- final Association assoc = createAssociation();
- assertTrue("Expected no roles in a newly created association",
- assoc.getRoles().isEmpty());
- try {
- assoc.createRole(createTopic(), null);
- fail("Role creation where player is null shouldn't be allowed");
- }
- catch (Exception ex) {
- // noop.
- }
- try {
- assoc.createRole(null, createTopic());
- fail("Role creation where type is null shouldn't be allowed");
- }
- catch (Exception ex) {
- // noop.
- }
- }
-
public void testRolePlayerSetGet() {
final Association assoc = createAssociation();
assertTrue("Expected no roles in a newly created association",
@@ -94,10 +61,10 @@
player2, role.getPlayer());
assertTrue("Role is not reported in getRolesPlayed()",
player2.getRolesPlayed().contains(role));
- assertTrue("'player' does not play the role anymore",
+ assertTrue("'player' should not play the role anymore",
player.getRolesPlayed().isEmpty());
role.setPlayer(player);
- assertEquals("Unexpected role player after setting to player",
+ assertEquals("Unexpected role player after setting to 'player'",
player, role.getPlayer());
try {
role.setPlayer(null);
Modified: trunk/src/test/java/org/tmapi/core/TestScoped.java
===================================================================
--- trunk/src/test/java/org/tmapi/core/TestScoped.java 2008-08-05 11:25:24 UTC (rev 52)
+++ trunk/src/test/java/org/tmapi/core/TestScoped.java 2008-08-05 11:26:51 UTC (rev 53)
@@ -1,7 +1,5 @@
/*
- * TMAPI 2.0
- *
- * Version 2.0 of the Topic Maps API (TMAPI), created collectively by
+ * The Topic Maps API (TMAPI) was created collectively by
* the membership of the tmapi-discuss mailing list
* <http://lists.sourceforge.net/mailman/listinfo/tmapi-discuss>,
* is hereby released into the public domain; and comes with
Modified: trunk/src/test/java/org/tmapi/core/TestTopic.java
===================================================================
--- trunk/src/test/java/org/tmapi/core/TestTopic.java 2008-08-05 11:25:24 UTC (rev 52)
+++ trunk/src/test/java/org/tmapi/core/TestTopic.java 2008-08-05 11:26:51 UTC (rev 53)
@@ -1,7 +1,5 @@
/*
- * TMAPI 2.0
- *
- * Version 2.0 of the Topic Maps API (TMAPI), created collectively by
+ * The Topic Maps API (TMAPI) was created collectively by
* the membership of the tmapi-discuss mailing list
* <http://lists.sourceforge.net/mailman/listinfo/tmapi-discuss>,
* is hereby released into the public domain; and comes with
@@ -15,6 +13,10 @@
*/
package org.tmapi.core;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+
/**
* Tests against the {@link Topic} interface.
*
@@ -46,4 +48,753 @@
assertTrue("Expected topic set size to decrement for topic map.",
parent.getTopics().isEmpty());
}
+
+ public void testAddSubjectIdentifierIllegal() {
+ Topic topic = createTopic();
+ try {
+ topic.addSubjectIdentifier(null);
+ fail("addSubjectIdentifier(null) is illegal");
+ }
+ catch (Exception ex) {
+ // noop.
+ }
+ }
+
+ public void testAddSubjectLocatorIllegal() {
+ Topic topic = createTopic();
+ try {
+ topic.addSubjectLocator(null);
+ fail("addSubjectLocator(null) is illegal");
+ }
+ catch (Exception ex) {
+ // noop.
+ }
+ }
+
+ public void testSubjectIdentifiers() {
+ final Locator loc1 = createLocator("http://www.example.org/1");
+ final Locator loc2 = createLocator("http://www.example.org/2");
+ final Topic topic = _tm.createTopicBySubjectIdentifier(loc1);
+ assertEquals(1, topic.getSubjectIdentifiers().size());
+ assertTrue(topic.getSubjectIdentifiers().contains(loc1));
+ topic.addSubjectIdentifier(loc2);
+ assertEquals(2, topic.getSubjectIdentifiers().size());
+ assertTrue(topic.getSubjectIdentifiers().contains(loc2));
+ topic.removeSubjectIdentifier(loc1);
+ assertEquals(1, topic.getSubjectIdentifiers().size());
+ assertTrue(topic.getSubjectIdentifiers().contains(loc2));
+ }
+
+ public void testSubjectLocators() {
+ final Locator loc1 = createLocator("http://www.example.org/1");
+ final Locator loc2 = createLocator("http://www.example.org/2");
+ final Topic topic = _tm.createTopicBySubjectLocator(loc1);
+ assertEquals(1, topic.getSubjectLocators().size());
+ assertTrue(topic.getSubjectLocators().contains(loc1));
+ topic.addSubjectLocator(loc2);
+ assertEquals(2, topic.getSubjectLocators().size());
+ assertTrue(topic.getSubjectLocators().contains(loc2));
+ topic.removeSubjectLocator(loc1);
+ assertEquals(1, topic.getSubjectLocators().size());
+ assertTrue(topic.getSubjectLocators().contains(loc2));
+ }
+
+ public void testTopicTypes() {
+ final Topic topic = createTopic();
+ final Topic type1 = createTopic();
+ final Topic type2 = createTopic();
+ assertTrue(topic.getTypes().isEmpty());
+ topic.addType(type1);
+ assertEquals(1, topic.getTypes().size());
+ assertTrue(topic.getTypes().contains(type1));
+ topic.addType(type2);
+ assertEquals(2, topic.getTypes().size());
+ assertTrue(topic.getTypes().contains(type2));
+ topic.removeType(type1);
+ assertEquals(1, topic.getTypes().size());
+ assertTrue(topic.getTypes().contains(type2));
+ topic.removeType(type2);
+ assertTrue(topic.getTypes().isEmpty());
+ }
+
+ public void testAddTypeIllegal() {
+ Topic topic = createTopic();
+ try {
+ topic.addType(null);
+ fail("addType(null) is illegal");
+ }
+ catch (Exception ex) {
+ // noop.
+ }
+ }
+
+ public void testRoleFilter() {
+ final Topic player = createTopic();
+ final Topic type1 = createTopic();
+ final Topic type2 = createTopic();
+ final Topic unusedType = createTopic();
+ final Association assoc = createAssociation();
+ assertEquals(0, player.getRolesPlayed(type1).size());
+ assertEquals(0, player.getRolesPlayed(type2).size());
+ assertEquals(0, player.getRolesPlayed(unusedType).size());
+ final Role role = assoc.createRole(type1, player);
+ assertEquals(1, player.getRolesPlayed(type1).size());
+ assertTrue(player.getRolesPlayed(type1).contains(role));
+ assertEquals(0, player.getRolesPlayed(type2).size());
+ assertEquals(0, player.getRolesPlayed(unusedType).size());
+ role.setType(type2);
+ assertEquals(1, player.getRolesPlayed(type2).size());
+ assertTrue(player.getRolesPlayed(type2).contains(role));
+ assertEquals(0, player.getRolesPlayed(type1).size());
+ assertEquals(0, player.getRolesPlayed(unusedType).size());
+ role.remove();
+ assertEquals(0, player.getRolesPlayed(type1).size());
+ assertEquals(0, player.getRolesPlayed(type2).size());
+ assertEquals(0, player.getRolesPlayed(unusedType).size());
+ }
+
+ public void testRoleFilterIllegal() {
+ final Role role = createRole();
+ final Topic player = role.getPlayer();
+ try {
+ player.getRolesPlayed(null);
+ fail("topic.getRolesPlayed(null) is illegal");
+ }
+ catch (Exception ex) {
+ // noop.
+ }
+ }
+
+ public void testRoleAssociationFilter() {
+ final Topic player = createTopic();
+ final Topic assocType1 = createTopic();
+ final Topic assocType2 = createTopic();
+ final Topic roleType1 = createTopic();
+ final Topic roleType2 = createTopic();
+ final Association assoc = _tm.createAssociation(assocType1);
+ assertEquals(0, player.getRolesPlayed(roleType1, assocType1).size());
+ assertEquals(0, player.getRolesPlayed(roleType1, assocType2).size());
+ assertEquals(0, player.getRolesPlayed(roleType2, assocType1).size());
+ assertEquals(0, player.getRolesPlayed(roleType2, assocType2).size());
+ final Role role1 = assoc.createRole(roleType1, player);
+ assertEquals(1, player.getRolesPlayed(roleType1, assocType1).size());
+ assertTrue(player.getRolesPlayed(roleType1, assocType1).contains(role1));
+ assertEquals(0, player.getRolesPlayed(roleType1, assocType2).size());
+ assertEquals(0, player.getRolesPlayed(roleType2, assocType1).size());
+ assertEquals(0, player.getRolesPlayed(roleType2, assocType2).size());
+ final Role role2 = assoc.createRole(roleType2, player);
+ assertEquals(1, player.getRolesPlayed(roleType1, assocType1).size());
+ assertTrue(player.getRolesPlayed(roleType1, assocType1).contains(role1));
+ assertEquals(0, player.getRolesPlayed(roleType1, assocType2).size());
+ assertEquals(1, player.getRolesPlayed(roleType2, assocType1).size());
+ assertTrue(player.getRolesPlayed(roleType2, assocType1).contains(role2));
+ assertEquals(0, player.getRolesPlayed(roleType2, assocType2).size());
+ role2.setType(roleType1);
+ assertEquals(2, player.getRolesPlayed(roleType1, assocType1).size());
+ assertTrue(player.getRolesPlayed(roleType1, assocType1).contains(role1));
+ assertTrue(player.getRolesPlayed(roleType1, assocType1).contains(role2));
+ assertEquals(0, player.getRolesPlayed(roleType1, assocType2).size());
+ assertEquals(0, player.getRolesPlayed(roleType2, assocType1).size());
+ assertEquals(0, player.getRolesPlayed(roleType2, assocType2).size());
+ role1.remove();
+ assertEquals(1, player.getRolesPlayed(roleType1, assocType1).size());
+ assertTrue(player.getRolesPlayed(roleType1, assocType1).contains(role2));
+ assertEquals(0, player.getRolesPlayed(roleType1, assocType2).size());
+ assertEquals(0, player.getRolesPlayed(roleType2, assocType1).size());
+ assertEquals(0, player.getRolesPlayed(roleType2, assocType2).size());
+ assoc.remove();
+ assertEquals(0, player.getRolesPlayed(roleType1, assocType1).size());
+ assertEquals(0, player.getRolesPlayed(roleType1, assocType2).size());
+ assertEquals(0, player.getRolesPlayed(roleType2, assocType1).size());
+ assertEquals(0, player.getRolesPlayed(roleType2, assocType2).size());
+ }
+
+ public void testRoleAssociationFilterIllegalAssociation() {
+ final Role role = createRole();
+ final Topic player = role.getPlayer();
+ try {
+ player.getRolesPlayed(role.getType(), null);
+ fail("topic.getRolesPlayed(type, null) is illegal");
+ }
+ catch (Exception ex) {
+ // noop.
+ }
+ }
+
+ public void testRoleAssociationFilterIllegalRole() {
+ final Role role = createRole();
+ final Topic player = role.getPlayer();
+ try {
+ player.getRolesPlayed(null, role.getParent().getType());
+ fail("topic.getRolesPlayed(null, type) is illegal");
+ }
+ catch (Exception ex) {
+ // noop.
+ }
+ }
+
+ public void testOccurrenceFilter() {
+ final Topic topic = createTopic();
+ final Topic type = createTopic();
+ final Topic type2 = createTopic();
+ final Topic unusedType = createTopic();
+ assertEquals(0, topic.getOccurrences(type).size());
+ assertEquals(0, topic.getOccurrences(type2).size());
+ assertEquals(0, topic.getOccurrences(unusedType).size());
+ final Occurrence occ = topic.createOccurrence(type, "Occurrence");
+ assertEquals(1, topic.getOccurrences(type).size());
+ assertTrue(topic.getOccurrences(type).contains(occ));
+ assertEquals(0, topic.getOccurrences(type2).size());
+ assertEquals(0, topic.getOccurrences(unusedType).size());
+ occ.setType(type2);
+ assertEquals(1, topic.getOccurrences(type2).size());
+ assertTrue(topic.getOccurrences(type2).contains(occ));
+ assertEquals(0, topic.getOccurrences(type).size());
+ assertEquals(0, topic.getOccurrences(unusedType).size());
+ occ.remove();
+ assertEquals(0, topic.getOccurrences(type).size());
+ assertEquals(0, topic.getOccurrences(type2).size());
+ assertEquals(0, topic.getOccurrences(unusedType).size());
+ }
+
+ public void testOccurrenceFilterIllegal() {
+ final Occurrence occ = createOccurrence();
+ final Topic parent = occ.getParent();
+ try {
+ parent.getOccurrences(null);
+ fail("topic.getOccurrences(null) is illegal");
+ }
+ catch (Exception ex) {
+ // noop.
+ }
+ }
+
+ public void testNameFilter() {
+ final Topic topic = createTopic();
+ final Topic type = createTopic();
+ final Topic type2 = createTopic();
+ final Topic unusedType = createTopic();
+ assertEquals(0, topic.getNames(type).size());
+ assertEquals(0, topic.getNames(type2).size());
+ assertEquals(0, topic.getNames(unusedType).size());
+ final Name occ = topic.createName(type, "Name");
+ assertEquals(1, topic.getNames(type).size());
+ assertTrue(topic.getNames(type).contains(occ));
+ assertEquals(0, topic.getNames(type2).size());
+ assertEquals(0, topic.getNames(unusedType).size());
+ occ.setType(type2);
+ assertEquals(1, topic.getNames(type2).size());
+ assertTrue(topic.getNames(type2).contains(occ));
+ assertEquals(0, topic.getNames(type).size());
+ assertEquals(0, topic.getNames(unusedType).size());
+ occ.remove();
+ assertEquals(0, topic.getNames(type).size());
+ assertEquals(0, topic.getNames(type2).size());
+ assertEquals(0, topic.getNames(unusedType).size());
+ }
+
+ public void testNameFilterIllegal() {
+ final Name name = createName();
+ final Topic parent = name.getParent();
+ try {
+ parent.getNames(null);
+ fail("topic.getNames(null) is illegal");
+ }
+ catch (Exception ex) {
+ // noop.
+ }
+ }
+
+ public void testOccurrenceCreationTypeString() {
+ final Topic topic = createTopic();
+ final Topic type = createTopic();
+ final String value = "Occurrence";
+ final Locator dt = createLocator("http://www.w3.org/2001/XMLSchema#string");
+ assertEquals(0, topic.getOccurrences().size());
+ final Occurrence occ = topic.createOccurrence(type, value);
+ assertEquals(1, topic.getOccurrences().size());
+ assertTrue(topic.getOccurrences().contains(occ));
+ assertTrue(occ.getScope().isEmpty());
+ assertEquals(type, occ.getType());
+ assertEquals(value, occ.getValue());
+ assertEquals(dt, occ.getDatatype());
+ assertTrue(occ.getItemIdentifiers().isEmpty());
+ }
+
+ public void testOccurrenceCreationTypeURI() {
+ final Topic topic = createTopic();
+ final Topic type = createTopic();
+ final Locator value = createLocator("http://www.example.org/");
+ final Locator dt = createLocator("http://www.w3.org/2001/XMLSchema#anyURI");
+ assertEquals(0, topic.getOccurrences().size());
+ final Occurrence occ = topic.createOccurrence(type, value);
+ assertEquals(1, topic.getOccurrences().size());
+ assertTrue(topic.getOccurrences().contains(occ));
+ assertTrue(occ.getScope().isEmpty());
+ assertEquals(type, occ.getType());
+ assertEquals(value.getReference(), occ.getValue());
+ assertEquals(value, occ.locatorValue());
+ assertEquals(dt, occ.getDatatype());
+ assertTrue(occ.getItemIdentifiers().isEmpty());
+ }
+
+ public void testOccurrenceCreationTypeExplicitDatatype() {
+ final Topic topic = createTopic();
+ final Topic type = createTopic();
+ final String value = "Occurrence";
+ final Locator dt = createLocator("http://www.example.org/datatype");
+ assertEquals(0, topic.getOccurrences().size());
+ final Occurrence occ = topic.createOccurrence(type, value, dt);
+ assertEquals(1, topic.getOccurrences().size());
+ assertTrue(topic.getOccurrences().contains(occ));
+ assertTrue(occ.getScope().isEmpty());
+ assertEquals(type, occ.getType());
+ assertEquals(value, occ.getValue());
+ assertEquals(dt, occ.getDatatype());
+ assertTrue(occ.getItemIdentifiers().isEmpty());
+ }
+
+ public void testOccurrenceCreationTypeScopeArrayString() {
+ final Topic topic = createTopic();
+ final Topic type = createTopic();
+ final Topic theme1 = createTopic();
+ final Topic theme2 = createTopic();
+ final String value = "Occurrence";
+ final Locator dt = createLocator("http://www.w3.org/2001/XMLSchema#string");
+ assertEquals(0, topic.getOccurrences().size());
+ final Occurrence occ = topic.createOccurrence(type, value, theme1, theme2);
+ assertEquals(1, topic.getOccurrences().size());
+ assertTrue(topic.getOccurrences().contains(occ));
+ assertEquals(2, occ.getScope().size());
+ assertTrue(occ.getScope().contains(theme1));
+ assertTrue(occ.getScope().contains(theme2));
+ assertEquals(type, occ.getType());
+ assertEquals(value, occ.getValue());
+ assertEquals(dt, occ.getDatatype());
+ assertTrue(occ.getItemIdentifiers().isEmpty());
+ }
+
+ public void testOccurrenceCreationTypeScopeArrayURI() {
+ final Topic topic = createTopic();
+ final Topic type = createTopic();
+ final Topic theme1 = createTopic();
+ final Topic theme2 = createTopic();
+ final Locator value = createLocator("http://www.example.org/");
+ final Locator dt = createLocator("http://www.w3.org/2001/XMLSchema#anyURI");
+ assertEquals(0, topic.getOccurrences().size());
+ final Occurrence occ = topic.createOccurrence(type, value, theme1, theme2);
+ assertEquals(1, topic.getOccurrences().size());
+ assertTrue(topic.getOccurrences().contains(occ));
+ assertEquals(2, occ.getScope().size());
+ assertTrue(occ.getScope().contains(theme1));
+ assertTrue(occ.getScope().contains(theme2));
+ assertEquals(type, occ.getType());
+ assertEquals(value.getReference(), occ.getValue());
+ assertEquals(value, occ.locatorValue());
+ assertEquals(dt, occ.getDatatype());
+ assertTrue(occ.getItemIdentifiers().isEmpty());
+ }
+
+ public void testOccurrenceCreationTypeScopeArrayExplicitDatatype() {
+ final Topic topic = createTopic();
+ final Topic type = createTopic();
+ final Topic theme1 = createTopic();
+ final Topic theme2 = createTopic();
+ final String value = "Occurrence";
+ final Locator dt = createLocator("http://www.example.org/datatype");
+ assertEquals(0, topic.getOccurrences().size());
+ final Occurrence occ = topic.createOccurrence(type, value, dt, theme1, theme2);
+ assertEquals(1, topic.getOccurrences().size());
+ assertTrue(topic.getOccurrences().contains(occ));
+ assertEquals(2, occ.getScope().size());
+ assertTrue(occ.getScope().contains(theme1));
+ assertTrue(occ.getScope().contains(theme2));
+ assertEquals(type, occ.getType());
+ assertEquals(value, occ.getValue());
+ assertEquals(dt, occ.getDatatype());
+ assertTrue(occ.getItemIdentifiers().isEmpty());
+ }
+
+ public void testOccurrenceCreationTypeScopeCollectionString() {
+ final Topic topic = createTopic();
+ final Topic type = createTopic();
+ final Topic theme1 = createTopic();
+ final Topic theme2 = createTopic();
+ final String value = "Occurrence";
+ final Locator dt = createLocator("http://www.w3.org/2001/XMLSchema#string");
+ assertEquals(0, topic.getOccurrences().size());
+ final Occurrence occ = topic.createOccurrence(type, value, Arrays.asList(theme1, theme2));
+ assertEquals(1, topic.getOccurrences().size());
+ assertTrue(topic.getOccurrences().contains(occ));
+ assertEquals(2, occ.getScope().size());
+ assertTrue(occ.getScope().contains(theme1));
+ assertTrue(occ.getScope().contains(theme2));
+ assertEquals(type, occ.getType());
+ assertEquals(value, occ.getValue());
+ assertEquals(dt, occ.getDatatype());
+ assertTrue(occ.getItemIdentifiers().isEmpty());
+ }
+
+ public void testOccurrenceCreationTypeScopeCollectionURI() {
+ final Topic topic = createTopic();
+ final Topic type = createTopic();
+ final Topic theme1 = createTopic();
+ final Topic theme2 = createTopic();
+ final Locator value = createLocator("http://www.example.org/");
+ final Locator dt = createLocator("http://www.w3.org/2001/XMLSchema#anyURI");
+ assertEquals(0, topic.getOccurrences().size());
+ final Occurrence occ = topic.createOccurrence(type, value, Arrays.asList(theme1, theme2));
+ assertEquals(1, topic.getOccurrences().size());
+ assertTrue(topic.getOccurrences().contains(occ));
+ assertEquals(2, occ.getScope().size());
+ assertTrue(occ.getScope().contains(theme1));
+ assertTrue(occ.getScope().contains(theme2));
+ assertEquals(type, occ.getType());
+ assertEquals(value.getReference(), occ.getValue());
+ assertEquals(value, occ.locatorValue());
+ assertEquals(dt, occ.getDatatype());
+ assertTrue(occ.getItemIdentifiers().isEmpty());
+ }
+
+ public void testOccurrenceCreationTypeScopeCollectionExplicitDatatype() {
+ final Topic topic = createTopic();
+ final Topic type = createTopic();
+ final Topic theme1 = createTopic();
+ final Topic theme2 = createTopic();
+ final String value = "Occurrence";
+ final Locator dt = createLocator("http://www.example.org/datatype");
+ assertEquals(0, topic.getOccurrences().size());
+ final Occurrence occ = topic.createOccurrence(type, value, dt, Arrays.asList(theme1, theme2));
+ assertEquals(1, topic.getOccurrences().size());
+ assertTrue(topic.getOccurrences().contains(occ));
+ assertEquals(2, occ.getScope().size());
+ assertTrue(occ.getScope().contains(theme1));
+ assertTrue(occ.getScope().contains(theme2));
+ assertEquals(type, occ.getType());
+ assertEquals(value, occ.getValue());
+ assertEquals(dt, occ.getDatatype());
+ assertTrue(occ.getItemIdentifiers().isEmpty());
+ }
+
+ public void testOccurrenceCreationTypeIllegalString() {
+ final Topic topic = createTopic();
+ try {
+ topic.createOccurrence(createTopic(), (String)null);
+ fail("createOccurrence(topic, (String)null) is illegal");
+ }
+ catch (Exception ex) {
+ // noop.
+ }
+ }
+
+ public void testOccurrenceCreationTypeIllegalURI() {
+ final Topic topic = createTopic();
+ try {
+ topic.createOccurrence(createTopic(), (Locator)null);
+ fail("createOccurrence(topic, (Locator)null) is illegal");
+ }
+ catch (Exception ex) {
+ // noop.
+ }
+ }
+
+ public void testOccurrenceCreationTypeIllegalDatatype() {
+ final Topic topic = createTopic();
+ try {
+ topic.createOccurrence(createTopic(), "Occurrence", (Locator)null);
+ fail("createOccurrence(topic, \"Occurrence\", (Locator)null) is illegal");
+ }
+ catch (Exception ex) {
+ // noop.
+ }
+ }
+
+ public void testOccurrenceCreationIllegalType() {
+ final Topic topic = createTopic();
+ try {
+ topic.createOccurrence(null, "Occurrence");
+ fail("createOccurrence(null, \"Occurrence\" is illegal");
+ }
+ catch (Exception ex) {
+ // noop.
+ }
+ }
+
+ public void testOccurrenceCreationTypeIllegalScopeArray() {
+ final Topic topic = createTopic();
+ try {
+ topic.createOccurrence(createTopic(), "Occurrence", (Topic[])null);
+ fail("createOccurrence(topic, \"Occurrence\", (Topic[])null) is illegal");
+ }
+ catch (Exception ex) {
+ // noop.
+ }
+ }
+
+ public void testOccurrenceCreationTypeIllegalScopeCollection() {
+ final Topic topic = createTopic();
+ try {
+ topic.createOccurrence(createTopic(), "Occurrence", (Collection<Topic>)null);
+ fail("createOccurrence(topic, \"Occurrence\", (Collection<Topic>)null) is illegal");
+ }
+ catch (Exception ex) {
+ // noop.
+ }
+ }
+
+ public void testNameCreationType() {
+ final Topic topic = createTopic();
+ final Topic type = createTopic();
+ final String value = "Name";
+ assertTrue(topic.getNames().isEmpty());
+ final Name name = topic.createName(type, value);
+ assertEquals(1, topic.getNames().size());
+ assertTrue(topic.getNames().contains(name));
+ assertTrue(name.getScope().isEmpty());
+ assertEquals(type, name.getType());
+ assertEquals(value, name.getValue());
+ assertTrue(name.getItemIdentifiers().isEmpty());
+ }
+
+ public void testNameCreationTypeScopeCollection() {
+ final Topic topic = createTopic();
+ final Topic type = createTopic();
+ final Topic theme = createTopic();
+ final String value = "Name";
+ assertTrue(topic.getNames().isEmpty());
+ final Name name = topic.createName(type, value, Collections.singleton(theme));
+ assertEquals(1, topic.getNames().size());
+ assertTrue(topic.getNames().contains(name));
+ assertEquals(1, name.getScope().size());
+ assertTrue(name.getScope().contains(theme));
+ assertEquals(type, name.getType());
+ assertEquals(value, name.getValue());
+ assertTrue(name.getItemIdentifiers().isEmpty());
+ }
+
+ public void testNameCreationTypeScopeArray() {
+ final Topic topic = createTopic();
+ final Topic type = createTopic();
+ final String value = "Name";
+ final Topic theme1 = createTopic();
+ final Topic theme2 = createTopic();
+ assertTrue(topic.getNames().isEmpty());
+ final Name name = topic.createName(type, value, theme1, theme2);
+ assertEquals(1, topic.getNames().size());
+ assertTrue(topic.getNames().contains(name));
+ assertEquals(2, name.getScope().size());
+ assertTrue(name.getScope().contains(theme1));
+ assertTrue(name.getScope().contains(theme2));
+ assertEquals(type, name.getType());
+ assertEquals(value, name.getValue());
+ assertTrue(name.getItemIdentifiers().isEmpty());
+ }
+
+ public void testNameCreationDefaultType() {
+ final Topic topic = createTopic();
+ final String value = "Name";
+ final Locator loc = createLocator("http://psi.topicmaps.org/iso13250/model/topic-name");
+ assertTrue(topic.getNames().isEmpty());
+ final Name name = topic.createName(value);
+ assertEquals(1, topic.getNames().size());
+ assertTrue(topic.getNames().contains(name));
+ assertTrue(name.getScope().isEmpty());
+ assertNotNull(name.getType());
+ assertEquals(value, name.getValue());
+ assertTrue(name.getItemIdentifiers().isEmpty());
+ Topic type = name.getType();
+ assertTrue(type.getSubjectIdentifiers().contains(loc));
+ }
+
+ public void testNameCreationDefaultTypeScopeCollection() {
+ final Topic topic = createTopic();
+ final Topic theme = createTopic();
+ final String value = "Name";
+ final Locator loc = createLocator("http://psi.topicmaps.org/iso13250/model/topic-name");
+ assertTrue(topic.getNames().isEmpty());
+ final Name name = topic.createName(value, Collections.singleton(theme));
+ assertEquals(1, topic.getNames().size());
+ assertTrue(topic.getNames().contains(name));
+ assertEquals(1, name.getScope().size());
+ assertTrue(name.getScope().contains(theme));
+ assertNotNull(name.getType());
+ assertEquals(value, name.getValue());
+ assertTrue(name.getItemIdentifiers().isEmpty());
+ Topic type = name.getType();
+ assertTrue(type.getSubjectIdentifiers().contains(loc));
+ }
+
+ public void testNameCreationDefaultTypeScopeArray() {
+ final Topic topic = createTopic();
+ final Topic theme1 = createTopic();
+ final Topic theme2 = createTopic();
+ final String value = "Name";
+ final Locator loc = createLocator("http://psi.topicmaps.org/iso13250/model/topic-name");
+ assertTrue(topic.getNames().isEmpty());
+ final Name name = topic.createName(value, theme1, theme2);
+ assertEquals(1, topic.getNames().size());
+ assertTrue(topic.getNames().contains(name));
+ assertEquals(2, name.getScope().size());
+ assertTrue(name.getScope().contains(theme1));
+ assertTrue(name.getScope().contains(theme2));
+ assertNotNull(name.getType());
+ assertEquals(value, name.getValue());
+ assertTrue(name.getItemIdentifiers().isEmpty());
+ Topic type = name.getType();
+ assertTrue(type.getSubjectIdentifiers().contains(loc));
+ }
+
+ public void testNameCreationTypeIllegalString() {
+ final Topic topic = createTopic();
+ try {
+ topic.createName(createTopic(), (String)null);
+ fail("createName(topic, null) is illegal");
+ }
+ catch (Exception ex) {
+ // noop.
+ }
+ }
+
+ public void testNameCreationTypeIllegalScopeArray() {
+ final Topic topic = createTopic();
+ try {
+ topic.createName(createTopic(), "Name", (Topic[])null);
+ fail("createName(topic, \"Name\", (Topic[])null) is illegal");
+ }
+ catch (Exception ex) {
+ // noop.
+ }
+ }
+
+ public void testNameCreationTypeIllegalScopeCollection() {
+ final Topic topic = createTopic();
+ try {
+ topic.createName(createTopic(), "Name", (Collection<Topic>)null);
+ fail("createName(topic, \"Name\", (Collection<Topic>)null) is illegal");
+ }
+ catch (Exception ex) {
+ // noop.
+ }
+ }
+
+ public void testNameCreationDefaultTypeIllegalString() {
+ final Topic topic = createTopic();
+ try {
+ topic.createName((String)null);
+ fail("createName(null) is illegal");
+ }
+ catch (Exception ex) {
+ // noop.
+ }
+ }
+
+ public void testNameCreationDefaultTypeIllegalScopeArray() {
+ final Topic topic = createTopic();
+ try {
+ topic.createName("Name", (Topic[])null);
+ fail("createName(\"Name\", (Topic[])null) is illegal");
+ }
+ catch (Exception ex) {
+ // noop.
+ }
+ }
+
+ public void testNameCreationDefaultTypeIllegalScopeCollection() {
+ final Topic topic = createTopic();
+ try {
+ topic.createName("Name", (Collection<Topic>)null);
+ fail("createName(\"Name\", (Collection<Topic>)null) is illegal");
+ }
+ catch (Exception ex) {
+ // noop.
+ }
+ }
+
+ public void testTopicRemovableUsedAsType() {
+ Topic topic = createTopic();
+ assertEquals(1, _tm.getTopics().size());
+ topic.remove();
+ assertEquals(0, _tm.getTopics().size());
+ topic = createTopic();
+ assertEquals(1, _tm.getTopics().size());
+ Association assoc = _tm.createAssociation(topic);
+ try {
+ topic.remove();
+ fail("The topic is used as type");
+ }
+ catch (TopicInUseException ex) {
+ assertEquals(topic, ex.getSender());
+ }
+ assoc.setType(createTopic());
+ assertEquals(2, _tm.getTopics().size());
+ topic.remove();
+ assertEquals(1, _tm.getTopics().size());
+ }
+
+ public void testTopicRemovableUsedAsPlayer() {
+ Topic topic = createTopic();
+ assertEquals(1, _tm.getTopics().size());
+ topic.remove();
+ assertEquals(0, _tm.getTopics().size());
+ topic = createTopic();
+ assertEquals(1, _tm.getTopics().size());
+ Association assoc = createAssociation();
+ assertEquals(2, _tm.getTopics().size());
+ Role role = assoc.createRole(_tm.createTopic(), topic);
+ assertEquals(3, _tm.getTopics().size());
+ try {
+ topic.remove();
+ fail("The topic is used as player");
+ }
+ catch (TopicInUseException ex) {
+ assertEquals(topic, ex.getSender());
+ }
+ role.setPlayer(createTopic());
+ assertEquals(4, _tm.getTopics().size());
+ topic.remove();
+ assertEquals(3, _tm.getTopics().size());
+ }
+
+ public void testRemovableUsedAsTheme() {
+ Topic topic = createTopic();
+ assertEquals(1, _tm.getTopics().size());
+ topic.remove();
+ assertEquals(0, _tm.getTopics().size());
+ topic = createTopic();
+ assertEquals(1, _tm.getTopics().size());
+ Association assoc = _tm.createAssociation(createTopic(), topic);
+ assertEquals(2, _tm.getTopics().size());
+ try {
+ topic.remove();
+ fail("The topic is used as theme");
+ }
+ catch (TopicInUseException ex) {
+ assertEquals(topic, ex.getSender());
+ }
+ assoc.removeTheme(topic);
+ topic.remove();
+ assertEquals(1, _tm.getTopics().size());
+ }
+
+ public void testRemovableUsedAsReifier() {
+ Topic topic = createTopic();
+ assertEquals(1, _tm.getTopics().size());
+ topic.remove();
+ assertEquals(0, _tm.getTopics().size());
+ topic = createTopic();
+ assertEquals(1, _tm.getTopics().size());
+ Association assoc = createAssociation();
+ assertEquals(2, _tm.getTopics().size());
+ assoc.setReifier(topic);
+ try {
+ topic.remove();
+ fail("The topic is used as reifier");
+ }
+ catch (TopicInUseException ex) {
+ assertEquals(topic, ex.getSender());
+ }
+ assoc.setReifier(null);
+ topic.remove();
+ assertEquals(1, _tm.getTopics().size());
+ }
}
Modified: trunk/src/test/java/org/tmapi/core/TestTopicMap.java
===================================================================
--- trunk/src/test/java/org/tmapi/core/TestTopicMap.java 2008-08-05 11:25:24 UTC (rev 52)
+++ trunk/src/test/java/org/tmapi/core/TestTopicMap.java 2008-08-05 11:26:51 UTC (rev 53)
@@ -1,7 +1,5 @@
/*
- * TMAPI 2.0
- *
- * Version 2.0 of the Topic Maps API (TMAPI), created collectively by
+ * The Topic Maps API (TMAPI) was created collectively by
* the membership of the tmapi-discuss mailing list
* <http://lists.sourceforge.net/mailman/listinfo/tmapi-discuss>,
* is hereby released into the public domain; and comes with
@@ -15,6 +13,9 @@
*/
package org.tmapi.core;
+import java.util.Collection;
+import java.util.Collections;
+
/**
* Tests against the {@link TopicMap} interface.
*
@@ -33,4 +34,176 @@
public void testParent() throws Exception {
assertNull("A topic map has no parent", _tm.getParent());
}
+
+ public void testTopicCreationSubjectIdentifier() {
+ final Locator loc = createLocator("http://www.example.org/");
+ assertTrue(_tm.getTopics().isEmpty());
+ final Topic topic = _tm.createTopicBySubjectIdentifier(loc);
+ assertEquals(1, _tm.getTopics().size());
+ assertTrue(_tm.getTopics().contains(topic));
+ assertEquals(1, topic.getSubjectIdentifiers().size());
+ assertTrue(topic.getItemIdentifiers().isEmpty());
+ assertTrue(topic.getSubjectLocators().isEmpty());
+ final Locator loc2 = topic.getSubjectIdentifiers().iterator().next();
+ assertEquals(loc, loc2);
+ }
+
+ public void testTopicCreationSubjectIdentifierIllegal() {
+ try {
+ _tm.createTopicBySubjectIdentifier(null);
+ fail("Subject identifier == null is illegal");
+ }
+ catch (Exception ex) {
+ // noop.
+ }
+ }
+
+ public void testTopicCreationSubjectLocator() {
+ final Locator loc = createLocator("http://www.example.org/");
+ assertTrue(_tm.getTopics().isEmpty());
+ final Topic topic = _tm.createTopicBySubjectLocator(loc);
+ assertEquals(1, _tm.getTopics().size());
+ assertTrue(_tm.getTopics().contains(topic));
+ assertEquals(1, topic.getSubjectLocators().size());
+ assertTrue(topic.getItemIdentifiers().isEmpty());
+ assertTrue(topic.getSubjectIdentifiers().isEmpty());
+ final Locator loc2 = topic.getSubjectLocators().iterator().next();
+ assertEquals(loc, loc2);
+ }
+
+ public void testTopicCreationSubjectLocatorIllegal() {
+ try {
+ _tm.createTopicBySubjectLocator(null);
+ fail("Subject locator == null is illegal");
+ }
+ catch (Exception ex) {
+ // noop.
+ }
+ }
+
+ public void testTopicCreationItemIdentifier() {
+ final Locator loc = createLocator("http://www.example.org/");
+ assertTrue(_tm.getTopics().isEmpty());
+ final Topic topic = _tm.createTopicByItemIdentifier(loc);
+ assertEquals(1, _tm.getTopics().size());
+ assertTrue(_tm.getTopics().contains(topic));
+ assertEquals(1, topic.getItemIdentifiers().size());
+ assertTrue(topic.getSubjectIdentifiers().isEmpty());
+ assertTrue(topic.getSubjectLocators().isEmpty());
+ final Locator loc2 = topic.getItemIdentifiers().iterator().next();
+ assertEquals(loc, loc2);
+ }
+
+ public void testTopicCreationItemIdentifierIllegal() {
+ try {
+ _tm.createTopicByItemIdentifier(null);
+ fail("item identifier == null is illegal");
+ }
+ catch (Exception ex) {
+ // noop.
+ }
+ }
+
+ public void testTopicCreationAutomagicItemIdentifier() {
+ assertTrue(_tm.getTopics().isEmpty());
+ final Topic topic = _tm.createTopic();
+ assertEquals(1, _tm.getTopics().size());
+ assertTrue(_tm.getTopics().contains(topic));
+ assertEquals(1, topic.getItemIdentifiers().size());
+ assertTrue(topic.getSubjectIdentifiers().isEmpty());
+ assertTrue(topic.getSubjectLocators().isEmpty());
+ }
+
+ public void testTopicBySubjectIdentifier() {
+ final Locator loc = createLocator("http://www.example.org/");
+ Topic t = _tm.getTopicBySubjectIdentifier(loc);
+ assertNull(t);
+ final Topic topic = _tm.createTopicBySubjectIdentifier(loc);
+ t = _tm.getTopicBySubjectIdentifier(loc);
+ assertNotNull(t);
+ assertEquals(topic, t);
+ topic.remove();
+ t = _tm.getTopicBySubjectIdentifier(loc);
+ assertNull(t);
+ }
+
+ public void testTopicBySubjectLocator() {
+ final Locator loc = createLocator("http://www.example.org/");
+ Topic t = _tm.getTopicBySubjectLocator(loc);
+ assertNull(t);
+ final Topic topic = _tm.createTopicBySubjectLocator(loc);
+ t = _tm.getTopicBySubjectLocator(loc);
+ assertNotNull(t);
+ assertEquals(topic, t);
+ topic.remove();
+ t = _tm.getTopicBySubjectLocator(loc);
+ assertNull(t);
+ }
+
+ public void testAssociationCreationType() {
+ final Topic type = createTopic();
+ assertTrue(_tm.getAssociations().isEmpty());
+ final Association assoc = _tm.createAssociation(type);
+ assertEquals(1, _tm.getAssociations().size());
+ assertTrue(_tm.getAssociations().contains(assoc));
+ assertTrue(assoc.getRoles().isEmpty());
+ assertEquals(type, assoc.getType());
+ assertTrue(assoc.getScope().isEmpty());
+ }
+
+ public void testAssociationCreationTypeScopeCollection() {
+ final Topic type = createTopic();
+ final Topic theme = createTopic();
+ assertTrue(_tm.getAssociations().isEmpty());
+ final Association assoc = _tm.createAssociation(type, Collections.singleton(theme));
+ assertEquals(1, _tm.getAssociations().size());
+ assertTrue(_tm.getAssociations().contains(assoc));
+ assertTrue(assoc.getRoles().isEmpty());
+ assertEquals(type, assoc.getType());
+ assertEquals(1, assoc.getScope().size());
+ assertTrue(assoc.getScope().contains(theme));
+ }
+
+ public void testAssociationCreationTypeScopeArray() {
+ final Topic type = createTopic();
+ final Topic theme = createTopic();
+ final Topic theme2 = createTopic();
+ assertTrue(_tm.getAssociations().isEmpty());
+ final Association assoc = _tm.createAssociation(type, theme, theme2);
+ assertEquals(1, _tm.getAssociations().size());
+ assertTrue(_tm.getAssociations().contains(assoc));
+ assertTrue(assoc.getRoles().isEmpty());
+ assertEquals(type, assoc.getType());
+ assertEquals(2, assoc.getScope().size());
+ assertTrue(assoc.getScope().contains(theme));
+ assertTrue(assoc.getScope().contains(theme2));
+ }
+
+ public void testAssociationCreationIllegalType() {
+ try {
+ _tm.createAssociation(null);
+ fail("Creating an association with type == null is not allowed");
+ }
+ catch (Exception ex) {
+ // noop.
+ }
+ }
+
+ public void testAssociationCreationIllegalNullScope() {
+ try {
+ _tm.createAssociation(createTopic(), (Topic[])null);
+ fail("Creating an association with scope == null is not allowed");
+ }
+ catch (Exception ex) {
+ // noop.
+ }
+ try {
+ _tm.createAssociation(createTopic(), (Collection<Topic>)null);
+ fail("Creating an association with scope == (Collection) null is not allowed");
+ }
+ catch (Exception ex) {
+ // noop.
+ }
+ }
+
}
Modified: trunk/src/test/java/org/tmapi/core/TestTopicMapMerge.java
===================================================================
--- trunk/src/test/java/org/tmapi/core/TestTopicMapMerge.java 2008-08-05 11:25:24 UTC (rev 52)
+++ trunk/src/test/java/org/tmapi/core/TestTopicMapMerge.java 2008-08-05 11:26:51 UTC (rev 53)
@@ -1,7 +1,5 @@
/*
- * TMAPI 2.0
- *
- * Version 2.0 of the Topic Maps API (TMAPI), created collectively by
+ * The Topic Maps API (TMAPI) was created collectively by
* the membership of the tmapi-discuss mailing list
* <http://lists.sourceforge.net/mailman/listinfo/tmapi-discuss>,
* is hereby released into the public domain; and comes with
Modified: trunk/src/test/java/org/tmapi/core/TestTopicMapSystem.java
===================================================================
--- trunk/src/test/java/org/tmapi/core/TestTopicMapSystem.java 2008-08-05 11:25:24 UTC (rev 52)
+++ trunk/src/test/java/org/tmapi/core/TestTopicMapSystem.java 2008-08-05 11:26:51 UTC (rev 53)
@@ -1,7 +1,5 @@
/*
- * TMAPI 2.0
- *
- * Version 2.0 of the Topic Maps API (TMAPI), created collectively by
+ * The Topic Maps API (TMAPI) was created collectively by
* the membership of the tmapi-discuss mailing list
* <http://lists.sourceforge.net/mailman/listinfo/tmapi-discuss>,
* is hereby released into the public domain; and comes with
Modified: trunk/src/test/java/org/tmapi/core/TestTopicMerge.java
===================================================================
--- trunk/src/test/java/org/tmapi/core/TestTopicMerge.java 2008-08-05 11:25:24 UTC (rev 52)
+++ trunk/src/test/java/org/tmapi/core/TestTopicMerge.java 2008-08-05 11:26:51 UTC (rev 53)
@@ -1,7 +1,5 @@
/*
- * TMAPI 2.0
- *
- * Version 2.0 of the Topic Maps API (TMAPI), created collectively by
+ * The Topic Maps API (TMAPI) was created collectively by
* the membership of the tmapi-discuss mailing list
* <http://lists.sourceforge.net/mailman/listinfo/tmapi-discuss>,
* is hereby released into the public domain; and comes with
Modified: trunk/src/test/java/org/tmapi/core/TestTopicMergeDetection.java
===================================================================
--- trunk/src/test/java/org/tmapi/core/TestTopicMergeDetection.java 2008-08-05 11:25:24 UTC (rev 52)
+++ trunk/src/test/java/org/tmapi/core/TestTopicMergeDetection.java 2008-08-05 11:26:51 UTC (rev 53)
@@ -1,7 +1,5 @@
/*
- * TMAPI 2.0
- *
- * Version 2.0 of the Topic Maps API (TMAPI), created collectively by
+ * The Topic Maps API (TMAPI) was created collectively by
* the membership of the tmapi-discuss mailing list
* <http://lists.sourceforge.net/mailman/listinfo/tmapi-discuss>,
* is hereby released into the public domain; and comes with
Modified: trunk/src/test/java/org/tmapi/core/TestTyped.java
===================================================================
--- trunk/src/test/java/org/tmapi/core/TestTyped.java 2008-08-05 11:25:24 UTC (rev 52)
+++ trunk/src/test/java/org/tmapi/core/TestTyped.java 2008-08-05 11:26:51 UTC (rev 53)
@@ -1,7 +1,5 @@
/*
- * TMAPI 2.0
- *
- * Version 2.0 of the Topic Maps API (TMAPI), created collectively by
+ * The Topic Maps API (TMAPI) was created collectively by
* the membership of the ...
[truncated message content] |