Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30131/src/org/tmapiutils/query/tolog/test Modified Files: AndClauseTest.java AssociationPredicateTest.java BackendTests.java ImportTest.java Increment.java MemoryQueryEvaluatorImplTest.java NotClauseTest.java OrClauseTest.java ProjectionTest.java RuleTest.java SortingTest.java TologParserTest.java TologParserTestBase.java VariableSetTest.java Log Message: Tabs -> Whitespaces Index: AssociationPredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test/AssociationPredicateTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** AssociationPredicateTest.java 9 Mar 2005 12:40:20 -0000 1.4 --- AssociationPredicateTest.java 8 Jul 2005 16:03:21 -0000 1.5 *************** *** 1,216 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * 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.tmapiutils.query.tolog.test; ! ! import java.io.StringReader; ! import java.util.ArrayList; ! import java.util.List; ! import java.util.HashMap; ! ! import junit.framework.TestCase; ! ! import org.apache.log4j.BasicConfigurator; ! import org.tmapiutils.query.tolog.parser.ClauseList; ! import org.tmapiutils.query.tolog.parser.PlayerRoleVarPair; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.predicates.DynamicAssociationPredicate; ! import org.tmapiutils.query.tolog.utils.TologContext; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // 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; ! import org.tmapi.core.Topic; ! import org.tmapi.core.Association; ! ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class AssociationPredicateTest extends TestCase { ! ! private TopicMap m_tm; ! private TopicMapSystem _tmSystem; ! private HashMap _objectMap; ! ! /** ! * Constructor for AssociationPredicateTest. ! * @param arg0 ! */ ! public AssociationPredicateTest(String arg0) { ! super(arg0); ! } ! ! public static void main(String[] args) { ! junit.textui.TestRunner.run(AssociationPredicateTest.class); ! BasicConfigurator.configure(); ! } ! ! public void testSimpleMatch() throws Exception { ! ! ClauseList c = new ClauseList(); ! DynamicAssociationPredicate p = new DynamicAssociationPredicate(); ! ArrayList params = new ArrayList(); ! params.add(m_tm.getObjectById("worksfor")); ! params.add(new PlayerRoleVarPair((Topic) getObjectById("kal"), (Topic) getObjectById("employee"))); ! params.add(new PlayerRoleVarPair(new Variable("A"), (Topic) getObjectById("employer"))); ! p.setParameters(params); ! c.addPredicate(p); ! VariableSet varsIn = new VariableSet(); ! varsIn.addColumn(new Variable("A")); ! varsIn.addRow(varsIn.getColumns()); ! VariableSet varsOut = c.execute(varsIn, new TologContext()); ! assertEquals(1, varsOut.size()); ! List row = varsOut.getRow(0); ! assertNotNull(row); ! assertEquals(row.size(), 1); ! assertEquals(getObjectById("techquila"), row.get(0)); ! ! } ! ! public void testMultipleMatch() throws Exception { ! ! ClauseList c = new ClauseList(); ! DynamicAssociationPredicate p = new DynamicAssociationPredicate(); ! p.initialise(m_tm); ! ArrayList params = new ArrayList(); ! params.add(m_tm.getObjectById("worksfor")); ! params.add(new PlayerRoleVarPair(new Variable("PERSON"), (Topic) getObjectById("employee"))); ! params.add(new PlayerRoleVarPair(new Variable("COMPANY"), (Topic) getObjectById("employer"))); ! p.setParameters(params); ! c.addPredicate(p); ! VariableSet varsIn = new VariableSet(); ! varsIn.addColumn(new Variable("PERSON")); ! varsIn.addColumn(new Variable("COMPANY")); ! varsIn.addRow(varsIn.getColumns()); ! VariableSet varsOut = c.execute(varsIn, new TologContext()); ! assertEquals(2, varsOut.size()); ! for (int i = 0; i < 2; i++) { ! List row = varsOut.getRow(i); ! assertNotNull(row); ! assertEquals(row.size(), 2); ! assertTrue( ! row.get(0).equals(getObjectById("kal")) || ! row.get(0).equals(getObjectById("fred"))); ! assertTrue( ! row.get(1).equals(getObjectById("techquila")) || ! row.get(1).equals(getObjectById("bigcorp"))); ! } ! } ! ! public void testRoleMatch() throws Exception { ! ClauseList c = new ClauseList(); ! DynamicAssociationPredicate p = new DynamicAssociationPredicate(); ! p.initialise(m_tm); ! ArrayList params = new ArrayList(); ! params.add(new Variable("ASSOC")); ! params.add(new PlayerRoleVarPair(new Variable("PERSON"), (Topic) getObjectById("employee"))); ! params.add(new PlayerRoleVarPair(new Variable("COMPANY"), (Topic) getObjectById("employer"))); ! p.setParameters(params); ! c.addPredicate(p); ! VariableSet varsIn = new VariableSet(); ! varsIn.addColumn(new Variable("ASSOC")); ! varsIn.addColumn(new Variable("PERSON")); ! varsIn.addColumn(new Variable("COMPANY")); ! varsIn.addRow(varsIn.getColumns()); ! VariableSet varsOut = c.execute(varsIn, new TologContext()); ! assertEquals(2, varsOut.size()); ! for (int i = 0; i < 2; i++) { ! List row = varsOut.getRow(i); ! assertNotNull(row); ! assertEquals(row.size(), 3); ! assertEquals(row.get(0), getObjectById("worksfor")); ! assertTrue( ! row.get(1).equals(getObjectById("kal")) || ! row.get(1).equals(getObjectById("fred"))); ! assertTrue( ! row.get(2).equals(getObjectById("techquila")) || ! row.get(2).equals(getObjectById("bigcorp"))); ! } ! } ! ! protected void setUp() throws Exception { ! super.setUp(); ! _objectMap = new HashMap(); ! _tmSystem = TopicMapSystemFactory.newInstance().newTopicMapSystem(); ! m_tm = _tmSystem.createTopicMap("http://tmapiutils.org/test/tolog1.0/"); ! createTestMap(m_tm); ! // 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(TESTMAP), loc, new LTMBuilder()); ! // m_tm = m_provider.addTopicMap(src); ! } ! ! protected void tearDown() throws Exception{ ! super.tearDown(); ! _objectMap.clear(); ! // remove created TopicMaps from TopicMapSystem ! m_tm.remove(); ! // Close TopicMapSystem instance ! _tmSystem.close(); ! } ! ! public void createTestMap(TopicMap tm) { ! Topic works_for = tm.createTopic(); ! Topic fred = tm.createTopic(); ! Topic kal = tm.createTopic(); ! Topic techquila = tm.createTopic(); ! Topic employee = tm.createTopic(); ! Topic employer = tm.createTopic(); ! Topic bigco = tm.createTopic(); ! ! Association assoc1 = tm.createAssociation(); ! assoc1.setType(works_for); ! assoc1.createAssociationRole(kal, employee); ! assoc1.createAssociationRole(techquila, employer); ! ! ! Association assoc2 = tm.createAssociation(); ! assoc2.setType(works_for); ! assoc2.createAssociationRole(fred, employee); ! assoc2.createAssociationRole(bigco, employer); ! ! registerObject("works-for", works_for); ! registerObject("fred", fred); ! registerObject("kal", kal); ! registerObject("techquila", techquila); ! registerObject("employee", employee); ! registerObject("bigco", bigco); ! registerObject("employer", employer); ! } ! ! protected void registerObject(String name, TopicMapObject obj) { ! _objectMap.put(name, obj); ! } ! ! protected TopicMapObject getObjectById(String name) { ! TopicMapObject obj = (TopicMapObject) _objectMap.get(name); ! if (obj == null) { ! throw new RuntimeException("Object Id not found :" + name); ! } ! return obj; ! } ! ! private static final String TESTMAP ="worksfor(kal:employee, techquila:employer)\n" + "worksfor(fred:employee, bigcorp:employer)\n"; ! } ! --- 1,216 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * 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.tmapiutils.query.tolog.test; ! ! import java.io.StringReader; ! import java.util.ArrayList; ! import java.util.List; ! import java.util.HashMap; ! ! import junit.framework.TestCase; ! ! import org.apache.log4j.BasicConfigurator; ! import org.tmapiutils.query.tolog.parser.ClauseList; ! import org.tmapiutils.query.tolog.parser.PlayerRoleVarPair; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.predicates.DynamicAssociationPredicate; ! import org.tmapiutils.query.tolog.utils.TologContext; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // 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; ! import org.tmapi.core.Topic; ! import org.tmapi.core.Association; ! ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class AssociationPredicateTest extends TestCase { ! ! private TopicMap m_tm; ! private TopicMapSystem _tmSystem; ! private HashMap _objectMap; ! ! /** ! * Constructor for AssociationPredicateTest. ! * @param arg0 ! */ ! public AssociationPredicateTest(String arg0) { ! super(arg0); ! } ! ! public static void main(String[] args) { ! junit.textui.TestRunner.run(AssociationPredicateTest.class); ! BasicConfigurator.configure(); ! } ! ! public void testSimpleMatch() throws Exception { ! ! ClauseList c = new ClauseList(); ! DynamicAssociationPredicate p = new DynamicAssociationPredicate(); ! ArrayList params = new ArrayList(); ! params.add(m_tm.getObjectById("worksfor")); ! params.add(new PlayerRoleVarPair((Topic) getObjectById("kal"), (Topic) getObjectById("employee"))); ! params.add(new PlayerRoleVarPair(new Variable("A"), (Topic) getObjectById("employer"))); ! p.setParameters(params); ! c.addPredicate(p); ! VariableSet varsIn = new VariableSet(); ! varsIn.addColumn(new Variable("A")); ! varsIn.addRow(varsIn.getColumns()); ! VariableSet varsOut = c.execute(varsIn, new TologContext()); ! assertEquals(1, varsOut.size()); ! List row = varsOut.getRow(0); ! assertNotNull(row); ! assertEquals(row.size(), 1); ! assertEquals(getObjectById("techquila"), row.get(0)); ! ! } ! ! public void testMultipleMatch() throws Exception { ! ! ClauseList c = new ClauseList(); ! DynamicAssociationPredicate p = new DynamicAssociationPredicate(); ! p.initialise(m_tm); ! ArrayList params = new ArrayList(); ! params.add(m_tm.getObjectById("worksfor")); ! params.add(new PlayerRoleVarPair(new Variable("PERSON"), (Topic) getObjectById("employee"))); ! params.add(new PlayerRoleVarPair(new Variable("COMPANY"), (Topic) getObjectById("employer"))); ! p.setParameters(params); ! c.addPredicate(p); ! VariableSet varsIn = new VariableSet(); ! varsIn.addColumn(new Variable("PERSON")); ! varsIn.addColumn(new Variable("COMPANY")); ! varsIn.addRow(varsIn.getColumns()); ! VariableSet varsOut = c.execute(varsIn, new TologContext()); ! assertEquals(2, varsOut.size()); ! for (int i = 0; i < 2; i++) { ! List row = varsOut.getRow(i); ! assertNotNull(row); ! assertEquals(row.size(), 2); ! assertTrue( ! row.get(0).equals(getObjectById("kal")) || ! row.get(0).equals(getObjectById("fred"))); ! assertTrue( ! row.get(1).equals(getObjectById("techquila")) || ! row.get(1).equals(getObjectById("bigcorp"))); ! } ! } ! ! public void testRoleMatch() throws Exception { ! ClauseList c = new ClauseList(); ! DynamicAssociationPredicate p = new DynamicAssociationPredicate(); ! p.initialise(m_tm); ! ArrayList params = new ArrayList(); ! params.add(new Variable("ASSOC")); ! params.add(new PlayerRoleVarPair(new Variable("PERSON"), (Topic) getObjectById("employee"))); ! params.add(new PlayerRoleVarPair(new Variable("COMPANY"), (Topic) getObjectById("employer"))); ! p.setParameters(params); ! c.addPredicate(p); ! VariableSet varsIn = new VariableSet(); ! varsIn.addColumn(new Variable("ASSOC")); ! varsIn.addColumn(new Variable("PERSON")); ! varsIn.addColumn(new Variable("COMPANY")); ! varsIn.addRow(varsIn.getColumns()); ! VariableSet varsOut = c.execute(varsIn, new TologContext()); ! assertEquals(2, varsOut.size()); ! for (int i = 0; i < 2; i++) { ! List row = varsOut.getRow(i); ! assertNotNull(row); ! assertEquals(row.size(), 3); ! assertEquals(row.get(0), getObjectById("worksfor")); ! assertTrue( ! row.get(1).equals(getObjectById("kal")) || ! row.get(1).equals(getObjectById("fred"))); ! assertTrue( ! row.get(2).equals(getObjectById("techquila")) || ! row.get(2).equals(getObjectById("bigcorp"))); ! } ! } ! ! protected void setUp() throws Exception { ! super.setUp(); ! _objectMap = new HashMap(); ! _tmSystem = TopicMapSystemFactory.newInstance().newTopicMapSystem(); ! m_tm = _tmSystem.createTopicMap("http://tmapiutils.org/test/tolog1.0/"); ! createTestMap(m_tm); ! // 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(TESTMAP), loc, new LTMBuilder()); ! // m_tm = m_provider.addTopicMap(src); ! } ! ! protected void tearDown() throws Exception{ ! super.tearDown(); ! _objectMap.clear(); ! // remove created TopicMaps from TopicMapSystem ! m_tm.remove(); ! // Close TopicMapSystem instance ! _tmSystem.close(); ! } ! ! public void createTestMap(TopicMap tm) { ! Topic works_for = tm.createTopic(); ! Topic fred = tm.createTopic(); ! Topic kal = tm.createTopic(); ! Topic techquila = tm.createTopic(); ! Topic employee = tm.createTopic(); ! Topic employer = tm.createTopic(); ! Topic bigco = tm.createTopic(); ! ! Association assoc1 = tm.createAssociation(); ! assoc1.setType(works_for); ! assoc1.createAssociationRole(kal, employee); ! assoc1.createAssociationRole(techquila, employer); ! ! ! Association assoc2 = tm.createAssociation(); ! assoc2.setType(works_for); ! assoc2.createAssociationRole(fred, employee); ! assoc2.createAssociationRole(bigco, employer); ! ! registerObject("works-for", works_for); ! registerObject("fred", fred); ! registerObject("kal", kal); ! registerObject("techquila", techquila); ! registerObject("employee", employee); ! registerObject("bigco", bigco); ! registerObject("employer", employer); ! } ! ! protected void registerObject(String name, TopicMapObject obj) { ! _objectMap.put(name, obj); ! } ! ! protected TopicMapObject getObjectById(String name) { ! TopicMapObject obj = (TopicMapObject) _objectMap.get(name); ! if (obj == null) { ! throw new RuntimeException("Object Id not found :" + name); ! } ! return obj; ! } ! ! private static final String TESTMAP ="worksfor(kal:employee, techquila:employer)\n" + "worksfor(fred:employee, bigcorp:employer)\n"; ! } ! Index: ImportTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test/ImportTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ImportTest.java 8 Mar 2005 12:33:58 -0000 1.2 --- ImportTest.java 8 Jul 2005 16:03:21 -0000 1.3 *************** *** 1,79 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * 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.tmapiutils.query.tolog.test; ! ! import java.io.File; ! import java.io.StringReader; ! import java.util.Map; ! ! import org.tmapiutils.query.tolog.parser.TologLexer; ! import org.tmapiutils.query.tolog.parser.TologParser; ! import org.tmapiutils.query.tolog.parser.TologRule; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class ImportTest extends TologParserTestBase ! { ! File m_modulesDir; ! ! /** ! * @param arg0 ! */ ! public ImportTest(String arg0) { ! super(arg0); ! String testdir = System.getProperty("testdir"); ! m_modulesDir = new File(testdir + File.separator + "tologx"); ! } ! ! public void testImport() throws Exception { ! File refModule = new File(m_modulesDir, "module1.tl"); ! assertTrue("Cannot locate module to be referenced at " + refModule.getAbsolutePath(), ! refModule.exists()); ! ! String rootModule = "import \"" + refModule.toURL().toString() + "\" as test"; ! TologParser p = new TologParser(new TologLexer(new StringReader(rootModule))); ! p.setTopicMap(m_tm); ! p.module(); ! Map rules = p.getRules(); ! assertNotNull(rules); ! assertEquals(1, rules.size()); ! TologRule r = (TologRule)rules.get("test:nestedin"); ! assertNotNull(r); ! } ! ! public void testNestedImport() throws Exception { ! File refModule = new File(m_modulesDir, "nested-module-parent.tl"); ! assertTrue("Cannot locate module to be referenced at " + refModule.getAbsolutePath(), ! refModule.exists()); ! ! String rootModule = "import \"" + refModule.toURL().toString() + "\" as test"; ! TologParser p = new TologParser(new TologLexer(new StringReader(rootModule))); ! p.setTopicMap(m_tm); ! p.module(); ! Map rules = p.getRules(); ! assertNotNull(rules); ! assertEquals(1, rules.size()); ! TologRule r = (TologRule)rules.get("test:crosscontinent"); ! assertNotNull(r); ! } ! ! } ! --- 1,79 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * 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.tmapiutils.query.tolog.test; ! ! import java.io.File; ! import java.io.StringReader; ! import java.util.Map; ! ! import org.tmapiutils.query.tolog.parser.TologLexer; ! import org.tmapiutils.query.tolog.parser.TologParser; ! import org.tmapiutils.query.tolog.parser.TologRule; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class ImportTest extends TologParserTestBase ! { ! File m_modulesDir; ! ! /** ! * @param arg0 ! */ ! public ImportTest(String arg0) { ! super(arg0); ! String testdir = System.getProperty("testdir"); ! m_modulesDir = new File(testdir + File.separator + "tologx"); ! } ! ! public void testImport() throws Exception { ! File refModule = new File(m_modulesDir, "module1.tl"); ! assertTrue("Cannot locate module to be referenced at " + refModule.getAbsolutePath(), ! refModule.exists()); ! ! String rootModule = "import \"" + refModule.toURL().toString() + "\" as test"; ! TologParser p = new TologParser(new TologLexer(new StringReader(rootModule))); ! p.setTopicMap(m_tm); ! p.module(); ! Map rules = p.getRules(); ! assertNotNull(rules); ! assertEquals(1, rules.size()); ! TologRule r = (TologRule)rules.get("test:nestedin"); ! assertNotNull(r); ! } ! ! public void testNestedImport() throws Exception { ! File refModule = new File(m_modulesDir, "nested-module-parent.tl"); ! assertTrue("Cannot locate module to be referenced at " + refModule.getAbsolutePath(), ! refModule.exists()); ! ! String rootModule = "import \"" + refModule.toURL().toString() + "\" as test"; ! TologParser p = new TologParser(new TologLexer(new StringReader(rootModule))); ! p.setTopicMap(m_tm); ! p.module(); ! Map rules = p.getRules(); ! assertNotNull(rules); ! assertEquals(1, rules.size()); ! TologRule r = (TologRule)rules.get("test:crosscontinent"); ! assertNotNull(r); ! } ! ! } ! Index: RuleTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test/RuleTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RuleTest.java 8 Mar 2005 12:33:58 -0000 1.2 --- RuleTest.java 8 Jul 2005 16:03:21 -0000 1.3 *************** *** 1,100 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * 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.tmapiutils.query.tolog.test; ! ! import java.util.ArrayList; ! import java.util.List; ! ! import junit.framework.TestCase; ! ! import org.apache.log4j.BasicConfigurator; ! import org.tmapiutils.query.tolog.parser.ClauseList; ! import org.tmapiutils.query.tolog.parser.Predicate; ! import org.tmapiutils.query.tolog.parser.TologRule; ! import org.tmapiutils.query.tolog.parser.TologRuleImpl; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.TologContext; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class RuleTest extends TestCase { ! ! /** ! * Constructor for RuleTest. ! * @param arg0 ! */ ! public RuleTest(String arg0) { ! super(arg0); ! BasicConfigurator.configure(); ! } ! ! public static void main(String[] args) { ! junit.textui.TestRunner.run(RuleTest.class); ! } ! ! public void testRule() throws Exception ! { ! TologRule r = new TologRuleImpl(); ! r.setName("MyRule"); ! r.addHeadParameter(new Variable("A")); ! r.addHeadParameter(new Variable("B")); ! ClauseList ruleBody = new ClauseList(); ! ! Increment i1 = new Increment(); ! ArrayList i1Params = new ArrayList(); ! i1Params.add(new Variable("A")); ! i1Params.add(new Variable("C")); ! i1.setParameters(i1Params); ! ! Increment i2 = new Increment(); ! ArrayList i2Params = new ArrayList(); ! i2Params.add(new Variable("C")); ! i2Params.add(new Variable("B")); ! i2.setParameters(i2Params); ! ! ruleBody.addPredicate(i1); ! ruleBody.addPredicate(i2); ! ! r.setRuleBody(ruleBody); ! ! ClauseList cl = new ClauseList(); ! Predicate p = r.newInstance(); ! ArrayList pParams = new ArrayList(); ! pParams.add(new Integer(1)); ! pParams.add(new Variable("X")); ! p.setParameters(pParams); ! cl.addPredicate(p); ! ! VariableSet vsIn = new VariableSet(); ! vsIn.addColumn(new Variable("X")); ! vsIn.addRow(vsIn.getColumns()); ! VariableSet vsOut = cl.execute(vsIn, new TologContext()); ! assertNotNull(vsOut); ! assertEquals(1, vsOut.size()); ! List row = vsOut.getRow(0); ! assertNotNull(row); ! assertEquals(1, row.size()); ! assertEquals(new Integer(3), row.get(0)); ! } ! ! } ! --- 1,100 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * 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.tmapiutils.query.tolog.test; ! ! import java.util.ArrayList; ! import java.util.List; ! ! import junit.framework.TestCase; ! ! import org.apache.log4j.BasicConfigurator; ! import org.tmapiutils.query.tolog.parser.ClauseList; ! import org.tmapiutils.query.tolog.parser.Predicate; ! import org.tmapiutils.query.tolog.parser.TologRule; ! import org.tmapiutils.query.tolog.parser.TologRuleImpl; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.TologContext; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class RuleTest extends TestCase { ! ! /** ! * Constructor for RuleTest. ! * @param arg0 ! */ ! public RuleTest(String arg0) { ! super(arg0); ! BasicConfigurator.configure(); ! } ! ! public static void main(String[] args) { ! junit.textui.TestRunner.run(RuleTest.class); ! } ! ! public void testRule() throws Exception ! { ! TologRule r = new TologRuleImpl(); ! r.setName("MyRule"); ! r.addHeadParameter(new Variable("A")); ! r.addHeadParameter(new Variable("B")); ! ClauseList ruleBody = new ClauseList(); ! ! Increment i1 = new Increment(); ! ArrayList i1Params = new ArrayList(); ! i1Params.add(new Variable("A")); ! i1Params.add(new Variable("C")); ! i1.setParameters(i1Params); ! ! Increment i2 = new Increment(); ! ArrayList i2Params = new ArrayList(); ! i2Params.add(new Variable("C")); ! i2Params.add(new Variable("B")); ! i2.setParameters(i2Params); ! ! ruleBody.addPredicate(i1); ! ruleBody.addPredicate(i2); ! ! r.setRuleBody(ruleBody); ! ! ClauseList cl = new ClauseList(); ! Predicate p = r.newInstance(); ! ArrayList pParams = new ArrayList(); ! pParams.add(new Integer(1)); ! pParams.add(new Variable("X")); ! p.setParameters(pParams); ! cl.addPredicate(p); ! ! VariableSet vsIn = new VariableSet(); ! vsIn.addColumn(new Variable("X")); ! vsIn.addRow(vsIn.getColumns()); ! VariableSet vsOut = cl.execute(vsIn, new TologContext()); ! assertNotNull(vsOut); ! assertEquals(1, vsOut.size()); ! List row = vsOut.getRow(0); ! assertNotNull(row); ! assertEquals(1, row.size()); ! assertEquals(new Integer(3), row.get(0)); ! } ! ! } ! Index: SortingTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test/SortingTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SortingTest.java 9 Mar 2005 12:40:20 -0000 1.4 --- SortingTest.java 8 Jul 2005 16:03:21 -0000 1.5 *************** *** 1,197 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * 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.tmapiutils.query.tolog.test; ! ! import java.util.ArrayList; ! import java.util.HashMap; ! import java.util.Arrays; ! ! import junit.framework.TestCase; ! ! import org.tmapiutils.query.tolog.parser.Sorting; ! import org.tmapiutils.query.tolog.parser.Variable; ! ! // TMAPI ! import org.tmapi.core.TopicMapSystemFactory; ! import org.tmapi.core.TopicMapSystem; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.Topic; ! import org.tmapi.core.TopicName; ! ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class SortingTest extends TestCase { ! ! private TopicMapSystem _tmSystem; ! ! /** ! * Constructor for SortingTest. ! * @param arg0 ! */ ! public SortingTest(String arg0) throws Exception { ! super(arg0); ! _tmSystem = TopicMapSystemFactory.newInstance().newTopicMapSystem(); ! } ! ! public static void main(String[] args) { ! junit.textui.TestRunner.run(SortingTest.class); ! } ! ! public void testSortIntegers() throws Exception { ! ArrayList cols = new ArrayList(); ! cols.add(new Variable("A")); ! cols.add(new Variable("B")); ! ! ArrayList rows = new ArrayList(); ! ! ArrayList row1 = new ArrayList(); ! row1.add(new Integer(2)); ! row1.add(new Integer(1)); ! rows.add(row1); ! ! ArrayList row2 = new ArrayList(); ! row2.add(new Integer(1)); ! row2.add(new Integer(2)); ! rows.add(row2); ! ! ArrayList row3 = new ArrayList(); ! row3.add(new Integer(1)); ! row3.add(new Integer(1)); ! rows.add(row3); ! ! Sorting sorting = new Sorting(); ! sorting.addSort(new Variable("A")); ! sorting.addSort(new Variable("B")); ! sorting.sort(cols, rows); ! ! assertEquals(row3, rows.get(0)); ! assertEquals(row2, rows.get(1)); ! assertEquals(row1, rows.get(2)); ! } ! ! public void testSortTopics() throws Exception { ! // TopicMap tm = newTopicMap(); ! // Topic t1 = tm.createTopic("t1"); ! // Topic t2 = tm.createTopic("t2"); ! // Topic t3 = tm.createTopic("t3"); ! ! TopicMap tm = _tmSystem.createTopicMap("http://tmapiutils.org/test/tolog1.0/test/SortTopics"); ! Topic t1 = tm.createTopic(); ! Topic t2 = tm.createTopic(); ! Topic t3 = tm.createTopic(); ! ! String[] objectIds = new String[3]; ! objectIds[0] = t1.getObjectId(); ! objectIds[1] = t2.getObjectId(); ! objectIds[2] = t3.getObjectId(); ! Arrays.sort(objectIds); ! ! HashMap topics = new HashMap(); ! topics.put(t1.getObjectId(), t1); ! topics.put(t2.getObjectId(), t2); ! topics.put(t3.getObjectId(), t3); ! ! ArrayList cols = new ArrayList(); ! cols.add(new Variable("A")); ! ArrayList rows = new ArrayList(); ! ! ArrayList row1 = new ArrayList(); ! //row1.add(t3); ! row1.add(topics.get(objectIds[2])); ! rows.add(row1); ! ! ArrayList row2 = new ArrayList(); ! // row2.add(t1); ! row2.add(topics.get(objectIds[0])); ! rows.add(row2); ! ! ArrayList row3 = new ArrayList(); ! // row3.add(t2); ! row3.add(topics.get(objectIds[1])); ! rows.add(row3); ! ! Sorting sorting = new Sorting(); ! sorting.addSort(new Variable("A")); ! sorting.sort(cols, rows); ! sorting.setSortAscending(true); ! ! assertEquals(row2, rows.get(0)); ! assertEquals(row3, rows.get(1)); ! assertEquals(row1, rows.get(2)); ! ! sorting.setSortAscending(false); ! sorting.sort(cols, rows); ! assertEquals(row1, rows.get(0)); ! assertEquals(row3, rows.get(1)); ! assertEquals(row2, rows.get(2)); ! ! } ! ! public void testSortNames() throws Exception { ! // TopicMap tm = newTopicMap(); ! // Topic t1 = tm.createTopic("t1"); ! // TopicName bn1 = t1.createName("bn1","Topic C"); ! // Topic t2 = tm.createTopic("t2"); ! // TopicName bn2 = t2.createName("bn2", "Topic B"); ! // Topic t3 = tm.createTopic("t3"); ! // TopicName bn3 = t3.createName("bn3", "Topic A"); ! TopicMap tm = _tmSystem.createTopicMap("http://tmapiutils.org/test/tolog1.0/test/SortNames"); ! Topic t1 = tm.createTopic(); ! TopicName bn1 = t1.createTopicName("Topic C", null); ! Topic t2 = tm.createTopic(); ! TopicName bn2 = t2.createTopicName("Topic B", null); ! Topic t3 = tm.createTopic(); ! TopicName bn3 = t3.createTopicName("Topic A", null); ! ! ArrayList cols = new ArrayList(); ! cols.add(new Variable("A")); ! ArrayList rows = new ArrayList(); ! ! ArrayList row1 = new ArrayList(); ! row1.add(bn3); ! rows.add(row1); ! ! ArrayList row2 = new ArrayList(); ! row2.add(bn1); ! rows.add(row2); ! ! ArrayList row3 = new ArrayList(); ! row3.add(bn2); ! rows.add(row3); ! ! Sorting sorting = new Sorting(); ! sorting.addSort(new Variable("A")); ! sorting.sort(cols, rows); ! ! assertEquals(row1, rows.get(0)); ! assertEquals(row3, rows.get(1)); ! assertEquals(row2, rows.get(2)); ! ! ! } ! ! // private TopicMap newTopicMap() throws Exception { ! // Locator loc = m_provider.getLocatorFactory().createLocator("URI", "http://www.tm4j.org/tests/" + m_idgen.getObjectId()); ! // return m_provider.createTopicMap(loc); ! // } ! } ! --- 1,197 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * 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.tmapiutils.query.tolog.test; ! ! import java.util.ArrayList; ! import java.util.HashMap; ! import java.util.Arrays; ! ! import junit.framework.TestCase; ! ! import org.tmapiutils.query.tolog.parser.Sorting; ! import org.tmapiutils.query.tolog.parser.Variable; ! ! // TMAPI ! import org.tmapi.core.TopicMapSystemFactory; ! import org.tmapi.core.TopicMapSystem; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.Topic; ! import org.tmapi.core.TopicName; ! ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class SortingTest extends TestCase { ! ! private TopicMapSystem _tmSystem; ! ! /** ! * Constructor for SortingTest. ! * @param arg0 ! */ ! public SortingTest(String arg0) throws Exception { ! super(arg0); ! _tmSystem = TopicMapSystemFactory.newInstance().newTopicMapSystem(); ! } ! ! public static void main(String[] args) { ! junit.textui.TestRunner.run(SortingTest.class); ! } ! ! public void testSortIntegers() throws Exception { ! ArrayList cols = new ArrayList(); ! cols.add(new Variable("A")); ! cols.add(new Variable("B")); ! ! ArrayList rows = new ArrayList(); ! ! ArrayList row1 = new ArrayList(); ! row1.add(new Integer(2)); ! row1.add(new Integer(1)); ! rows.add(row1); ! ! ArrayList row2 = new ArrayList(); ! row2.add(new Integer(1)); ! row2.add(new Integer(2)); ! rows.add(row2); ! ! ArrayList row3 = new ArrayList(); ! row3.add(new Integer(1)); ! row3.add(new Integer(1)); ! rows.add(row3); ! ! Sorting sorting = new Sorting(); ! sorting.addSort(new Variable("A")); ! sorting.addSort(new Variable("B")); ! sorting.sort(cols, rows); ! ! assertEquals(row3, rows.get(0)); ! assertEquals(row2, rows.get(1)); ! assertEquals(row1, rows.get(2)); ! } ! ! public void testSortTopics() throws Exception { ! // TopicMap tm = newTopicMap(); ! // Topic t1 = tm.createTopic("t1"); ! // Topic t2 = tm.createTopic("t2"); ! // Topic t3 = tm.createTopic("t3"); ! ! TopicMap tm = _tmSystem.createTopicMap("http://tmapiutils.org/test/tolog1.0/test/SortTopics"); ! Topic t1 = tm.createTopic(); ! Topic t2 = tm.createTopic(); ! Topic t3 = tm.createTopic(); ! ! String[] objectIds = new String[3]; ! objectIds[0] = t1.getObjectId(); ! objectIds[1] = t2.getObjectId(); ! objectIds[2] = t3.getObjectId(); ! Arrays.sort(objectIds); ! ! HashMap topics = new HashMap(); ! topics.put(t1.getObjectId(), t1); ! topics.put(t2.getObjectId(), t2); ! topics.put(t3.getObjectId(), t3); ! ! ArrayList cols = new ArrayList(); ! cols.add(new Variable("A")); ! ArrayList rows = new ArrayList(); ! ! ArrayList row1 = new ArrayList(); ! //row1.add(t3); ! row1.add(topics.get(objectIds[2])); ! rows.add(row1); ! ! ArrayList row2 = new ArrayList(); ! // row2.add(t1); ! row2.add(topics.get(objectIds[0])); ! rows.add(row2); ! ! ArrayList row3 = new ArrayList(); ! // row3.add(t2); ! row3.add(topics.get(objectIds[1])); ! rows.add(row3); ! ! Sorting sorting = new Sorting(); ! sorting.addSort(new Variable("A")); ! sorting.sort(cols, rows); ! sorting.setSortAscending(true); ! ! assertEquals(row2, rows.get(0)); ! assertEquals(row3, rows.get(1)); ! assertEquals(row1, rows.get(2)); ! ! sorting.setSortAscending(false); ! sorting.sort(cols, rows); ! assertEquals(row1, rows.get(0)); ! assertEquals(row3, rows.get(1)); ! assertEquals(row2, rows.get(2)); ! ! } ! ! public void testSortNames() throws Exception { ! // TopicMap tm = newTopicMap(); ! // Topic t1 = tm.createTopic("t1"); ! // TopicName bn1 = t1.createName("bn1","Topic C"); ! // Topic t2 = tm.createTopic("t2"); ! // TopicName bn2 = t2.createName("bn2", "Topic B"); ! // Topic t3 = tm.createTopic("t3"); ! // TopicName bn3 = t3.createName("bn3", "Topic A"); ! TopicMap tm = _tmSystem.createTopicMap("http://tmapiutils.org/test/tolog1.0/test/SortNames"); ! Topic t1 = tm.createTopic(); ! TopicName bn1 = t1.createTopicName("Topic C", null); ! Topic t2 = tm.createTopic(); ! TopicName bn2 = t2.createTopicName("Topic B", null); ! Topic t3 = tm.createTopic(); ! TopicName bn3 = t3.createTopicName("Topic A", null); ! ! ArrayList cols = new ArrayList(); ! cols.add(new Variable("A")); ! ArrayList rows = new ArrayList(); ! ! ArrayList row1 = new ArrayList(); ! row1.add(bn3); ! rows.add(row1); ! ! ArrayList row2 = new ArrayList(); ! row2.add(bn1); ! rows.add(row2); ! ! ArrayList row3 = new ArrayList(); ! row3.add(bn2); ! rows.add(row3); ! ! Sorting sorting = new Sorting(); ! sorting.addSort(new Variable("A")); ! sorting.sort(cols, rows); ! ! assertEquals(row1, rows.get(0)); ! assertEquals(row3, rows.get(1)); ! assertEquals(row2, rows.get(2)); ! ! ! } ! ! // private TopicMap newTopicMap() throws Exception { ! // Locator loc = m_provider.getLocatorFactory().createLocator("URI", "http://www.tm4j.org/tests/" + m_idgen.getObjectId()); ! // return m_provider.createTopicMap(loc); ! // } ! } ! Index: ProjectionTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test/ProjectionTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ProjectionTest.java 9 Mar 2005 12:40:20 -0000 1.4 --- ProjectionTest.java 8 Jul 2005 16:03:21 -0000 1.5 *************** *** 1,200 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * 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.tmapiutils.query.tolog.test; ! ! import java.io.StringReader; ! import java.util.ArrayList; ! import java.util.Iterator; ! import java.util.List; ! import java.util.HashMap; ! ! import junit.framework.TestCase; ! ! import org.tmapiutils.query.tolog.parser.ClauseList; ! import org.tmapiutils.query.tolog.parser.PlayerRoleVarPair; ! import org.tmapiutils.query.tolog.parser.Projection; ! import org.tmapiutils.query.tolog.parser.ProjectionImpl; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.predicates.DynamicAssociationPredicate; ! import org.tmapiutils.query.tolog.utils.TologContext; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // 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; ! import org.tmapi.core.Topic; ! import org.tmapi.core.Association; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class ProjectionTest extends TestCase { ! ! private TopicMap m_tm; ! private TopicMapSystem _tmSystem; ! private HashMap _objectMap; ! ! /** ! * Constructor for ProjectionTest. ! * @param arg0 ! */ ! public ProjectionTest(String arg0) { ! super(arg0); ! } ! ! public static void main(String[] args) { ! junit.textui.TestRunner.run(ProjectionTest.class); ! } ! ! public void testCount() throws Exception { ! ClauseList c = new ClauseList(); ! DynamicAssociationPredicate p = new DynamicAssociationPredicate(); ! ArrayList params = new ArrayList(); ! params.add(getObjectById("contains")); ! params.add(new PlayerRoleVarPair(new Variable("CONTAINER"), (Topic) getObjectById("container"))); ! params.add(new PlayerRoleVarPair(new Variable("CONTAINEE"), (Topic) getObjectById("containee"))); ! p.setParameters(params); ! p.initialise(m_tm); ! VariableSet varsIn = new VariableSet(); ! varsIn.addColumn(new Variable("CONTAINER")); ! varsIn.addColumn(new Variable("CONTAINEE")); ! varsIn.addRow(varsIn.getColumns()); ! c.addPredicate(p); ! VariableSet varsOut = c.execute(varsIn, new TologContext()); ! assertNotNull(varsOut); ! assertEquals(5, varsOut.size()); ! Projection proj = new ProjectionImpl(); ! proj.addVariable(new Variable("CONTAINER")); ! proj.addCount(new Variable("CONTAINEE")); ! proj.addVariableSet(varsOut); ! List projRows = proj.getRows(); ! assertNotNull(projRows); ! assertEquals(2, projRows.size()); ! Iterator it = projRows.iterator(); ! while (it.hasNext()) { ! List row = (List) it.next(); ! assertNotNull(row); ! assertEquals(2, row.size()); ! assertTrue(row.get(0) instanceof Topic); ! assertTrue(row.get(1) instanceof Integer); ! if (row.get(0).equals(getObjectById("europe"))) { ! assertEquals(new Integer(3), row.get(1)); ! } else if (row.get(0).equals(getObjectById("asia"))) { ! assertEquals(new Integer(2), row.get(1)); ! } ! } ! } ! ! /* ! * @see TestCase#setUp() ! */ ! protected void setUp() throws Exception { ! super.setUp(); ! _objectMap = new HashMap(); ! _tmSystem = TopicMapSystemFactory.newInstance().newTopicMapSystem(); ! m_tm = _tmSystem.createTopicMap("http://tmapiutils.org/test/tolog1.0/"); ! createTestMap(m_tm); ! // 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(TESTMAP), loc, new LTMBuilder()); ! // m_tm = m_provider.addTopicMap(src); ! } ! ! protected void tearDown() throws Exception{ ! super.tearDown(); ! _objectMap.clear(); ! // remove created TopicMaps from TopicMapSystem ! m_tm.remove(); ! // Close TopicMapSystem instance ! _tmSystem.close(); ! } ! ! public void createTestMap(TopicMap tm) { ! Topic contains = tm.createTopic(); ! Topic europe = tm.createTopic(); ! Topic container = tm.createTopic(); ! Topic uk = tm.createTopic(); ! Topic containee = tm.createTopic(); ! Topic germany = tm.createTopic(); ! Topic france = tm.createTopic(); ! Topic asia = tm.createTopic(); ! Topic japan = tm.createTopic(); ! Topic india = tm.createTopic(); ! ! Association assoc1 = tm.createAssociation(); ! assoc1.setType(contains); ! assoc1.createAssociationRole(europe, container); ! assoc1.createAssociationRole(germany, containee); ! ! Association assoc2 = tm.createAssociation(); ! assoc2.setType(contains); ! assoc2.createAssociationRole(europe, container); ! assoc2.createAssociationRole(uk, containee); ! ! Association assoc3 = tm.createAssociation(); ! assoc3.setType(contains); ! assoc3.createAssociationRole(europe, container); ! assoc3.createAssociationRole(france, containee); ! ! Association assoc4 = tm.createAssociation(); ! assoc4.setType(contains); ! assoc4.createAssociationRole(asia, container); ! assoc4.createAssociationRole(japan, containee); ! ! Association assoc5 = tm.createAssociation(); ! assoc5.setType(contains); ! assoc5.createAssociationRole(asia, container); ! assoc5.createAssociationRole(india, containee); ! ! registerObject("contains", contains); ! registerObject("container", container); ! registerObject("containee", containee); ! registerObject("europe", europe); ! registerObject("uk", uk); ! registerObject("germany", germany); ! registerObject("france", france); ! registerObject("asia", asia); ! registerObject("japan", japan); ! registerObject("india", india); ! } ! ! protected void registerObject(String name, TopicMapObject obj) { ! _objectMap.put(name, obj); ! } ! ! protected TopicMapObject getObjectById(String name) { ! TopicMapObject obj = (TopicMapObject) _objectMap.get(name); ! if (obj == null) { ! throw new RuntimeException("Object Id not found :" + name); ! } ! return obj; ! } ! ! private static final String TESTMAP = ! "contains(europe:container, uk:containee)\n" + ! "contains(europe:container, germany:containee)\n" + ! "contains(europe:container, france:containee)\n" + ! "contains(asia:container, japan:containee)\n" + ! "contains(asia:container, india:containee)\n"; ! } ! --- 1,200 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * 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.tmapiutils.query.tolog.test; ! ! import java.io.StringReader; ! import java.util.ArrayList; ! import java.util.Iterator; ! import java.util.List; ! import java.util.HashMap; ! ! import junit.framework.TestCase; ! ! import org.tmapiutils.query.tolog.parser.ClauseList; ! import org.tmapiutils.query.tolog.parser.PlayerRoleVarPair; ! import org.tmapiutils.query.tolog.parser.Projection; ! import org.tmapiutils.query.tolog.parser.ProjectionImpl; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.predicates.DynamicAssociationPredicate; ! import org.tmapiutils.query.tolog.utils.TologContext; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // 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; ! import org.tmapi.core.Topic; ! import org.tmapi.core.Association; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class ProjectionTest extends TestCase { ! ! private TopicMap m_tm; ! private TopicMapSystem _tmSystem; ! private HashMap _objectMap; ! ! /** ! * Constructor for ProjectionTest. ! * @param arg0 ! */ ! public ProjectionTest(String arg0) { ! super(arg0); ! } ! ! public static void main(String[] args) { ! junit.textui.TestRunner.run(ProjectionTest.class); ! } ! ! public void testCount() throws Exception { ! ClauseList c = new ClauseList(); ! DynamicAssociationPredicate p = new DynamicAssociationPredicate(); ! ArrayList params = new ArrayList(); ! params.add(getObjectById("contains")); ! params.add(new PlayerRoleVarPair(new Variable("CONTAINER"), (Topic) getObjectById("container"))); ! params.add(new PlayerRoleVarPair(new Variable("CONTAINEE"), (Topic) getObjectById("containee"))); ! p.setParameters(params); ! p.initialise(m_tm); ! VariableSet varsIn = new VariableSet(); ! varsIn.addColumn(new Variable("CONTAINER")); ! varsIn.addColumn(new Variable("CONTAINEE")); ! varsIn.addRow(varsIn.getColumns()); ! c.addPredicate(p); ! VariableSet varsOut = c.execute(varsIn, new TologContext()); ! assertNotNull(varsOut); ! assertEquals(5, varsOut.size()); ! Projection proj = new ProjectionImpl(); ! proj.addVariable(new Variable("CONTAINER")); ! proj.addCount(new Variable("CONTAINEE")); ! proj.addVariableSet(varsOut); ! List projRows = proj.getRows(); ! assertNotNull(projRows); ! assertEquals(2, projRows.size()); ! Iterator it = projRows.iterator(); ! while (it.hasNext()) { ! List row = (List) it.next(); ! assertNotNull(row); ! assertEquals(2, row.size()); ! assertTrue(row.get(0) instanceof Topic); ! assertTrue(row.get(1) instanceof Integer); ! if (row.get(0).equals(getObjectById("europe"))) { ! assertEquals(new Integer(3), row.get(1)); ! } else if (row.get(0).equals(getObjectById("asia"))) { ! assertEquals(new Integer(2), row.get(1)); ! } ! } ! } ! ! /* ! * @see TestCase#setUp() ! */ ! protected void setUp() throws Exception { ! super.setUp(); ! _objectMap = new HashMap(); ! _tmSystem = TopicMapSystemFactory.newInstance().newTopicMapSystem(); ! m_tm = _tmSystem.createTopicMap("http://tmapiutils.org/test/tolog1.0/"); ! createTestMap(m_tm); ! // 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(TESTMAP), loc, new LTMBuilder()); ! // m_tm = m_provider.addTopicMap(src); ! } ! ! protected void tearDown() throws Exception{ ! super.tearDown(); ! _objectMap.clear(); ! // remove created TopicMaps from TopicMapSystem ! m_tm.remove(); ! // Close TopicMapSystem instance ! _tmSystem.close(); ! } ! ! public void createTestMap(TopicMap tm) { ! Topic contains = tm.createTopic(); ! Topic europe = tm.createTopic(); ! Topic container = tm.createTopic(); ! Topic uk = tm.createTopic(); ! Topic containee = tm.createTopic(); ! Topic germany = tm.createTopic(); ! Topic france = tm.createTopic(); ! Topic asia = tm.createTopic(); ! Topic japan = tm.createTopic(); ! Topic india = tm.createTopic(); ! ! Association assoc1 = tm.createAssociation(); ! assoc1.setType(contains); ! assoc1.createAssociationRole(europe, container); ! assoc1.createAssociationRole(germany, containee); ! ! Association assoc2 = tm.createAssociation(); ! assoc2.setType(contains); ! assoc2.createAssociationRole(europe, container); ! assoc2.createAssociationRole(uk, containee); ! ! Association assoc3 = tm.createAssociation(); ! assoc3.setType(contains); ! assoc3.createAssociationRole(europe, container); ! assoc3.createAssociationRole(france, containee); ! ! Association assoc4 = tm.createAssociation(); ! assoc4.setType(contains); ! assoc4.createAssociationRole(asia, container); ! assoc4.createAssociationRole(japan, containee); ! ! Association assoc5 = tm.createAssociation(); ! assoc5.setType(contains); ! assoc5.createAssociationRole(asia, container); ! assoc5.createAssociationRole(india, containee); ! ! registerObject("contains", contains); ! registerObject("container", container); ! registerObject("containee", containee); ! registerObject("europe", europe); ! registerObject("uk", uk); ! registerObject("germany", germany); ! registerObject("france", france); ! registerObject("asia", asia); ! registerObject("japan", japan); ! registerObject("india", india); ! } ! ! protected void registerObject(String name, TopicMapObject obj) { ! _objectMap.put(name, obj); ! } ! ! protected TopicMapObject getObjectById(String name) { ! TopicMapObject obj = (TopicMapObject) _objectMap.get(name); ! if (obj == null) { ! throw new RuntimeException("Object Id not found :" + name); ! } ! return obj; ! } ! ! private static final String TESTMAP = ! "contains(europe:container, uk:containee)\n" + ! "contains(europe:container, germany:containee)\n" + ! "contains(europe:container, france:containee)\n" + ! "contains(asia:container... [truncated message content] |