• 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

Registering a DataSource in JNDI

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic