Guest User

Untitled

a guest
Apr 26th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. require 'spec_helper'
  2.  
  3. import 'javax.naming.InitialContext'
  4. import 'javax.jms.QueueConnectionFactory'
  5. import 'javax.jms.Queue'
  6. import 'javax.jms.QueueConnection'
  7. import 'javax.jms.QueueSession'
  8. import 'javax.jms.ObjectMessage'
  9. import 'javax.jms.QueueSender'
  10. import 'gov.oasis.notification.JmsNotificationFacade'
  11.  
  12. describe JmsNotificationFacade do
  13. describe "notify" do
  14. Q_CON_FACTORY_NAME = "UIL2ConnectionFactory"
  15. Q_NAME = "queue/notify"
  16. RETRY_MILLIS = 10_000
  17.  
  18. before(:each) do
  19. @q_conn_factory = mock QueueConnectionFactory
  20. @q = mock Queue
  21. @q_connection = mock QueueConnection
  22. @q_session = mock QueueSession
  23. @msg = mock ObjectMessage
  24. @q_sender = mock QueueSender
  25.  
  26. @ctx = mock InitialContext
  27. @ctx.stubs(:lookup).with(Q_CON_FACTORY_NAME).returns(@q_conn_factory)
  28. @ctx.stubs(:lookup).with(Q_NAME).returns(@q)
  29.  
  30. @q_conn_factory.stubs(:createQueueConnection).returns(@q_connection)
  31. @q_connection.stubs(:createQueueSession).returns(@q_session)
  32. @q_session.stubs(:createSender).returns(@q_sender)
  33. @q_session.stubs(:createObjectMessage).returns(@msg)
  34. @q_sender.stubs(:send)
  35. @q_connection.stubs(:close)
  36.  
  37. @msg.stubs(:setLongProperty)
  38.  
  39. @facade = JmsNotificationFacade.new
  40. @facade.setInitialContext(@ctx)
  41. @facade.setJmsQueueConnectionFactoryName(Q_CON_FACTORY_NAME)
  42. @facade.setJmsNotifQueueName(Q_NAME)
  43. @facade.setJmsRetryDelayMillis(RETRY_MILLIS)
  44. end
  45.  
  46. def when_notify_is_called
  47. yield if block_given?
  48. @facade.notify "profileName", "a subject", "a body"
  49. end
  50.  
  51. describe "when successful" do
  52. it "should return 'true'" do
  53. when_notify_is_called.should == true
  54. end
  55. end
  56.  
  57. describe "when unsuccessful" do
  58. it "should return 'false'" do
  59. when_notify_is_called {
  60. @facade.setInitialContext(nil)
  61. }.should == false
  62. end
  63. end
  64.  
  65. it "should use a suppled JMS Queue Connection Factory name to lookup the QueueConnectionFactory" do
  66. when_notify_is_called { @ctx.expects(:lookup).with(Q_CON_FACTORY_NAME) }
  67. end
  68.  
  69. it "should send a JMS message" do
  70. when_notify_is_called { @q_sender.expects(:send)#.with { |o| o.is_a? ObjectMessage }
  71. }
  72. end
  73.  
  74. it "should use a supplied JMS Queue name when performing the JNDI lookup for the Queue" do
  75. when_notify_is_called { @ctx.expects(:lookup).with(Q_NAME) }
  76. end
  77.  
  78. it "should use a supplied delay when sending a JMS message" do
  79. when_notify_is_called {
  80. @msg.expects(:setLongProperty).with("JMS_JBOSS_REDELIVERY_DELAY", RETRY_MILLIS)
  81. }
  82. end
  83.  
  84. ##### The below tests aren't necessary but are here for my mental health
  85.  
  86. it "should use create a Qeueue Connection using the Queue Connection Factory" do
  87. when_notify_is_called { @q_conn_factory.expects(:createQueueConnection) }
  88. end
  89.  
  90. it "should create a queue connection" do
  91. when_notify_is_called { @q_conn_factory.expects(:createQueueConnection) }
  92. end
  93.  
  94. it "should create a queue session" do
  95. when_notify_is_called { @q_connection.expects(:createQueueSession) }
  96. end
  97.  
  98. it "should create a queue sender" do
  99. when_notify_is_called { @q_session.expects(:createSender).with { |o| o == @q } }
  100. end
  101.  
  102. it "should create an Object Message" do
  103. when_notify_is_called { @q_session.expects(:createObjectMessage) }
  104. end
  105.  
  106. it "should close the queue connection" do
  107. when_notify_is_called { @q_connection.expects(:close) }
  108. end
  109. end
  110. end
Add Comment
Please, Sign In to add comment