This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
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="http://webtools.servehttp.com" target="_blank" rel="nofollow">http://webtools.servehttp.com</a> down for a while...
Joined: Apr 07, 2004
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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com