summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2013-08-25 16:39:06 (GMT)
committerRemko Tronçon <git@el-tramo.be>2013-08-27 19:47:48 (GMT)
commit1bb607f96e79845ce30dd5590b0d53cc394ac150 (patch)
tree6156622ddd1b3238aec73536e0dc25b632965a71 /Swiften/QA/ScriptedTests
parentc4431ee90f3f1daac0a12b35bfa3378d5c570eaa (diff)
downloadswift-1bb607f96e79845ce30dd5590b0d53cc394ac150.zip
swift-1bb607f96e79845ce30dd5590b0d53cc394ac150.tar.bz2
PubSub implementation & Sluift refactoring.
Change-Id: I04ff7111b73565c00bff6db183451774a633344f
Diffstat (limited to 'Swiften/QA/ScriptedTests')
-rw-r--r--Swiften/QA/ScriptedTests/MultipleClients.lua8
-rw-r--r--Swiften/QA/ScriptedTests/PubSub.lua288
-rw-r--r--Swiften/QA/ScriptedTests/SendMessage.lua16
3 files changed, 300 insertions, 12 deletions
diff --git a/Swiften/QA/ScriptedTests/MultipleClients.lua b/Swiften/QA/ScriptedTests/MultipleClients.lua
index ce51481..ddc7c44 100644
--- a/Swiften/QA/ScriptedTests/MultipleClients.lua
+++ b/Swiften/QA/ScriptedTests/MultipleClients.lua
@@ -1,5 +1,5 @@
--
--- Copyright (c) 2010 Remko Tronçon
+-- Copyright (c) 2010-2013 Remko Tronçon
-- Licensed under the GNU General Public License v3.
-- See Documentation/Licenses/GPLv3.txt for more information.
--
@@ -16,17 +16,17 @@ for i = 1, num_clients do
client = sluift.new_client(jid, os.getenv("SWIFT_CLIENTTEST_PASS"))
client:set_options({compress = false})
client:async_connect()
- table.insert(clients, client)
+ clients[#clients+1] = client
end
print("Waiting for clients to be connected")
-for i, client in ipairs(clients) do
+for _, client in ipairs(clients) do
client:wait_connected()
client:send_presence("Hello")
end
print("Disconnecting clients")
-for i, client in ipairs(clients) do
+for _, client in ipairs(clients) do
client:disconnect()
end
diff --git a/Swiften/QA/ScriptedTests/PubSub.lua b/Swiften/QA/ScriptedTests/PubSub.lua
new file mode 100644
index 0000000..a9c0fe8
--- /dev/null
+++ b/Swiften/QA/ScriptedTests/PubSub.lua
@@ -0,0 +1,288 @@
+ --[[
+ Copyright (c) 2013 Remko Tronçon
+ Licensed under the GNU General Public License.
+ See the COPYING file for more information.
+--]]
+
+require 'sluift'
+
+sluift.debug = os.getenv("SLUIFT_DEBUG")
+
+local publisher
+local publisher_jid = os.getenv("SLUIFT_JID")
+local pubsub_jid = os.getenv("SLUIFT_PUBSUB_SERVICE") or sluift.jid.to_bare(publisher_jid)
+local pubsub
+local node_id = os.getenv("SLUIFT_PUBSUB_NODE") or "http://swift.im/Swiften/QA/PubSub"
+local node
+
+local subscriber
+local subscriber_jid = os.getenv("SLUIFT_JID2")
+local subscriber_pubsub
+local subscriber_node
+
+local publish_item = {id = 'item_id', data = {{ _type = 'software_version', name = 'MyTest', os = 'Lua' }} }
+local publish_item2 = {id = 'item_id2', data = {{ _type = 'software_version', name = 'MyTest2', os = 'Lua' }} }
+
+--------------------------------------------------------------------------------
+-- Helper methods
+--------------------------------------------------------------------------------
+
+function purge_pubsub_events(client)
+ client:for_each_pubsub_event({timeout = 2000}, function() end)
+end
+
+--------------------------------------------------------------------------------
+-- 5. Entity use cases
+--------------------------------------------------------------------------------
+function test_entity_use_cases()
+ node:delete()
+
+ -- 5.2 List nodes
+ assert(node:create())
+ local nodes = assert(pubsub:list_nodes()).items
+ local found_item = false
+ for _, node in ipairs(nodes) do
+ if node.node == node_id then found_item = true end
+ end
+ assert(found_item)
+ assert(node:delete())
+
+
+ -- 5.5 Discover items of node
+ assert(node:create())
+ assert(node:publish {items = {publish_item}})
+ local items = assert(node:list_items()).items
+ assert(#items == 1)
+ assert(items[1].name == 'item_id')
+ assert(node:delete())
+
+ -- 5.6 Subscriptions
+ assert(node:create())
+ assert(subscriber_node:subscribe({ jid = subscriber_jid }))
+ local service_subscriptions = assert(pubsub:get_subscriptions())
+ -- FIXME: Doesn't seem to return anything on M-Link. Test this later if this is supposed to work.
+ --print(service_subscriptions)
+ local node_subscriptions = assert(node:get_subscriptions())
+ --print(node_subscriptions)
+ assert(node:delete())
+
+ -- 5.7 Retrieve affiliations
+ --print(pubsub:get_affiliations()) -- Freezes Isode
+ --print(node:get_affiliations()) -- Freezes isode
+end
+
+--------------------------------------------------------------------------------
+-- 6. Subscriber use cases
+--------------------------------------------------------------------------------
+
+function test_subscriber_use_cases()
+ node:delete()
+
+ -- 6.1 Subscribe to a node
+ assert(node:create())
+ local subscription = assert(subscriber_node:subscribe({ jid = subscriber_jid }))
+ -- TODO: Test subscription id etc. Doesn't work with M-link atm
+ -- TODO: Test pending subscription
+ -- TODO: Test configuration required
+ assert(node:delete())
+
+ -- 6.2 Unsubscribe from a node
+ assert(node:create())
+ assert(subscriber_node:subscribe({ jid = subscriber_jid }))
+ assert(subscriber_node:unsubscribe({ jid = subscriber_jid }))
+ assert(node:delete())
+
+ -- 6.3 Configure subscription options
+ -- TODO: Not supported by M-Link? Finish it later
+ --assert(node:create())
+ --assert(subscriber_node:subscribe({ jid = subscriber_jid }))
+ --local options = assert(subscriber_node:get_subscription_options({ jid = subscriber_jid }))
+ --print(options)
+ --assert(node:delete())
+
+ -- 6.4 Request default subscription configuration options
+ -- TODO: Not supported by M-Link? Finish it later
+ --local options = assert(subscriber_pubsub:get_default_subscription_options())
+ --print(options)
+ --local options = assert(subscriber_node:get_default_subscription_options())
+ --print(options)
+
+ -- 6.5 Retrieve items of a node
+ assert(node:create())
+ assert(node:publish {item = publish_item})
+ local items = assert(subscriber_node:get_items())
+ assert(#items == 1)
+ assert(items[1].id == 'item_id')
+ assert(items[1].data[1].name == 'MyTest')
+ assert(node:delete())
+end
+
+--------------------------------------------------------------------------------
+-- 7. Publisher use cases
+--------------------------------------------------------------------------------
+
+function test_publisher_use_cases()
+ node:delete()
+
+ -- 7.1 Publish item to a node
+ assert(node:create())
+ assert(subscriber_node:subscribe({ jid = subscriber_jid }))
+ purge_pubsub_events(subscriber)
+ assert(node:publish {items = {publish_item}})
+ local event = assert(subscriber:get_next_event { type = 'pubsub' })
+ assert(event.from == publisher_jid)
+ assert(event._type == 'pubsub_event_items')
+ assert(event.items[1].id == publish_item.id)
+ assert(event.items[1].data[1].os == publish_item.data[1].os)
+ assert(event.item.os == publish_item.data[1].os)
+ assert(node:delete())
+
+ -- 7.2 Delete item from a node
+ assert(node:create())
+ assert(subscriber_node:subscribe({ jid = subscriber_jid }))
+ assert(node:publish {items = {publish_item}})
+ assert(node:retract { item = 'item_id', notify = true })
+ assert(node:delete())
+
+ -- 7.2.2.1 Delete and notify
+ assert(node:create())
+ assert(subscriber_node:subscribe({ jid = subscriber_jid }))
+ assert(node:publish {items = {publish_item}})
+ purge_pubsub_events(subscriber)
+ assert(node:retract { item = 'item_id', notify = true })
+ local event = assert(subscriber:get_next_event { type = 'pubsub' })
+ assert(event._type == 'pubsub_event_items')
+ assert(event.retracts[1].id == 'item_id')
+ assert(node:delete())
+
+ -- Publish an unknown element type
+ atom = [[
+ <entry xmlns='http://www.w3.org/2005/Atom'>
+ <title>Down the Rabbit Hole</title>
+ <summary>
+ Alice was beginning to get very tired of sitting by her sister on the
+ bank and of having nothing to do: once or twice she had peeped into the
+ book her sister was reading, but it had no pictures or conversations in
+ it, "and what is the use of a book," thought Alice, "without pictures
+ or conversations?'
+ </summary>
+ <link rel='alternate' type='text/html'
+ href='http://www.gutenberg.org/files/11/11-h/11-h.htm#link2HCH0001'/>
+ <id>tag:gutenberg.org,2008:entry-1234</id>
+ <published>2008-06-25T18:30:02Z</published>
+ <updated>2008-06-25T18:30:02Z</updated>
+ </entry>
+ ]]
+ assert(node:create())
+ assert(subscriber_node:subscribe({ jid = subscriber_jid }))
+ purge_pubsub_events(subscriber)
+ assert(node:publish { item = atom })
+ local event_item = assert(subscriber:get_next_event { type = 'pubsub' }).item
+ assert(event_item._type == 'dom')
+ assert(event_item.ns == 'http://www.w3.org/2005/Atom')
+ assert(event_item.tag == 'entry')
+ assert(node:delete())
+end
+
+--------------------------------------------------------------------------------
+-- 8 Owner Use Cases
+--------------------------------------------------------------------------------
+
+function test_owner_use_cases()
+ node:delete()
+
+ -- 8.1 Create a node
+ -- Create node with default config
+ assert(node:create())
+ configuration = assert(node:get_configuration())['data']
+ assert(node:delete())
+
+ -- Create node with custom config
+ print("Creating with configuration")
+ assert(node:create { configuration = { ['pubsub#access_model'] = 'whitelist' } })
+ configuration = assert(node:get_configuration())['data']
+ assert(configuration['pubsub#access_model']['value'] == 'whitelist')
+ assert(node:delete())
+
+ -- 8.2 Configure node
+ -- Set configuration
+ assert(node:create())
+ assert(node:set_configuration {configuration = {['pubsub#access_model'] = 'whitelist'}})
+ configuration = assert(node:get_configuration())['data']
+ assert(configuration['pubsub#access_model']['value'] == 'whitelist')
+ assert(node:delete())
+
+ -- Untested: 8.2.5.3 Success With Notifications
+
+ -- 8.3 Request Default Node Configuration Options
+ configuration = assert(pubsub:get_default_configuration())['data']
+ assert(configuration['pubsub#access_model'] ~= nil)
+
+ -- 8.4 Delete node
+ -- Without redirection (see above)
+ -- With redirection
+ assert(node:create())
+ assert(subscriber_node:subscribe({ jid = subscriber_jid }))
+ purge_pubsub_events(subscriber)
+ assert(node:delete {redirect = 'foo@bar.com'})
+ -- FIXME: M-Link doesn't send out an event. Test this later.
+ --local event = assert(subscriber:get_next_event { type = 'pubsub' })
+ --print(event)
+ --assert(event._type == 'pubsub_event_items')
+ --assert(event.retracts[1].id == 'item_id')
+
+ -- 8.5 Purge node items
+ assert(node:create())
+ assert(subscriber_node:subscribe({ jid = subscriber_jid }))
+ -- Publishing multiple items doesn't seem to work in M-Link
+ --assert(node:publish {items = { publish_item, publish_item2 }})
+ assert(node:publish {items = {publish_item} })
+ assert(node:publish {items = {publish_item2} })
+ purge_pubsub_events(subscriber)
+ if node:purge() then
+ -- Hasn't worked yet. Add more to this test later (including notifications)
+ else
+ print("Warning: Purge not supported. Skipping test")
+ end
+ assert(node:delete())
+
+ -- 8.6 Manage subscription requests
+ -- TODO
+
+ -- 8.7 Process pending subscription requests
+ -- TODO
+
+ -- ...
+end
+
+function run_tests()
+ connect_options = {}
+
+ -- Set up publisher & subscriber
+ publisher = sluift.new_client(publisher_jid, os.getenv("SLUIFT_PASS"))
+ assert(publisher:connect(connect_options))
+ subscriber = sluift.new_client(subscriber_jid, os.getenv("SLUIFT_PASS2"))
+ assert(subscriber:connect(connect_options))
+
+ pubsub = publisher:pubsub(pubsub_jid)
+ node = pubsub:node(node_id)
+
+ subscriber_pubsub = subscriber:pubsub(pubsub_jid)
+ subscriber_node = subscriber_pubsub:node(node_id)
+
+ -- The tests
+ test_entity_use_cases()
+ test_subscriber_use_cases()
+ test_publisher_use_cases()
+ test_owner_use_cases()
+end
+
+success, err = pcall(run_tests)
+
+if subscriber then subscriber:disconnect() end
+if publisher then publisher:disconnect() end
+
+if not success then
+ print(err)
+ os.exit(-1)
+end
diff --git a/Swiften/QA/ScriptedTests/SendMessage.lua b/Swiften/QA/ScriptedTests/SendMessage.lua
index 8c54d00..9623ef4 100644
--- a/Swiften/QA/ScriptedTests/SendMessage.lua
+++ b/Swiften/QA/ScriptedTests/SendMessage.lua
@@ -1,5 +1,5 @@
--
--- Copyright (c) 2010 Remko Tronçon
+-- Copyright (c) 2010-2013 Remko Tronçon
-- Licensed under the GNU General Public License v3.
-- See Documentation/Licenses/GPLv3.txt for more information.
--
@@ -23,22 +23,22 @@ client2:send_presence("I'm here")
print "Checking version of client 2 from client 1"
client2:set_version({name = "Sluift Test", version = "1.0"})
-client2_version = client1:get_version(client2_jid)
+client2_version = client1:get_software_version {to=client2_jid}
assert(client2_version["name"] == "Sluift Test")
assert(client2_version["version"] == "1.0")
print "Sending message from client 1 to client 2"
client1:send_message(client2_jid, "Hello")
-received_message = client2:for_event(function(event)
- if event["type"] == "message" and event["from"] == client1_jid then
- return event["body"]
- end
- end, 10000)
+received_message = client2:for_each_message({timeout = 1000}, function(message)
+ if message["from"] == client1_jid then
+ return message["body"]
+ end
+end)
assert(received_message == "Hello")
print "Retrieving the roster"
roster = client1:get_roster()
-tprint(roster)
+sluift.tprint(roster)
client1:disconnect()
client2:disconnect()