Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Registering a DataSource in JNDI

 
Mike Raath
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Mike Raath
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic