From: Lars H. <lh...@us...> - 2005-03-07 12:32:12
|
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16920/src/org/tmapiutils/query/tolog/predicates/test Modified Files: AssociationPredicateTest.java AssociationRolePredicateTest.java BaseLocatorPredicateTest.java DirectInstanceOfPredicateTest.java InstanceOfPredicateTest.java PredicateTestBase.java ReifiesPredicateTest.java ResourcePredicateTest.java TopicMapPredicateTest.java TypePredicateTest.java Log Message: More TM4J -> TMAPI translations Updated ToDo ResourcePredicate can handle Variants, too Index: ResourcePredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/ResourcePredicateTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ResourcePredicateTest.java 6 Mar 2005 19:37:40 -0000 1.3 --- ResourcePredicateTest.java 7 Mar 2005 12:32:00 -0000 1.4 *************** *** 8,12 **** *$Header$ */ ! package org.tmapiutils.query.tolog.predicates.test; --- 8,12 ---- *$Header$ */ ! package org.tmapiutils.query.tolog.predicates.test; *************** *** 20,28 **** // TMAPI import org.tmapi.core.Locator; import org.tmapi.core.Topic; import org.tmapi.core.Occurrence; /** ! * * @author Kal Ahmed (ka...@te...) */ --- 20,30 ---- // TMAPI import org.tmapi.core.Locator; + import org.tmapi.core.TopicMap; import org.tmapi.core.Topic; import org.tmapi.core.Occurrence; + import org.tmapi.index.core.TopicsIndex; /** ! * * @author Kal Ahmed (ka...@te...) */ *************** *** 36,40 **** } ! private static final String TESTMAP = "[techquila]\n" + "{techquila, homepage, \"http://www.techquila.com/\"}\n" + --- 38,42 ---- } ! private static final String TESTMAP = "[techquila]\n" + "{techquila, homepage, \"http://www.techquila.com/\"}\n" + *************** *** 50,53 **** --- 52,67 ---- } + + public void createTestMap(TopicMap tm) { + Topic tmapiutils = tm.createTopic(); + tmapiutils.addSubjectIdentifier(createLocator("tmapiutils")); + Topic homepage = tm.createTopic(); + tmapiutils.createOccurrence(createLocator("http://tmapiutils.org/", homepage, null); + Topic tmapi = tm.createTopic(); + tmapiutils.addSubjectIdentifier(createLocator("tmapi")); + tmapi.createOccurrence(createLocator("http://tmapi.org/", homepage, null); + } + + /* (non-Javadoc) * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getPredicateClass() *************** *** 62,65 **** --- 76,84 ---- public void testOpenMatch() throws Exception { + TopicsIndex topicsIdx = m_tm.getHelperObjects(TopicsIndex.class); + topicsIdx.open(); + topicsIdx.reindex(); + Topic tmapiutils = topicsIdx.getTopicBySubjectIdentifier(createLocator("tmapiutils")); + Topic tmapi = topicsIdx.getTopicBySubjectIdentifier(createLocator("tmapi")); List params = new ArrayList(); Variable a = new Variable("A"); *************** *** 72,76 **** assertEquals(2, out.getColumns().size()); assertEquals(3, out.getRows().size()); ! Iterator it = ((Topic) m_tm.getObjectById("techquila")).getOccurrences().iterator(); while (it.hasNext()) { Occurrence o = (Occurrence)it.next(); --- 91,95 ---- assertEquals(2, out.getColumns().size()); assertEquals(3, out.getRows().size()); ! Iterator it = tmapiutils.getOccurrences().iterator(); while (it.hasNext()) { Occurrence o = (Occurrence)it.next(); *************** *** 80,84 **** assertTrue(l.equals(o.getResource())); } ! it = ((Topic) m_tm.getObjectById("tm4j")).getOccurrences().iterator(); while (it.hasNext()) { Occurrence o = (Occurrence)it.next(); --- 99,103 ---- assertTrue(l.equals(o.getResource())); } ! it = tmapi.getOccurrences().iterator(); while (it.hasNext()) { Occurrence o = (Occurrence)it.next(); *************** *** 91,99 **** public void testOccurrenceByLocator() throws Exception { List params = new ArrayList(); Variable a = new Variable("A"); ! Locator l = m_tm.getLocatorFactory().createLocator("URI", "http://www.techquila.com/"); params.add(a); ! params.add(l); m_predicate.setParameters(params); VariableSet out = m_predicate.matches(params, m_context); --- 110,122 ---- public void testOccurrenceByLocator() throws Exception { + TopicsIndex topicsIdx = m_tm.getHelperObjects(TopicsIndex.class); + topicsIdx.open(); + topicsIdx.reindex(); + Topic tmapiutils = topicsIdx.getTopicBySubjectIdentifier(createLocator("tmapiutils")); List params = new ArrayList(); Variable a = new Variable("A"); ! Locator loc = m_tm.createLocator("http://tmapiutils.org/"); params.add(a); ! params.add(loc); m_predicate.setParameters(params); VariableSet out = m_predicate.matches(params, m_context); *************** *** 101,108 **** assertEquals(1, out.getColumns().size()); assertEquals(1, out.getRows().size()); ! Iterator it = ((Topic) m_tm.getObjectById("techquila")).getOccurrences().iterator(); while (it.hasNext()) { Occurrence o = (Occurrence)it.next(); ! if (o.getResource().equals(l)) { assertTrue(out.getColumn(a).contains(o)); } else { --- 124,131 ---- assertEquals(1, out.getColumns().size()); assertEquals(1, out.getRows().size()); ! Iterator it = tmapiutils.getOccurrences().iterator(); while (it.hasNext()) { Occurrence o = (Occurrence)it.next(); ! if (o.getResource().equals(loc)) { assertTrue(out.getColumn(a).contains(o)); } else { *************** *** 111,126 **** } } ! public void testLocatorByOccurrence() throws Exception { List params = new ArrayList(); Variable b = new Variable("B"); ! Locator l = m_tm.getLocatorFactory().createLocator("URI", "http://www.techquila.com/"); Occurrence o = null; ! Iterator it = ((Topic) m_tm.getObjectById("techquila")).getOccurrences().iterator(); while (it.hasNext()) { o = (Occurrence)it.next(); ! if (o.getResource().equals(l)) { break; ! } } assertNotNull("INTERNAL ERROR: Did not find occurrence to use in the query test.", o); --- 134,153 ---- } } ! public void testLocatorByOccurrence() throws Exception { + TopicsIndex topicsIdx = m_tm.getHelperObjects(TopicsIndex.class); + topicsIdx.open(); + topicsIdx.reindex(); + Topic tmapiutils = topicsIdx.getTopicBySubjectIdentifier(createLocator("tmapiutils")); List params = new ArrayList(); Variable b = new Variable("B"); ! Locator loc = m_tm.createLocator("http://tmapiutils.org/"); Occurrence o = null; ! Iterator it = tmapiutils.getOccurrences().iterator(); while (it.hasNext()) { o = (Occurrence)it.next(); ! if (o.getResource().equals(loc)) { break; ! } } assertNotNull("INTERNAL ERROR: Did not find occurrence to use in the query test.", o); *************** *** 132,139 **** assertEquals(1, out.getColumns().size()); assertEquals(1, out.getRows().size()); ! assertTrue(out.getColumn(b).contains(l)); } ! // TODO: Implement tests for closed matches. } --- 159,167 ---- assertEquals(1, out.getColumns().size()); assertEquals(1, out.getRows().size()); ! assertTrue(out.getColumn(b).contains(loc)); } ! // TODO: Implement tests for closed matches. + // Variant Tests! } *************** *** 141,144 **** --- 169,177 ---- /* * $Log$ + * Revision 1.4 2005/03/07 12:32:00 lheuer + * More TM4J -> TMAPI translations + * Updated ToDo + * ResourcePredicate can handle Variants, too + * * Revision 1.3 2005/03/06 19:37:40 lheuer * Changed getTopicByID to getObjectById Index: PredicateTestBase.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/PredicateTestBase.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PredicateTestBase.java 6 Mar 2005 19:37:40 -0000 1.3 --- PredicateTestBase.java 7 Mar 2005 12:32:00 -0000 1.4 *************** *** 10,66 **** package org.tmapiutils.query.tolog.predicates.test; ! import java.io.StringReader; import junit.framework.TestCase; - import org.tmapi.core.Locator; import org.tmapiutils.query.tolog.parser.Predicate; import org.tmapiutils.query.tolog.utils.TologContext; import org.tmapi.core.TopicMap; - import org.tmapi.core.TopicMapProvider; - import org.tmapi.core.TopicMapProviderFactory; - import org.tmapi.core.memory.TopicMapProviderFactoryImpl; - import org.tmapi.core.source.SerializedTopicMapSource; - import org.tmapi.core.utils.LTMBuilder; - import org.tmapi.core.utils.TopicMapBuilder; /** * @author Kal ! * * Describe PredicateTestBase here. */ public abstract class PredicateTestBase extends TestCase { protected Predicate m_predicate; ! protected TopicMap m_tm; ! protected TopicMapProvider m_provider; protected TologContext m_context; ! ! public abstract String getTestMap(); public abstract Class getPredicateClass(); ! public PredicateTestBase(String name) { super(name); } ! ! public TopicMapBuilder getBuilder() { ! return new LTMBuilder(); ! } ! public void setUp() throws Exception { ! TopicMapProviderFactory tmpf = new TopicMapProviderFactoryImpl(); ! m_provider = tmpf.newTopicMapProvider(); ! Locator loc = m_provider.getLocatorFactory().createLocator("URI", "http://www.techquila.com/test/tolog1.0.xtm"); ! SerializedTopicMapSource src = new SerializedTopicMapSource(new StringReader(getTestMap()), loc, getBuilder()); ! m_tm = m_provider.addTopicMap(src); ! m_predicate = (Predicate) getPredicateClass().newInstance(); ! m_predicate.initialise(m_tm); ! m_context = new TologContext(); } } /* * $Log$ * Revision 1.3 2005/03/06 19:37:40 lheuer * Changed getTopicByID to getObjectById --- 10,111 ---- package org.tmapiutils.query.tolog.predicates.test; ! import java.util.HashMap; ! ! //import java.io.StringReader; import junit.framework.TestCase; import org.tmapiutils.query.tolog.parser.Predicate; import org.tmapiutils.query.tolog.utils.TologContext; + // TMAPI + import org.tmapi.core.Locator; + import org.tmapi.core.TopicMapSystemFactory; + import org.tmapi.core.TopicMapSystem; + import org.tmapi.core.TopicMapObject; import org.tmapi.core.TopicMap; /** * @author Kal ! * * Describe PredicateTestBase here. */ public abstract class PredicateTestBase extends TestCase { + protected Predicate m_predicate; ! protected TopicMap _topicMap; ! private HashMap _maps; ! private HashMap _objectMap; ! protected static TopicMapSystem _system; protected TologContext m_context; ! ! /** ! * Creates a topic map to work with. ! */ ! public abstract void createTestMap(TopicMap tm); public abstract Class getPredicateClass(); ! public PredicateTestBase(String name) { super(name); + _maps = new HashMap(); + _objectMap = new HashMap(); } ! public void setUp() throws Exception { ! super().setUp(); ! _tmSystem = TopicMapSystemFactory().newInstance().newTopicMapSystem(); ! removeAllMaps(); ! m_tm = createTopicMap('http://tmapiutils.org/test/tolog1.0/'); ! m_predicate = (Predicate) getPredicateClass().newInstance(); ! m_predicate.createTestMap(m_tm); ! m_predicate.initialise(m_tm); ! m_context = new TologContext(); } + protected void tearDown() throws Exception{ + super.tearDown(); + // remove created TopicMaps from TopicMapSystem + removeAllMaps(); + // Close TopicMapSystem instance + _tmSystem.close(); + } + + protected void registerObject(String name, TopicMapObject obj) { + _objectMap.put(name, obj); + } + + protected TopicMapObject getObjectById(String name) { + return (TopicMapObject) _objectMap.get(name); + } + + protected Locator createLocator(String reference) { + return m_tm.createLocator(reference); + } + + protected void removeAllMaps() throws TMAPIException { + for (Iterator iter = _tmSystem.getBaseLocators().iterator(); iter.hasNext();) + removeTopicMap(_tmSystem.getTopicMap((Locator)iter.next())); + } + } + + protected TopicMap createTopicMap(String reference)throws TopicMapExistsException{ + TopicMap tm = _tmSystem.createTopicMap(reference); + _maps.put(reference,tm); + return tm; + } + protected void removeTopicMap(TopicMap tm)throws TMAPIException{ + _maps.remove(tm.getBaseLocator().getReference()); + tm.remove(); + } + } /* * $Log$ + * Revision 1.4 2005/03/07 12:32:00 lheuer + * More TM4J -> TMAPI translations + * Updated ToDo + * ResourcePredicate can handle Variants, too + * * Revision 1.3 2005/03/06 19:37:40 lheuer * Changed getTopicByID to getObjectById Index: TopicMapPredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/TopicMapPredicateTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TopicMapPredicateTest.java 6 Mar 2005 19:37:40 -0000 1.2 --- TopicMapPredicateTest.java 7 Mar 2005 12:32:00 -0000 1.3 *************** *** 16,19 **** --- 16,23 ---- import org.tmapiutils.query.tolog.predicates.TopicMapPredicate; import org.tmapiutils.query.tolog.utils.VariableSet; + // TMAPI + import org.tmapi.core.TopicMapObject; + import org.tmapi.core.Topic; + import org.tmapi.index.core.TopicMapObjectsIndex; /** *************** *** 37,40 **** --- 41,49 ---- } + public void createTestMap(TopicMap tm) { + Topic topic = tm.createTopic(); + topic.addSourceLocator(createLocator("hello-world")); + } + /* (non-Javadoc) * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getPredicateClass() *************** *** 55,58 **** --- 64,70 ---- public void testClosedMatch() throws Exception { + tmoIdx = (TopicMapObjectsIndex) m_tm.getHelperObject(TopicMapObjectsIndex.class); + tmoIdx.open(); + tmoIdx.reindex(); ArrayList params = new ArrayList(); params.add(new Variable("A")); *************** *** 64,68 **** assertEquals(m_tm, out.getRow(0).get(0)); ! params.set(0, m_tm.getObjectById("hello-world")); out = m_predicate.matches(params, m_context); assertNotNull(out); --- 76,81 ---- assertEquals(m_tm, out.getRow(0).get(0)); ! TopicMapObject tmo = tmoIdx.getTopicMapObjectBySourceLocator(createLocator("hello-world")); ! params.set(0, tmo); out = m_predicate.matches(params, m_context); assertNotNull(out); *************** *** 74,77 **** --- 87,95 ---- /* * $Log$ + * Revision 1.3 2005/03/07 12:32:00 lheuer + * More TM4J -> TMAPI translations + * Updated ToDo + * ResourcePredicate can handle Variants, too + * * Revision 1.2 2005/03/06 19:37:40 lheuer * Changed getTopicByID to getObjectById Index: ReifiesPredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/ReifiesPredicateTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ReifiesPredicateTest.java 6 Mar 2005 21:11:33 -0000 1.2 --- ReifiesPredicateTest.java 7 Mar 2005 12:32:00 -0000 1.3 *************** *** 15,20 **** import org.tmapiutils.query.tolog.predicates.ReifiesPredicate; import org.tmapiutils.query.tolog.utils.VariableSet; ! import org.tmapi.core.utils.TopicMapBuilder; ! import org.tmapi.core.utils.XTMBuilder; /** --- 15,21 ---- import org.tmapiutils.query.tolog.predicates.ReifiesPredicate; import org.tmapiutils.query.tolog.utils.VariableSet; ! // import org.tmapi.core.utils.TopicMapBuilder; ! // import org.tmapi.core.utils.XTMBuilder; ! import org.tmapi.index.core.TopicMapObjectsIndex; /** *************** *** 40,46 **** } ! public TopicMapBuilder getBuilder() { ! return new XTMBuilder(); ! } /* (non-Javadoc) --- 41,65 ---- } ! // public TopicMapBuilder getBuilder() { ! // return new XTMBuilder(); ! // } ! ! public void createTestMap(TopicMap tm) { ! Topic works_for = tm.createTopic(); ! Topic fred = tm.createTopic(); ! Topic fredemp = tm.createTopic(); ! fred.addSubjectIdentifier(tm.createLocator("fred")); ! Topic barney = tm.createTopic(); ! barney.addSubjectIdentifier(tm.createLocator("barney")); ! Topic employee = tm.createTopic(); ! Topic employer = tm.createTopic(); ! Topic bigco = tm.createTopic(); ! Association assoc = tm.createAssociation(); ! assoc.setType(works_for); ! assoc.createAssociationRole(fred, employee); ! assoc.createAssociationRole(bigco, employer); ! assoc.createAssociationRole(barney, employee); ! } ! /* (non-Javadoc) *************** *** 52,55 **** --- 71,77 ---- public void testMatchReifier() throws Exception { + tmoIdx = (TopicMapObjectsIndex) m_tm.getHelperObject(TopicMapObjectsIndex.class); + tmoIdx.open(); + tmoIdx.reindex(); ArrayList params = new ArrayList(); Variable a = new Variable("A"); *************** *** 61,68 **** assertEquals(1, out.getColumns().size()); assertEquals(1, out.getRows().size()); ! assertTrue(out.getRow(0).contains(m_tm.getObjectById("fredemp"))); } public void testMatchReified() throws Exception { ArrayList params = new ArrayList(); Variable a = new Variable("A"); --- 83,94 ---- assertEquals(1, out.getColumns().size()); assertEquals(1, out.getRows().size()); ! TopicMapObject tmo = tmoIdx.getTopicMapObjectBySourceLocator(createLocator("fredemp")); ! assertTrue(out.getRow(0).contains(tmo)); } public void testMatchReified() throws Exception { + tmoIdx = (TopicMapObjectsIndex) m_tm.getHelperObject(TopicMapObjectsIndex.class); + tmoIdx.open(); + tmoIdx.reindex(); ArrayList params = new ArrayList(); Variable a = new Variable("A"); *************** *** 74,81 **** assertEquals(1, out.getColumns().size()); assertEquals(1, out.getRows().size()); ! assertTrue(out.getRow(0).contains(m_tm.getObjectById("assoc1"))); } public void testOpenMatch() throws Exception { ArrayList params = new ArrayList(); Variable a = new Variable("A"); --- 100,111 ---- assertEquals(1, out.getColumns().size()); assertEquals(1, out.getRows().size()); ! TopicMapObject tmo = tmoIdx.getTopicMapObjectBySourceLocator(createLocator("assoc1")); ! assertTrue(out.getRow(0).contains(tmo)); } public void testOpenMatch() throws Exception { + tmoIdx = (TopicMapObjectsIndex) m_tm.getHelperObject(TopicMapObjectsIndex.class); + tmoIdx.open(); + tmoIdx.reindex(); ArrayList params = new ArrayList(); Variable a = new Variable("A"); *************** *** 88,96 **** assertEquals(2, out.getColumns().size()); assertEquals(1, out.getRows().size()); ! assertTrue(out.getRow(0).get(0).equals(m_tm.getObjectById("fredemp"))); ! assertTrue(out.getRow(0).get(1).equals(m_tm.getObjectById("assoc1"))); } public void testClosedMatch() throws Exception { ArrayList params = new ArrayList(); Variable a = new Variable("A"); --- 118,131 ---- assertEquals(2, out.getColumns().size()); assertEquals(1, out.getRows().size()); ! TopicMapObject fredemp = tmoIdx.getTopicMapObjectBySourceLocator(createLocator("fredemp")); ! TopicMapObject assoc1 = tmoIdx.getTopicMapObjectBySourceLocator(createLocator("assoc1")); ! assertTrue(out.getRow(0).get(0).equals(fredemp)); ! assertTrue(out.getRow(0).get(1).equals(assoc1)); } public void testClosedMatch() throws Exception { + tmoIdx = (TopicMapObjectsIndex) m_tm.getHelperObject(TopicMapObjectsIndex.class); + tmoIdx.open(); + tmoIdx.reindex(); ArrayList params = new ArrayList(); Variable a = new Variable("A"); *************** *** 99,111 **** params.add(b); m_predicate.setParameters(params); ! params.set(0, m_tm.getObjectById("fredemp")); ! params.set(1, m_tm.getObjectById("assoc1")); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(2, out.getColumns().size()); assertEquals(1, out.getRows().size()); ! ! params.set(0, m_tm.getObjectById("fredemp")); ! params.set(1, m_tm.getObjectById("m1")); out = m_predicate.matches(params, m_context); assertNotNull(out); --- 134,148 ---- params.add(b); m_predicate.setParameters(params); ! TopicMapObject fredemp = tmoIdx.getTopicMapObjectBySourceLocator(createLocator("fredemp")); ! TopicMapObject assoc1 = tmoIdx.getTopicMapObjectBySourceLocator(createLocator("assoc1")); ! params.set(0, fredemp)); ! params.set(1, assoc1)); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(2, out.getColumns().size()); assertEquals(1, out.getRows().size()); ! TopicMapObject m1 = tmoIdx.getTopicMapObjectBySourceLocator(createLocator("m1")); ! params.set(0, fredemp)); ! params.set(1, m1)); out = m_predicate.matches(params, m_context); assertNotNull(out); *************** *** 117,120 **** --- 154,162 ---- /* * $Log$ + * Revision 1.3 2005/03/07 12:32:00 lheuer + * More TM4J -> TMAPI translations + * Updated ToDo + * ResourcePredicate can handle Variants, too + * * Revision 1.2 2005/03/06 21:11:33 lheuer * More TM4J -> TMAPI translations Index: AssociationRolePredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/AssociationRolePredicateTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AssociationRolePredicateTest.java 6 Mar 2005 19:37:23 -0000 1.2 --- AssociationRolePredicateTest.java 7 Mar 2005 12:32:00 -0000 1.3 *************** *** 19,33 **** import org.tmapiutils.query.tolog.predicates.AssociationRolePredicate; import org.tmapiutils.query.tolog.utils.VariableSet; import org.tmapi.core.Association; import org.tmapi.core.AssociationRole; ! import org.tmapi.core.Topic; /** * @author Kal ! * * Describe AssociationRolePredicateTest here. */ public class AssociationRolePredicateTest extends PredicateTestBase { /** * @param name --- 19,37 ---- import org.tmapiutils.query.tolog.predicates.AssociationRolePredicate; import org.tmapiutils.query.tolog.utils.VariableSet; + // TMAPI + import org.tmapi.core.Topic; + import org.tmapi.core.TopicMap; import org.tmapi.core.Association; import org.tmapi.core.AssociationRole; ! import org.tmapi.index.core.TopicsIndex; /** * @author Kal ! * * Describe AssociationRolePredicateTest here. */ public class AssociationRolePredicateTest extends PredicateTestBase { + /** * @param name *************** *** 45,48 **** --- 49,69 ---- } + + public void createTestMap(TopicMap tm) { + Topic works_for = tm.createTopic(); + Topic fred = tm.createTopic(); + fred.addSubjectIdentifier(tm.createLocator("fred")); + Topic barney = tm.createTopic(); + barney.addSubjectIdentifier(tm.createLocator("barney")); + Topic employee = tm.createTopic(); + Topic employer = tm.createTopic(); + Topic bigco = tm.createTopic(); + Association assoc = tm.createAssociation(); + assoc.setType(works_for); + assoc.createAssociationRole(fred, employee); + assoc.createAssociationRole(bigco, employer); + assoc.createAssociationRole(barney, employee); + } + /* (non-Javadoc) * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getPredicateClass() *************** *** 53,61 **** public void testMatchAssociation() throws Exception { ArrayList params = new ArrayList(); Variable a = new Variable("A"); ! AssociationRole m = (AssociationRole) ((Topic) m_tm.getObjectById("fred")).getRolesPlayed().iterator().next(); params.add(a); ! params.add(m); m_predicate.setParameters(params); VariableSet out = m_predicate.matches(params, m_context); --- 74,86 ---- public void testMatchAssociation() throws Exception { + TopicsIndex topicsIdx = m_tm.getHelperObjects(TopicsIndex.class); + topicsIdx.open(); + topicsIdx.reindex(); ArrayList params = new ArrayList(); Variable a = new Variable("A"); ! Topic fred = topicsIdx.getTopicBySubjectIdentifier(createLocator("fred")); ! AssociationRole role = (AssociationRole) fred.getRolesPlayed().iterator().next(); params.add(a); ! params.add(role); m_predicate.setParameters(params); VariableSet out = m_predicate.matches(params, m_context); *************** *** 63,72 **** assertEquals(1, out.getColumns().size()); assertEquals(1, out.getRows().size()); ! assertEquals(m.getParent(), out.getRow(0).get(0)); } ! public void testMatchRoles() throws Exception { ArrayList params = new ArrayList(); ! Association assoc = ((AssociationRole) ((Topic) m_tm.getObjectById("barney")).getRolesPlayed().iterator().next()).getParent(); Variable a = new Variable("A"); params.add(assoc); --- 88,101 ---- assertEquals(1, out.getColumns().size()); assertEquals(1, out.getRows().size()); ! assertEquals(role.getAssociation(), out.getRow(0).get(0)); } ! public void testMatchRoles() throws Exception { + TopicsIndex topicsIdx = m_tm.getHelperObjects(TopicsIndex.class); + topicsIdx.open(); + topicsIdx.reindex(); ArrayList params = new ArrayList(); ! Topic barney = topicsIdx.getTopicBySubjectIdentifier(createLocator("fred")); ! Association assoc = ((AssociationRole) barney.getRolesPlayed().iterator().next()).getAssociation(); Variable a = new Variable("A"); params.add(assoc); *************** *** 80,84 **** assertEquals(assoc, ((AssociationRole)out.getRow(1).get(0)).getParent()); } ! public void testOpenMatch() throws Exception { ArrayList params = new ArrayList(); --- 109,113 ---- assertEquals(assoc, ((AssociationRole)out.getRow(1).get(0)).getParent()); } ! public void testOpenMatch() throws Exception { ArrayList params = new ArrayList(); *************** *** 92,103 **** assertEquals(2, out.getColumns().size()); assertEquals(4, out.getRows().size()); ! Iterator it = out.getRows().iterator(); while (it.hasNext()) { List row = (List)it.next(); ! assertEquals(row.get(0), ((AssociationRole)row.get(1)).getParent()); } } ! public void testClosedMatch() throws Exception { ArrayList params = new ArrayList(); Variable a = new Variable("A"); --- 121,135 ---- assertEquals(2, out.getColumns().size()); assertEquals(4, out.getRows().size()); ! Iterator it = out.getRows().iterator(); while (it.hasNext()) { List row = (List)it.next(); ! assertEquals(row.get(0), ((AssociationRole)row.get(1)).getAssociation()); } } ! public void testClosedMatch() throws Exception { + TopicsIndex topicsIdx = m_tm.getHelperObjects(TopicsIndex.class); + topicsIdx.open(); + topicsIdx.reindex(); ArrayList params = new ArrayList(); Variable a = new Variable("A"); *************** *** 106,130 **** params.add(b); m_predicate.setParameters(params); ! Topic fred = (Topic) m_tm.getObjectById("fred"); ! AssociationRole m = (AssociationRole) fred.getRolesPlayed().iterator().next(); ! Association assoc = m.getParent(); params.set(0, assoc); ! params.set(1, m); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(2, out.getColumns().size()); assertEquals(1, out.getRows().size()); ! ! Topic barney = (Topic) m_tm.getObjectById("barney"); ! AssociationRole m2 = (AssociationRole)barney.getRolesPlayed().iterator().next(); ! params.set(1, m2); out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(2, out.getColumns().size()); ! assertEquals(0, out.getRows().size()); } } /* * $Log$ * Revision 1.2 2005/03/06 19:37:23 lheuer * Changed getTopicByID to getObjectById --- 138,167 ---- params.add(b); m_predicate.setParameters(params); ! Topic fred = topicsIdx.getTopicBySubjectIdentifier(createLocator("fred")); ! AssociationRole role = (AssociationRole) fred.getRolesPlayed().iterator().next(); ! Association assoc = role.getAssociation(); params.set(0, assoc); ! params.set(1, role); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(2, out.getColumns().size()); assertEquals(1, out.getRows().size()); ! ! Topic barney = topicsIdx.getTopicBySubjectIdentifier(createLocator("barney")); ! AssociationRole role2 = (AssociationRole)barney.getRolesPlayed().iterator().next(); ! params.set(1, role2); out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(2, out.getColumns().size()); ! assertEquals(0, out.getRows().size()); } } /* * $Log$ + * Revision 1.3 2005/03/07 12:32:00 lheuer + * More TM4J -> TMAPI translations + * Updated ToDo + * ResourcePredicate can handle Variants, too + * * Revision 1.2 2005/03/06 19:37:23 lheuer * Changed getTopicByID to getObjectById Index: DirectInstanceOfPredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/DirectInstanceOfPredicateTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** DirectInstanceOfPredicateTest.java 6 Mar 2005 21:11:33 -0000 1.4 --- DirectInstanceOfPredicateTest.java 7 Mar 2005 12:32:00 -0000 1.5 *************** *** 9,13 **** import java.util.List; - import org.tmapi.core.Locator; import org.tmapiutils.query.tolog.parser.Predicate; import org.tmapiutils.query.tolog.parser.Variable; --- 9,12 ---- *************** *** 15,24 **** import org.tmapiutils.query.tolog.utils.TologContext; import org.tmapiutils.query.tolog.utils.VariableSet; import org.tmapi.core.TopicMap; - import org.tmapi.core.TopicMapProvider; - import org.tmapi.core.TopicMapProviderFactory; - import org.tmapi.core.memory.TopicMapProviderFactoryImpl; - import org.tmapi.core.source.SerializedTopicMapSource; - import org.tmapi.core.utils.LTMBuilder; import junit.framework.TestCase; --- 14,26 ---- import org.tmapiutils.query.tolog.utils.TologContext; import org.tmapiutils.query.tolog.utils.VariableSet; + //import org.tmapi.core.TopicMapProvider; + //import org.tmapi.core.TopicMapProviderFactory; + //import org.tmapi.core.memory.TopicMapProviderFactoryImpl; + //import org.tmapi.core.source.SerializedTopicMapSource; + //import org.tmapi.core.utils.LTMBuilder; + + // TMAPI + import org.tmapi.core.Locator; import org.tmapi.core.TopicMap; import junit.framework.TestCase; *************** *** 26,30 **** /** * @author Kal ! * * Describe DirectInstanceOfPredicateTest here. */ --- 28,32 ---- /** * @author Kal ! * * Describe DirectInstanceOfPredicateTest here. */ *************** *** 35,39 **** private TopicMapProvider m_provider; private TologContext m_context; ! /** * Constructor for DirectInstanceOfPredicateTest. --- 37,41 ---- private TopicMapProvider m_provider; private TologContext m_context; ! /** * Constructor for DirectInstanceOfPredicateTest. *************** *** 67,71 **** assertTrue(out.getColumn(b).contains(m_tm.getObjectById("cake"))); } ! public void testClassMatch() throws Exception { --- 69,73 ---- assertTrue(out.getColumn(b).contains(m_tm.getObjectById("cake"))); } ! public void testClassMatch() throws Exception { *************** *** 82,86 **** assertTrue(out.getColumn(a).contains(m_tm.getObjectById("jaffacake"))); } ! public void testInstanceMatch() throws Exception { List params = new ArrayList(); --- 84,88 ---- assertTrue(out.getColumn(a).contains(m_tm.getObjectById("jaffacake"))); } ! public void testInstanceMatch() throws Exception { List params = new ArrayList(); *************** *** 94,100 **** assertEquals(2, out.getRows().size()); assertTrue(out.getColumn(a).contains(m_tm.getObjectById("cake"))); ! assertTrue(out.getColumn(a).contains(m_tm.getObjectById("biscuit"))); } ! public void testClosedMatch() throws Exception { List params = new ArrayList(); --- 96,102 ---- assertEquals(2, out.getRows().size()); assertTrue(out.getColumn(a).contains(m_tm.getObjectById("cake"))); ! assertTrue(out.getColumn(a).contains(m_tm.getObjectById("biscuit"))); } ! public void testClosedMatch() throws Exception { List params = new ArrayList(); *************** *** 110,114 **** assertTrue(out.getColumn(a).contains(m_tm.getObjectById("jaffacake"))); } ! protected void setUp() throws Exception { TopicMapProviderFactory tmpf = new TopicMapProviderFactoryImpl(); --- 112,116 ---- assertTrue(out.getColumn(a).contains(m_tm.getObjectById("jaffacake"))); } ! protected void setUp() throws Exception { TopicMapProviderFactory tmpf = new TopicMapProviderFactoryImpl(); Index: BaseLocatorPredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/BaseLocatorPredicateTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** BaseLocatorPredicateTest.java 6 Mar 2005 17:33:23 -0000 1.1 --- BaseLocatorPredicateTest.java 7 Mar 2005 12:32:00 -0000 1.2 *************** *** 31,34 **** --- 31,38 ---- return "[test]"; } + + public void createTestMap(TopicMap tm) { + // noop. + } /* (non-Javadoc) Index: TypePredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/TypePredicateTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TypePredicateTest.java 6 Mar 2005 19:37:40 -0000 1.2 --- TypePredicateTest.java 7 Mar 2005 12:32:00 -0000 1.3 *************** *** 8,12 **** *$Header$ */ ! package org.tmapiutils.query.tolog.predicates.test; --- 8,12 ---- *$Header$ */ ! package org.tmapiutils.query.tolog.predicates.test; *************** *** 24,28 **** /** ! * * @author Kal Ahmed (ka...@te...) */ --- 24,28 ---- /** ! * * @author Kal Ahmed (ka...@te...) */ *************** *** 43,46 **** --- 43,75 ---- } + public void createTestMap(TopicMap tm) { + Topic works_for = tm.createTopic(); + Topic fred = tm.createTopic(); + Topic person = tm.createTopic(); + Topic bootsize = tm.createTopic(); + fred.addType(person); + fred.createOccurrence("12", bootsize, null); + + Topic bigco = tm.createTopic(); + Topic company = tm.createTopic(); + bigco.addType(company); + + Topic employee = tm.createTopic(); + Topic employer = tm.createTopic(); + + Association assoc = tm.createAssociation(); + assoc.setType(works_for); + assoc.createAssociationRole(fred, employee); + assoc.createAssociationRole(bigco, employer); + + registerObject("works-for", works_for); + registerObject("fred", fred); + registerObject("employee", employee); + registerObject("employer", employer); + registerObject("bigco", bigco); + registerObject("person", person); + registerObject("bootsize", bootsize); + } + /* (non-Javadoc) * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getPredicateClass() *************** *** 58,81 **** m_predicate.setParameters(params); ! Topic fred = (Topic) m_tm.getObjectById("fred"); ! params.set(0, fred.getOccurrences().iterator().next()); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(1, out.getRows().size()); ! assertEquals(m_tm.getObjectById("bootsize"), out.getRow(0).get(1)); ! AssociationRole fredRole = (AssociationRole) fred.getRolesPlayed().iterator().next(); params.set(0, fredRole); out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(1, out.getRows().size()); ! assertEquals(m_tm.getObjectById("employee"), out.getRow(0).get(1)); ! params.set(0, fredRole.getParent()); out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(1, out.getRows().size()); ! assertEquals(m_tm.getObjectById("works-for"), out.getRow(0).get(1)); } --- 87,110 ---- m_predicate.setParameters(params); ! Topic fred = (Topic) getObjectById("fred"); ! params.set(0, fred.getOccurrences().iterator().next()); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(1, out.getRows().size()); ! assertEquals(getObjectById("bootsize"), out.getRow(0).get(1)); ! AssociationRole fredRole = (AssociationRole) fred.getRolesPlayed().iterator().next(); params.set(0, fredRole); out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(1, out.getRows().size()); ! assertEquals(getObjectById("employee"), out.getRow(0).get(1)); ! params.set(0, fredRole.getParent()); out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(1, out.getRows().size()); ! assertEquals(getObjectById("works-for"), out.getRow(0).get(1)); } *************** *** 88,92 **** m_predicate.setParameters(params); ! params.set(1, m_tm.getObjectById("bootsize")); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); --- 117,121 ---- m_predicate.setParameters(params); ! params.set(1, getObjectById("bootsize")); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); *************** *** 94,98 **** assertTrue(out.getRow(0).get(0) instanceof Occurrence); ! params.set(1, m_tm.getObjectById("employee")); out = m_predicate.matches(params, m_context); assertNotNull(out); --- 123,127 ---- assertTrue(out.getRow(0).get(0) instanceof Occurrence); ! params.set(1, getObjectById("employee")); out = m_predicate.matches(params, m_context); assertNotNull(out); *************** *** 106,110 **** assertTrue(out.getRow(0).get(0) instanceof Association); } ! public void testClosedMatch() throws Exception { ArrayList params = new ArrayList(); --- 135,139 ---- assertTrue(out.getRow(0).get(0) instanceof Association); } ! public void testClosedMatch() throws Exception { ArrayList params = new ArrayList(); *************** *** 115,128 **** m_predicate.setParameters(params); ! Topic fred = (Topic) m_tm.getObjectById("fred"); params.set(0, fred.getOccurrences().iterator().next()); ! params.set(1, m_tm.getObjectById("bootsize")); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(1, out.getRows().size()); ! AssociationRole fredRole = (AssociationRole) fred.getRolesPlayed().iterator().next(); params.set(0, fredRole); ! params.set(1, m_tm.getObjectById("employee")); out = m_predicate.matches(params, m_context); assertNotNull(out); --- 144,157 ---- m_predicate.setParameters(params); ! Topic fred = (Topic) getObjectById("fred"); params.set(0, fred.getOccurrences().iterator().next()); ! params.set(1, getObjectById("bootsize")); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(1, out.getRows().size()); ! AssociationRole fredRole = (AssociationRole) fred.getRolesPlayed().iterator().next(); params.set(0, fredRole); ! params.set(1, getObjectById("employee")); out = m_predicate.matches(params, m_context); assertNotNull(out); *************** *** 130,139 **** params.set(0, fredRole.getParent()); ! params.set(1, m_tm.getObjectById("works-for")); out = m_predicate.matches(params, m_context); assertNotNull(out); ! assertEquals(1, out.getRows().size()); } ! public void testOpenMatch() throws Exception { ArrayList params = new ArrayList(); --- 159,168 ---- params.set(0, fredRole.getParent()); ! params.set(1, getObjectById("works-for")); out = m_predicate.matches(params, m_context); assertNotNull(out); ! assertEquals(1, out.getRows().size()); } ! public void testOpenMatch() throws Exception { ArrayList params = new ArrayList(); *************** *** 164,167 **** --- 193,201 ---- /* * $Log$ + * Revision 1.3 2005/03/07 12:32:00 lheuer + * More TM4J -> TMAPI translations + * Updated ToDo + * ResourcePredicate can handle Variants, too + * * Revision 1.2 2005/03/06 19:37:40 lheuer * Changed getTopicByID to getObjectById Index: AssociationPredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/AssociationPredicateTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AssociationPredicateTest.java 6 Mar 2005 19:37:23 -0000 1.2 --- AssociationPredicateTest.java 7 Mar 2005 12:32:00 -0000 1.3 *************** *** 18,23 **** import org.tmapiutils.query.tolog.predicates.AssociationPredicate; import org.tmapiutils.query.tolog.utils.VariableSet; import org.tmapi.core.Association; ! /** * @author Kal --- 18,24 ---- import org.tmapiutils.query.tolog.predicates.AssociationPredicate; import org.tmapiutils.query.tolog.utils.VariableSet; + // TMAPI import org.tmapi.core.Association; ! import org.tmapi.index.core.TopicsIndex; /** * @author Kal *************** *** 41,44 **** --- 42,61 ---- "works-for(barney:employee, bigco:employer)\n"; } + + public void createTestMap(TopicMap tm) { + Topic works_for = tm.createTopic(); + Topic fred = tm.createTopic(); + fred.addSubjectIdentifier(tm.createLocator("fred")); + Topic barney = tm.createTopic(); + barney.addSubjectIdentifier(tm.createLocator("barney")); + Topic employee = tm.createTopic(); + Topic employer = tm.createTopic(); + Topic bigco = tm.createTopic(); + Association assoc = tm.createAssociation(); + assoc.setType(works_for); + assoc.createAssociationRole(fred, employee); + assoc.createAssociationRole(bigco, employer); + assoc.createAssociationRole(barney, employee); + } /* (non-Javadoc) *************** *** 66,69 **** --- 83,89 ---- public void testClosedMatch() throws Exception { + TopicsIndex topicsIdx = m_tm.getHelperObjects(TopicsIndex.class); + topicsIdx.open(); + topicsIdx.reindex(); ArrayList params = new ArrayList(); Variable a = new Variable("A"); *************** *** 75,80 **** assertEquals(1, out.getColumns().size()); assertEquals(1, out.getRows().size()); ! ! params.set(0, m_tm.getObjectById("fred")); out = m_predicate.matches(params, m_context); assertNotNull(out); --- 95,100 ---- assertEquals(1, out.getColumns().size()); assertEquals(1, out.getRows().size()); ! fred = topicsIdx.getTopicBySubjectIdentifier(createLocator("fred")); ! params.set(0, fred); out = m_predicate.matches(params, m_context); assertNotNull(out); *************** *** 86,89 **** --- 106,114 ---- /* * $Log$ + * Revision 1.3 2005/03/07 12:32:00 lheuer + * More TM4J -> TMAPI translations + * Updated ToDo + * ResourcePredicate can handle Variants, too + * * Revision 1.2 2005/03/06 19:37:23 lheuer * Changed getTopicByID to getObjectById Index: InstanceOfPredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/InstanceOfPredicateTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** InstanceOfPredicateTest.java 6 Mar 2005 21:11:33 -0000 1.3 --- InstanceOfPredicateTest.java 7 Mar 2005 12:32:00 -0000 1.4 *************** *** 16,23 **** import org.tmapiutils.query.tolog.predicates.InstanceOfPredicate; import org.tmapiutils.query.tolog.utils.VariableSet; /** * @author Kal ! * * Describe InstanceOfPredicateTest here. */ --- 16,29 ---- import org.tmapiutils.query.tolog.predicates.InstanceOfPredicate; import org.tmapiutils.query.tolog.utils.VariableSet; + // TMAPI + import org.tmapi.core.TopicMapObject; + import org.tmapi.core.TopicMap; + import org.tmapi.core.Topic; + import org.tmapi.index.core.TopicMapObjectsIndex; + import org.tmapi.index.core.TopicsIndex; /** * @author Kal ! * * Describe InstanceOfPredicateTest here. */ *************** *** 44,47 **** --- 50,81 ---- } + public void createTestMap(TopicMap tm) { + Topic animal = tm.createTopic(); + animal.addSourceLocator(createLocator("animal")); + Topic mammal = tm.createTopic(); + mammal.addSourceLocator(createLocator("mammal")); + Topic reptile = tm.createTopic(); + reptile.addSourceLocator(createLocator("reptile")); + Topic elephant = tm.createTopic(); + elephant.addSourceLocator(createLocator("elephant")); + Topic nelly = tm.createTopic(); + nelly.addSourceLocator(createLocator("nelly")); + nelly.addType(elephant); + Topic supersub = tm.createTopic(); + supersub.addSubjectIdentifier(createLocator("http://www.topicmaps.org/xtm/1.0/core.xtm#superclass-subclass")); + sub = tm.createTopic(); + sub.addSubjectIdentifier(createLocator("http://www.topicmaps.org/xtm/1.0/core.xtm#subclass")); + supr = tm.createTopic(); + supr.addSubjectIdentifier(createLocator("http://www.topicmaps.org/xtm/1.0/core.xtm#superclass")); + + Association assoc = tm.createAssociation(); + assoc.setType(supersub); + assoc.createAssociationRole(animal, supr); + assoc.createAssociationRole(mammal, sub); + assoc.createAssociationRole(reptile, sub); + assoc.createAssociationRole(mammal, supr); + assoc.createAssociationRole(elephant, sub); + } + /* (non-Javadoc) * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getPredicateClass() *************** *** 52,58 **** public void testClassMatch() throws Exception { ArrayList params = new ArrayList(); ! Variable a = new Variable("A"); ! params.add(m_tm.getObjectById("nelly")); params.add(a); m_predicate.setParameters(params); --- 86,99 ---- public void testClassMatch() throws Exception { + tmoIdx = (TopicMapObjectsIndex) m_tm.getHelperObject(TopicMapObjectsIndex.class); + tmoIdx.open(); + tmoIdx.reindex(); + TopicMapObject nelly = tmoIdx.getTopicMapObjectBySourceLocator(createLocator("nelly")); + TopicMapObject elephant = tmoIdx.getTopicMapObjectBySourceLocator(createLocator("elephant")); + TopicMapObject mammal = tmoIdx.getTopicMapObjectBySourceLocator(createLocator("mammal")); + TopicMapObject animal = tmoIdx.getTopicMapObjectBySourceLocator(createLocator("animal")); ArrayList params = new ArrayList(); ! Variable a = new Variable("A"); ! params.add(nelly); params.add(a); m_predicate.setParameters(params); *************** *** 61,74 **** assertEquals(1, out.getColumns().size()); assertEquals(3, out.getRows().size()); ! assertTrue(out.getColumn(a).contains(m_tm.getObjectById("elephant"))); ! assertTrue(out.getColumn(a).contains(m_tm.getObjectById("mammal"))); ! assertTrue(out.getColumn(a).contains(m_tm.getObjectById("animal"))); } ! public void testInstanceMatch() throws Exception { ArrayList params = new ArrayList(); Variable a = new Variable("A"); params.add(a); ! params.add(m_tm.getObjectById("animal")); m_predicate.setParameters(params); VariableSet out = m_predicate.matches(params, m_context); --- 102,120 ---- assertEquals(1, out.getColumns().size()); assertEquals(3, out.getRows().size()); ! assertTrue(out.getColumn(a).contains(elephant)); ! assertTrue(out.getColumn(a).contains(mammal)); ! assertTrue(out.getColumn(a).contains(animal)); } ! public void testInstanceMatch() throws Exception { + tmoIdx = (TopicMapObjectsIndex) m_tm.getHelperObject(TopicMapObjectsIndex.class); + tmoIdx.open(); + tmoIdx.reindex(); + TopicMapObject animal = tmoIdx.getTopicMapObjectBySourceLocator(createLocator("animal")); + TopicMapObject nelly = tmoIdx.getTopicMapObjectBySourceLocator(createLocator("nelly")); ArrayList params = new ArrayList(); Variable a = new Variable("A"); params.add(a); ! params.add(animal); m_predicate.setParameters(params); VariableSet out = m_predicate.matches(params, m_context); *************** *** 76,83 **** assertEquals(1, out.getColumns().size()); assertEquals(1, out.getRows().size()); ! assertTrue(out.getColumn(a).contains(m_tm.getObjectById("nelly"))); } ! public void testOpenMatch() throws Exception { ArrayList params = new ArrayList(); Variable a = new Variable("A"); --- 122,136 ---- assertEquals(1, out.getColumns().size()); assertEquals(1, out.getRows().size()); ! assertTrue(out.getColumn(a).contains(nelly)); } ! public void testOpenMatch() throws Exception { + tmoIdx = (TopicMapObjectsIndex) m_tm.getHelperObject(TopicMapObjectsIndex.class); + tmoIdx.open(); + tmoIdx.reindex(); + TopicMapObject animal = tmoIdx.getTopicMapObjectBySourceLocator(createLocator("animal")); + TopicMapObject nelly = tmoIdx.getTopicMapObjectBySourceLocator(createLocator("nelly")); + TopicMapObject elephant = tmoIdx.getTopicMapObjectBySourceLocator(createLocator("elephant")); + TopicMapObject mammal = tmoIdx.getTopicMapObjectBySourceLocator(createLocator("mammal")); ArrayList params = new ArrayList(); Variable a = new Variable("A"); *************** *** 90,100 **** assertEquals(2, out.getColumns().size()); assertEquals(3, out.getRows().size()); ! assertTrue(out.getColumn(a).contains(m_tm.getObjectById("nelly"))); ! assertTrue(out.getColumn(b).contains(m_tm.getObjectById("elephant"))); ! assertTrue(out.getColumn(b).contains(m_tm.getObjectById("mammal"))); ! assertTrue(out.getColumn(b).contains(m_tm.getObjectById("animal"))); } ! public void testClosedMatch() throws Exception { ArrayList params = new ArrayList(); Variable a = new Variable("A"); --- 143,160 ---- assertEquals(2, out.getColumns().size()); assertEquals(3, out.getRows().size()); ! assertTrue(out.getColumn(a).contains(nelly)); ! assertTrue(out.getColumn(b).contains(elephant)); ! assertTrue(out.getColumn(b).contains(mammal)); ! assertTrue(out.getColumn(b).contains(animal)); } ! public void testClosedMatch() throws Exception { + tmoIdx = (TopicMapObjectsIndex) m_tm.getHelperObject(TopicMapObjectsIndex.class); + tmoIdx.open(); + tmoIdx.reindex(); + TopicMapObject animal = tmoIdx.getTopicMapObjectBySourceLocator(createLocator("animal")); + TopicMapObject nelly = tmoIdx.getTopicMapObjectBySourceLocator(createLocator("nelly")); + TopicMapObject reptile = tmoIdx.getTopicMapObjectBySourceLocator(createLocator("reptile")); + TopicMapObject mammal = tmoIdx.getTopicMapObjectBySourceLocator(createLocator("mammal")); ArrayList params = new ArrayList(); Variable a = new Variable("A"); *************** *** 103,118 **** params.add(b); m_predicate.setParameters(params); ! params.set(0, m_tm.getObjectById("nelly")); ! params.set(1, m_tm.getObjectById("mammal")); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(1, out.getRows().size()); ! params.set(0, m_tm.getObjectById("nelly")); ! params.set(1, m_tm.getObjectById("reptile")); out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(0, out.getRows().size()); ! } } --- 163,178 ---- params.add(b); m_predicate.setParameters(params); ! params.set(0, nelly); ! params.set(1, mammal); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(1, out.getRows().size()); ! params.set(0, nelly); ! params.set(1, reptile); out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(0, out.getRows().size()); ! } } *************** *** 120,123 **** --- 180,188 ---- /* * $Log$ + * Revision 1.4 2005/03/07 12:32:00 lheuer + * More TM4J -> TMAPI translations + * Updated ToDo + * ResourcePredicate can handle Variants, too + * * Revision 1.3 2005/03/06 21:11:33 lheuer * More TM4J -> TMAPI translations |