Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: globaldev/integrate
base: 541f38d80b
...
head fork: globaldev/integrate
compare: d3cf92ec45
  • 20 commits
  • 29 files changed
  • 0 commit comments
  • 3 contributors
Showing with 463 additions and 137 deletions.
  1. +0 −13 example/amqp_printer.rb
  2. +0 −14 example/amqp_sender.rb
  3. +0 −26 example/stdio.rb
  4. +13 −0 examples/amqp_printer.rb
  5. +14 −0 examples/amqp_sender.rb
  6. +26 −0 examples/stdio.rb
  7. +0 −1  lib/integrate.rb
  8. +24 −0 lib/integrate/abstract_component.rb
  9. +5 −2 lib/integrate/{handler.rb → abstract_handler.rb}
  10. +5 −5 lib/integrate/{adaptor → adapters}/inbound/amqp.rb
  11. +4 −4 lib/integrate/{adaptor → adapters}/inbound/io.rb
  12. +6 −6 lib/integrate/{adaptor → adapters}/outbound/amqp.rb
  13. +5 −5 lib/integrate/{adaptor → adapters}/outbound/io.rb
  14. +9 −7 lib/integrate/channel.rb
  15. +2 −2 lib/integrate/dispatcher.rb
  16. +0 −16 lib/integrate/handlers/block_transformer.rb
  17. +34 −0 lib/integrate/handlers/filter.rb
  18. +37 −0 lib/integrate/handlers/header_enricher.rb
  19. +31 −0 lib/integrate/handlers/splitter.rb
  20. +25 −2 lib/integrate/handlers/transformer.rb
  21. +4 −0 test/helper.rb
  22. +30 −0 test/integrate/abstract_component_test.rb
  23. +8 −8 test/integrate/{handler_test.rb → abstract_handler_test.rb}
  24. +11 −9 test/integrate/channel_test.rb
  25. +15 −13 test/integrate/dispatcher_test.rb
  26. +34 −0 test/integrate/handlers/filter_test.rb
  27. +59 −0 test/integrate/handlers/header_enricher_test.rb
  28. +39 −0 test/integrate/handlers/splitter_test.rb
  29. +23 −4 test/integrate/handlers/transformer_test.rb
View
13 example/amqp_printer.rb
@@ -1,13 +0,0 @@
-require_relative "../lib/integrate/adaptor/inbound/amqp"
-require_relative "../lib/integrate/adaptor/outbound/io"
-require_relative "../lib/integrate/channel"
-
-include Integrate
-
-received = Channel.new
-
-inbound_adaptor = Adaptor::Inbound::AMQP.new(out: received,
- queue: "testqueue")
-outbound_adaptor = Adaptor::Outbound::IO.new(STDOUT, in: received)
-
-inbound_adaptor.start
View
14 example/amqp_sender.rb
@@ -1,14 +0,0 @@
-require_relative "../lib/integrate/adaptor/outbound/amqp"
-require_relative "../lib/integrate/adaptor/inbound/io"
-require_relative "../lib/integrate/channel"
-
-include Integrate
-
-received = Channel.new
-
-stdin = Adaptor::Inbound::IO.new(STDIN, out: received)
-
-outbound_adaptor = Adaptor::Outbound::AMQP.new(in: received,
- exchange: "",
- key: "testqueue")
-stdin.start
View
26 example/stdio.rb
@@ -1,26 +0,0 @@
-require_relative "../lib/integrate/adaptor/inbound/io"
-require_relative "../lib/integrate/adaptor/outbound/io"
-require_relative "../lib/integrate/handlers/block_transformer"
-require_relative "../lib/integrate/channel"
-
-include Integrate
-
-inbound = Channel.new
-connecting = Channel.new
-outbound = Channel.new
-
-stdin = Adaptor::Inbound::IO.new(STDIN, out: inbound)
-
-upcaser = BlockTransformer.new(in: inbound, out: connecting) do |message|
- message["payload"] = message["payload"].upcase
- message
-end
-
-reverser = BlockTransformer.new(in: connecting, out: outbound) do |message|
- message["payload"] = message["payload"].reverse
- message
-end
-
-stdout = Adaptor::Outbound::IO.new(STDOUT, in: outbound)
-
-stdin.start
View
13 examples/amqp_printer.rb
@@ -0,0 +1,13 @@
+require_relative "../lib/integrate/adapters/inbound/amqp"
+require_relative "../lib/integrate/adapters/outbound/io"
+require_relative "../lib/integrate/channel"
+
+include Integrate
+
+received = Channel.new(id: "stdin_received")
+
+inbound_adaptor = Adapters::Inbound::AMQP.new(out: received,
+ queue: "testqueue")
+outbound_adaptor = Adapters::Outbound::IO.new(STDOUT, in: received)
+
+inbound_adaptor.start
View
14 examples/amqp_sender.rb
@@ -0,0 +1,14 @@
+require_relative "../lib/integrate/adapters/outbound/amqp"
+require_relative "../lib/integrate/adapters/inbound/io"
+require_relative "../lib/integrate/channel"
+
+include Integrate
+
+received = Channel.new(id: "amqp_received")
+
+stdin = Adapters::Inbound::IO.new(STDIN, out: received)
+
+outbound_adaptor = Adapters::Outbound::AMQP.new(in: received,
+ exchange: "",
+ key: "testqueue")
+stdin.start
View
26 examples/stdio.rb
@@ -0,0 +1,26 @@
+require_relative "../lib/integrate/adapters/inbound/io"
+require_relative "../lib/integrate/adapters/outbound/io"
+require_relative "../lib/integrate/handlers/transformer"
+require_relative "../lib/integrate/channel"
+
+include Integrate
+
+inbound = Channel.new(id: "from_stdin")
+connecting = Channel.new(id: "connecting")
+outbound = Channel.new(id: "to_stdout")
+
+stdin = Adapters::Inbound::IO.new(STDIN, out: inbound)
+
+upcaser = Transformer.new(id: "upcaser", in: inbound, out: connecting) do |message|
+ message["payload"] = message["payload"].upcase
+ message
+end
+
+reverser = Transformer.new(id: "reverser", in: connecting, out: outbound) do |message|
+ message["payload"] = message["payload"].reverse
+ message
+end
+
+stdout = Adapters::Outbound::IO.new(STDOUT, in: outbound)
+
+stdin.start
View
1  lib/integrate.rb
@@ -1,4 +1,3 @@
-
module Integrate
# Your code goes here...
end
View
24 lib/integrate/abstract_component.rb
@@ -0,0 +1,24 @@
+module Integrate
+
+ # An AbstractComponent describes any part of the integration workflow, and
+ # encapsulates attributes common to all components.
+ #
+ class AbstractComponent
+
+ attr_reader :id
+
+ # options should be a hash, with the following available options:
+ # [:id] the component id
+ #
+ def initialize(options={})
+ @id = options[:id] || self.class.generate_id
+ end
+
+ def self.generate_id
+ @counter ||= -1
+ @counter += 1
+ "#{name}-#{@counter}"
+ end
+
+ end
+end
View
7 lib/integrate/handler.rb → lib/integrate/abstract_handler.rb
@@ -1,5 +1,7 @@
+require 'integrate/abstract_component'
+
module Integrate
- class Handler
+ class AbstractHandler < AbstractComponent
attr_reader :output_channel
private :output_channel
@@ -9,8 +11,9 @@ class Handler
# [:out] the output channel
#
def initialize(options)
+ super(options)
@output_channel = options[:out]
- options[:in].subscribe(self)
+ options[:in].register(self)
end
def call(message)
View
10 lib/integrate/adaptor/inbound/amqp.rb → lib/integrate/adapters/inbound/amqp.rb
@@ -1,10 +1,10 @@
require 'bunny'
module Integrate
- module Adaptor
+ module Adapters
module Inbound
class AMQP
-
+
# options should be a hash, with the following available options:
# [:out] (required) the output channel
# [:queue] (required) the AMQP queue to subscribe to
@@ -14,7 +14,7 @@ def initialize(options)
@queue_name = options[:queue]
@client = Bunny.new
end
-
+
def start
@client.start
queue = @client.queue(@queue_name)
@@ -24,8 +24,8 @@ def start
@output_channel.send(message)
end
end
-
+
end
end
end
-end
+end
View
8 lib/integrate/adaptor/inbound/io.rb → lib/integrate/adapters/inbound/io.rb
@@ -1,8 +1,8 @@
module Integrate
- module Adaptor
+ module Adapters
module Inbound
class IO
-
+
# options should be a hash, with the following available options:
# [:out] (required) the output channel
#
@@ -11,13 +11,13 @@ def initialize(io, separator=$/, options)
@separator = separator
@output_channel = options[:out]
end
-
+
def start
while line = @io.gets(@separator)
@output_channel.send({"payload" => line.chomp(@separator)})
end
end
-
+
end
end
end
View
12 lib/integrate/adaptor/outbound/amqp.rb → lib/integrate/adapters/outbound/amqp.rb
@@ -1,34 +1,34 @@
require 'bunny'
module Integrate
- module Adaptor
+ module Adapters
module Outbound
class AMQP
-
+
# options should be a hash, with the following available options:
# [:in] (required) the input channel
# [:exchange] the exchange to which messages will be published
# [:key] (required) the routing key for published messages
#
def initialize(options)
- options[:in].subscribe(self)
+ options[:in].register(self)
@exchange_name = options[:exchange] || ""
@routing_key = options[:key]
@client = Bunny.new
end
-
+
def call(message)
output = message["payload"].to_s
exchange.publish(output, key: @routing_key,
content_type: message["content_type"])
end
-
+
def exchange
return @exchange if @exchange
@client.start
@exchange = @client.exchange(@exchange_name)
end
-
+
end
end
end
View
10 lib/integrate/adaptor/outbound/io.rb → lib/integrate/adapters/outbound/io.rb
@@ -1,23 +1,23 @@
module Integrate
- module Adaptor
+ module Adapters
module Outbound
class IO
-
+
# options should be a hash, with the following available options:
# [:in] (required) the input channel
#
def initialize(io, separator=$/, options)
@io = io
@separator = separator
- options[:in].subscribe(self)
+ options[:in].register(self)
end
-
+
def call(message)
output = message["payload"].to_s
output += @separator if @separator
@io.write(output)
end
-
+
end
end
end
View
16 lib/integrate/channel.rb
@@ -1,21 +1,23 @@
-require_relative 'dispatcher'
+require 'integrate/abstract_component'
+require 'integrate/dispatcher'
module Integrate
- class Channel
+ class Channel < AbstractComponent
attr_reader :dispatcher
- def initialize
+ def initialize(options={})
+ super(options)
@dispatcher = Dispatcher.new
end
- def subscribe(message_handler)
- dispatcher.register_handler(message_handler)
+ def register(handler)
+ dispatcher.register(handler)
# TODO Log handler registration with count.
end
- def unsubscribe(message_handler)
- dispatcher.unregister_handler(message_handler)
+ def unregister(handler)
+ dispatcher.unregister(handler)
end
def send(message)
View
4 lib/integrate/dispatcher.rb
@@ -12,11 +12,11 @@ def handlers
@handlers.dup
end
- def register_handler(handler)
+ def register(handler)
@handlers.add(handler)
end
- def unregister_handler(handler)
+ def unregister(handler)
@handlers.delete(handler)
end
View
16 lib/integrate/handlers/block_transformer.rb
@@ -1,16 +0,0 @@
-require_relative 'transformer'
-
-module Integrate
- class BlockTransformer < Transformer
-
- def initialize(*args, &block)
- @block = block.nil? && args.last.respond_to?(:call) ? args.pop : block
- super(*args)
- end
-
- def transform(message)
- @block.call(message.dup)
- end
-
- end
-end
View
34 lib/integrate/handlers/filter.rb
@@ -0,0 +1,34 @@
+require 'integrate/abstract_handler'
+
+module Integrate
+
+ # A filter is a message handler that conditionally passes, or not, the
+ # message on to the next stage of the workflow.
+ #
+ # The Filter class is available as a superclass for any kind of filter,
+ # simply subclass and override the #allow? method.
+ #
+ # Filter may be used without subclassing by supplying a block to ::new,
+ # the block will then be invoked to perform the message filtering.
+ #
+ class Filter < AbstractHandler
+
+ # options should be a hash, with the following available options:
+ # [:in] (required) the input channel
+ # [:out] the output channel
+ #
+ def initialize(options, &block)
+ super
+ @block = block if block
+ end
+
+ def call(message)
+ super if allow?(message)
+ end
+
+ def allow?(message)
+ @block.call(message) if @block
+ end
+
+ end
+end
View
37 lib/integrate/handlers/header_enricher.rb
@@ -0,0 +1,37 @@
+require_relative 'transformer'
+
+module Integrate
+
+ # A Header Enricher is used to add headers to a Message.
+ #
+ # The HeaderEnricher class is available as a superclass when header values
+ # must be resolved dynamically based upon message content; simply subclass
+ # and override the #transform method.
+ #
+ # When headers need not be resolved dynamically, a Hash of static headers and
+ # values may be supplied to HeaderEnricher.
+ #
+ class HeaderEnricher < Transformer
+
+ def initialize(options)
+ check_options(options)
+ super(options)
+ @headers = options[:headers]
+ @overwrite = options[:overwrite] || false
+ end
+
+ def check_options(options)
+ raise ArgumentError, "HeaderEnricher must be provided :headers" unless options[:headers]
+ raise ArgumentError, "HeaderEnricher is unable to enrich payload" if options[:headers]["payload"]
+ end
+
+ def transform(message)
+ result = message.dup
+ @headers.each do |header, val|
+ result[header] = val unless result[header] && !@overwrite
+ end
+ result
+ end
+
+ end
+end
View
31 lib/integrate/handlers/splitter.rb
@@ -0,0 +1,31 @@
+require 'integrate/abstract_handler'
+
+module Integrate
+
+ # A splitter is a message handler that generates multiple downstream messages
+ # from a single input message.
+ #
+ # The Splitter class is available as a superclass for any kind of splitter,
+ # simply subclass and override the #split method.
+ #
+ # Splitter may be used without subclassing by supplying a block to ::new,
+ # the block will then be invoked to perform the message splitting.
+ #
+ class Splitter < AbstractHandler
+
+ def initialize(options, &block)
+ super
+ @block = block if block
+ end
+
+ def call(message)
+ split.each { super(message) }
+ end
+
+ # Returns an Array of messages
+ def split(message)
+ @block.call(message) if @block
+ end
+
+ end
+end
View
27 lib/integrate/handlers/transformer.rb
@@ -1,12 +1,35 @@
-require_relative '../handler'
+require 'integrate/abstract_handler'
module Integrate
- class Transformer < Handler
+
+ # A transformer is a message handler that modifies the message it handles.
+ #
+ # The Transformer class is available as a superclass for any kind of
+ # transformer, simply subclass and override the #transform method.
+ #
+ # Transformer may be used without subclassing by supplying a block to ::new,
+ # the block will then be invoked to perform the message transformation.
+ #
+ class Transformer < AbstractHandler
+
+ # options should be a hash, with the following available options:
+ # [:in] (required) the input channel
+ # [:out] (required) the output channel
+ #
+ def initialize(options, &block)
+ raise ArgumentError, "Transformer requires an output channel" unless options[:out]
+ super
+ @block = block if block
+ end
def call(message)
result = transform(message)
super(result)
end
+ def transform(message)
+ @block.call(message.dup)
+ end
+
end
end
View
4 test/helper.rb
@@ -0,0 +1,4 @@
+$:.push File.expand_path('../lib', __FILE__)
+
+require 'minitest/autorun'
+require 'minitest/pride'
View
30 test/integrate/abstract_component_test.rb
@@ -0,0 +1,30 @@
+require_relative '../helper'
+
+require 'integrate/abstract_component'
+
+module Integrate
+ class AbstractComponentTest < MiniTest::Unit::TestCase
+
+ def test_id_generated
+ component = AbstractComponent.new
+
+ refute_nil(component.id)
+ end
+
+ def test_generated_ids_different
+ first = AbstractComponent.new
+ second = AbstractComponent.new
+
+ assert_equal(false, first.id == second.id)
+ end
+
+ def test_subclasses_receive_sensible_name
+ child = SubComponent.new
+
+ assert_equal(true, !child.id.match(/SubComponent/).nil?)
+ end
+
+ class SubComponent < AbstractComponent; end
+
+ end
+end
View
16 test/integrate/handler_test.rb → test/integrate/abstract_handler_test.rb
@@ -1,20 +1,20 @@
-require 'minitest/autorun'
-require_relative '../../lib/integrate/handlers/transformer'
-require_relative '../../lib/integrate/channel'
+require_relative '../helper'
+
+require 'integrate/channel'
+require 'integrate/handlers/transformer'
module Integrate
- class HandlerTest < MiniTest::Unit::TestCase
+ class AbstractHandlerTest < MiniTest::Unit::TestCase
def test_reply_sent_if_output_channel
- incoming_message = {"payload" => "test"}
+ incoming_message = { "payload" => "test" }
output_channel = MiniTest::Mock.new
output_channel.expect :send, true, [incoming_message]
input_channel = Channel.new
- transformer = PayloadUpcasingTransformer.new(in: input_channel, out: output_channel)
-
- input_channel.subscribe(transformer)
+ transformer = PayloadUpcasingTransformer.new(in: input_channel,
+ out: output_channel)
input_channel.send(incoming_message)
View
20 test/integrate/channel_test.rb
@@ -1,6 +1,7 @@
-require 'minitest/autorun'
+require_relative '../helper'
+
require 'set'
-require_relative '../../lib/integrate/channel'
+require 'integrate/channel'
module Integrate
class ChannelTest < MiniTest::Unit::TestCase
@@ -19,38 +20,39 @@ def test_instantiation
refute_nil(@channel)
end
- def test_subscribe
+ def test_register
subscribing_handler = MiniTest::Mock.new
subscribing_handler.expect :hash, 3735928559
dispatcher = @channel.dispatcher
- @channel.subscribe(subscribing_handler)
+ @channel.register(subscribing_handler)
assert_equal(Set[subscribing_handler], dispatcher.handlers)
end
def test_send
- message = {"payload" => "test"}
+ message = { "payload" => "test" }
handler = MiniTest::Mock.new
handler.expect :hash, 3735928559
handler.expect :call, true, [message]
- @channel.subscribe(handler)
+ @channel.register(handler)
@channel.send(message)
handler.verify
end
- def test_unsubscribe
+ def test_unregister
subscribing_handler = MiniTest::Mock.new
subscribing_handler.expect :hash, 3735928559
dispatcher = @channel.dispatcher
- @channel.subscribe(subscribing_handler)
+ @channel.register(subscribing_handler)
assert_equal(Set[subscribing_handler], dispatcher.handlers)
- @channel.unsubscribe(subscribing_handler)
+
+ @channel.unregister(subscribing_handler)
assert_equal(Set[], dispatcher.handlers)
end
end
View
28 test/integrate/dispatcher_test.rb
@@ -1,6 +1,7 @@
-require 'minitest/autorun'
+require_relative '../helper'
+
require 'set'
-require_relative '../../lib/integrate/dispatcher'
+require 'integrate/dispatcher'
module Integrate
class DispatcherTest < MiniTest::Unit::TestCase
@@ -20,23 +21,24 @@ def test_instantiation
end
def test_register_message_handler
- dispatcher = Dispatcher.new
+ dispatcher = Dispatcher.new
dummy_handler = DummyMessageHandler.new
- dispatcher.register_handler(dummy_handler)
+
+ dispatcher.register(dummy_handler)
assert_equal(Set[dummy_handler], dispatcher.handlers)
end
def test_remove_message_handler
- dispatcher = Dispatcher.new
+ dispatcher = Dispatcher.new
handler_one = DummyMessageHandler.new
handler_two = DummyMessageHandler.new
- dispatcher.register_handler(handler_one)
- dispatcher.register_handler(handler_two)
+ dispatcher.register(handler_one)
+ dispatcher.register(handler_two)
assert_equal(Set[handler_one, handler_two], dispatcher.handlers)
- dispatcher.unregister_handler(handler_one)
+ dispatcher.unregister(handler_one)
assert_equal(Set[handler_two], dispatcher.handlers)
end
@@ -46,14 +48,14 @@ def call(message)
end
def test_successful_dispatch
- dispatcher = Dispatcher.new
- test_message = {"payload" => "test"}
+ dispatcher = Dispatcher.new
+ test_message = { "payload" => "test" }
handler_one = MiniTest::Mock.new
handler_one.expect :hash, 3735928559
handler_one.expect :call, true, [test_message]
- dispatcher.register_handler(handler_one)
+ dispatcher.register(handler_one)
assert_equal(true, dispatcher.call(test_message))
@@ -61,8 +63,8 @@ def test_successful_dispatch
end
def test_error_dispatch
- dispatcher = Dispatcher.new
- test_message = {"payload" => "test"}
+ dispatcher = Dispatcher.new
+ test_message = { "payload" => "test" }
assert_raises(StandardError) do
dispatcher.call(test_message)
View
34 test/integrate/handlers/filter_test.rb
@@ -0,0 +1,34 @@
+require_relative '../../helper'
+
+require 'integrate/handlers/filter'
+require 'integrate/channel'
+
+module Integrate
+ class FilterTest < MiniTest::Unit::TestCase
+
+ def test_instantiation
+ filter = Filter.new(in: Channel.new,
+ out: Channel.new)
+
+ refute_nil(filter)
+ end
+
+ def test_instantiation_with_block
+ filter = Filter.new(in: Channel.new,
+ out: Channel.new) {}
+
+ refute_nil(filter)
+ end
+
+ def test_filters_correctly
+ filter = Filter.new(in: Channel.new,
+ out: Channel.new) do |message|
+ message["payload"] == "TesT"
+ end
+
+ assert_equal(true, filter.allow?({"payload" => "TesT"}))
+ assert_equal(false, filter.allow?({"payload" => "test"}))
+ end
+
+ end
+end
View
59 test/integrate/handlers/header_enricher_test.rb
@@ -0,0 +1,59 @@
+require_relative '../../helper'
+
+require 'integrate/handlers/header_enricher'
+require 'integrate/channel'
+
+module Integrate
+ class HeaderEnricherTest < MiniTest::Unit::TestCase
+
+ def enricher(options)
+ HeaderEnricher.new(in: Channel.new,
+ out: Channel.new,
+ headers: options[:headers],
+ overwrite: options[:overwrite])
+ end
+
+ def test_requires_headers
+ assert_raises(ArgumentError) do
+ HeaderEnricher.new(in: Channel.new,
+ out: Channel.new)
+ end
+ end
+
+ def test_rejects_payload_enrichment
+ assert_raises(ArgumentError) do
+ enricher = enricher(headers:{"payload" => "foo"})
+ end
+ end
+
+ def test_instantiation
+ enricher = enricher(headers:{"key" => "val"})
+ refute_nil(enricher)
+ end
+
+ def test_headers_added
+ enricher = enricher(headers:{"region" => "uk"})
+ input = {"id" => 123,}
+ expected = {"id" => 123, "region" => "uk"}
+
+ assert_equal(expected, enricher.transform(input))
+ end
+
+ def test_headers_not_overwritten_by_default
+ enricher = enricher(headers:{"region" => "uk"})
+ input = {"region" => "de"}
+ expected = {"region" => "de"}
+
+ assert_equal(expected, enricher.transform(input))
+ end
+
+ def test_headers_overwritten_when_configured
+ enricher = enricher(headers: {"region" => "uk"}, overwrite: true)
+ input = {"region" => "de"}
+ expected = {"region" => "uk"}
+
+ assert_equal(expected, enricher.transform(input))
+
+ end
+ end
+end
View
39 test/integrate/handlers/splitter_test.rb
@@ -0,0 +1,39 @@
+require_relative '../../helper'
+
+require 'integrate/handlers/splitter'
+require 'integrate/channel'
+
+module Integrate
+ class SplitterTest < MiniTest::Unit::TestCase
+
+ def test_instantiation
+ splitter = Splitter.new(in: Channel.new,
+ out: Channel.new)
+
+ refute_nil(splitter)
+ end
+
+ def test_instantiation_with_block
+ splitter = Splitter.new(in: Channel.new,
+ out: Channel.new) {}
+
+ refute_nil(splitter)
+ end
+
+ def test_splits_correctly
+ splitter = Splitter.new(in: Channel.new,
+ out: Channel.new) do |message|
+ message["items"].each_with_object([]) do |item_id, result|
+ result << {"item_id" => item_id}
+ end
+ end
+
+ in_message = {"items" => [1,5,54]}
+
+ assert_equal([{"item_id" => 1},
+ {"item_id" => 5},
+ {"item_id" => 54}], splitter.split(in_message))
+ end
+
+ end
+end
View
27 test/integrate/handlers/transformer_test.rb
@@ -1,14 +1,33 @@
-require 'minitest/autorun'
-require_relative '../../../lib/integrate/handlers/transformer'
-require_relative '../../../lib/integrate/channel'
+require_relative '../../helper'
+
+require 'integrate/handlers/transformer'
+require 'integrate/channel'
module Integrate
class TransformerTest < MiniTest::Unit::TestCase
def test_instantiation
- transformer = Transformer.new(in: Channel.new)
+ transformer = Transformer.new(in: Channel.new,
+ out: Channel.new)
+ refute_nil(transformer)
+ end
+
+ def test_instantiation_with_block
+ transformer = Transformer.new(in: Channel.new,
+ out: Channel.new) {}
+
refute_nil(transformer)
end
+ def test_transforms_correctly
+ transformer = Transformer.new(in: Channel.new,
+ out: Channel.new) do |message|
+ message["payload"] = message["payload"].reverse
+ message
+ end
+
+ assert_equal({"payload" => "foo"}, transformer.transform({"payload" => "oof"}))
+ end
+
end
end

No commit comments for this range

Something went wrong with that request. Please try again.