• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Spring JMS Junit problem

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wish to know about the right approach for testing JMS in my Spring application using JUnit. The JMS resources are being injected in the config XML file using JNDI. Obviously, this cannot be used by JUnit as the objects are bound with the application server (Websphere). With this config file in place, I am not even able to run my other test cases in the application which have nothing to do with JMS. I get BeanCreationException because of NoClassDefFoundError for com.ibm.webspere.naming.WsnInitialContextFactory.

So, if any one can point me to a tutorial or document which would help me with this, I would be grateful.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to... Spring, I guess.

If you're trying to test JMS code, you have to run something JMS-aware.

If you're trying to test code separate from JMS, then you need to configure your environment more granularly. I always try to make a distinction between my code that uses JMS as a transport mechanism, and JMS itself: I'm not trying to test the underlying JMS implementation, I'm almost always trying to test my code that happens to use JMS.
 
Pradeep Mudaliar
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I get what you are implying. I guess testing the code using JMS as stand alone unit would the only option unless someone proves otherwise.
 
Ranch Hand
Posts: 85
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For testing JMS without using the server, This is what we did in one of our applications (with Weblogic, But i believe it should work fine for Websphere as well).

Instead of using server specific objects in application try using classes provided by spring:

define Your message sender which will have a JmsTemplate that you can use to send messages like this:



Define the jndiTemplate



and the jms factory:



Now you can just pass the connectionFactory and the jndiname of the JMS Q and initiate the beans which are not dependent on the server.

PS: you will have to use some JMS API for creating the Q's in developement mode... We used ActiveMQ to create the Q's while running tests... On production mode that will be available on the server where the application is deployed...
 
reply
    Bookmark Topic Watch Topic
  • New Topic