|
From: <lh...@us...> - 2008-04-29 13:15:55
|
Revision: 51
http://tinytim.svn.sourceforge.net/tinytim/?rev=51&view=rev
Author: lheuer
Date: 2008-04-29 06:15:34 -0700 (Tue, 29 Apr 2008)
Log Message:
-----------
- Minor bug fixes
- More tests
Modified Paths:
--------------
tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java
tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.java
Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java
===================================================================
--- tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java 2008-04-28 18:42:12 UTC (rev 50)
+++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java 2008-04-29 13:15:34 UTC (rev 51)
@@ -27,6 +27,7 @@
import org.tinytim.IReifiable;
import org.tinytim.ITyped;
import org.tinytim.TopicMapImpl;
+import org.tinytim.TypeInstanceConverter;
import org.tmapi.core.Association;
import org.tmapi.core.AssociationRole;
import org.tmapi.core.Locator;
@@ -65,6 +66,14 @@
private int _stackPointer;
private List<TopicMapObject> _constructStack;
+ public MapInputHandler() {
+ }
+
+ public MapInputHandler(TopicMap topicMap) {
+ this();
+ setTopicMap(topicMap);
+ }
+
/**
* Sets the topic map instance to operate on.
*
@@ -91,7 +100,7 @@
if (_state() != State.INITIAL) {
LOG.warning("The topic map import seems to be unfinished due to errors");
}
- //TODO: Convert type-instance assocs.
+ TypeInstanceConverter.convertAssociationsToTypes(_tm);
_constructStack = null;
_stateStack = null;
_tm = null;
@@ -354,7 +363,7 @@
*/
public void value(String value, String datatype) throws MIOException {
boolean isLocator = _XSD_ANY_URI.equals(datatype);
- if (!isLocator && _XSD_STRING.equals(datatype)) {
+ if (!isLocator && !_XSD_STRING.equals(datatype)) {
LOG.warning("The datatype '" + datatype + "' was converted into xsd:string");
}
if (_state() == State.OCCURRENCE) {
Modified: tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.java
===================================================================
--- tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.java 2008-04-28 18:42:12 UTC (rev 50)
+++ tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.java 2008-04-29 13:15:34 UTC (rev 51)
@@ -22,6 +22,8 @@
import org.tinytim.Property;
import org.tinytim.TopicMapImpl;
+import org.tmapi.core.Locator;
+import org.tmapi.core.Occurrence;
import org.tmapi.core.Topic;
import org.tmapi.core.TopicMapSystem;
import org.tmapi.core.TopicMapSystemFactory;
@@ -39,6 +41,9 @@
*/
public class TestMapInputHandler extends TestCase {
+ private static final String _XSD_STRING = "http://www.w3.org/2001/XMLSchema#string";
+ private static final String _XSD_ANY_URI = "http://www.w3.org/2001/XMLSchema#anyURI";
+
private TopicMapImpl _tm;
private MapInputHandler _handler;
@@ -55,6 +60,9 @@
_handler.setTopicMap(_tm);
}
+ /**
+ * Simple startTopicMap, followed by an endTopicMap event.
+ */
public void testEmpty() throws Exception {
assertEquals(0, _tm.getTopics().size());
assertEquals(0, _tm.getAssociations().size());
@@ -64,6 +72,9 @@
assertEquals(0, _tm.getAssociations().size());
}
+ /**
+ * Tests topic creation with an item identifier.
+ */
public void testTopicIdentityItemIdentifier() throws Exception {
String itemIdent = "http://sf.net/projects/tinytim/test#1";
_handler.startTopicMap();
@@ -75,6 +86,9 @@
assertNotNull(topic);
}
+ /**
+ * Tests topic creation with a subject identifier.
+ */
public void testTopicIdentitySubjectIdentifier() throws Exception {
String subjIdent = "http://sf.net/projects/tinytim/test#1";
_handler.startTopicMap();
@@ -86,6 +100,9 @@
assertNotNull(topic);
}
+ /**
+ * Tests topic creation with a subject locator.
+ */
public void testTopicIdentitySubjectLocator() throws Exception {
String subjLoc = "http://sf.net/projects/tinytim/test#1";
_handler.startTopicMap();
@@ -97,11 +114,15 @@
assertNotNull(topic);
}
- public void testTopicMerging1() throws Exception {
+ /**
+ * Tests transparent merging.
+ */
+ public void testTopicMerging() throws Exception {
String ref = "http://sf.net/projects/tinytim/test#1";
String itemIdent = "http://example.org/1";
_handler.startTopicMap();
_handler.startTopic(Ref.createSubjectIdentifier(ref));
+ // Topic in topic event
_handler.startTopic(Ref.createItemIdentifier(itemIdent));
_handler.itemIdentifier(ref);
_handler.endTopic();
@@ -120,6 +141,43 @@
assertEquals("tinyTiM", name.getValue());
}
+ /**
+ * Tests assigning identities to a topic.
+ */
+ public void testTopicIdentities1() throws Exception {
+ String ref = "http://sf.net/projects/tinytim/test#1";
+ _handler.startTopicMap();
+ _handler.startTopic(Ref.createSubjectIdentifier(ref));
+ _handler.itemIdentifier(ref);
+ _handler.endTopic();
+ _handler.endTopicMap();
+ assertEquals(1, _tm.getTopics().size());
+ Locator loc = _tm.createLocator(ref);
+ Topic topic = _tm.getTopicBySubjectIdentifier(loc);
+ assertNotNull(topic);
+ assertEquals(topic, _tm.getObjectByItemIdentifier(loc));
+ }
+
+ /**
+ * Tests assigning identities to a topic.
+ */
+ public void testTopicIdentities2() throws Exception {
+ String ref = "http://sf.net/projects/tinytim/test#1";
+ _handler.startTopicMap();
+ _handler.startTopic(Ref.createItemIdentifier(ref));
+ _handler.subjectIdentifier(ref);
+ _handler.endTopic();
+ _handler.endTopicMap();
+ assertEquals(1, _tm.getTopics().size());
+ Locator loc = _tm.createLocator(ref);
+ Topic topic = _tm.getTopicBySubjectIdentifier(loc);
+ assertNotNull(topic);
+ assertEquals(topic, _tm.getObjectByItemIdentifier(loc));
+ }
+
+ /**
+ * Tests reifying the topic map.
+ */
public void testTopicMapReifier() throws Exception {
String ref = "http://sf.net/projects/tinytim/test#1";
_handler.startTopicMap();
@@ -134,4 +192,43 @@
assertEquals(topic, _tm.getReifier());
}
+ /**
+ * Tests occurrence creation with a value of datatype xsd:string.
+ */
+ public void testOccurrenceValueString() throws Exception {
+ String ref = "http://sf.net/projects/tinytim/test#1";
+ String val = "tinyTiM";
+ _handler.startTopicMap();
+ _handler.startTopic(Ref.createSubjectIdentifier(ref));
+ _handler.startOccurrence();
+ _handler.value(val, _XSD_STRING);
+ _handler.endOccurrence();
+ _handler.endTopic();
+ _handler.endTopicMap();
+ Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(ref));
+ assertNotNull(topic);
+ Occurrence occ = (Occurrence) topic.getOccurrences().iterator().next();
+ assertEquals(val, occ.getValue());
+ }
+
+ /**
+ * Tests occurrence creation with a value of datatype xsd:anyURI.
+ */
+ public void testOccurrenceValueURI() throws Exception {
+ String ref = "http://sf.net/projects/tinytim/test#1";
+ String val = "http://sf.net/projects/tinytim";
+ _handler.startTopicMap();
+ _handler.startTopic(Ref.createSubjectIdentifier(ref));
+ _handler.startOccurrence();
+ _handler.value(val, _XSD_ANY_URI);
+ _handler.endOccurrence();
+ _handler.endTopic();
+ _handler.endTopicMap();
+ Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(ref));
+ assertNotNull(topic);
+ Occurrence occ = (Occurrence) topic.getOccurrences().iterator().next();
+ assertNull(occ.getValue());
+ assertEquals(val, occ.getResource().getReference());
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|