Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30131/src/org/tmapiutils/query/tolog/predicates/test Modified Files: AssociationPredicateTest.java AssociationRolePredicateTest.java BaseLocatorPredicateTest.java DirectInstanceOfPredicateTest.java DynamicAssociationPredicateTest.java InstanceOfPredicateTest.java OccurrencePredicateTest.java PredicateTestBase.java ReifiesPredicateTest.java ResourcePredicateTest.java TopicMapPredicateTest.java TopicNameTest.java TypePredicateTest.java ValueLikePredicateTest.java ValuePredicateTest.java VariantPredicateTest.java Log Message: Tabs -> Whitespaces Index: ResourcePredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/ResourcePredicateTest.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ResourcePredicateTest.java 9 Mar 2005 12:40:19 -0000 1.6 --- ResourcePredicateTest.java 8 Jul 2005 16:03:21 -0000 1.7 *************** *** 1,165 **** ! /* ! * 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.predicates.test; ! ! import java.util.ArrayList; ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.predicates.ResourcePredicate; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.Locator; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.Topic; ! import org.tmapi.core.Occurrence; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class ResourcePredicateTest extends PredicateTestBase { ! ! /** ! * @param name ! */ ! public ResourcePredicateTest(String name) { ! super(name); ! } ! ! private static final String TESTMAP = ! "[techquila]\n" + ! "{techquila, homepage, \"http://www.techquila.com/\"}\n" + ! "{techquila, contact-details, \"http://www.techquila.com/contact.html\"}" + ! "[tm4j]\n" + ! "{tm4j, homepage, \"http://www.tm4j.org/\"}"; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getTestMap() ! */ ! public String getTestMap() { ! return TESTMAP; ! } ! ! ! public void createTestMap(TopicMap tm) { ! Topic tmapiutils = tm.createTopic(); ! Topic homepage = tm.createTopic(); ! Topic contact_details = tm.createTopic(); ! tmapiutils.createOccurrence(createLocator("http://tmapiutils.org/"), homepage, null); ! tmapiutils.createOccurrence(createLocator("http://tmapiutils.org/contact/"), contact_details, null); ! Topic tmapi = tm.createTopic(); ! tmapi.createOccurrence(createLocator("http://tmapi.org/"), homepage, null); ! ! registerObject("tmapiutils", tmapiutils); ! registerObject("homepage", homepage); ! registerObject("tmapi", tmapi); ! } ! ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getPredicateClass() ! */ ! public Class getPredicateClass() { ! return ResourcePredicate.class; ! } ! ! public static void main(String[] args) { ! junit.textui.TestRunner.run(OccurrencePredicateTest.class); ! } ! ! public void testOpenMatch() throws Exception { ! List params = new ArrayList(); ! Variable a = new Variable("A"); ! Variable b = new Variable("B"); ! params.add(a); ! params.add(b); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(2, out.getColumns().size()); ! assertEquals(3, out.getRows().size()); ! Iterator it = ((Topic) getObjectById("tmapiutils")).getOccurrences().iterator(); ! while (it.hasNext()) { ! Occurrence o = (Occurrence)it.next(); ! int ix = out.getColumn(a).indexOf(o); ! assertTrue("Expected occurrence to be in results set.", ix > -1); ! Locator l = (Locator)out.getColumn(b).get(ix); ! assertTrue(l.equals(o.getResource())); ! } ! it = ((Topic) getObjectById("tmapiutils")).getOccurrences().iterator(); ! while (it.hasNext()) { ! Occurrence o = (Occurrence)it.next(); ! int ix = out.getColumn(a).indexOf(o); ! assertTrue("Expected occurrence to be in results set.", ix > -1); ! Locator l = (Locator)out.getColumn(b).get(ix); ! assertTrue(l.equals(o.getResource())); ! } ! } ! ! public void testOccurrenceByLocator() throws Exception { ! 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); ! assertNotNull(out); ! assertEquals(1, out.getColumns().size()); ! assertEquals(1, out.getRows().size()); ! Iterator it = ((Topic) getObjectById("tmapiutils")).getOccurrences().iterator(); ! while (it.hasNext()) { ! Occurrence o = (Occurrence)it.next(); ! if (o.getResource().equals(loc)) { ! assertTrue(out.getColumn(a).contains(o)); ! } else { ! assertFalse(out.getColumn(a).contains(o)); ! } ! } ! } ! ! public void testLocatorByOccurrence() throws Exception { ! List params = new ArrayList(); ! Variable b = new Variable("B"); ! Locator loc = m_tm.createLocator("http://tmapiutils.org/"); ! Occurrence o = null; ! Iterator it = ((Topic) getObjectById("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); ! params.add(o); ! params.add(b); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getColumns().size()); ! assertEquals(1, out.getRows().size()); ! assertTrue(out.getColumn(b).contains(loc)); ! } ! ! // TODO: Implement tests for closed matches. ! // Variant Tests! ! } ! --- 1,165 ---- ! /* ! * 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.predicates.test; ! ! import java.util.ArrayList; ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.predicates.ResourcePredicate; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.Locator; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.Topic; ! import org.tmapi.core.Occurrence; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class ResourcePredicateTest extends PredicateTestBase { ! ! /** ! * @param name ! */ ! public ResourcePredicateTest(String name) { ! super(name); ! } ! ! private static final String TESTMAP = ! "[techquila]\n" + ! "{techquila, homepage, \"http://www.techquila.com/\"}\n" + ! "{techquila, contact-details, \"http://www.techquila.com/contact.html\"}" + ! "[tm4j]\n" + ! "{tm4j, homepage, \"http://www.tm4j.org/\"}"; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getTestMap() ! */ ! public String getTestMap() { ! return TESTMAP; ! } ! ! ! public void createTestMap(TopicMap tm) { ! Topic tmapiutils = tm.createTopic(); ! Topic homepage = tm.createTopic(); ! Topic contact_details = tm.createTopic(); ! tmapiutils.createOccurrence(createLocator("http://tmapiutils.org/"), homepage, null); ! tmapiutils.createOccurrence(createLocator("http://tmapiutils.org/contact/"), contact_details, null); ! Topic tmapi = tm.createTopic(); ! tmapi.createOccurrence(createLocator("http://tmapi.org/"), homepage, null); ! ! registerObject("tmapiutils", tmapiutils); ! registerObject("homepage", homepage); ! registerObject("tmapi", tmapi); ! } ! ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getPredicateClass() ! */ ! public Class getPredicateClass() { ! return ResourcePredicate.class; ! } ! ! public static void main(String[] args) { ! junit.textui.TestRunner.run(OccurrencePredicateTest.class); ! } ! ! public void testOpenMatch() throws Exception { ! List params = new ArrayList(); ! Variable a = new Variable("A"); ! Variable b = new Variable("B"); ! params.add(a); ! params.add(b); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(2, out.getColumns().size()); ! assertEquals(3, out.getRows().size()); ! Iterator it = ((Topic) getObjectById("tmapiutils")).getOccurrences().iterator(); ! while (it.hasNext()) { ! Occurrence o = (Occurrence)it.next(); ! int ix = out.getColumn(a).indexOf(o); ! assertTrue("Expected occurrence to be in results set.", ix > -1); ! Locator l = (Locator)out.getColumn(b).get(ix); ! assertTrue(l.equals(o.getResource())); ! } ! it = ((Topic) getObjectById("tmapiutils")).getOccurrences().iterator(); ! while (it.hasNext()) { ! Occurrence o = (Occurrence)it.next(); ! int ix = out.getColumn(a).indexOf(o); ! assertTrue("Expected occurrence to be in results set.", ix > -1); ! Locator l = (Locator)out.getColumn(b).get(ix); ! assertTrue(l.equals(o.getResource())); ! } ! } ! ! public void testOccurrenceByLocator() throws Exception { ! 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); ! assertNotNull(out); ! assertEquals(1, out.getColumns().size()); ! assertEquals(1, out.getRows().size()); ! Iterator it = ((Topic) getObjectById("tmapiutils")).getOccurrences().iterator(); ! while (it.hasNext()) { ! Occurrence o = (Occurrence)it.next(); ! if (o.getResource().equals(loc)) { ! assertTrue(out.getColumn(a).contains(o)); ! } else { ! assertFalse(out.getColumn(a).contains(o)); ! } ! } ! } ! ! public void testLocatorByOccurrence() throws Exception { ! List params = new ArrayList(); ! Variable b = new Variable("B"); ! Locator loc = m_tm.createLocator("http://tmapiutils.org/"); ! Occurrence o = null; ! Iterator it = ((Topic) getObjectById("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); ! params.add(o); ! params.add(b); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getColumns().size()); ! assertEquals(1, out.getRows().size()); ! assertTrue(out.getColumn(b).contains(loc)); ! } ! ! // TODO: Implement tests for closed matches. ! // Variant Tests! ! } ! Index: PredicateTestBase.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/PredicateTestBase.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** PredicateTestBase.java 9 Mar 2005 12:40:19 -0000 1.8 --- PredicateTestBase.java 8 Jul 2005 16:03:21 -0000 1.9 *************** *** 1,114 **** ! /* ! * 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.predicates.test; ! ! import java.util.Iterator; ! import java.util.HashMap; ! ! 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; ! import org.tmapi.core.TMAPIException; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public abstract class PredicateTestBase extends TestCase { ! ! ! protected Predicate m_predicate; ! protected TopicMap m_tm; ! private HashMap _maps; ! private HashMap _objectMap; ! protected static TopicMapSystem _tmSystem; ! 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/"); ! createTestMap(m_tm); ! m_predicate = (Predicate) getPredicateClass().newInstance(); ! m_predicate.initialise(m_tm); ! m_context = new TologContext(); ! } ! ! protected void tearDown() throws Exception{ ! super.tearDown(); ! _objectMap.clear(); ! // 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) { ! TopicMapObject obj = (TopicMapObject) _objectMap.get(name); ! if (obj == null) { ! throw new RuntimeException("Object Id not found :" + name); ! } ! return obj; ! } ! ! 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 TMAPIException { ! 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(); ! } ! } --- 1,114 ---- ! /* ! * 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.predicates.test; ! ! import java.util.Iterator; ! import java.util.HashMap; ! ! 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; ! import org.tmapi.core.TMAPIException; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public abstract class PredicateTestBase extends TestCase { ! ! ! protected Predicate m_predicate; ! protected TopicMap m_tm; ! private HashMap _maps; ! private HashMap _objectMap; ! protected static TopicMapSystem _tmSystem; ! 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/"); ! createTestMap(m_tm); ! m_predicate = (Predicate) getPredicateClass().newInstance(); ! m_predicate.initialise(m_tm); ! m_context = new TologContext(); ! } ! ! protected void tearDown() throws Exception{ ! super.tearDown(); ! _objectMap.clear(); ! // 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) { ! TopicMapObject obj = (TopicMapObject) _objectMap.get(name); ! if (obj == null) { ! throw new RuntimeException("Object Id not found :" + name); ! } ! return obj; ! } ! ! 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 TMAPIException { ! 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(); ! } ! } Index: TopicMapPredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/TopicMapPredicateTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** TopicMapPredicateTest.java 9 Mar 2005 12:40:19 -0000 1.5 --- TopicMapPredicateTest.java 8 Jul 2005 16:03:21 -0000 1.6 *************** *** 1,90 **** ! /* ! * 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.predicates.test; ! ! import java.util.ArrayList; ! ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.predicates.TopicMapPredicate; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.TopicMapObject; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.Topic; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class TopicMapPredicateTest extends PredicateTestBase { ! ! /** ! * @param name ! */ ! public TopicMapPredicateTest(String name) { ! super(name); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getTestMap() ! */ ! public String getTestMap() { ! return "[hello-world]"; ! } ! ! public void createTestMap(TopicMap tm) { ! Topic topic = tm.createTopic(); ! ! registerObject("hello-world", topic); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getPredicateClass() ! */ ! public Class getPredicateClass() { ! return TopicMapPredicate.class; ! } ! ! public void testOpenMatch() throws Exception { ! ArrayList params = new ArrayList(); ! params.add(new Variable("A")); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getRows().size()); ! assertEquals(m_tm, out.getRow(0).get(0)); ! } ! ! public void testClosedMatch() throws Exception { ! ArrayList params = new ArrayList(); ! params.add(new Variable("A")); ! m_predicate.setParameters(params); ! params.set(0, m_tm); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getRows().size()); ! assertEquals(m_tm, out.getRow(0).get(0)); ! ! params.set(0, getObjectById("hello-world")); ! out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(0, out.getRows().size()); ! } ! } ! --- 1,90 ---- ! /* ! * 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.predicates.test; ! ! import java.util.ArrayList; ! ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.predicates.TopicMapPredicate; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.TopicMapObject; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.Topic; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class TopicMapPredicateTest extends PredicateTestBase { ! ! /** ! * @param name ! */ ! public TopicMapPredicateTest(String name) { ! super(name); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getTestMap() ! */ ! public String getTestMap() { ! return "[hello-world]"; ! } ! ! public void createTestMap(TopicMap tm) { ! Topic topic = tm.createTopic(); ! ! registerObject("hello-world", topic); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getPredicateClass() ! */ ! public Class getPredicateClass() { ! return TopicMapPredicate.class; ! } ! ! public void testOpenMatch() throws Exception { ! ArrayList params = new ArrayList(); ! params.add(new Variable("A")); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getRows().size()); ! assertEquals(m_tm, out.getRow(0).get(0)); ! } ! ! public void testClosedMatch() throws Exception { ! ArrayList params = new ArrayList(); ! params.add(new Variable("A")); ! m_predicate.setParameters(params); ! params.set(0, m_tm); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getRows().size()); ! assertEquals(m_tm, out.getRow(0).get(0)); ! ! params.set(0, getObjectById("hello-world")); ! out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(0, out.getRows().size()); ! } ! } ! Index: ReifiesPredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/ReifiesPredicateTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ReifiesPredicateTest.java 9 Mar 2005 12:40:19 -0000 1.5 --- ReifiesPredicateTest.java 8 Jul 2005 16:03:21 -0000 1.6 *************** *** 1,164 **** ! /* ! * 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.predicates.test; ! ! import java.util.ArrayList; ! ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.predicates.ReifiesPredicate; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! 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 ReifiesPredicateTest extends PredicateTestBase { ! ! /** ! * @param name ! */ ! public ReifiesPredicateTest(String name) { ! super(name); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getTestMap() ! */ ! public String getTestMap() { ! return "<topicMap xmlns=\"http://www.topicmaps.org/xtm/1.0/\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">" + ! "<topic id=\"fred\"/> <topic id=\"bigco\"/> <topic id=\"worksfor\"/>" + ! "<association id=\"assoc1\">" + ! "<instanceOf><topicRef xlink:href=\"#worksfor\"/></instanceOf>" + ! "<member id=\"m1\"><topicRef xlink:href=\"#fred\"/></member>" + ! "<member id=\"m2\"><topicRef xlink:href=\"#bigco\"/></member>" + ! "</association>" + ! "<topic id=\"fredemp\"> <subjectIdentity><resourceRef xlink:href=\"#assoc1\"/> </subjectIdentity> </topic>" + ! "</topicMap>"; ! } ! ! // public TopicMapBuilder getBuilder() { ! // return new XTMBuilder(); ! // } ! ! public void createTestMap(TopicMap tm) { ! Topic works_for = tm.createTopic(); ! Topic fred = tm.createTopic(); ! Topic barney = tm.createTopic(); ! Topic employee = tm.createTopic(); ! Topic employer = tm.createTopic(); ! Topic bigco = tm.createTopic(); ! Topic fredemp = tm.createTopic(); ! fredemp.addSubjectIdentifier(tm.createLocator("assoc1")); ! ! ! Association assoc1 = tm.createAssociation(); ! assoc1.setType(works_for); ! assoc1.createAssociationRole(fred, employee); ! assoc1.createAssociationRole(bigco, employer); ! assoc1.addSourceLocator(tm.createLocator("assoc1")); ! ! Association assoc2 = tm.createAssociation(); ! assoc2.setType(works_for); ! assoc2.createAssociationRole(barney, employee); ! assoc2.createAssociationRole(bigco, employer); ! ! registerObject("works-for", works_for); ! registerObject("fred", fred); ! registerObject("barney", barney); ! registerObject("employee", employee); ! registerObject("bigco", bigco); ! registerObject("employer", employer); ! registerObject("fredemp", fredemp); ! } ! ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getPredicateClass() ! */ ! public Class getPredicateClass() { ! return ReifiesPredicate.class; ! } ! ! public void testMatchReifier() throws Exception { ! ArrayList params = new ArrayList(); ! Variable a = new Variable("A"); ! params.add(a); ! params.add(getObjectById("assoc1")); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getColumns().size()); ! assertEquals(1, out.getRows().size()); ! assertTrue(out.getRow(0).contains(getObjectById("fredemp"))); ! } ! ! public void testMatchReified() throws Exception { ! ArrayList params = new ArrayList(); ! Variable a = new Variable("A"); ! params.add(getObjectById("fredemp")); ! params.add(a); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getColumns().size()); ! assertEquals(1, out.getRows().size()); ! assertTrue(out.getRow(0).contains(getObjectById("fredemp"))); ! } ! ! public void testOpenMatch() throws Exception { ! ArrayList params = new ArrayList(); ! Variable a = new Variable("A"); ! Variable b = new Variable("B"); ! params.add(a); ! params.add(b); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(2, out.getColumns().size()); ! assertEquals(1, out.getRows().size()); ! assertTrue(out.getRow(0).get(0).equals(getObjectById("fredemp"))); ! assertTrue(out.getRow(0).get(1).equals(getObjectById("assoc1"))); ! } ! ! public void testClosedMatch() throws Exception { ! ArrayList params = new ArrayList(); ! Variable a = new Variable("A"); ! Variable b = new Variable("B"); ! params.add(a); ! params.add(b); ! m_predicate.setParameters(params); ! params.set(0, getObjectById("fredemp")); ! params.set(1, 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, getObjectById("fredemp")); ! params.set(1, getObjectById("m1")); ! out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(2, out.getColumns().size()); ! assertEquals(0, out.getRows().size()); ! ! } ! } --- 1,164 ---- ! /* ! * 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.predicates.test; ! ! import java.util.ArrayList; ! ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.predicates.ReifiesPredicate; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! 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 ReifiesPredicateTest extends PredicateTestBase { ! ! /** ! * @param name ! */ ! public ReifiesPredicateTest(String name) { ! super(name); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getTestMap() ! */ ! public String getTestMap() { ! return "<topicMap xmlns=\"http://www.topicmaps.org/xtm/1.0/\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">" + ! "<topic id=\"fred\"/> <topic id=\"bigco\"/> <topic id=\"worksfor\"/>" + ! "<association id=\"assoc1\">" + ! "<instanceOf><topicRef xlink:href=\"#worksfor\"/></instanceOf>" + ! "<member id=\"m1\"><topicRef xlink:href=\"#fred\"/></member>" + ! "<member id=\"m2\"><topicRef xlink:href=\"#bigco\"/></member>" + ! "</association>" + ! "<topic id=\"fredemp\"> <subjectIdentity><resourceRef xlink:href=\"#assoc1\"/> </subjectIdentity> </topic>" + ! "</topicMap>"; ! } ! ! // public TopicMapBuilder getBuilder() { ! // return new XTMBuilder(); ! // } ! ! public void createTestMap(TopicMap tm) { ! Topic works_for = tm.createTopic(); ! Topic fred = tm.createTopic(); ! Topic barney = tm.createTopic(); ! Topic employee = tm.createTopic(); ! Topic employer = tm.createTopic(); ! Topic bigco = tm.createTopic(); ! Topic fredemp = tm.createTopic(); ! fredemp.addSubjectIdentifier(tm.createLocator("assoc1")); ! ! ! Association assoc1 = tm.createAssociation(); ! assoc1.setType(works_for); ! assoc1.createAssociationRole(fred, employee); ! assoc1.createAssociationRole(bigco, employer); ! assoc1.addSourceLocator(tm.createLocator("assoc1")); ! ! Association assoc2 = tm.createAssociation(); ! assoc2.setType(works_for); ! assoc2.createAssociationRole(barney, employee); ! assoc2.createAssociationRole(bigco, employer); ! ! registerObject("works-for", works_for); ! registerObject("fred", fred); ! registerObject("barney", barney); ! registerObject("employee", employee); ! registerObject("bigco", bigco); ! registerObject("employer", employer); ! registerObject("fredemp", fredemp); ! } ! ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getPredicateClass() ! */ ! public Class getPredicateClass() { ! return ReifiesPredicate.class; ! } ! ! public void testMatchReifier() throws Exception { ! ArrayList params = new ArrayList(); ! Variable a = new Variable("A"); ! params.add(a); ! params.add(getObjectById("assoc1")); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getColumns().size()); ! assertEquals(1, out.getRows().size()); ! assertTrue(out.getRow(0).contains(getObjectById("fredemp"))); ! } ! ! public void testMatchReified() throws Exception { ! ArrayList params = new ArrayList(); ! Variable a = new Variable("A"); ! params.add(getObjectById("fredemp")); ! params.add(a); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getColumns().size()); ! assertEquals(1, out.getRows().size()); ! assertTrue(out.getRow(0).contains(getObjectById("fredemp"))); ! } ! ! public void testOpenMatch() throws Exception { ! ArrayList params = new ArrayList(); ! Variable a = new Variable("A"); ! Variable b = new Variable("B"); ! params.add(a); ! params.add(b); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(2, out.getColumns().size()); ! assertEquals(1, out.getRows().size()); ! assertTrue(out.getRow(0).get(0).equals(getObjectById("fredemp"))); ! assertTrue(out.getRow(0).get(1).equals(getObjectById("assoc1"))); ! } ! ! public void testClosedMatch() throws Exception { ! ArrayList params = new ArrayList(); ! Variable a = new Variable("A"); ! Variable b = new Variable("B"); ! params.add(a); ! params.add(b); ! m_predicate.setParameters(params); ! params.set(0, getObjectById("fredemp")); ! params.set(1, 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, getObjectById("fredemp")); ! params.set(1, getObjectById("m1")); ! out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(2, out.getColumns().size()); ! assertEquals(0, out.getRows().size()); ! ! } ! } Index: AssociationRolePredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/AssociationRolePredicateTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** AssociationRolePredicateTest.java 9 Mar 2005 12:40:19 -0000 1.5 --- AssociationRolePredicateTest.java 8 Jul 2005 16:03:21 -0000 1.6 *************** *** 1,165 **** ! /* ! * 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.predicates.test; ! ! import java.util.ArrayList; ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.parser.Variable; ! 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; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class AssociationRolePredicateTest extends PredicateTestBase { ! ! ! /** ! * @param name ! */ ! public AssociationRolePredicateTest(String name) { ! super(name); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getTestMap() ! */ ! public String getTestMap() { ! return "works-for(fred:employee, bigco:employer)\n" + ! "works-for(barney:employee, bigco:employer)\n"; ! } ! ! ! public void createTestMap(TopicMap tm) { ! Topic works_for = tm.createTopic(); ! Topic fred = tm.createTopic(); ! Topic barney = tm.createTopic(); ! Topic employee = tm.createTopic(); ! Topic employer = tm.createTopic(); ! Topic bigco = tm.createTopic(); ! ! Association assoc1 = tm.createAssociation(); ! assoc1.setType(works_for); ! assoc1.createAssociationRole(fred, employee); ! assoc1.createAssociationRole(bigco, employer); ! ! Association assoc2 = tm.createAssociation(); ! assoc2.setType(works_for); ! assoc2.createAssociationRole(barney, employee); ! assoc2.createAssociationRole(bigco, employer); ! ! registerObject("works-for", works_for); ! registerObject("fred", fred); ! registerObject("barney", barney); ! registerObject("employee", employee); ! registerObject("bigco", bigco); ! registerObject("employer", employer); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getPredicateClass() ! */ ! public Class getPredicateClass() { ! return AssociationRolePredicate.class; ! } ! ! public void testMatchAssociation() throws Exception { ! ArrayList params = new ArrayList(); ! Variable a = new Variable("A"); ! Topic fred = (Topic) getObjectById("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); ! assertNotNull(out); ! assertEquals(1, out.getColumns().size()); ! assertEquals(1, out.getRows().size()); ! assertEquals(role.getAssociation(), out.getRow(0).get(0)); ! } ! ! public void testMatchRoles() throws Exception { ! ArrayList params = new ArrayList(); ! Topic barney =(Topic) getObjectById("barney"); ! Association assoc = ((AssociationRole) barney.getRolesPlayed().iterator().next()).getAssociation(); ! Variable a = new Variable("A"); ! params.add(assoc); ! params.add(a); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getColumns().size()); ! assertEquals(2, out.getRows().size()); ! assertEquals(assoc, ((AssociationRole)out.getRow(0).get(0)).getAssociation()); ! assertEquals(assoc, ((AssociationRole)out.getRow(1).get(0)).getAssociation()); ! } ! ! public void testOpenMatch() throws Exception { ! ArrayList params = new ArrayList(); ! Variable a = new Variable("A"); ! Variable b = new Variable("B"); ! params.add(a); ! params.add(b); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! 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 { ! ArrayList params = new ArrayList(); ! Variable a = new Variable("A"); ! Variable b = new Variable("B"); ! params.add(a); ! params.add(b); ! m_predicate.setParameters(params); ! Topic fred = (Topic) getObjectById("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 =(Topic) getObjectById("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()); ! } ! } ! --- 1,165 ---- ! /* ! * 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.predicates.test; ! ! import java.util.ArrayList; ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.parser.Variable; ! 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; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class AssociationRolePredicateTest extends PredicateTestBase { ! ! ! /** ! * @param name ! */ ! public AssociationRolePredicateTest(String name) { ! super(name); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getTestMap() ! */ ! public String getTestMap() { ! return "works-for(fred:employee, bigco:employer)\n" + ! "works-for(barney:employee, bigco:employer)\n"; ! } ! ! ! public void createTestMap(TopicMap tm) { ! Topic works_for = tm.createTopic(); ! Topic fred = tm.createTopic(); ! Topic barney = tm.createTopic(); ! Topic employee = tm.createTopic(); ! Topic employer = tm.createTopic(); ! Topic bigco = tm.createTopic(); ! ! Association assoc1 = tm.createAssociation(); ! assoc1.setType(works_for); ! assoc1.createAssociationRole(fred, employee); ! assoc1.createAssociationRole(bigco, employer); ! ! Association assoc2 = tm.createAssociation(); ! assoc2.setType(works_for); ! assoc2.createAssociationRole(barney, employee); ! assoc2.createAssociationRole(bigco, employer); ! ! registerObject("works-for", works_for); ! registerObject("fred", fred); ! registerObject("barney", barney); ! registerObject("employee", employee); ! registerObject("bigco", bigco); ! registerObject("employer", employer); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getPredicateClass() ! */ ! public Class getPredicateClass() { ! return AssociationRolePredicate.class; ! } ! ! public void testMatchAssociation() throws Exception { ! ArrayList params = new ArrayList(); ! Variable a = new Variable("A"); ! Topic fred = (Topic) getObjectById("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); ! assertNotNull(out); ! assertEquals(1, out.getColumns().size()); ! assertEquals(1, out.getRows().size()); ! assertEquals(role.getAssociation(), out.getRow(0).get(0)); ! } ! ! public void testMatchRoles() throws Exception { ! ArrayList params = new ArrayList(); ! Topic barney =(Topic) getObjectById("barney"); ! Association assoc = ((AssociationRole) barney.getRolesPlayed().iterator().next()).getAssociation(); ! Variable a = new Variable("A"); ! params.add(assoc); ! params.add(a); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getColumns().size()); ! assertEquals(2, out.getRows().size()); ! assertEquals(assoc, ((AssociationRole)out.getRow(0).get(0)).getAssociation()); ! assertEquals(assoc, ((AssociationRole)out.getRow(1).get(0)).getAssociation()); ! } ! ! public void testOpenMatch() throws Exception { ! ArrayList params = new ArrayList(); ! Variable a = new Variable("A"); ! Variable b = new Variable("B"); ! params.add(a); ! params.add(b); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! 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 { ! ArrayList params = new ArrayList(); ! Variable a = new Variable("A"); ! Variable b = new Variable("B"); ! params.add(a); ! params.add(b); ! m_predicate.setParameters(params); ! Topic fred = (Topic) getObjectById("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 =(Topic) getObjectById("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()); ! } ! } ! Index: DirectInstanceOfPredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/DirectInstanceOfPredicateTest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** DirectInstanceOfPredicateTest.java 9 Mar 2005 12:40:19 -0000 1.7 --- DirectInstanceOfPredicateTest.java 8 Jul 2005 16:03:21 -0000 1.8 *************** *** 1,157 **** ! /* ! * 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.predicates.test; ! ! import java.util.ArrayList; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.predicates.DirectInstanceOfPredicate; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.Topic; ! ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class DirectInstanceOfPredicateTest extends PredicateTestBase { ! ! ! /** ! * Constructor for DirectInstanceOfPredicateTest. ! * @param arg0 ! */ ! public DirectInstanceOfPredicateTest(String arg0) { ! super(arg0); ! } ! ! public Class getPredicateClass() { ! return DirectInstanceOfPredicate.class; ! } ! ! private static final String TESTMAP = ! "[digestive:biscuit]\n" + ! "[battenburg:cake]\n" + ! "[jaffacake:cake]\n" + ! "[jaffacake:biscuit]\n" + ! "[custardcream:biscuit]\n"; ! ! ! public void createTestMap(TopicMap tm) { ! Topic digestive = tm.createTopic(); ! Topic biscuit = tm.createTopic(); ! Topic battenburg = tm.createTopic(); ! Topic cake = tm.createTopic(); ! Topic jaffacake = tm.createTopic(); ! Topic custardcream = tm.createTopic(); ! ! digestive.addType(biscuit); ! battenburg.addType(cake); ! jaffacake.addType(cake); ! jaffacake.addType(biscuit); ! custardcream.addType(biscuit); ! ! registerObject("digestive", digestive); ! registerObject("biscuit", biscuit); ! registerObject("battenburg", battenburg); ! registerObject("cake", cake); ! registerObject("jaffacake", jaffacake); ! registerObject("custardcream", custardcream); ! } ! ! ! public void testOpenMatch() throws Exception ! { ! List params = new ArrayList(); ! Variable a = new Variable("A"); ! Variable b = new Variable("B"); ! params.add(a); ! params.add(b); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(2, out.getColumns().size()); ! assertEquals(5, out.getRows().size()); ! assertTrue(out.getColumn(a).contains(getObjectById("digestive"))); ! assertTrue(out.getColumn(a).contains(getObjectById("battenburg"))); ! assertTrue(out.getColumn(a).contains(getObjectById("custardcream"))); ! assertTrue(out.getColumn(a).contains(getObjectById("jaffacake"))); ! assertTrue(out.getColumn(b).contains(getObjectById("biscuit"))); ! assertTrue(out.getColumn(b).contains(getObjectById("cake"))); ! } ! ! public void testClassMatch() throws Exception ! { ! List params = new ArrayList(); ! Variable a = new Variable("A"); ! params.add(a); ! params.add(m_tm.getObjectById("cake")); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getColumns().size()); ! assertEquals(2, out.getRows().size()); ! assertTrue(out.getColumn(a).contains(getObjectById("battenburg"))); ! assertTrue(out.getColumn(a).contains(getObjectById("jaffacake"))); ! } ! ! public void testInstanceMatch() throws Exception { ! List params = new ArrayList(); ! Variable a = new Variable("A"); ! params.add(getObjectById("jaffacake")); ! params.add(a); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getColumns().size()); ! assertEquals(2, out.getRows().size()); ! assertTrue(out.getColumn(a).contains(getObjectById("cake"))); ! assertTrue(out.getColumn(a).contains(getObjectById("biscuit"))); ! } ! ! public void testClosedMatch() throws Exception { ! List params = new ArrayList(); ! Variable a = new Variable("A"); ! params.add(a); ! params.add(getObjectById("cake")); ! m_predicate.setParameters(params); ! params.set(0, getObjectById("jaffacake")); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getColumns().size()); ! assertEquals(1, out.getRows().size()); ! assertTrue(out.getColumn(a).contains(getObjectById("jaffacake"))); ! } ! ! // protected 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(TESTMAP), loc, new LTMBuilder()); ! // m_tm = m_provider.addTopicMap(src); ! // m_predicate = new DirectInstanceOfPredicate(); ! // m_predicate.initialise(m_tm); ! // m_context = new TologContext(); ! // } ! ! ! } --- 1,157 ---- ! /* ! * 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 a... [truncated message content] |