diff options
| author | Kenneth Anthony Giusti <kgiusti@apache.org> | 2010-01-28 21:10:07 +0000 |
|---|---|---|
| committer | Kenneth Anthony Giusti <kgiusti@apache.org> | 2010-01-28 21:10:07 +0000 |
| commit | 7b81d62e6dbc82ebdd931b8141a6844e9ee0ed99 (patch) | |
| tree | e6a23e07bd148b45ab0eb3ff4034e118d07c09d6 /qpid/python/qmf2/tests | |
| parent | 117227c2d909b4813d15d8b355bcd855e8c9f682 (diff) | |
| download | qpid-python-7b81d62e6dbc82ebdd931b8141a6844e9ee0ed99.tar.gz | |
QPID-2261: Rework query impl to use list-based approach
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@904268 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/python/qmf2/tests')
| -rw-r--r-- | qpid/python/qmf2/tests/agent_discovery.py | 6 | ||||
| -rw-r--r-- | qpid/python/qmf2/tests/basic_method.py | 18 | ||||
| -rw-r--r-- | qpid/python/qmf2/tests/basic_query.py | 106 | ||||
| -rw-r--r-- | qpid/python/qmf2/tests/events.py | 2 | ||||
| -rw-r--r-- | qpid/python/qmf2/tests/obj_gets.py | 2 |
5 files changed, 111 insertions, 23 deletions
diff --git a/qpid/python/qmf2/tests/agent_discovery.py b/qpid/python/qmf2/tests/agent_discovery.py index ce346d84e6..59b65221e0 100644 --- a/qpid/python/qmf2/tests/agent_discovery.py +++ b/qpid/python/qmf2/tests/agent_discovery.py @@ -180,9 +180,9 @@ class BaseTest(unittest.TestCase): self.console.add_connection(self.conn) query = qmf2.common.QmfQuery.create_predicate( - qmf2.common.QmfQuery.TARGET_AGENT, - qmf2.common.QmfQueryPredicate({qmf2.common.QmfQuery.CMP_EQ: - [qmf2.common.QmfQuery.KEY_AGENT_NAME, "agent1"]})) + qmf2.common.QmfQuery.TARGET_AGENT, + [qmf2.common.QmfQuery.EQ, qmf2.common.QmfQuery.KEY_AGENT_NAME, + [qmf2.common.QmfQuery.QUOTE, "agent1"]]) self.console.enable_agent_discovery(query) agent1_found = agent2_found = False diff --git a/qpid/python/qmf2/tests/basic_method.py b/qpid/python/qmf2/tests/basic_method.py index a12bbe7c4a..a1847efee9 100644 --- a/qpid/python/qmf2/tests/basic_method.py +++ b/qpid/python/qmf2/tests/basic_method.py @@ -22,7 +22,7 @@ from threading import Thread, Event import qpid.messaging from qmf2.common import (Notifier, SchemaObjectClass, SchemaClassId, SchemaProperty, qmfTypes, SchemaMethod, QmfQuery, - QmfData, QmfQueryPredicate, WorkItem) + QmfData, WorkItem) import qmf2.console from qmf2.agent import(QmfAgentData, Agent, MethodCallParams) @@ -247,11 +247,9 @@ class BaseTest(unittest.TestCase): self.assertTrue(agent and agent.get_name() == aname) query = QmfQuery.create_predicate(QmfQuery.TARGET_OBJECT, - QmfQueryPredicate( - {QmfQuery.LOGIC_AND: - [{QmfQuery.CMP_EXISTS: [SchemaClassId.KEY_PACKAGE]}, - {QmfQuery.CMP_EQ: [SchemaClassId.KEY_PACKAGE, - "MyPackage"]}]})) + [QmfQuery.AND, + [QmfQuery.EXISTS, [QmfQuery.QUOTE, SchemaClassId.KEY_PACKAGE]], + [QmfQuery.EQ, SchemaClassId.KEY_PACKAGE, [QmfQuery.QUOTE, "MyPackage"]]]) obj_list = self.console.do_query(agent, query) self.assertTrue(len(obj_list) == 2) @@ -297,11 +295,9 @@ class BaseTest(unittest.TestCase): self.assertTrue(agent and agent.get_name() == aname) query = QmfQuery.create_predicate(QmfQuery.TARGET_OBJECT, - QmfQueryPredicate( - {QmfQuery.LOGIC_AND: - [{QmfQuery.CMP_EXISTS: [SchemaClassId.KEY_PACKAGE]}, - {QmfQuery.CMP_EQ: [SchemaClassId.KEY_PACKAGE, - "MyPackage"]}]})) + [QmfQuery.AND, + [QmfQuery.EXISTS, [QmfQuery.QUOTE, SchemaClassId.KEY_PACKAGE]], + [QmfQuery.EQ, [QmfQuery.UNQUOTE, SchemaClassId.KEY_PACKAGE], [QmfQuery.QUOTE, "MyPackage"]]]) obj_list = self.console.do_query(agent, query) self.assertTrue(len(obj_list) == 2) diff --git a/qpid/python/qmf2/tests/basic_query.py b/qpid/python/qmf2/tests/basic_query.py index 61002976a2..5a1f4c55c8 100644 --- a/qpid/python/qmf2/tests/basic_query.py +++ b/qpid/python/qmf2/tests/basic_query.py @@ -22,7 +22,7 @@ from threading import Thread, Event import qpid.messaging from qmf2.common import (Notifier, SchemaObjectClass, SchemaClassId, SchemaProperty, qmfTypes, SchemaMethod, QmfQuery, - QmfData, QmfQueryPredicate) + QmfData) import qmf2.console from qmf2.agent import(QmfAgentData, Agent) @@ -107,6 +107,7 @@ class _agentApp(Thread): _obj2.set_value("field2", 2) _obj2.set_value("field3", {"a":1, "map":2, "value":3}) _obj2.set_value("field4", ["a", "list", "value"]) + _obj2.set_value("index1", 50) self.agent.add_object(_obj2) self.running = False @@ -296,9 +297,9 @@ class BaseTest(unittest.TestCase): self.assertTrue(agent and agent.get_name() == aname) query = QmfQuery.create_predicate(QmfQuery.TARGET_SCHEMA, - QmfQueryPredicate( - {QmfQuery.CMP_EQ: [SchemaClassId.KEY_PACKAGE, - "MyPackage"]})) + [QmfQuery.EQ, + SchemaClassId.KEY_PACKAGE, + [QmfQuery.QUOTE, "MyPackage"]]) schema_list = self.console.do_query(agent, query) self.assertTrue(len(schema_list)) @@ -330,9 +331,9 @@ class BaseTest(unittest.TestCase): self.assertTrue(agent and agent.get_name() == aname) query = QmfQuery.create_predicate(QmfQuery.TARGET_SCHEMA, - QmfQueryPredicate( - {QmfQuery.CMP_EQ: [SchemaClassId.KEY_PACKAGE, - "No-Such-Package"]})) + [QmfQuery.EQ, + [QmfQuery.UNQUOTE, SchemaClassId.KEY_PACKAGE], + [QmfQuery.QUOTE, "No-Such-Package"]]) schema_list = self.console.do_query(agent, query) self.assertTrue(len(schema_list) == 0) @@ -340,3 +341,94 @@ class BaseTest(unittest.TestCase): self.console.destroy(10) + def test_predicate_match_string(self): + # create console + # find agents + # synchronous query for all objects with a value named + # set_string which is < or equal to "UNSET" + self.notifier = _testNotifier() + self.console = qmf2.console.Console(notifier=self.notifier, + agent_timeout=3) + self.conn = qpid.messaging.Connection(self.broker.host, + self.broker.port, + self.broker.user, + self.broker.password) + self.conn.connect() + self.console.add_connection(self.conn) + + for aname in ["agent1", "agent2"]: + agent = self.console.find_agent(aname, timeout=3) + self.assertTrue(agent and agent.get_name() == aname) + + query = QmfQuery.create_predicate(QmfQuery.TARGET_OBJECT, + [QmfQuery.AND, + [QmfQuery.EXISTS, [QmfQuery.QUOTE, "set_string"]], + [QmfQuery.EQ, "set_string", [QmfQuery.QUOTE, "UNSET"]]]) + + obj_list = self.console.do_query(agent, query) + self.assertTrue(len(obj_list) == 2) + for obj in obj_list: + self.assertTrue(obj.has_value("set_string")) + self.assertTrue(obj.get_value("set_string") == "UNSET") + + self.console.destroy(10) + + + + def test_predicate_match_integer(self): + # create console + # find agents + # synchronous query for all objects with a value named + # "index1" which is < or equal to various values + self.notifier = _testNotifier() + self.console = qmf2.console.Console(notifier=self.notifier, + agent_timeout=3) + self.conn = qpid.messaging.Connection(self.broker.host, + self.broker.port, + self.broker.user, + self.broker.password) + self.conn.connect() + self.console.add_connection(self.conn) + + for aname in ["agent1", "agent2"]: + agent = self.console.find_agent(aname, timeout=3) + self.assertTrue(agent and agent.get_name() == aname) + + # == 99 + query = QmfQuery.create_predicate(QmfQuery.TARGET_OBJECT, + [QmfQuery.AND, + [QmfQuery.EXISTS, [QmfQuery.QUOTE, "index1"]], + [QmfQuery.EQ, "index1", 99]]) + + obj_list = self.console.do_query(agent, query) + self.assertTrue(len(obj_list) == 1) + self.assertTrue(obj_list[0].has_value("index1")) + self.assertTrue(obj_list[0].get_value("index1") == 99) + + # <= 99 + query = QmfQuery.create_predicate(QmfQuery.TARGET_OBJECT, + [QmfQuery.AND, + [QmfQuery.EXISTS, [QmfQuery.QUOTE, "index1"]], + [QmfQuery.LE, "index1", 99]]) + + obj_list = self.console.do_query(agent, query) + self.assertTrue(len(obj_list) == 2) + for obj in obj_list: + self.assertTrue(obj.has_value("index1")) + self.assertTrue(obj.get_value("index1") <= 99) + + + # > 99 + query = QmfQuery.create_predicate(QmfQuery.TARGET_OBJECT, + [QmfQuery.AND, + [QmfQuery.EXISTS, [QmfQuery.QUOTE, "index1"]], + [QmfQuery.GT, "index1", 99]]) + + obj_list = self.console.do_query(agent, query) + self.assertTrue(len(obj_list) == 1) + for obj in obj_list: + self.assertTrue(obj.has_value("index1")) + self.assertTrue(obj.get_value("index1") > 99) + + self.console.destroy(10) + diff --git a/qpid/python/qmf2/tests/events.py b/qpid/python/qmf2/tests/events.py index 9ee6b6af8d..a621aa0392 100644 --- a/qpid/python/qmf2/tests/events.py +++ b/qpid/python/qmf2/tests/events.py @@ -25,7 +25,7 @@ import qpid.messaging from qpid.harness import Skipped from qmf2.common import (Notifier, SchemaObjectClass, SchemaClassId, SchemaProperty, qmfTypes, SchemaMethod, QmfQuery, - QmfData, QmfQueryPredicate, SchemaEventClass, + QmfData, SchemaEventClass, QmfEvent) import qmf2.console from qmf2.agent import(QmfAgentData, Agent) diff --git a/qpid/python/qmf2/tests/obj_gets.py b/qpid/python/qmf2/tests/obj_gets.py index 50d585a718..514121980e 100644 --- a/qpid/python/qmf2/tests/obj_gets.py +++ b/qpid/python/qmf2/tests/obj_gets.py @@ -22,7 +22,7 @@ from threading import Thread, Event import qpid.messaging from qmf2.common import (Notifier, SchemaObjectClass, SchemaClassId, SchemaProperty, qmfTypes, SchemaMethod, QmfQuery, - QmfData, QmfQueryPredicate) + QmfData) import qmf2.console from qmf2.agent import(QmfAgentData, Agent) |
