From: <lh...@us...> - 2009-07-22 08:33:22
|
Revision: 318 http://tinytim.svn.sourceforge.net/tinytim/?rev=318&view=rev Author: lheuer Date: 2009-07-22 08:33:17 +0000 (Wed, 22 Jul 2009) Log Message: ----------- - Added MapHander test case to AllTests - MapHandler checks for invalid names / variants (no value) - Updated TMAPI tests Modified Paths: -------------- tinytim/trunk/lib/tmapi-2.0a2-tests.jar tinytim/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java tinytim/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java Modified: tinytim/trunk/lib/tmapi-2.0a2-tests.jar =================================================================== (Binary files differ) Modified: tinytim/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java 2009-07-21 15:03:43 UTC (rev 317) +++ tinytim/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java 2009-07-22 08:33:17 UTC (rev 318) @@ -216,6 +216,9 @@ @Override public void endName() throws MIOException { IName name = (IName) _leaveStatePopConstruct(NAME); + if (name.getLiteral() == null) { + throw new MIOException("The name '" + name + "' has no value"); + } if (name.getType() == null) { name.setType(_tm.createTopicBySubjectIdentifier(TMDM.TOPIC_NAME)); } @@ -237,6 +240,9 @@ @Override public void endVariant() throws MIOException { IVariant variant = (IVariant) _leaveStatePopConstruct(VARIANT); + if (variant.getLiteral() == null) { + throw new MIOException("The variant '" + variant + "' has no value"); + } IName name = (IName) _peekConstruct(); IScope scope = variant.getScopeObject(); if (scope.isUnconstrained() || name.getScopeObject().equals(scope)) { @@ -604,8 +610,7 @@ private void _handleReifier(Reifiable reifiable, Topic reifier) throws MIOException { final Reifiable reified = reifier.getReified(); if (reified != null && !reifiable.equals(reified)) { - if (!_sameConstructKind((IConstruct) reifiable, (IConstruct) reified) - || !_areMergable((IConstruct) reifiable, (IConstruct) reified)) { + if (!_areMergable((IConstruct) reifiable, (IConstruct) reified)) { throw new MIOException("The topic " + reifier + " reifies another construct"); } // The construct reified by 'reifier' has the same parent as the @@ -619,6 +624,14 @@ } } + /** + * Returns if <tt>a</tt> and <tt>b</tt> represent the same information + * item (i.e. both are associations). + * + * @param a A Topic Maps construct. + * @param b A Topic Maps construct. + * @return <tt>true</tt> if they represent the same information item, otherwise <tt>false</tt>. + */ private boolean _sameConstructKind(IConstruct a, IConstruct b) { return a.isAssociation() && b.isAssociation() || a.isName() && b.isName() @@ -630,9 +643,10 @@ } private boolean _areMergable(IConstruct a, IConstruct b) { - return a.isRole() && b.isRole() - || (a.isVariant() && b.isVariant() && a.getParent().getParent().equals(b.getParent().getParent())) - || a.getParent().equals(b.getParent()); + return _sameConstructKind(a, b) + && (a.isRole() && b.isRole() + || (a.isVariant() && b.isVariant() && a.getParent().getParent().equals(b.getParent().getParent())) + || a.getParent().equals(b.getParent())); } /** Modified: tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java 2009-07-21 15:03:43 UTC (rev 317) +++ tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java 2009-07-22 08:33:17 UTC (rev 318) @@ -19,6 +19,7 @@ import org.tinytim.core.value.TestLiteralNormalizer; import org.tinytim.core.value.TestLocatorImpl; import org.tinytim.internal.utils.TestSignatureGenerator; +import org.tinytim.mio.TestTinyTimMapInputHandler; import org.tinytim.utils.TestDuplicateRemovalUtils; import org.tinytim.utils.TestTopicUtils; @@ -45,6 +46,7 @@ suite.addTestSuite(TestIConstructFactory.class); suite.addTestSuite(TestScope.class); suite.addTestSuite(TestLiteral.class); + suite.addTestSuite(TestTinyTimMapInputHandler.class); suite.addTestSuite(TestLiteralNormalizer.class); suite.addTestSuite(TestSignatureGenerator.class); suite.addTest(TestTMAPICore.suite()); Modified: tinytim/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java 2009-07-21 15:03:43 UTC (rev 317) +++ tinytim/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java 2009-07-22 08:33:17 UTC (rev 318) @@ -51,6 +51,44 @@ _handler = new TinyTimMapInputHandler(_tm); } + public void testVariantNoValue() throws Exception { + final IRef theTopic = Ref.createItemIdentifier("http://test.semagia.com/the-topic"); + final IRef theme = Ref.createItemIdentifier("http://test.semagia.com/theme"); + TinyTimMapInputHandler handler = _handler; + handler.startTopicMap(); + handler.startTopic(theTopic); + handler.startName(); + handler.value("Semagia"); + handler.startVariant(); + handler.startScope(); + handler.startTheme(); + handler.topicRef(theme); + handler.endTheme(); + handler.endScope(); + try { + handler.endVariant(); + fail("Expected an error since the variant has no value"); + } + catch (MIOException ex) { + // noop. + } + } + + public void testNameNoValue() throws Exception { + final IRef theTopic = Ref.createItemIdentifier("http://test.semagia.com/the-topic"); + TinyTimMapInputHandler handler = _handler; + handler.startTopicMap(); + handler.startTopic(theTopic); + handler.startName(); + try { + handler.endName(); + fail("Expected an error since the name has no value"); + } + catch (MIOException ex) { + // noop. + } + } + /** * <a href="http://code.google.com/p/mappa/issues/detail?id=23">http://code.google.com/p/mappa/issues/detail?id=23</a> */ @@ -320,6 +358,7 @@ handler.startReifier(); handler.topicRef(reifier); handler.endReifier(); + handler.value("variant", _XSD_STRING); handler.itemIdentifier(variantIID); handler.startScope(); handler.startTheme(); @@ -335,6 +374,7 @@ handler.startReifier(); handler.topicRef(reifier); handler.endReifier(); + handler.value("variant", _XSD_STRING); handler.startScope(); handler.startTheme(); handler.topicRef(theme); @@ -369,6 +409,7 @@ handler.startReifier(); handler.topicRef(reifier); handler.endReifier(); + handler.value("variant", _XSD_STRING); handler.startScope(); handler.startTheme(); handler.topicRef(theme); @@ -383,6 +424,7 @@ handler.startReifier(); handler.topicRef(reifier); handler.endReifier(); + handler.value("variant", _XSD_STRING); handler.itemIdentifier(variantIID); handler.startScope(); handler.startTheme(); @@ -418,6 +460,7 @@ handler.startReifier(); handler.topicRef(reifier); handler.endReifier(); + handler.value("variant", _XSD_STRING); handler.startScope(); handler.startTheme(); handler.topicRef(theme); @@ -433,6 +476,7 @@ handler.startReifier(); handler.topicRef(reifier); handler.endReifier(); + handler.value("variant", _XSD_STRING); handler.itemIdentifier(variantIID); handler.startScope(); handler.startTheme(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |