t2-server 0.6.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/.rvmrc +1 -0
  2. data/CHANGES.rdoc +48 -0
  3. data/LICENCE.rdoc +2 -2
  4. data/README.rdoc +245 -10
  5. data/Rakefile +108 -0
  6. data/bin/t2-delete-runs +21 -34
  7. data/bin/t2-get-output +134 -0
  8. data/bin/t2-run-workflow +121 -109
  9. data/bin/t2-server-admin +128 -0
  10. data/bin/t2-server-info +25 -38
  11. data/lib/t2-server-cli.rb +116 -0
  12. data/lib/t2-server.rb +16 -27
  13. data/lib/t2-server/admin.rb +147 -0
  14. data/lib/t2-server/connection-parameters.rb +144 -0
  15. data/lib/t2-server/connection.rb +352 -0
  16. data/lib/t2-server/credentials.rb +84 -0
  17. data/lib/t2-server/exceptions.rb +42 -21
  18. data/lib/t2-server/port.rb +472 -0
  19. data/lib/t2-server/run.rb +822 -227
  20. data/lib/t2-server/server.rb +313 -317
  21. data/lib/t2-server/util.rb +71 -0
  22. data/lib/t2-server/xml/libxml.rb +87 -0
  23. data/lib/t2-server/xml/nokogiri.rb +85 -0
  24. data/lib/t2-server/xml/rexml.rb +85 -0
  25. data/lib/t2-server/xml/xml.rb +111 -0
  26. data/lib/t2server.rb +4 -1
  27. data/t2-server.gemspec +112 -0
  28. data/test/tc_admin.rb +63 -0
  29. data/test/{tc_paths.rb → tc_params.rb} +11 -25
  30. data/test/tc_perms.rb +132 -0
  31. data/test/tc_run.rb +200 -67
  32. data/test/tc_secure.rb +191 -0
  33. data/test/tc_server.rb +25 -23
  34. data/test/tc_util.rb +74 -0
  35. data/test/ts_t2server.rb +57 -12
  36. data/test/workflows/always_fail.t2flow +69 -0
  37. data/test/workflows/list_and_value.t2flow +12 -0
  38. data/test/workflows/list_with_errors.t2flow +107 -0
  39. data/test/workflows/secure/basic-http.t2flow +74 -0
  40. data/test/workflows/secure/basic-https.t2flow +74 -0
  41. data/test/workflows/secure/client-https.t2flow +162 -0
  42. data/test/workflows/secure/digest-http.t2flow +129 -0
  43. data/test/workflows/secure/digest-https.t2flow +107 -0
  44. data/test/workflows/secure/heater-pk.pem +20 -0
  45. data/test/workflows/secure/user-cert.p12 +0 -0
  46. data/test/workflows/secure/ws-http.t2flow +180 -0
  47. data/test/workflows/secure/ws-https.t2flow +180 -0
  48. data/test/workflows/strings.txt +10 -0
  49. data/test/workflows/xml_xpath.t2flow +136 -136
  50. data/version.yml +4 -0
  51. metadata +132 -34
  52. data/lib/t2-server/xml.rb +0 -86
data/t2-server.gemspec ADDED
@@ -0,0 +1,112 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "t2-server"
8
+ s.version = "0.9.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Robert Haines"]
12
+ s.date = "2012-03-26"
13
+ s.description = "This gem provides access to the Taverna 2 Server REST interface from Ruby."
14
+ s.email = ["rhaines@manchester.ac.uk"]
15
+ s.executables = ["t2-delete-runs", "t2-run-workflow", "t2-server-info", "t2-get-output", "t2-server-admin"]
16
+ s.extra_rdoc_files = [
17
+ "CHANGES.rdoc",
18
+ "LICENCE.rdoc",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ "CHANGES.rdoc",
23
+ "LICENCE.rdoc",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "bin/t2-delete-runs",
27
+ "bin/t2-get-output",
28
+ "bin/t2-run-workflow",
29
+ "bin/t2-server-admin",
30
+ "bin/t2-server-info",
31
+ "lib/t2-server-cli.rb",
32
+ "lib/t2-server.rb",
33
+ "lib/t2-server/admin.rb",
34
+ "lib/t2-server/connection-parameters.rb",
35
+ "lib/t2-server/connection.rb",
36
+ "lib/t2-server/credentials.rb",
37
+ "lib/t2-server/exceptions.rb",
38
+ "lib/t2-server/port.rb",
39
+ "lib/t2-server/run.rb",
40
+ "lib/t2-server/server.rb",
41
+ "lib/t2-server/util.rb",
42
+ "lib/t2-server/xml/libxml.rb",
43
+ "lib/t2-server/xml/nokogiri.rb",
44
+ "lib/t2-server/xml/rexml.rb",
45
+ "lib/t2-server/xml/xml.rb",
46
+ "lib/t2server.rb",
47
+ "test/tc_admin.rb",
48
+ "test/tc_params.rb",
49
+ "test/tc_perms.rb",
50
+ "test/tc_run.rb",
51
+ "test/tc_secure.rb",
52
+ "test/tc_server.rb",
53
+ "test/tc_util.rb",
54
+ "test/ts_t2server.rb",
55
+ "test/workflows/always_fail.t2flow",
56
+ "test/workflows/empty_list.t2flow",
57
+ "test/workflows/empty_list_input.baclava",
58
+ "test/workflows/in.txt",
59
+ "test/workflows/list_and_value.t2flow",
60
+ "test/workflows/list_with_errors.t2flow",
61
+ "test/workflows/pass_through.t2flow",
62
+ "test/workflows/secure/basic-http.t2flow",
63
+ "test/workflows/secure/basic-https.t2flow",
64
+ "test/workflows/secure/client-https.t2flow",
65
+ "test/workflows/secure/digest-http.t2flow",
66
+ "test/workflows/secure/digest-https.t2flow",
67
+ "test/workflows/secure/heater-pk.pem",
68
+ "test/workflows/secure/user-cert.p12",
69
+ "test/workflows/secure/ws-http.t2flow",
70
+ "test/workflows/secure/ws-https.t2flow",
71
+ "test/workflows/strings.txt",
72
+ "test/workflows/xml_xpath.t2flow",
73
+ "version.yml"
74
+ ]
75
+ s.homepage = "http://www.taverna.org.uk/"
76
+ s.rdoc_options = ["-N", "--tab-width=2", "--main=README.rdoc"]
77
+ s.require_paths = ["lib"]
78
+ s.rubygems_version = "1.8.10"
79
+ s.summary = "Support for interacting with Taverna 2 Server."
80
+ s.test_files = ["test/ts_t2server.rb"]
81
+
82
+ if s.respond_to? :specification_version then
83
+ s.specification_version = 3
84
+
85
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
86
+ s.add_development_dependency(%q<rake>, ["~> 0.9.2"])
87
+ s.add_development_dependency(%q<libxml-ruby>, [">= 1.1.4"])
88
+ s.add_development_dependency(%q<nokogiri>, [">= 1.5.0"])
89
+ s.add_development_dependency(%q<rdoc>, [">= 3.9.4"])
90
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
91
+ s.add_runtime_dependency(%q<taverna-baclava>, ["~> 1.0.0"])
92
+ s.add_runtime_dependency(%q<hirb>, [">= 0.4.0"])
93
+ else
94
+ s.add_dependency(%q<rake>, ["~> 0.9.2"])
95
+ s.add_dependency(%q<libxml-ruby>, [">= 1.1.4"])
96
+ s.add_dependency(%q<nokogiri>, [">= 1.5.0"])
97
+ s.add_dependency(%q<rdoc>, [">= 3.9.4"])
98
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
99
+ s.add_dependency(%q<taverna-baclava>, ["~> 1.0.0"])
100
+ s.add_dependency(%q<hirb>, [">= 0.4.0"])
101
+ end
102
+ else
103
+ s.add_dependency(%q<rake>, ["~> 0.9.2"])
104
+ s.add_dependency(%q<libxml-ruby>, [">= 1.1.4"])
105
+ s.add_dependency(%q<nokogiri>, [">= 1.5.0"])
106
+ s.add_dependency(%q<rdoc>, [">= 3.9.4"])
107
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
108
+ s.add_dependency(%q<taverna-baclava>, ["~> 1.0.0"])
109
+ s.add_dependency(%q<hirb>, [">= 0.4.0"])
110
+ end
111
+ end
112
+
data/test/tc_admin.rb ADDED
@@ -0,0 +1,63 @@
1
+ # Copyright (c) 2010-2012 The University of Manchester, UK.
2
+ #
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # * Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ #
11
+ # * Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # * Neither the names of The University of Manchester nor the names of its
16
+ # contributors may be used to endorse or promote products derived from this
17
+ # software without specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ # POSSIBILITY OF SUCH DAMAGE.
30
+ #
31
+ # Author: Robert Haines
32
+
33
+ require 't2-server'
34
+
35
+ class TestAdmin < Test::Unit::TestCase
36
+
37
+ def test_admin
38
+ T2Server::Server.new($uri, $conn_params) do |server|
39
+
40
+ # unauthorized
41
+ assert_raise(T2Server::AuthorizationError) do
42
+ server.administrator(T2Server::HttpBasic.new("u", "p"))
43
+ end
44
+
45
+ begin
46
+ server.administrator($creds)
47
+ rescue T2Server::T2ServerError => e
48
+ # ignore, just don't run more tests
49
+ return
50
+ end
51
+
52
+ server.administrator($creds) do |admin|
53
+ assert_equal(admin["allownew"].name, "allowNew")
54
+
55
+ save = admin["allownew"].value
56
+ admin["allownew"].value = false
57
+ assert_equal(admin["allownew"].value, "false")
58
+ admin["allownew"].value = save
59
+ assert_equal(admin["allownew"].value, save)
60
+ end
61
+ end
62
+ end
63
+ end
@@ -14,7 +14,7 @@
14
14
  #
15
15
  # * Neither the names of The University of Manchester nor the names of its
16
16
  # contributors may be used to endorse or promote products derived from this
17
- # software without specific prior written permission.
17
+ # software without specific prior written permission.
18
18
  #
19
19
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
20
  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -31,30 +31,16 @@
31
31
  # Author: Robert Haines
32
32
 
33
33
  require 't2-server'
34
- require 'test/unit'
35
34
 
36
- class TestFilePaths < Test::Unit::TestCase
37
- def test_standard
38
- assert_equal("dir/with/child", "dir/with/child".strip_path)
39
- assert_equal("dir/with/child", "/dir/with/child".strip_path)
40
- assert_equal("dir/with/child", "dir/with/child/".strip_path)
41
- assert_equal("dir/with/child", "/dir/with/child/".strip_path)
42
-
43
- # make sure it is not stripping in place
44
- dir = "/dir/with/child/"
45
- dir.strip_path
46
- assert_equal("/dir/with/child/", dir)
47
- end
48
-
49
- def test_inplace
50
- assert_nil("dir/with/child".strip_path!)
51
- assert_not_nil("/dir/with/child".strip_path!)
52
- assert_not_nil("dir/with/child/".strip_path!)
53
- assert_not_nil("/dir/with/child/".strip_path!)
54
-
55
- # make sure it is stripping in place
56
- dir = "/dir/with/child/"
57
- dir.strip_path!
58
- assert_equal("dir/with/child", dir)
35
+ class TestParams < Test::Unit::TestCase
36
+
37
+ def test_params
38
+ params = T2Server::ConnectionParameters.new
39
+
40
+ params[:verify_peer] = true
41
+ assert_not_nil(params[:verify_peer])
42
+
43
+ params[:not_a_chance] = true
44
+ assert_nil(params[:not_a_chance])
59
45
  end
60
46
  end
data/test/tc_perms.rb ADDED
@@ -0,0 +1,132 @@
1
+ # Copyright (c) 2010-2012 The University of Manchester, UK.
2
+ #
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # * Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ #
11
+ # * Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # * Neither the names of The University of Manchester nor the names of its
16
+ # contributors may be used to endorse or promote products derived from this
17
+ # software without specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ # POSSIBILITY OF SUCH DAMAGE.
30
+ #
31
+ # Author: Robert Haines
32
+
33
+ require 't2-server'
34
+
35
+ class TestPermissions < Test::Unit::TestCase
36
+
37
+ def test_ownership
38
+ server = T2Server::Server.new($uri, $conn_params)
39
+
40
+ server.create_run($wkf_pass, $creds) do |run|
41
+ assert(run.owner?)
42
+ assert_equal(run.owner, $creds.username)
43
+
44
+ run.grant_permission($creds1.username, :read)
45
+ run_id = run.identifier
46
+ run1 = server.run(run_id, $creds1)
47
+
48
+ assert(!run1.owner?)
49
+ assert_not_equal(run1.owner, $creds1.username)
50
+ end
51
+ end
52
+
53
+ def test_read_permission
54
+ server = T2Server::Server.new($uri, $conn_params)
55
+
56
+ server.create_run($wkf_pass, $creds) do |run|
57
+ assert_nothing_raised(T2Server::AccessForbiddenError) do
58
+ run.grant_permission($creds1.username, :read)
59
+ end
60
+
61
+ run_id = run.identifier
62
+
63
+ run1 = nil
64
+ assert_nothing_raised(T2Server::AccessForbiddenError) do
65
+ run1 = server.run(run_id, $creds1)
66
+ end
67
+
68
+ assert_raise(T2Server::AccessForbiddenError) do
69
+ run1.input_port("IN").value = "Hello, World!"
70
+ run1.start
71
+ end
72
+
73
+ run.input_port("IN").value = "Hello, World!"
74
+ run.start
75
+ run.wait
76
+
77
+ assert_nothing_raised(T2Server::AccessForbiddenError) do
78
+ run1.output_port("OUT").value
79
+ end
80
+
81
+ assert_raise(T2Server::AccessForbiddenError) do
82
+ run1.delete
83
+ end
84
+ end
85
+ end
86
+
87
+ def test_update_permission
88
+ server = T2Server::Server.new($uri, $conn_params)
89
+
90
+ server.create_run($wkf_pass, $creds) do |run|
91
+ assert_nothing_raised(T2Server::AccessForbiddenError) do
92
+ run.grant_permission($creds1.username, :update)
93
+ end
94
+
95
+ run_id = run.identifier
96
+
97
+ run1 = nil
98
+ assert_nothing_raised(T2Server::AccessForbiddenError) do
99
+ run1 = server.run(run_id, $creds1)
100
+ run1.input_port("IN").value = "Hello, World!"
101
+ run1.start
102
+ run1.wait
103
+ run1.output_port("OUT").value
104
+ end
105
+
106
+ assert_raise(T2Server::AccessForbiddenError) do
107
+ run1.delete
108
+ end
109
+ end
110
+ end
111
+
112
+ def test_destroy_permission
113
+ server = T2Server::Server.new($uri, $conn_params)
114
+
115
+ server.create_run($wkf_pass, $creds) do |run|
116
+ assert_nothing_raised(T2Server::AccessForbiddenError) do
117
+ run.grant_permission($creds1.username, :destroy)
118
+ end
119
+
120
+ run_id = run.identifier
121
+
122
+ assert_nothing_raised(T2Server::AccessForbiddenError) do
123
+ run1 = server.run(run_id, $creds1)
124
+ run1.input_port("IN").value = "Hello, World!"
125
+ run1.start
126
+ run1.wait
127
+ run1.output_port("OUT").value
128
+ run1.delete
129
+ end
130
+ end
131
+ end
132
+ end
data/test/tc_run.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2010, 2011 The University of Manchester, UK.
1
+ # Copyright (c) 2010-2012 The University of Manchester, UK.
2
2
  #
3
3
  # All rights reserved.
4
4
  #
@@ -14,7 +14,7 @@
14
14
  #
15
15
  # * Neither the names of The University of Manchester nor the names of its
16
16
  # contributors may be used to endorse or promote products derived from this
17
- # software without specific prior written permission.
17
+ # software without specific prior written permission.
18
18
  #
19
19
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
20
  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -34,93 +34,226 @@ require 't2-server'
34
34
 
35
35
  class TestRun < Test::Unit::TestCase
36
36
 
37
- def test_run
38
- # connection
37
+ # Test run connection
38
+ def test_run_misc
39
39
  assert_nothing_raised(T2Server::ConnectionError) do
40
- @run = T2Server::Run.create($address, $wkf_pass)
40
+ T2Server::Run.create($uri, $wkf_pass, $creds, $conn_params)
41
41
  end
42
+ end
42
43
 
43
- # test bad state code
44
- assert_raise(T2Server::RunStateError) do
45
- @run.wait
46
- end
44
+ # Test misc run functions
45
+ def test_status_codes
46
+ T2Server::Run.create($uri, $wkf_pass, $creds, $conn_params) do |run|
47
47
 
48
- # test mkdir
49
- assert(@run.mkdir("test"))
48
+ # test mkdir
49
+ assert(run.mkdir("test"))
50
50
 
51
- # set input, start, check state and wait
52
- assert_nothing_raised(T2Server::AttributeNotFoundError) do
53
- @run.set_input("IN", "Hello, World!")
54
- end
55
- @run.start
56
- assert(@run.running?)
57
- assert_nothing_raised(T2Server::RunStateError) do
58
- @run.wait
51
+ # set input, start, check state and wait
52
+ assert_nothing_raised(T2Server::AttributeNotFoundError) do
53
+ run.input_port("IN").value = "Hello, World!"
54
+ end
55
+ assert_equal(run.input_port("IN").value, "Hello, World!")
56
+
57
+ # test correct/incorrect status codes
58
+ assert_equal(run.status, :initialized)
59
+ assert_raise(T2Server::RunStateError) { run.wait }
60
+ assert_nothing_raised(T2Server::RunStateError) { run.start }
61
+ assert(run.running?)
62
+ assert_equal(run.status, :running)
63
+ assert_nothing_raised(T2Server::RunStateError) { run.wait }
64
+ assert_equal(run.status, :finished)
65
+ assert_raise(T2Server::RunStateError) { run.start }
66
+
67
+ # exitcode and output
68
+ assert_instance_of(Fixnum, run.exitcode)
69
+ assert_equal(run.output_port("OUT").value, "Hello, World!")
70
+ assert_equal(run.output_port("wrong!"), nil)
71
+
72
+ # get zip file
73
+ assert_nothing_raised(T2Server::T2ServerError) do
74
+ assert_not_equal(run.zip_output, "")
75
+ end
76
+
77
+ # deletion
78
+ assert(run.delete)
59
79
  end
80
+ end
81
+
82
+ # Test run with list inputs
83
+ def test_run_list_input
84
+ T2Server::Run.create($uri, $wkf_lists, $creds, $conn_params) do |run|
85
+ many = [[["boo"]], [["", "Hello"]], [], [[], ["test"], []]]
86
+ single = [1, 2, 3, 4, 5]
87
+ single_out = single.map { |v| v.to_s } # Taverna outputs strings!
88
+
89
+ run.input_port("SINGLE_IN").value = single
90
+ run.input_port("MANY_IN").value = many
91
+ assert_nothing_raised { run.start }
92
+ assert(run.running?)
93
+ run.wait
60
94
 
61
- # exitcode and output
62
- assert_instance_of(Fixnum, @run.exitcode)
63
- assert_equal(@run.get_output("OUT"), "Hello, World!")
64
- assert_raise(T2Server::AccessForbiddenError) do
65
- @run.get_output("wrong!")
95
+ assert_equal(run.output_port("MANY").value, many)
96
+ assert_equal(run.output_port("SINGLE").value, single_out)
66
97
  end
98
+ end
67
99
 
68
- # deletion
69
- assert(@run.delete)
100
+ # Test run with a list and file input
101
+ def test_run_list_and_file
102
+ T2Server::Run.create($uri, $wkf_l_v, $creds, $conn_params) do |run|
103
+ list = ["one", 2, :three]
104
+ list_out = list.map { |v| v.to_s }
70
105
 
71
- # run with xml input
72
- @run = T2Server::Run.create($address, $wkf_xml)
73
- @run.set_input("xml","<hello><yes>hello</yes><no>everybody</no><yes>world</yes></hello>")
74
- @run.set_input("xpath","//yes")
75
- @run.start
76
- @run.wait
77
- assert_equal(@run.get_output("nodes"), ["hello", "world"])
106
+ run.input_port("list_in").value = list
107
+ run.input_port("singleton_in").file = $file_input
108
+ assert_nothing_raised { run.start }
109
+ assert(run.running?)
110
+ run.wait
78
111
 
79
- # run with file input
80
- @run = T2Server::Run.create($address, $wkf_pass)
112
+ assert_equal(run.output_port("list_out").value, list_out)
113
+ assert_equal(run.output_port("singleton_out").value, "Hello, World!")
114
+ end
115
+ end
81
116
 
82
- assert_nothing_raised(T2Server::AttributeNotFoundError) do
83
- @run.upload_input_file("IN", $file_input)
117
+ # Test run with xml input
118
+ def test_run_xml_input
119
+ T2Server::Run.create($uri, $wkf_xml, $creds, $conn_params) do |run|
120
+ run.input_port("xml").value =
121
+ "<hello><yes>hello</yes><no>everybody</no><yes>world</yes></hello>"
122
+ run.input_port("xpath").value = "//yes"
123
+ run.start
124
+ run.wait
125
+ assert_equal(run.output_port("nodes").value, ["hello", "world"])
84
126
  end
127
+ end
85
128
 
86
- @run.start
87
- assert(@run.running?)
88
- assert_nothing_raised(T2Server::RunStateError) do
89
- @run.wait
129
+ def test_run_file_input
130
+ # run with file input
131
+ T2Server::Run.create($uri, $wkf_pass, $creds, $conn_params) do |run|
132
+
133
+ assert_nothing_raised(T2Server::AttributeNotFoundError) do
134
+ run.input_port("IN").file = $file_input
135
+ end
136
+
137
+ run.start
138
+ assert(run.running?)
139
+ assert_nothing_raised(T2Server::RunStateError) { run.wait }
140
+ assert_equal(run.output_port("OUT").value, "Hello, World!")
90
141
  end
91
- assert_equal(@run.get_output("OUT"), "Hello, World!")
142
+ end
143
+
144
+ # Test run that returns list of lists, some empty, using baclava for input
145
+ def test_baclava_input
146
+ T2Server::Run.create($uri, $wkf_lists, $creds, $conn_params) do |run|
147
+ assert_nothing_raised(T2Server::AttributeNotFoundError) do
148
+ run.baclava_input = $list_input
149
+ end
92
150
 
93
- # run that returns list of lists, some empty, using baclava for input
94
- @run = T2Server::Run.create($address, $wkf_lists)
95
- assert_nothing_raised(T2Server::AttributeNotFoundError) do
96
- @run.upload_baclava_file($list_input)
151
+ assert_equal(run.input_ports.keys.sort, ["MANY_IN", "SINGLE_IN"])
152
+ assert_equal(run.input_port("MANY_IN").depth, 3)
153
+ assert_equal(run.input_port("SINGLE_IN").depth, 1)
154
+ assert(run.baclava_input?)
155
+ assert(run.input_port("SINGLE_IN").baclava?)
156
+ assert(run.input_port("SINGLE_IN").set?)
157
+
158
+ run.start
159
+ assert(run.running?)
160
+ assert_nothing_raised(T2Server::RunStateError) { run.wait }
161
+ assert_equal(run.output_ports.keys.sort, ["MANY", "SINGLE"])
162
+ assert_equal(run.output_port("SINGLE").value, [])
163
+ assert_equal(run.output_port("MANY").value,
164
+ [[["boo"]], [["", "Hello"]], [], [[], ["test"], []]])
165
+ assert_equal(run.output_port("MANY").total_size, 12)
166
+ assert_equal(run.output_port("MANY")[1][0][1].value(1..3), "ell")
167
+ assert_raise(NoMethodError) { run.output_port("SINGLE")[0].value }
97
168
  end
98
-
99
- @run.start
100
- assert(@run.running?)
101
- assert_nothing_raised(T2Server::RunStateError) do
102
- @run.wait
169
+ end
170
+
171
+ # Test run with baclava output
172
+ def test_baclava_output
173
+ T2Server::Run.create($uri, $wkf_pass, $creds, $conn_params) do |run|
174
+ run.input_port("IN").value = "Some input..."
175
+ assert_nothing_raised(T2Server::AttributeNotFoundError) do
176
+ run.request_baclava_output
177
+ end
178
+ assert(run.baclava_output?)
179
+
180
+ run.start
181
+ assert(run.running?)
182
+ assert_nothing_raised(T2Server::RunStateError) { run.wait }
183
+
184
+ assert_nothing_raised(T2Server::AccessForbiddenError) do
185
+ output = run.baclava_output
186
+ end
103
187
  end
104
- assert_equal(@run.get_output_ports, ["SINGLE", "MANY"])
105
- assert_equal(@run.get_output("SINGLE"), [])
106
- assert_equal(@run.get_output("MANY"),
107
- [[["boo"]], [["", "Hello"]], [], [[], ["test"], []]])
108
-
109
- # run with baclava output
110
- @run = T2Server::Run.create($address, $wkf_pass)
111
- @run.set_input("IN", "Some input...")
112
- assert_nothing_raised(T2Server::AttributeNotFoundError) do
113
- @run.set_baclava_output
188
+ end
189
+
190
+ # Test partial result download
191
+ def test_result_download
192
+ T2Server::Run.create($uri, $wkf_pass, $creds, $conn_params) do |run|
193
+ assert_nothing_raised(T2Server::AttributeNotFoundError) do
194
+ file = run.upload_file($file_strs)
195
+ run.input_port("IN").remote_file = file
196
+ end
197
+
198
+ run.start
199
+ run.wait
200
+
201
+ # get total data size (without downloading the data)
202
+ assert_equal(run.output_port("OUT").total_size, 100)
203
+ assert_equal(run.output_port("OUT").size, 100)
204
+
205
+ # no data downloaded yet
206
+ assert(run.output_port("OUT").value(:debug).nil?)
207
+
208
+ # get just the first 10 bytes
209
+ assert_equal(run.output_port("OUT").value(0...10),
210
+ "123456789\n")
211
+
212
+ # get a bad range - should return the first 10 bytes
213
+ assert_equal(run.output_port("OUT").value(-10...10),
214
+ "123456789\n")
215
+
216
+ # confirm only the first 10 bytes have been downloaded
217
+ assert_equal(run.output_port("OUT").value(:debug),
218
+ "123456789\n")
219
+
220
+ # ask for a separate 10 byte range
221
+ assert_equal(run.output_port("OUT").value(20...30),
222
+ "323456789\n")
223
+
224
+ # confirm that enough was downloaded to connect the two ranges
225
+ assert_equal(run.output_port("OUT").value(:debug),
226
+ "123456789\n223456789\n323456789\n")
227
+
228
+ # ask for a range that we already have
229
+ assert_equal(run.output_port("OUT").value(5..25),
230
+ "6789\n223456789\n323456")
231
+
232
+ # confirm that no more has actually been downloaded
233
+ assert_equal(run.output_port("OUT").value(:debug),
234
+ "123456789\n223456789\n323456789\n")
235
+
236
+ # now get the lot and check its size
237
+ out = run.output_port("OUT").value
238
+ assert_equal(out.length, 100)
114
239
  end
240
+ end
115
241
 
116
- @run.start
117
- assert(@run.running?)
118
- assert_nothing_raised(T2Server::RunStateError) do
119
- @run.wait
242
+ # test error handling
243
+ def test_always_fail
244
+ T2Server::Run.create($uri, $wkf_fail, $creds, $conn_params) do |run|
245
+ run.start
246
+ run.wait
247
+ assert(run.output_port("OUT").value.nil?)
248
+ assert(run.output_port("OUT").error?)
120
249
  end
250
+ end
121
251
 
122
- assert_nothing_raised(T2Server::AttributeNotFoundError) do
123
- output = @run.get_baclava_output
252
+ def test_errors
253
+ T2Server::Run.create($uri, $wkf_errors, $creds, $conn_params) do |run|
254
+ run.start
255
+ run.wait
256
+ assert(run.output_port("OUT").error?)
124
257
  end
125
258
  end
126
259
  end