Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'spec_helper'
- import 'javax.naming.InitialContext'
- import 'javax.jms.QueueConnectionFactory'
- import 'javax.jms.Queue'
- import 'javax.jms.QueueConnection'
- import 'javax.jms.QueueSession'
- import 'javax.jms.ObjectMessage'
- import 'javax.jms.QueueSender'
- import 'gov.oasis.notification.JmsNotificationFacade'
- describe JmsNotificationFacade do
- describe "notify" do
- Q_CON_FACTORY_NAME = "UIL2ConnectionFactory"
- Q_NAME = "queue/notify"
- RETRY_MILLIS = 10_000
- before(:each) do
- @q_conn_factory = mock QueueConnectionFactory
- @q = mock Queue
- @q_connection = mock QueueConnection
- @q_session = mock QueueSession
- @msg = mock ObjectMessage
- @q_sender = mock QueueSender
- @ctx = mock InitialContext
- @ctx.stubs(:lookup).with(Q_CON_FACTORY_NAME).returns(@q_conn_factory)
- @ctx.stubs(:lookup).with(Q_NAME).returns(@q)
- @q_conn_factory.stubs(:createQueueConnection).returns(@q_connection)
- @q_connection.stubs(:createQueueSession).returns(@q_session)
- @q_session.stubs(:createSender).returns(@q_sender)
- @q_session.stubs(:createObjectMessage).returns(@msg)
- @q_sender.stubs(:send)
- @q_connection.stubs(:close)
- @msg.stubs(:setLongProperty)
- @facade = JmsNotificationFacade.new
- @facade.setInitialContext(@ctx)
- @facade.setJmsQueueConnectionFactoryName(Q_CON_FACTORY_NAME)
- @facade.setJmsNotifQueueName(Q_NAME)
- @facade.setJmsRetryDelayMillis(RETRY_MILLIS)
- end
- def when_notify_is_called
- yield if block_given?
- @facade.notify "profileName", "a subject", "a body"
- end
- describe "when successful" do
- it "should return 'true'" do
- when_notify_is_called.should == true
- end
- end
- describe "when unsuccessful" do
- it "should return 'false'" do
- when_notify_is_called {
- @facade.setInitialContext(nil)
- }.should == false
- end
- end
- it "should use a suppled JMS Queue Connection Factory name to lookup the QueueConnectionFactory" do
- when_notify_is_called { @ctx.expects(:lookup).with(Q_CON_FACTORY_NAME) }
- end
- it "should send a JMS message" do
- when_notify_is_called { @q_sender.expects(:send)#.with { |o| o.is_a? ObjectMessage }
- }
- end
- it "should use a supplied JMS Queue name when performing the JNDI lookup for the Queue" do
- when_notify_is_called { @ctx.expects(:lookup).with(Q_NAME) }
- end
- it "should use a supplied delay when sending a JMS message" do
- when_notify_is_called {
- @msg.expects(:setLongProperty).with("JMS_JBOSS_REDELIVERY_DELAY", RETRY_MILLIS)
- }
- end
- ##### The below tests aren't necessary but are here for my mental health
- it "should use create a Qeueue Connection using the Queue Connection Factory" do
- when_notify_is_called { @q_conn_factory.expects(:createQueueConnection) }
- end
- it "should create a queue connection" do
- when_notify_is_called { @q_conn_factory.expects(:createQueueConnection) }
- end
- it "should create a queue session" do
- when_notify_is_called { @q_connection.expects(:createQueueSession) }
- end
- it "should create a queue sender" do
- when_notify_is_called { @q_session.expects(:createSender).with { |o| o == @q } }
- end
- it "should create an Object Message" do
- when_notify_is_called { @q_session.expects(:createObjectMessage) }
- end
- it "should close the queue connection" do
- when_notify_is_called { @q_connection.expects(:close) }
- end
- end
- end
Add Comment
Please, Sign In to add comment