Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Junit and Ejb - com/ibm/ejs/jts/jts/Current

 
Alana Sparx
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

I've been trying to write a Junit test class for an ejb that delegates calls to various business services.

I've tried bypassing the Ejb and calling the services directly, but either way the same error appears (as the Business Services ultimately call the database, therefor the contect needs to be set up).

The error could just be a classpath conflict (com/ibm/ejs/jts/jts/Current), but I cannot find the appropriate class or jar anywhere. I'm Using Websphere 5.1.

The error is


How else can I test this - how would I 'mock' a call to the database without altering the business code?

Thanx

As
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The stack trace you posted implies that the code you're invoking eventually does a JNDI lookup to find a DataSource. You can use MockEJB for setting up a fake, local JNDI tree and bind whatever objects you want to it, therefore making your JNDI lookup for "jdbc/ds1" obtain exactly what you want instead of the real thing.

In your case, you might bind a mock object that you've configured with tools like EasyMock or jMock, or alternatively an actual DataSource object that connects to a local, embedded database such as HSQLDB.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic