spec/spec_helper.rb in jsparrow-1.1.3 vs spec/spec_helper.rb in jsparrow-1.1.4

- old
+ new

@@ -2,65 +2,80 @@ require 'spec' require File.dirname(File.expand_path(__FILE__)) + '/../lib/jsparrow.rb' # -# Modulo com metodos uteis para as specs. +# Helper methods for specs. # module JSparrowHelperMethods def configure_connection JSparrow::Connection.configure do use_jms_client_jar '/opt/openjms/lib/openjms-0.7.7-beta-1.jar' - + use_jndi_properties :initial_context_factory => 'org.exolab.jms.jndi.InitialContextFactory', - :provider_url => 'tcp://localhost:3035' - # :security_principal => 'user', - # :security_credentials => 'password' + :provider_url => 'tcp://localhost:3035' + # :security_principal => 'user', + # :security_credentials => 'password' enable_connection_factories :queue_connection_factory => 'ConnectionFactory', :topic_connection_factory => 'ConnectionFactory' enable_queues :test_queue => 'TestQueue' enable_topics :test_topic => 'TestTopic' end end - def create_jms_client + def new_jms_client configure_connection - JSparrow::Connection.new_client + new_jsparrow_client end - def create_jms_listener + def new_named_jms_listener configure_connection - JSparrow::Connection.new_listener :as => JSparrowHelperClasses::TestQueueListener + new_jsparrow_listener :as => JSparrowHelperClasses::TestQueueListener end + def new_anonymous_jms_listener + listener = new_jsparrow_listener( + :listen_to => { :queue => :test_queue }, + :receive_only_in_criteria => { :selector => "recipient = 'jsparrow-spec' and to_listener = 'anonymous'" } + ) do |received_message| + + received_messages << received_message + end + + def listener.received_messages + @received_messages ||= [] + end + + listener + end + def send_message_to_listener(listener_name) - @jms_client = create_jms_client + @jms_client = new_jms_client @jms_client.start - my_text = 'Mensagem de texto enviada da spec para o listener TestQueueListener' + my_text = "Mensagem de texto enviada da spec para o listener #{listener_name}" @jms_client.queue_sender(:test_queue).send_text_message(my_text) do |msg| - msg.set_string_property('recipient', 'jsparrow-spec') - msg.set_string_property('to_listener', listener_name) + msg.add_criteria_to_reception('recipient', 'jsparrow-spec') + msg.add_criteria_to_reception('to_listener', listener_name) end @jms_client.stop end end module JSparrowHelperClasses - # - # Listener da queue TestQueue + # Listener for test against "TestQueue" queue # - class TestQueueListener < JSparrow::Connection::Listener + class TestQueueListener < JSparrow::Interactors::Listener listen_to :queue => :test_queue receive_only_in_criteria :selector => "recipient = 'jsparrow-spec' and to_listener = 'TestQueueListener'" attr_reader :received_messages @@ -70,15 +85,16 @@ @received_messages = [] end def on_receive_message(received_message) - @received_messages << received_messages + @received_messages << received_message end end end + # -# Enriquece a classe Spec::Example::ExampleGroup com o helper. +# Some steroids for Spec::Example::ExampleGroup. # class Spec::Example::ExampleGroup include JSparrowHelperMethods end