ruote-jig 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/LICENSE.txt +22 -0
- data/README.rdoc +79 -0
- data/Rakefile +17 -0
- data/VERSION +1 -0
- data/example.rb +30 -0
- data/lib/ruote/jig/part/jig_participant.rb +204 -0
- data/ruote-jig.gemspec +57 -0
- data/test/test.rb +4 -0
- data/test/ut_0.rb +97 -0
- metadata +88 -0
data/.gitignore
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
Copyright (c) 2001-2009, Torsten Schönebaum (http://github.com/tosch/),
|
3
|
+
Planquadrat Software-Integration GmbH
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
22
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
= ruote-jig
|
2
|
+
|
3
|
+
Ruote 2.0 participant which does a HTTP call using rufus-jig
|
4
|
+
(http://rufus.rubyforge.org/rufus-jig/), a HTTP client, greedy with JSON
|
5
|
+
content.
|
6
|
+
|
7
|
+
By default, it POSTs received workitems as JSON to a HTTP server and stores the
|
8
|
+
answer back into the workitem. If the answer is in JSON, it is automatically
|
9
|
+
converted into Ruby data types (this magic is thanks to rufus-jig).
|
10
|
+
|
11
|
+
The handling of outgoing and incoming data may be customized by Procs.
|
12
|
+
|
13
|
+
== usage
|
14
|
+
|
15
|
+
require 'yajl' # by default, you will need some JSON lib (yajl-ruby or json_pure or ActiveSupport)
|
16
|
+
|
17
|
+
# require this lib
|
18
|
+
require 'ruote/jig/part/jig_participant'
|
19
|
+
|
20
|
+
# let's assume you have a ruote engine in '''engine'''
|
21
|
+
engine.register_participant :jig_default, Ruote::Jig::JigParticipant
|
22
|
+
engine.register_participant :jig_advanced, Ruote::Jig::JigParticipant.new(
|
23
|
+
:host => 'somehost',
|
24
|
+
:port => 80,
|
25
|
+
:path => '/path/to/the/magic',
|
26
|
+
:method => :post,
|
27
|
+
:content_type => 'foo/bar',
|
28
|
+
:data_preparition => Proc.new {|workitem| workitem.fields['foo_bar'].to_s},
|
29
|
+
:response_handling => Proc.new do |response, workitem|
|
30
|
+
workitem.set_field('incoming_foo_bar', FooBar.from_str(response.body))
|
31
|
+
end
|
32
|
+
)
|
33
|
+
|
34
|
+
# in a workflow definition...
|
35
|
+
participant :ref => 'jig_default' # will POST the current workitem as JSON
|
36
|
+
# to http://127.0.0.1:3000/ and save the
|
37
|
+
# responded data in the workitem field
|
38
|
+
# \_\_jig_response__
|
39
|
+
|
40
|
+
participant :ref => 'jig_advanced', # will PUT the the string returned by
|
41
|
+
:host => 'anotherhost', # workitem.fields['foo_bar'].to_s to
|
42
|
+
:path => '/path/to/bar', # http://anotherhost:80/path/to/bar,
|
43
|
+
:method => :put # processes the response body and
|
44
|
+
# saves the result in the workitem
|
45
|
+
# field 'incoming_foo_bar'
|
46
|
+
|
47
|
+
== running tests
|
48
|
+
|
49
|
+
to run unit tests
|
50
|
+
|
51
|
+
ruby test/test.rb
|
52
|
+
|
53
|
+
fakeweb and yajl-ruby have to be installed.
|
54
|
+
|
55
|
+
|
56
|
+
== license
|
57
|
+
|
58
|
+
MIT
|
59
|
+
|
60
|
+
|
61
|
+
== links
|
62
|
+
|
63
|
+
* http://github.com/tosch/ruote-jig
|
64
|
+
* http://rufus.rubyforge.org/rufus-jig/
|
65
|
+
* http://ruote.rubyforge.org/
|
66
|
+
|
67
|
+
|
68
|
+
== feedback
|
69
|
+
|
70
|
+
mailing list:: http://groups.google.com/group/openwferu-users
|
71
|
+
irc:: irc.freenode.net \#ruote
|
72
|
+
|
73
|
+
== credits
|
74
|
+
|
75
|
+
* Torsten Schönebaum, Planquadrat Software-Integration GmbH (http://github.com/tosch)
|
76
|
+
|
77
|
+
Many thanks to John Mettraux (http://jmettraux.wordpress.com) for his tireless
|
78
|
+
work on Ruote and the many rufus libs. Thanks to Kenneth Kalmer
|
79
|
+
(http://github.com/kennethkalmer) for his work on rufus-jig.
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gemspec|
|
4
|
+
gemspec.name = "ruote-jig"
|
5
|
+
gemspec.summary = "Ruote participant using rufus-jig"
|
6
|
+
gemspec.description = "A ruote 2.0 participant implementation using rufus-jig to notify HTTP interfaces (mostly JSON-aware) about workitems."
|
7
|
+
gemspec.email = "torsten.schoenebaum@planquadrat-software.de"
|
8
|
+
gemspec.homepage = "http://github.com/tosch/ruote-jig"
|
9
|
+
gemspec.authors = ["Torsten Schönebaum"]
|
10
|
+
gemspec.add_dependency('ruote', '>= 2.0.0')
|
11
|
+
gemspec.add_dependency('rufus-jig', '>= 0.1.2')
|
12
|
+
gemspec.rdoc_options << '--line-numbers' << '--main' << 'README.rdoc'
|
13
|
+
end
|
14
|
+
Jeweler::GemcutterTasks.new
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler not available. Install it with: sudo gem install jeweler"
|
17
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/example.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
require 'ruote/engine' # gem install ruote
|
4
|
+
require 'ruote/log/logger'
|
5
|
+
|
6
|
+
require 'patron' # gem install patron
|
7
|
+
require 'yajl' # gem install yajl-ruby
|
8
|
+
|
9
|
+
require 'lib/ruote/jig/part/jig_participant'
|
10
|
+
|
11
|
+
|
12
|
+
e = Ruote::Engine.new
|
13
|
+
|
14
|
+
# e.register_listener Ruote::Logger.new, :name => :s_logger # uncomment to have some debug output
|
15
|
+
|
16
|
+
e.register_participant :jig, Ruote::Jig::JigParticipant
|
17
|
+
e.register_participant :put_fields do |wi|
|
18
|
+
puts wi.fields.inspect
|
19
|
+
end
|
20
|
+
|
21
|
+
pdef = Ruote.process_definition :name => 'test' do
|
22
|
+
sequence do
|
23
|
+
jig :path => '/my/index', :method => :post
|
24
|
+
put_fields
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
wfid = e.launch(pdef)
|
29
|
+
|
30
|
+
e.wait_for(wfid)
|
@@ -0,0 +1,204 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2009, Torsten Schönebaum (http://github.com/tosch/)
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
#
|
22
|
+
# Made in Europe.
|
23
|
+
#++
|
24
|
+
|
25
|
+
require 'rufus/jig' # gem install rufus-jig
|
26
|
+
|
27
|
+
require 'ruote/engine/context' # gem install ruote
|
28
|
+
require 'ruote/part/local_participant' # gem install ruote
|
29
|
+
|
30
|
+
module Ruote #:nodoc:
|
31
|
+
module Jig #:nodoc:
|
32
|
+
#
|
33
|
+
# Ruote 2.0 participant which does a HTTP call using rufus-jig
|
34
|
+
# (http://rufus.rubyforge.org/rufus-jig/), a HTTP client, greedy with JSON
|
35
|
+
# content.
|
36
|
+
#
|
37
|
+
# By default, it POSTs received workitems as JSON to a HTTP server and
|
38
|
+
# stores the answer back into the workitem. If the answer is in JSON, it is
|
39
|
+
# automatically converted into Ruby data types (this magic is thanks to
|
40
|
+
# rufus-jig).
|
41
|
+
#
|
42
|
+
# The handling of outgoing and incoming data may be customized by Procs.
|
43
|
+
#
|
44
|
+
# == Using it
|
45
|
+
# require 'yajl' # by default, you will need some JSON lib (yajl-ruby or json_pure or ActiveSupport)
|
46
|
+
#
|
47
|
+
# # require this lib
|
48
|
+
# require 'ruote/jig/part/jig_participant'
|
49
|
+
#
|
50
|
+
# # let's assume you have a ruote engine in '''engine'''
|
51
|
+
# engine.register_participant :jig_default, Ruote::Jig::JigParticipant
|
52
|
+
# engine.register_participant :jig_advanced, Ruote::Jig::JigParticipant.new(
|
53
|
+
# :host => 'somehost',
|
54
|
+
# :port => 80,
|
55
|
+
# :path => '/path/to/the/magic',
|
56
|
+
# :method => :post,
|
57
|
+
# :content_type => 'foo/bar',
|
58
|
+
# :data_preparition => Proc.new {|workitem| workitem.fields['foo_bar'].to_s},
|
59
|
+
# :response_handling => Proc.new do |response, workitem|
|
60
|
+
# workitem.set_field('incoming_foo_bar', FooBar.from_str(response.body))
|
61
|
+
# end
|
62
|
+
# )
|
63
|
+
#
|
64
|
+
# # in a workflow definition...
|
65
|
+
# participant :ref => 'jig_default' # will POST the current workitem as JSON
|
66
|
+
# # to http://127.0.0.1:3000/ and save the
|
67
|
+
# # responded data in the workitem field
|
68
|
+
# # __jig_response__
|
69
|
+
#
|
70
|
+
# participant :ref => 'jig_advanced', # will PUT the the string returned by
|
71
|
+
# :host => 'anotherhost', # workitem.fields['foo_bar'].to_s to
|
72
|
+
# :path => '/path/to/bar', # http://anotherhost:80/path/to/bar,
|
73
|
+
# :method => :put # processes the response body and
|
74
|
+
# # saves the result in the workitem
|
75
|
+
# # field 'incoming_foo_bar'
|
76
|
+
#
|
77
|
+
# == Getting help
|
78
|
+
# * http://groups.google.com/group/openwferu-users
|
79
|
+
# * irc.freenode.net #ruote
|
80
|
+
#
|
81
|
+
# == Issue tracker
|
82
|
+
# http://github.com/tosch/ruote-jig/issues
|
83
|
+
#
|
84
|
+
class JigParticipant
|
85
|
+
include Ruote::EngineContext
|
86
|
+
include Ruote::LocalParticipant
|
87
|
+
|
88
|
+
#
|
89
|
+
# ==options hash
|
90
|
+
# :host <String>:: The host to connect to (defaults to 127.0.0.1)
|
91
|
+
# :port <Fixnum>:: ...and its port (defaults to 3000)
|
92
|
+
# :path <String>:: The path part of the URL. Defaults to '/'.
|
93
|
+
# :method <Symbol>:: Which HTTP method shall be used? One of :get, :post, :put and :delete.
|
94
|
+
# :options_for_jig <Hash>:: Hash of options which will be passed to Rufus::Jig::Http.new.
|
95
|
+
# :options_for_jig_requests <Hash>:: Hash of options which will be passed to the get, put, post or delete method of Rufus::Jig::Http
|
96
|
+
# :response_handling <Proc>:: An optional Proc which handles the results Rufus::Jig::Http returns. Takes the results and the workitem as arguments. By default (when no Proc is given), the server's response is stored in the workitem field \_\_jig_response__ and the HTTP status code in \_\_jig_status__.
|
97
|
+
# :data_preparition <Proc>:: An optional Proc which prepares the data being sent with POST or PUT requests. Takes the workitem as argument. Should return a string or another type Rufus::Jig::Http can handle. By default (if no Proc is given), the workitem will be converted into a Hash (and then into a JSON string by rufus-jig).
|
98
|
+
# :content_type <String or Symbol>:: The content type to use for the HTTP request. Defaults to :json. Other types has to be submitted as strings. Note that you really should provide a :data_preparition-Proc if you don't use JSON!
|
99
|
+
#
|
100
|
+
# All options may be overridden by params when calling the participant in
|
101
|
+
# a workflow definition.
|
102
|
+
#
|
103
|
+
def initialize(options = {})
|
104
|
+
@options = options
|
105
|
+
|
106
|
+
# some defaults
|
107
|
+
@options[:host] ||= '127.0.0.1'
|
108
|
+
@options[:port] ||= 3000
|
109
|
+
@options[:method] ||= :post
|
110
|
+
@options[:path] ||= '/'
|
111
|
+
@options[:content_type] ||= :json
|
112
|
+
|
113
|
+
@http = Rufus::Jig::Http.new @options[:host], @options[:port], @options[:options_for_jig] || {}
|
114
|
+
end
|
115
|
+
|
116
|
+
#
|
117
|
+
# This is where the work is done...
|
118
|
+
#
|
119
|
+
# The engine calls this method and passes it a workitem as argument. The
|
120
|
+
# HTTP request will be processed and the workitem will be returned to the
|
121
|
+
# engine immediately after that.
|
122
|
+
#
|
123
|
+
def consume workitem
|
124
|
+
# do we need a new instance of the http client?
|
125
|
+
http = if(@http.host == param(workitem, :host) and @http.port == param(workitem, :port))
|
126
|
+
@http
|
127
|
+
else
|
128
|
+
Rufus::Jig::Http.new param(workitem, :host), param(workitem, :port), @options[:options_for_jig] || {}
|
129
|
+
end
|
130
|
+
|
131
|
+
# fire the request...
|
132
|
+
response = case param(workitem, :method).to_sym
|
133
|
+
when :get
|
134
|
+
http.get param(workitem, :path), prepare_request_options(workitem)
|
135
|
+
when :post
|
136
|
+
http.post param(workitem, :path), prepare_data(workitem), prepare_request_options(workitem)
|
137
|
+
when :put
|
138
|
+
http.put param(workitem, :path), prepare_data(workitem), prepare_request_options(workitem)
|
139
|
+
when :delete
|
140
|
+
http.delete param(workitem, :path), prepare_request_options(workitem)
|
141
|
+
else
|
142
|
+
raise "Method #{param(workitem, :method).to_s} not supported"
|
143
|
+
end
|
144
|
+
|
145
|
+
# ... and handle the response
|
146
|
+
if (block = param(workitem, :response_handling)).is_a?(Proc)
|
147
|
+
# there is a proc which does the response handling for us
|
148
|
+
block.call(response, workitem)
|
149
|
+
else
|
150
|
+
# we'll have to do the handling by ourselves
|
151
|
+
case response
|
152
|
+
when Rufus::Jig::HttpResponse
|
153
|
+
workitem.set_field '__jig_response__', response.body
|
154
|
+
workitem.set_field '__jig_status__', response.status
|
155
|
+
else
|
156
|
+
workitem.set_field '__jig_response__', response
|
157
|
+
workitem.set_field '__jig_status__', http.last_response.status
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
# reply the workitem to the engine
|
162
|
+
reply_to_engine(workitem)
|
163
|
+
end
|
164
|
+
|
165
|
+
# For now, does nothing.
|
166
|
+
# Could stop a running consume method some day?
|
167
|
+
def cancel
|
168
|
+
end
|
169
|
+
|
170
|
+
protected
|
171
|
+
|
172
|
+
#
|
173
|
+
# extract parameter from params field of workitem or use default from
|
174
|
+
# options hash
|
175
|
+
#
|
176
|
+
def param workitem, key
|
177
|
+
workitem.fields['params'][key.to_s] || @options[key]
|
178
|
+
end
|
179
|
+
|
180
|
+
#
|
181
|
+
# Prepare the data for post and put requests. Returns the workitem as
|
182
|
+
# hash by default or the results of the executed Proc given in the options
|
183
|
+
# as :data_preparition.
|
184
|
+
#
|
185
|
+
def prepare_data workitem
|
186
|
+
if((block = param(workitem, :data_preparition)).is_a?(Proc))
|
187
|
+
block.call workitem
|
188
|
+
else
|
189
|
+
workitem.to_h
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
#
|
194
|
+
# Prepare the request options to be submitted to rufus-jig.
|
195
|
+
#
|
196
|
+
def prepare_request_options workitem
|
197
|
+
{
|
198
|
+
:content_type => param(workitem, :content_type),
|
199
|
+
:params => param(workitem, :params) || nil
|
200
|
+
}.merge(param(workitem, :options_for_jig_request) || {})
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
data/ruote-jig.gemspec
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{ruote-jig}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Torsten Sch\303\266nebaum"]
|
12
|
+
s.date = %q{2009-12-08}
|
13
|
+
s.description = %q{A ruote 2.0 participant implementation using rufus-jig to notify HTTP interfaces (mostly JSON-aware) about workitems.}
|
14
|
+
s.email = %q{torsten.schoenebaum@planquadrat-software.de}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".gitignore",
|
21
|
+
"LICENSE.txt",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"example.rb",
|
26
|
+
"lib/ruote/jig/part/jig_participant.rb",
|
27
|
+
"ruote-jig.gemspec",
|
28
|
+
"test/test.rb",
|
29
|
+
"test/ut_0.rb"
|
30
|
+
]
|
31
|
+
s.homepage = %q{http://github.com/tosch/ruote-jig}
|
32
|
+
s.rdoc_options = ["--charset=UTF-8", "--line-numbers", "--main", "README.rdoc"]
|
33
|
+
s.require_paths = ["lib"]
|
34
|
+
s.rubygems_version = %q{1.3.5}
|
35
|
+
s.summary = %q{Ruote participant using rufus-jig}
|
36
|
+
s.test_files = [
|
37
|
+
"test/test.rb",
|
38
|
+
"test/ut_0.rb"
|
39
|
+
]
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
46
|
+
s.add_runtime_dependency(%q<ruote>, [">= 2.0.0"])
|
47
|
+
s.add_runtime_dependency(%q<rufus-jig>, [">= 0.1.2"])
|
48
|
+
else
|
49
|
+
s.add_dependency(%q<ruote>, [">= 2.0.0"])
|
50
|
+
s.add_dependency(%q<rufus-jig>, [">= 0.1.2"])
|
51
|
+
end
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<ruote>, [">= 2.0.0"])
|
54
|
+
s.add_dependency(%q<rufus-jig>, [">= 0.1.2"])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
data/test/test.rb
ADDED
data/test/ut_0.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
class JigParticipantTests < Test::Unit::TestCase
|
2
|
+
def setup
|
3
|
+
require 'fakeweb' # gem install fakeweg
|
4
|
+
require 'yajl' # gem install yaijl-ruby
|
5
|
+
require 'lib/ruote/jig/part/jig_participant'
|
6
|
+
require 'rufus/jig/json'
|
7
|
+
|
8
|
+
@engine = Engine.new
|
9
|
+
@jig_participant = new_jig_participant()
|
10
|
+
@test_hash = {'test' => {'foo' => 'bar', 'dash' => 'buzz'}}
|
11
|
+
@test_hash_json = Rufus::Jig::Json.encode(@test_hash)
|
12
|
+
end
|
13
|
+
|
14
|
+
# test if the default options are treated ok
|
15
|
+
def test_defaults
|
16
|
+
FakeWeb.register_uri(:post, "http://127.0.0.1:3000/", :body => @test_hash_json, :content_type => 'application/json')
|
17
|
+
@jig_participant.consume(wi = new_workitem) # ('params' => {'host' => 'localhost', 'port' => 3000, 'path' => '/'}))
|
18
|
+
assert_equal(wi, @engine.workitem)
|
19
|
+
assert_equal(@test_hash, @engine.workitem.fields['__jig_response__'])
|
20
|
+
assert_equal(200, @engine.workitem.fields['__jig_status__'])
|
21
|
+
end
|
22
|
+
|
23
|
+
# test if the default options are overridden when others are passed at initialization time
|
24
|
+
def test_initialization_options
|
25
|
+
FakeWeb.register_uri(:get, 'http://foo:123/bar', :body => 'this is just a test', :content_type => 'text/plain')
|
26
|
+
jp = new_jig_participant(:host => 'foo', :port => 123, :path => 'bar', :method => :get, :content_type => 'text/plain')
|
27
|
+
jp.consume(new_workitem)
|
28
|
+
assert_equal('this is just a test', @engine.workitem.fields['__jig_response__'])
|
29
|
+
end
|
30
|
+
|
31
|
+
# test if the options from the params field of the workitem are used above the defaults
|
32
|
+
def test_params
|
33
|
+
FakeWeb.register_uri(:post, 'http://127.100.100.100:80/baz', :body => @test_hash_json, :content_type => 'application/json')
|
34
|
+
@jig_participant.consume(new_workitem('params' => {'host' => '127.100.100.100', 'port' => 80, 'path' => '/baz'}))
|
35
|
+
assert_equal(@test_hash, @engine.workitem.fields['__jig_response__'])
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_data_preparition
|
39
|
+
jp = new_jig_participant(
|
40
|
+
:content_type => 'text/plain',
|
41
|
+
:data_preparition => Proc.new { |workitem| workitem.fields['my_data'] }
|
42
|
+
)
|
43
|
+
# overwrite Rufus::Jig::Http#do_post
|
44
|
+
http = jp.instance_variable_get(:@http)
|
45
|
+
def http.do_post(path, data, opts)
|
46
|
+
r = {:status => 200, :body => data.reverse, :headers => {'Content-Type' => opts['Content-Type']}}
|
47
|
+
def r.method_missing sym
|
48
|
+
self[sym]
|
49
|
+
end
|
50
|
+
r
|
51
|
+
end
|
52
|
+
jp.consume(new_workitem('my_data' => '1234567890'))
|
53
|
+
assert_equal('0987654321', @engine.workitem.fields['__jig_response__'])
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_response_handling
|
57
|
+
FakeWeb.register_uri(:post, "http://127.0.0.1:3000/", :body => '1234567890', :content_type => 'text/plain')
|
58
|
+
jp = new_jig_participant(
|
59
|
+
:content_type => 'text/plain',
|
60
|
+
:response_handling => Proc.new {|response, workitem| workitem.set_field('my_result', response.reverse)}
|
61
|
+
)
|
62
|
+
jp.consume(new_workitem)
|
63
|
+
assert_equal('0987654321', @engine.workitem.fields['my_result'])
|
64
|
+
end
|
65
|
+
|
66
|
+
protected
|
67
|
+
|
68
|
+
class Engine
|
69
|
+
attr_accessor :workitem
|
70
|
+
def reply (wi)
|
71
|
+
@workitem = wi
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def new_jig_participant(opts = {})
|
76
|
+
jp = Ruote::Jig::JigParticipant.new opts
|
77
|
+
jp.instance_variable_set(:@engine, @engine)
|
78
|
+
def jp.engine
|
79
|
+
@engine
|
80
|
+
end
|
81
|
+
jp
|
82
|
+
end
|
83
|
+
|
84
|
+
def new_workitem(fields = {})
|
85
|
+
wi = {'params' => {}}.merge(fields)
|
86
|
+
def wi.fields
|
87
|
+
self
|
88
|
+
end
|
89
|
+
def wi.to_h
|
90
|
+
self
|
91
|
+
end
|
92
|
+
def wi.set_field(k, v)
|
93
|
+
self[k] = v
|
94
|
+
end
|
95
|
+
wi
|
96
|
+
end
|
97
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruote-jig
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "Torsten Sch\xC3\xB6nebaum"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-08 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: ruote
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.0.0
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rufus-jig
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.2
|
34
|
+
version:
|
35
|
+
description: A ruote 2.0 participant implementation using rufus-jig to notify HTTP interfaces (mostly JSON-aware) about workitems.
|
36
|
+
email: torsten.schoenebaum@planquadrat-software.de
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE.txt
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- .gitignore
|
46
|
+
- LICENSE.txt
|
47
|
+
- README.rdoc
|
48
|
+
- Rakefile
|
49
|
+
- VERSION
|
50
|
+
- example.rb
|
51
|
+
- lib/ruote/jig/part/jig_participant.rb
|
52
|
+
- ruote-jig.gemspec
|
53
|
+
- test/test.rb
|
54
|
+
- test/ut_0.rb
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://github.com/tosch/ruote-jig
|
57
|
+
licenses: []
|
58
|
+
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options:
|
61
|
+
- --charset=UTF-8
|
62
|
+
- --line-numbers
|
63
|
+
- --main
|
64
|
+
- README.rdoc
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: "0"
|
72
|
+
version:
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
version:
|
79
|
+
requirements: []
|
80
|
+
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.3.5
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: Ruote participant using rufus-jig
|
86
|
+
test_files:
|
87
|
+
- test/test.rb
|
88
|
+
- test/ut_0.rb
|