File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Registering a DataSource in JNDI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Registering a DataSource in JNDI" Watch "Registering a DataSource in JNDI" New topic

Registering a DataSource in JNDI

Mike Raath

Joined: Apr 07, 2004
Posts: 2
I'm struggling like mad setting up test cases for a web application I'm trying to test using JUnit.
To briefly describe the setup: we have a number of possible data servers, all defined in jndi-definitions.xml and loaded into JNDI on web-app start up. Our DB class takes an argument to the constructor: the name of the server to use and does a context.lookup to get the DataSource. This is all wrapped up in a jar which is referenced from the web-application.
This all works fine and dandy as a web application, but when I try to run a test suite (not as a web app) which creates my Services object (which in turn invokes the DB class) I get a node not found error - this is because nowhere in the Test have I registered the JNDI definitions.
My question is - how can I? If I try to create the DataSource and do a bind or rebind on the context, I get a javax.naming.OperationNotSupportedException: The "java:comp" naming context and its subcontexts are read-only.
As the test suite runs as a standalone application and intends to test my Service (which has no Http awareness) I'm at a loss how to do it. Any help would be greatly appreciated.
Brahim Bakayoko
Ranch Hand

Joined: Aug 29, 2003
Posts: 155
Looks like you need a standalone JNDI provider. Try the filesystem.
The JNDI defined in the web application is setup when the web application starts.
How can you reference something that is non-existent?

SCJP, SCWCD, SCBCD, IBM CSD WebSphere v5, <br />A+, MCP 2000 and 2000 server, CST, and few incompleted certification tracks.<br /> <br />Ivory Coast<br /> <br />Analyze your web Request/Response @ <a href="" target="_blank" rel="nofollow"></a> down for a while...
Mike Raath

Joined: Apr 07, 2004
Posts: 2
Thanks Brahim for your reply. Just for clarity, what I was trying to do was create that non-existent JNDI context within the test suite, but I have been approaching this the wrong way. I should not be using JUnit for these tests, but Cactus.
I agree. Here's the link:
subject: Registering a DataSource in JNDI
jQuery in Action, 3rd edition