From: <lh...@us...> - 2008-11-13 18:00:09
|
Revision: 187 http://tinytim.svn.sourceforge.net/tinytim/?rev=187&view=rev Author: lheuer Date: 2008-11-13 18:00:03 +0000 (Thu, 13 Nov 2008) Log Message: ----------- - Added test case for IConstructFactory - Modified MemoryConstructFactory accordingly Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/core/MemoryConstructFactory.java tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java Added Paths: ----------- tinytim/trunk/src/test/java/org/tinytim/core/TestIConstructFactory.java Modified: tinytim/trunk/src/main/java/org/tinytim/core/MemoryConstructFactory.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/MemoryConstructFactory.java 2008-11-13 15:33:33 UTC (rev 186) +++ tinytim/trunk/src/main/java/org/tinytim/core/MemoryConstructFactory.java 2008-11-13 18:00:03 UTC (rev 187) @@ -43,14 +43,18 @@ * @see org.tinytim.internal.api.IConstructFactory#createTopic() */ public ITopic createTopic() { - return new TopicImpl(_tm); + TopicImpl topic = new TopicImpl(_tm); + _tm.addTopic(topic); + return topic; } /* (non-Javadoc) * @see org.tinytim.internal.api.IConstructFactory#createAssociation() */ public Association createAssociation() { - return new AssociationImpl(_tm); + AssociationImpl assoc = new AssociationImpl(_tm); + _tm.addAssociation(assoc); + return assoc; } /* (non-Javadoc) Modified: tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java 2008-11-13 15:33:33 UTC (rev 186) +++ tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java 2008-11-13 18:00:03 UTC (rev 187) @@ -243,7 +243,7 @@ return assoc; } - public void addAssociation(Association assoc_) { + void addAssociation(Association assoc_) { AssociationImpl assoc = (AssociationImpl) assoc_; if (assoc._parent == this) { return; Modified: tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java 2008-11-13 15:33:33 UTC (rev 186) +++ tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java 2008-11-13 18:00:03 UTC (rev 187) @@ -42,6 +42,7 @@ suite.addTestSuite(TestDuplicateRemovalUtils.class); suite.addTestSuite(TestLocatorImpl.class); suite.addTestSuite(TestIConstruct.class); + suite.addTestSuite(TestIConstructFactory.class); suite.addTestSuite(TestScope.class); suite.addTestSuite(TestLiteral.class); suite.addTestSuite(TestLiteralNormalizer.class); Added: tinytim/trunk/src/test/java/org/tinytim/core/TestIConstructFactory.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestIConstructFactory.java (rev 0) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestIConstructFactory.java 2008-11-13 18:00:03 UTC (rev 187) @@ -0,0 +1,172 @@ +/* + * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.core; + +import org.tinytim.internal.api.IConstructFactory; +import org.tinytim.internal.api.IName; +import org.tinytim.internal.api.IOccurrence; +import org.tinytim.internal.api.ITopic; +import org.tinytim.internal.api.IVariant; + +import org.tmapi.core.Association; +import org.tmapi.core.Role; +import org.tmapi.core.Topic; + +/** + * Tests against {@link IConstructFactory}. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +public class TestIConstructFactory extends TinyTimTestCase { + + private IConstructFactory _factory; + + /* (non-Javadoc) + * @see org.tinytim.core.TinyTimTestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + _factory = _tm.getConstructFactory(); + } + + /* (non-Javadoc) + * @see org.tinytim.core.TinyTimTestCase#tearDown() + */ + @Override + protected void tearDown() throws Exception { + super.tearDown(); + _factory = null; + } + + /** + * Tests topic creatation. + */ + public void testTopicCreation() { + final Topic topic = _factory.createTopic(); + assertNotNull(topic.getId()); + assertTrue(topic.getItemIdentifiers().isEmpty()); + assertTrue(topic.getSubjectIdentifiers().isEmpty()); + assertTrue(topic.getSubjectLocators().isEmpty()); + assertTrue(topic.getTypes().isEmpty()); + assertTrue(topic.getOccurrences().isEmpty()); + assertTrue(topic.getNames().isEmpty()); + assertTrue(topic.getRolesPlayed().isEmpty()); + assertEquals(topic, _tm.getConstructById(topic.getId())); + assertEquals(_tm, topic.getParent()); + assertEquals(_tm, topic.getTopicMap()); + } + + /** + * Tests association creatation. + */ + public void testAssociationCreation() { + final Association assoc = _factory.createAssociation(); + assertNotNull(assoc.getId()); + assertNull(assoc.getType()); + assertTrue(assoc.getItemIdentifiers().isEmpty()); + assertTrue(assoc.getRoles().isEmpty()); + assertTrue(assoc.getScope().isEmpty()); + assertEquals(assoc, _tm.getConstructById(assoc.getId())); + assertEquals(_tm, assoc.getParent()); + assertEquals(_tm, assoc.getTopicMap()); + } + + /** + * Tests role creation. + */ + public void testRoleCreation() { + final Association assoc = createAssociation(); + final Role role = _factory.createRole(assoc); + assertNotNull(role.getId()); + assertNull(role.getType()); + assertNull(role.getPlayer()); + assertTrue(role.getItemIdentifiers().isEmpty()); + assertEquals(role, _tm.getConstructById(role.getId())); + assertEquals(assoc, role.getParent()); + assertEquals(_tm, assoc.getTopicMap()); + } + + /** + * Tests occurrence creation. + */ + public void testOccurrenceCreation() { + final ITopic topic = (ITopic) createTopic(); + final IOccurrence occ = _factory.createOccurrence(topic); + assertNotNull(occ.getId()); + assertNull(occ.getType()); + assertTrue(occ.getItemIdentifiers().isEmpty()); + assertNull(occ.getLiteral()); + assertTrue(occ.getScope().isEmpty()); + assertEquals(occ, _tm.getConstructById(occ.getId())); + assertEquals(topic, occ.getParent()); + assertEquals(_tm, occ.getTopicMap()); + } + + /** + * Tests name creation. + */ + public void testNameCreation() { + final ITopic topic = (ITopic) createTopic(); + final IName name = _factory.createName(topic); + assertNotNull(name.getId()); + assertNull(name.getType()); + assertTrue(name.getItemIdentifiers().isEmpty()); + assertNull(name.getLiteral()); + assertTrue(name.getScope().isEmpty()); + assertEquals(name, _tm.getConstructById(name.getId())); + assertEquals(topic, name.getParent()); + assertEquals(_tm, name.getTopicMap()); + } + + /** + * Tests variant creation. + */ + public void testVariantCreation() { + final IName name = (IName) createName(); + final IVariant variant = _factory.createVariant(name); + assertNotNull(variant.getId()); + assertTrue(variant.getItemIdentifiers().isEmpty()); + assertNull(variant.getLiteral()); + assertTrue(variant.getScope().isEmpty()); + assertEquals(variant, _tm.getConstructById(variant.getId())); + assertEquals(name, variant.getParent()); + assertEquals(_tm, variant.getTopicMap()); + } + + /** + * Tests variant creation with a scoped name. + */ + public void testVariantCreationScope() { + final IName name = (IName) createName(); + final Topic theme1 = createTopic(); + final Topic theme2 = createTopic(); + name.addTheme(theme1); + name.addTheme(theme2); + final IVariant variant = _factory.createVariant(name); + assertNotNull(variant.getId()); + assertTrue(variant.getItemIdentifiers().isEmpty()); + assertNull(variant.getLiteral()); + assertEquals(2, variant.getScope().size()); + assertTrue(variant.getScope().contains(theme1)); + assertTrue(variant.getScope().contains(theme2)); + assertEquals(variant, _tm.getConstructById(variant.getId())); + assertEquals(name, variant.getParent()); + assertEquals(_tm, variant.getTopicMap()); + } + +} Property changes on: tinytim/trunk/src/test/java/org/tinytim/core/TestIConstructFactory.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. |