From: <tma...@li...> - 2008-08-04 17:56:38
|
Revision: 51 http://tmapi.svn.sourceforge.net/tmapi/?rev=51&view=rev Author: lheuer Date: 2008-08-04 17:56:41 +0000 (Mon, 04 Aug 2008) Log Message: ----------- - Variant creation tests Modified Paths: -------------- trunk/src/test/java/org/tmapi/core/TestName.java Modified: trunk/src/test/java/org/tmapi/core/TestName.java =================================================================== --- trunk/src/test/java/org/tmapi/core/TestName.java 2008-08-04 13:55:55 UTC (rev 50) +++ trunk/src/test/java/org/tmapi/core/TestName.java 2008-08-04 17:56:41 UTC (rev 51) @@ -15,6 +15,8 @@ */ package org.tmapi.core; +import java.util.Collections; + /** * Tests against the {@link Name} interface. * @@ -45,4 +47,105 @@ assertTrue("Expected name set size to decrement for topic.", parent.getNames().isEmpty()); } + + public void testValue() { + final String value1 = "TMAPI Name"; + final String value2 = "A name"; + final Name name = createName(); + name.setValue(value1); + assertEquals(value1, name.getValue()); + name.setValue(value2); + assertEquals(value2, name.getValue()); + try { + name.setValue(null); + fail("setValue(null) is not allowed"); + } + catch (Exception ex) { + // noop. + } + // Old value kept. + assertEquals(value2, name.getValue()); + } + + public void testVariantCreationString() { + final Name name = createName(); + final Topic theme = createTopic(); + final Locator xsdString = createLocator("http://www.w3.org/2001/XMLSchema#string"); + final Variant variant = name.createVariant("Variant", theme); + assertEquals("Variant", variant.getValue()); + assertEquals(xsdString, variant.getDatatype()); + assertEquals(1, variant.getScope().size()); + assertTrue(variant.getScope().contains(theme)); + } + + public void testVariantCreationURI() { + final Name name = createName(); + final Topic theme = createTopic(); + final Locator xsdAnyURI = createLocator("http://www.w3.org/2001/XMLSchema#anyURI"); + final Locator value = createLocator("http://www.example.org/"); + final Variant variant = name.createVariant(value, theme); + assertEquals(value.getReference(), variant.getValue()); + assertEquals(value, variant.locatorValue()); + assertEquals(xsdAnyURI, variant.getDatatype()); + assertEquals(1, variant.getScope().size()); + assertTrue(variant.getScope().contains(theme)); + } + + public void testVariantCreationExplicitDatatype() { + final Name name = createName(); + final Topic theme = createTopic(); + final Locator dt = createLocator("http://www.example.org/datatype"); + final Variant variant = name.createVariant("Variant", dt, theme); + assertEquals("Variant", variant.getValue()); + assertEquals(dt, variant.getDatatype()); + assertEquals(1, variant.getScope().size()); + assertTrue(variant.getScope().contains(theme)); + } + + public void testVariantCreationIllegalString() { + final Name name = createName(); + final Topic theme = createTopic(); + try { + name.createVariant((String)null, theme); + fail("Creation of a variant with (String) null value is not allowed"); + } + catch (Exception ex) { + // noop. + } + } + + public void testVariantCreationIllegalLocator() { + final Name name = createName(); + final Topic theme = createTopic(); + try { + name.createVariant((Locator)null, theme); + fail("Creation of a variant with (Locator) null value is not allowed"); + } + catch (Exception ex) { + // noop. + } + } + + public void testVariantCreationIllegalDatatype() { + final Name name = createName(); + final Topic theme = createTopic(); + try { + name.createVariant("Variant", (Locator)null, theme); + fail("Creation of a variant with datatype == null is not allowed"); + } + catch (Exception ex) { + // noop. + } + } + + public void testVariantCreationIllegalEmptyScope() { + final Name name = createName(); + try { + name.createVariant("Variant", Collections.<Topic>emptySet()); + fail("Creation of a variant with an empty scope is not allowed"); + } + catch (Exception ex) { + + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |