From: <lh...@us...> - 2009-06-30 14:14:41
|
Revision: 109 http://tmapi.svn.sourceforge.net/tmapi/?rev=109&view=rev Author: lheuer Date: 2009-06-30 13:53:17 +0000 (Tue, 30 Jun 2009) Log Message: ----------- Added same topic map constraint test cases Modified Paths: -------------- trunk/src/test/java/org/tmapi/core/AllCoreTests.java Added Paths: ----------- trunk/src/test/java/org/tmapi/core/TestSameTopicMap.java Modified: trunk/src/test/java/org/tmapi/core/AllCoreTests.java =================================================================== --- trunk/src/test/java/org/tmapi/core/AllCoreTests.java 2009-06-19 12:09:27 UTC (rev 108) +++ trunk/src/test/java/org/tmapi/core/AllCoreTests.java 2009-06-30 13:53:17 UTC (rev 109) @@ -47,6 +47,7 @@ suite.addTestSuite(TestTopicMap.class); suite.addTestSuite(TestTopic.class); suite.addTestSuite(TestAssociation.class); + suite.addTestSuite(TestSameTopicMap.class); suite.addTestSuite(TestRole.class); suite.addTestSuite(TestOccurrence.class); suite.addTestSuite(TestName.class); Added: trunk/src/test/java/org/tmapi/core/TestSameTopicMap.java =================================================================== --- trunk/src/test/java/org/tmapi/core/TestSameTopicMap.java (rev 0) +++ trunk/src/test/java/org/tmapi/core/TestSameTopicMap.java 2009-06-30 13:53:17 UTC (rev 109) @@ -0,0 +1,252 @@ +/* + * 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 + * NO WARRANTY. + * + * No one owns TMAPI: you may use it freely in both commercial and + * non-commercial applications, bundle it with your software + * distribution, include it on a CD-ROM, list the source code in a + * book, mirror the documentation at your own web site, or use it in + * any other way you see fit. + */ +package org.tmapi.core; + +import java.util.Arrays; + +import org.tmapi.core.ModelConstraintException; +import org.tmapi.core.Reifiable; +import org.tmapi.core.Scoped; +import org.tmapi.core.TopicMap; +import org.tmapi.core.Typed; + +/** + * Checks the "same topic map" constraint. + * + * @author <a href="http://tmapi.org/">The TMAPI Project</a> + * @version $Rev$ - $Date$ + */ +public class TestSameTopicMap extends TMAPITestCase { + + private TopicMap _tm2; + + public TestSameTopicMap(String name) { + super(name); + } + + /* (non-Javadoc) + * @see org.tinytim.core.TinyTimTestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + _tm2 = _sys.createTopicMap("http://www.tmapi.org/same-topicmap"); + } + + public void testAssociationCreationIllegalType() { + try { + _tm.createAssociation(_tm2.createTopic()); + fail("Expected a model contraint violation"); + } + catch (ModelConstraintException ex) { + // noop. + } + } + + public void testAssociationCreationIllegalScopeArray() { + try { + _tm.createAssociation(createTopic(), createTopic(), _tm2.createTopic()); + fail("Expected a model contraint violation"); + } + catch (ModelConstraintException ex) { + // noop. + } + } + + public void testAssociationCreationIllegalScopeCollection() { + try { + _tm.createAssociation(createTopic(), Arrays.asList(createTopic(), _tm2.createTopic())); + fail("Expected a model contraint violation"); + } + catch (ModelConstraintException ex) { + // noop. + } + } + + public void testNameCreationIllegalType() { + try { + createTopic().createName(_tm2.createTopic(), "value"); + fail("Expected a model contraint violation"); + } + catch (ModelConstraintException ex) { + // noop. + } + } + + public void testNameCreationIllegalScopeArray() { + try { + createTopic().createName(createTopic(), "value", createTopic(), _tm2.createTopic()); + fail("Expected a model contraint violation"); + } + catch (ModelConstraintException ex) { + // noop. + } + } + + public void testNameCreationIllegalScopeCollection() { + try { + createTopic().createName(createTopic(), "value", Arrays.asList(createTopic(), _tm2.createTopic())); + fail("Expected a model contraint violation"); + } + catch (ModelConstraintException ex) { + // noop. + } + } + + public void testOccurrenceCreationIllegalType() { + try { + createTopic().createOccurrence(_tm2.createTopic(), "value"); + fail("Expected a model contraint violation"); + } + catch (ModelConstraintException ex) { + // noop. + } + } + + public void testOccurrenceCreationIllegalScopeArray() { + try { + createTopic().createOccurrence(createTopic(), "value", createTopic(), _tm2.createTopic()); + fail("Expected a model contraint violation"); + } + catch (ModelConstraintException ex) { + // noop. + } + } + + public void testOccurrenceCreationIllegalScopeCollection() { + try { + createTopic().createOccurrence(createTopic(), "value", Arrays.asList(createTopic(), _tm2.createTopic())); + fail("Expected a model contraint violation"); + } + catch (ModelConstraintException ex) { + // noop. + } + } + + public void testRoleCreationIllegalType() { + try { + createAssociation().createRole(_tm2.createTopic(), createTopic()); + fail("Expected a model contraint violation"); + } + catch (ModelConstraintException ex) { + // noop. + } + } + + public void testRoleCreationIllegalPlayer() { + try { + createAssociation().createRole(createTopic(), _tm2.createTopic()); + fail("Expected a model contraint violation"); + } + catch (ModelConstraintException ex) { + // noop. + } + } + + private void _testIllegalTheme(Scoped scoped) { + try { + scoped.addTheme(_tm2.createTopic()); + fail("Adding a theme from another topic map shouldn't be allowed"); + } + catch (ModelConstraintException ex) { + // noop. + } + } + + public void testAssociationIllegalTheme() { + _testIllegalTheme(createAssociation()); + } + + public void testOccurrenceIllegalTheme() { + _testIllegalTheme(createOccurrence()); + } + + public void testNameIllegalTheme() { + _testIllegalTheme(createName()); + } + + public void testVariantIllegalTheme() { + _testIllegalTheme(createVariant()); + } + + private void _testIllegalType(Typed typed) { + try { + typed.setType(_tm2.createTopic()); + fail("Setting the type to a topic from another topic map shouldn't be allowed"); + } + catch (ModelConstraintException ex) { + // noop. + } + } + + public void testAssociationIllegalType() { + _testIllegalType(createAssociation()); + } + + public void testRoleIllegalType() { + _testIllegalType(createRole()); + } + + public void testOccurrenceIllegalType() { + _testIllegalType(createOccurrence()); + } + + public void testNameIllegalType() { + _testIllegalType(createName()); + } + + public void testRoleIllegalPlayer() { + try { + createRole().setPlayer(_tm2.createTopic()); + fail("Setting the player to a topic of another topic map shouldn't be allowed."); + } + catch (ModelConstraintException ex) { + // noop. + } + } + + private void _testIllegalReifier(Reifiable reifiable) { + try { + reifiable.setReifier(_tm2.createTopic()); + fail("Setting the reifier to a topic of another topic map shouldn't be allowed"); + } + catch (ModelConstraintException ex) { + // noop. + } + } + + public void testTopicMapIllegalReifier() { + _testIllegalReifier(_tm); + } + + public void testAssociationIllegalReifier() { + _testIllegalReifier(createAssociation()); + } + + public void testRoleIllegalReifier() { + _testIllegalReifier(createRole()); + } + + public void testOccurrenceIllegalReifier() { + _testIllegalReifier(createOccurrence()); + } + + public void testNameIllegalReifier() { + _testIllegalReifier(createName()); + } + + public void testVariantIllegalReifier() { + _testIllegalReifier(createVariant()); + } +} Property changes on: trunk/src/test/java/org/tmapi/core/TestSameTopicMap.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |