From: <lh...@us...> - 2008-08-07 11:25:18
|
Revision: 61 http://tmapi.svn.sourceforge.net/tmapi/?rev=61&view=rev Author: lheuer Date: 2008-08-07 11:25:25 +0000 (Thu, 07 Aug 2008) Log Message: ----------- - More tests - Initial TestLiteralIndex Modified Paths: -------------- trunk/src/test/java/org/tmapi/core/TestAssociation.java trunk/src/test/java/org/tmapi/core/TestDatatypeAware.java trunk/src/test/java/org/tmapi/core/TestName.java trunk/src/test/java/org/tmapi/core/TestTopicMap.java 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/TestAssociation.java =================================================================== --- trunk/src/test/java/org/tmapi/core/TestAssociation.java 2008-08-06 15:33:10 UTC (rev 60) +++ trunk/src/test/java/org/tmapi/core/TestAssociation.java 2008-08-07 11:25:25 UTC (rev 61) @@ -45,6 +45,9 @@ parent.getAssociations().isEmpty()); } + /** + * Test the creation of roles. + */ public void testRoleCreation() { final Association assoc = createAssociation(); assertTrue("Expected no roles in a newly created association", @@ -59,6 +62,9 @@ assertTrue(player.getRolesPlayed().contains(role)); } + /** + * Tests {@link Association#getRoleTypes()} + */ public void testRoleTypes() { final Association assoc = createAssociation(); final Topic type1 = createTopic(); @@ -87,6 +93,9 @@ assertEquals(0, assoc.getRoleTypes().size()); } + /** + * Tests {@link Association#getRoles(Topic)} + */ public void testRoleFilter() { final Association assoc = createAssociation(); final Topic type1 = createTopic(); Modified: trunk/src/test/java/org/tmapi/core/TestDatatypeAware.java =================================================================== --- trunk/src/test/java/org/tmapi/core/TestDatatypeAware.java 2008-08-06 15:33:10 UTC (rev 60) +++ trunk/src/test/java/org/tmapi/core/TestDatatypeAware.java 2008-08-07 11:25:25 UTC (rev 61) @@ -175,6 +175,161 @@ assertEquals(10.0F, dt.floatValue()); } + public void testInt() { + final int value = 1976; + final String strValue = "1976"; + final DatatypeAware dt = getDatatypeAware(); + dt.setValue(value); + assertEquals(strValue, dt.getValue()); + assertEquals(_xsdInt, dt.getDatatype()); + assertEquals(new BigDecimal(value), dt.decimalValue()); + assertEquals(new BigInteger(strValue), dt.integerValue()); + assertEquals(1976L, dt.longValue()); + assertEquals(1976, dt.intValue()); + assertEquals(1976.0F, dt.floatValue()); + } + + public void testLong() { + final long value = 1976L; + final String strValue = "1976"; + final DatatypeAware dt = getDatatypeAware(); + dt.setValue(value); + assertEquals(strValue, dt.getValue()); + assertEquals(_xsdLong, dt.getDatatype()); + assertEquals(new BigDecimal(value), dt.decimalValue()); + assertEquals(new BigInteger(strValue), dt.integerValue()); + assertEquals(value, dt.longValue()); + assertEquals(1976, dt.intValue()); + assertEquals(1976.0F, dt.floatValue()); + } + + public void testFloat() { + final float value = 1976.0F; + final String strValue = "1976.0"; + final DatatypeAware dt = getDatatypeAware(); + dt.setValue(value); + assertEquals(strValue, dt.getValue()); + assertEquals(_xsdFloat, dt.getDatatype()); + assertEquals(new BigDecimal(strValue), dt.decimalValue()); + assertFailInteger(dt); + assertFailLong(dt); + assertFailInt(dt); + assertEquals(value, dt.floatValue()); + } + + public void testUserDatatype() { + final Locator datatype = createLocator("http://www.example.org/datatype"); + final DatatypeAware dt = getDatatypeAware(); + final String value = "Value"; + dt.setValue(value, datatype); + assertEquals(datatype, dt.getDatatype()); + assertEquals(value, dt.getValue()); + assertFailInteger(dt); + assertFailInt(dt); + assertFailFloat(dt); + assertFailLong(dt); + assertFailDecimal(dt); + } + + public void testIllegalDatatype() { + final DatatypeAware dt = getDatatypeAware(); + try { + dt.setValue("value", null); + fail("datatypeAware.setValue(\"value\", null) is illegal"); + } + catch (Exception ex) { + // noop. + } + } + + public void testIllegalStringValue() { + final DatatypeAware dt = getDatatypeAware(); + try { + dt.setValue((String)null); + fail("datatypeAware.setValue((String)null) is illegal"); + } + catch (Exception ex) { + // noop. + } + } + + public void testIllegalStringValueExplicit() { + final DatatypeAware dt = getDatatypeAware(); + try { + dt.setValue(null, _xsdString); + fail("datatypeAware.setValue(null, datatype) is illegal"); + } + catch (Exception ex) { + // noop. + } + } + + public void testIllegalLocatorValue() { + final DatatypeAware dt = getDatatypeAware(); + try { + dt.setValue((Locator)null); + fail("datatypeAware.setValue((Locator)null) is illegal"); + } + catch (Exception ex) { + // noop. + } + } + + public void testIllegalIntegerValue() { + final DatatypeAware dt = getDatatypeAware(); + try { + dt.setValue((BigInteger)null); + fail("datatypeAware.setValue((BigInteger)null) is illegal"); + } + catch (Exception ex) { + // noop. + } + } + + public void testIllegalDecimalValue() { + final DatatypeAware dt = getDatatypeAware(); + try { + dt.setValue((BigDecimal)null); + fail("datatypeAware.setValue((BigDecimal)null) is illegal"); + } + catch (Exception ex) { + // noop. + } + } + + public void testIllegalFloatValue() { + final DatatypeAware dt = getDatatypeAware(); + try { + dt.setValue((Float)null); + fail("datatypeAware.setValue((Float)null) is illegal"); + } + catch (Exception ex) { + // noop. + } + } + + public void testIllegalLongValue() { + final DatatypeAware dt = getDatatypeAware(); + try { + dt.setValue((Long)null); + fail("datatypeAware.setValue((Long)null) is illegal"); + } + catch (Exception ex) { + // noop. + } + } + + public void testIllegalIntValue() { + final DatatypeAware dt = getDatatypeAware(); + try { + dt.setValue((Integer)null); + fail("datatypeAware.setValue((Integer)null) is illegal"); + } + catch (Exception ex) { + // noop. + } + } + protected void assertFailInteger(final DatatypeAware dt) { try { dt.integerValue(); Modified: trunk/src/test/java/org/tmapi/core/TestName.java =================================================================== --- trunk/src/test/java/org/tmapi/core/TestName.java 2008-08-06 15:33:10 UTC (rev 60) +++ trunk/src/test/java/org/tmapi/core/TestName.java 2008-08-07 11:25:25 UTC (rev 61) @@ -136,6 +136,21 @@ } } + public void testVariantCreationIllegalScope() { + final Name name = createName(); + final Topic theme = createTopic(); + name.addTheme(theme); + assertEquals(1, name.getScope().size()); + assertTrue(name.getScope().contains(theme)); + try { + name.createVariant("Variant", theme); + fail("The variant would be in the same scope as the parent"); + } + catch (ModelConstraintException ex) { + // noop. + } + } + public void testVariantCreationIllegalEmptyScope() { final Name name = createName(); try { @@ -143,7 +158,7 @@ fail("Creation of a variant with an empty scope is not allowed"); } catch (Exception ex) { - + // noop. } } @@ -154,7 +169,7 @@ fail("Creation of a variant with a null scope is not allowed"); } catch (Exception ex) { - + // noop. } } } Modified: trunk/src/test/java/org/tmapi/core/TestTopicMap.java =================================================================== --- trunk/src/test/java/org/tmapi/core/TestTopicMap.java 2008-08-06 15:33:10 UTC (rev 60) +++ trunk/src/test/java/org/tmapi/core/TestTopicMap.java 2008-08-07 11:25:25 UTC (rev 61) @@ -222,26 +222,10 @@ * Test index. */ private static class BogusIndex implements Index { - - @Override public void close() {} - - @Override - public boolean isAutoUpdated() { - return false; - } - - @Override - public boolean isOpen() { - return false; - } - - @Override - public void open() { - } - - @Override + public boolean isAutoUpdated() { return false; } + public boolean isOpen() { return false; } + public void open() { } public void reindex() {} - } } Modified: trunk/src/test/java/org/tmapi/index/AllIndexTests.java =================================================================== --- trunk/src/test/java/org/tmapi/index/AllIndexTests.java 2008-08-06 15:33:10 UTC (rev 60) +++ trunk/src/test/java/org/tmapi/index/AllIndexTests.java 2008-08-07 11:25:25 UTC (rev 61) @@ -20,7 +20,7 @@ * Provides a test suite which contains all test cases for the .index package. * * @author TMAPI <a href="http://www.tmapi.org">tmapi.org</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class AllIndexTests extends TestSuite { Modified: trunk/src/test/java/org/tmapi/index/TestLiteralIndex.java =================================================================== --- trunk/src/test/java/org/tmapi/index/TestLiteralIndex.java 2008-08-06 15:33:10 UTC (rev 60) +++ trunk/src/test/java/org/tmapi/index/TestLiteralIndex.java 2008-08-07 11:25:25 UTC (rev 61) @@ -13,17 +13,24 @@ */ package org.tmapi.index; +import org.tmapi.core.Locator; +import org.tmapi.core.Name; +import org.tmapi.core.Occurrence; import org.tmapi.core.TMAPITestCase; +import org.tmapi.core.Topic; +import org.tmapi.core.Variant; /** * Tests against the {@link LiteralInstanceIndex} interface. * * @author TMAPI <a href="http://www.tmapi.org">tmapi.org</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class TestLiteralIndex extends TMAPITestCase { private LiteralIndex _litIdx; + private Locator _xsdString; + private Locator _xsdAnyURI; public TestLiteralIndex(String name) { super(name); @@ -37,6 +44,9 @@ super.setUp(); _litIdx = (LiteralIndex) _tm.getIndex(LiteralIndex.class); _litIdx.open(); + final String XSD_BASE = "http://www.w3.org/2001/XMLSchema#"; + _xsdString = createLocator(XSD_BASE + "string"); + _xsdAnyURI = createLocator(XSD_BASE + "anyURI"); } /* (non-Javadoc) @@ -55,4 +65,262 @@ } } + public void testName() { + final String value = "Value"; + final String value2 = "Value2"; + _updateIndex(); + assertEquals(0, _litIdx.getNames(value).size()); + final Name name = createTopic().createName(value); + _updateIndex(); + assertEquals(1, _litIdx.getNames(value).size()); + assertTrue(_litIdx.getNames(value).contains(name)); + name.setValue(value2); + _updateIndex(); + assertEquals(0, _litIdx.getNames(value).size()); + assertEquals(1, _litIdx.getNames(value2).size()); + assertTrue(_litIdx.getNames(value2).contains(name)); + name.remove(); + _updateIndex(); + assertEquals(0, _litIdx.getNames(value).size()); + assertEquals(0, _litIdx.getNames(value2).size()); + } + + public void testNameIllegalString() { + try { + _litIdx.getNames(null); + fail("getNames(null) is illegal"); + } + catch (Exception ex) { + // noop. + } + } + + public void testOccurrenceString() { + final String value = "Value"; + final String value2 = "Value2"; + _updateIndex(); + assertEquals(0, _litIdx.getOccurrences(value).size()); + assertEquals(0, _litIdx.getOccurrences(value, _xsdString).size()); + final Topic type = createTopic(); + final Occurrence occ = createTopic().createOccurrence(type, value); + _updateIndex(); + assertEquals(1, _litIdx.getOccurrences(value).size()); + assertTrue(_litIdx.getOccurrences(value).contains(occ)); + assertEquals(1, _litIdx.getOccurrences(value, _xsdString).size()); + assertTrue(_litIdx.getOccurrences(value, _xsdString).contains(occ)); + occ.setValue(value2); + _updateIndex(); + assertEquals(0, _litIdx.getOccurrences(value).size()); + assertEquals(0, _litIdx.getOccurrences(value, _xsdString).size()); + assertEquals(1, _litIdx.getOccurrences(value2).size()); + assertTrue(_litIdx.getOccurrences(value2).contains(occ)); + assertEquals(1, _litIdx.getOccurrences(value2, _xsdString).size()); + assertTrue(_litIdx.getOccurrences(value2, _xsdString).contains(occ)); + occ.remove(); + _updateIndex(); + assertEquals(0, _litIdx.getOccurrences(value).size()); + assertEquals(0, _litIdx.getOccurrences(value, _xsdString).size()); + assertEquals(0, _litIdx.getOccurrences(value2).size()); + assertEquals(0, _litIdx.getOccurrences(value2, _xsdString).size()); + } + + public void testOccurrenceURI() { + final Locator value = createLocator("http://www.example.org/1"); + final Locator value2 = createLocator("http://www.example.org/2"); + _updateIndex(); + assertEquals(0, _litIdx.getOccurrences(value).size()); + assertEquals(0, _litIdx.getOccurrences(value.getReference(), _xsdAnyURI).size()); + final Topic type = createTopic(); + final Occurrence occ = createTopic().createOccurrence(type, value); + _updateIndex(); + assertEquals(1, _litIdx.getOccurrences(value).size()); + assertTrue(_litIdx.getOccurrences(value).contains(occ)); + assertEquals(1, _litIdx.getOccurrences(value.getReference(), _xsdAnyURI).size()); + assertTrue(_litIdx.getOccurrences(value.getReference(), _xsdAnyURI).contains(occ)); + occ.setValue(value2); + _updateIndex(); + assertEquals(0, _litIdx.getOccurrences(value).size()); + assertEquals(0, _litIdx.getOccurrences(value.getReference(), _xsdAnyURI).size()); + assertEquals(1, _litIdx.getOccurrences(value2).size()); + assertTrue(_litIdx.getOccurrences(value2).contains(occ)); + assertEquals(1, _litIdx.getOccurrences(value2.getReference(), _xsdAnyURI).size()); + assertTrue(_litIdx.getOccurrences(value2.getReference(), _xsdAnyURI).contains(occ)); + occ.remove(); + _updateIndex(); + assertEquals(0, _litIdx.getOccurrences(value).size()); + assertEquals(0, _litIdx.getOccurrences(value.getReference(), _xsdAnyURI).size()); + assertEquals(0, _litIdx.getOccurrences(value2).size()); + assertEquals(0, _litIdx.getOccurrences(value2.getReference(), _xsdAnyURI).size()); + } + + public void testOccurrenceExplicitDatatype() { + final String value = "http://www.example.org/1"; + final String value2 = "http://www.example.org/2"; + final Locator datatype = createLocator("http://www.example.org/datatype"); + _updateIndex(); + assertEquals(0, _litIdx.getOccurrences(value).size()); + assertEquals(0, _litIdx.getOccurrences(value, datatype).size()); + final Topic type = createTopic(); + final Occurrence occ = createTopic().createOccurrence(type, value, datatype); + _updateIndex(); + assertEquals(0, _litIdx.getOccurrences(value).size()); + assertEquals(1, _litIdx.getOccurrences(value, datatype).size()); + assertTrue(_litIdx.getOccurrences(value, datatype).contains(occ)); + occ.setValue(value2, datatype); + _updateIndex(); + assertEquals(0, _litIdx.getOccurrences(value).size()); + assertEquals(0, _litIdx.getOccurrences(value, datatype).size()); + assertEquals(0, _litIdx.getOccurrences(value2).size()); + assertEquals(1, _litIdx.getOccurrences(value2, datatype).size()); + assertTrue(_litIdx.getOccurrences(value2, datatype).contains(occ)); + occ.remove(); + _updateIndex(); + assertEquals(0, _litIdx.getOccurrences(value2).size()); + assertEquals(0, _litIdx.getOccurrences(value2, datatype).size()); + } + + public void testOccurrenceIllegalString() { + try { + _litIdx.getOccurrences((String)null); + fail("getOccurrences((String)null) is illegal"); + } + catch (Exception ex) { + // noop. + } + } + + public void testOccurrenceIllegalURI() { + try { + _litIdx.getOccurrences((Locator)null); + fail("getOccurrences((Locator)null) is illegal"); + } + catch (Exception ex) { + // noop. + } + } + + public void testOccurrenceIllegalDatatype() { + try { + _litIdx.getOccurrences("value", null); + fail("getOccurrences(\"value\", null) is illegal"); + } + catch (Exception ex) { + // noop. + } + } + + public void testVariantString() { + final String value = "Value"; + final String value2 = "Value2"; + _updateIndex(); + assertEquals(0, _litIdx.getVariants(value).size()); + assertEquals(0, _litIdx.getVariants(value, _xsdString).size()); + final Topic theme = createTopic(); + final Variant variant = createName().createVariant(value, theme); + _updateIndex(); + assertEquals(1, _litIdx.getVariants(value).size()); + assertTrue(_litIdx.getVariants(value).contains(variant)); + assertEquals(1, _litIdx.getVariants(value, _xsdString).size()); + assertTrue(_litIdx.getVariants(value, _xsdString).contains(variant)); + variant.setValue(value2); + _updateIndex(); + assertEquals(0, _litIdx.getVariants(value).size()); + assertEquals(0, _litIdx.getVariants(value, _xsdString).size()); + assertEquals(1, _litIdx.getVariants(value2).size()); + assertTrue(_litIdx.getVariants(value2).contains(variant)); + assertEquals(1, _litIdx.getVariants(value2, _xsdString).size()); + assertTrue(_litIdx.getVariants(value2, _xsdString).contains(variant)); + variant.remove(); + _updateIndex(); + assertEquals(0, _litIdx.getVariants(value).size()); + assertEquals(0, _litIdx.getVariants(value, _xsdString).size()); + assertEquals(0, _litIdx.getVariants(value2).size()); + assertEquals(0, _litIdx.getVariants(value2, _xsdString).size()); + } + + public void testVariantURI() { + final Locator value = createLocator("http://www.example.org/1"); + final Locator value2 = createLocator("http://www.example.org/2"); + _updateIndex(); + assertEquals(0, _litIdx.getVariants(value).size()); + assertEquals(0, _litIdx.getVariants(value.getReference(), _xsdAnyURI).size()); + final Topic theme = createTopic(); + final Variant variant = createName().createVariant(value, theme); + _updateIndex(); + assertEquals(1, _litIdx.getVariants(value).size()); + assertTrue(_litIdx.getVariants(value).contains(variant)); + assertEquals(1, _litIdx.getVariants(value.getReference(), _xsdAnyURI).size()); + assertTrue(_litIdx.getVariants(value.getReference(), _xsdAnyURI).contains(variant)); + variant.setValue(value2); + _updateIndex(); + assertEquals(0, _litIdx.getVariants(value).size()); + assertEquals(0, _litIdx.getVariants(value.getReference(), _xsdAnyURI).size()); + assertEquals(1, _litIdx.getVariants(value2).size()); + assertTrue(_litIdx.getVariants(value2).contains(variant)); + assertEquals(1, _litIdx.getVariants(value2.getReference(), _xsdAnyURI).size()); + assertTrue(_litIdx.getVariants(value2.getReference(), _xsdAnyURI).contains(variant)); + variant.remove(); + _updateIndex(); + assertEquals(0, _litIdx.getVariants(value).size()); + assertEquals(0, _litIdx.getVariants(value.getReference(), _xsdAnyURI).size()); + assertEquals(0, _litIdx.getVariants(value2).size()); + assertEquals(0, _litIdx.getVariants(value2.getReference(), _xsdAnyURI).size()); + } + + public void testVariantExplicitDatatype() { + final String value = "http://www.example.org/1"; + final String value2 = "http://www.example.org/2"; + final Locator datatype = createLocator("http://www.example.org/datatype"); + _updateIndex(); + assertEquals(0, _litIdx.getVariants(value).size()); + assertEquals(0, _litIdx.getVariants(value, datatype).size()); + final Topic theme = createTopic(); + final Variant variant = createName().createVariant(value, datatype, theme); + _updateIndex(); + assertEquals(0, _litIdx.getVariants(value).size()); + assertEquals(1, _litIdx.getVariants(value, datatype).size()); + assertTrue(_litIdx.getVariants(value, datatype).contains(variant)); + variant.setValue(value2, datatype); + _updateIndex(); + assertEquals(0, _litIdx.getVariants(value).size()); + assertEquals(0, _litIdx.getVariants(value, datatype).size()); + assertEquals(0, _litIdx.getVariants(value2).size()); + assertEquals(1, _litIdx.getVariants(value2, datatype).size()); + assertTrue(_litIdx.getVariants(value2, datatype).contains(variant)); + variant.remove(); + _updateIndex(); + assertEquals(0, _litIdx.getVariants(value2).size()); + assertEquals(0, _litIdx.getVariants(value2, datatype).size()); + } + + public void testVariantIllegalString() { + try { + _litIdx.getVariants((String)null); + fail("getVariants((String)null) is illegal"); + } + catch (Exception ex) { + // noop. + } + } + + public void testVariantIllegalURI() { + try { + _litIdx.getVariants((Locator)null); + fail("getVariants((Locator)null) is illegal"); + } + catch (Exception ex) { + // noop. + } + } + + public void testVariantIllegalDatatype() { + try { + _litIdx.getVariants("value", null); + fail("getVariants(\"value\", null) is illegal"); + } + catch (Exception ex) { + // noop. + } + } + } Modified: trunk/src/test/java/org/tmapi/index/TestScopedIndex.java =================================================================== --- trunk/src/test/java/org/tmapi/index/TestScopedIndex.java 2008-08-06 15:33:10 UTC (rev 60) +++ trunk/src/test/java/org/tmapi/index/TestScopedIndex.java 2008-08-07 11:25:25 UTC (rev 61) @@ -25,7 +25,7 @@ * Tests against the {@link ScopedIndex} interface. * * @author TMAPI <a href="http://www.tmapi.org">tmapi.org</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class TestScopedIndex extends TMAPITestCase { Modified: trunk/src/test/java/org/tmapi/index/TestTypeInstanceIndex.java =================================================================== --- trunk/src/test/java/org/tmapi/index/TestTypeInstanceIndex.java 2008-08-06 15:33:10 UTC (rev 60) +++ trunk/src/test/java/org/tmapi/index/TestTypeInstanceIndex.java 2008-08-07 11:25:25 UTC (rev 61) @@ -24,7 +24,7 @@ * Tests against the {@link TypeInstanceIndex} interface. * * @author TMAPI <a href="http://www.tmapi.org">tmapi.org</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class TestTypeInstanceIndex extends TMAPITestCase { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |