Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

changes of jndi.propertie are not reflected by DirContext

 
Tim Perkuhn
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to write a Junit Test that test the exceptions that are thrown if the user specifies wrong settings in the jndi.properie file.
My initial idea does not work.
1. Test with a correct configuration. Assert no exception.
2. Change the configuration to a wrong propertie setting.
3. Test with the broken configuration . Assert exception.
The changes that are made to the file are not be reflected to the DirContext object i create.
a example jndi.propertie:

a TestCase:

I found out that the jndi.propertie file in my CLASSPATH is only read one time, regardless how often i create
the object of type javax.naming.directory.InitialDirContext.


stat64("/home/edvs1/tperkuhn/testTruss/jndi.properties", 0xFFBED820) = 0
stat64("/home/edvs1/tperkuhn/testTruss/jndi.properties", 0xFFBEDE90) = 0
open("/home/edvs1/tperkuhn/testTruss/jndi.properties", O_RDONLY|O_LARGEFILE) = 5
open("/usr/j2se/jre/lib/jndi.properties", O_RDONLY|O_LARGEFILE) Err#2 ENOENT
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the Testing Forum...
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the actual unit you're testing?
Would it be appropriate to test that InitialDirContext fails to initialize if it receives the false configuration via the constructor that takes a Hashtable of environment entries? (i.e. test that your server is set up correctly)
Or do you want to test that InitialDirContext picks up the values from jndi.properties correctly? (i.e. test that your jndi.properties file is placed correctly)
 
Tim Perkuhn
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or do you want to test that InitialDirContext picks up the values from jndi.properties correctly? (i.e. test that your jndi.properties file is placed correctly)

My jndi.properties file is placed correctly, that is not the issue.
It picks up the values correctly the first time executing:

Then i change the value of a propertie by excecuting the method:

After that i create a new DirContext:

dctx1 and dctx2 do contain the same values.
My first post was about to proof that this happen and that the jndi.propertie file is just read one times.
That is perfectly if the application is to be in use, for the purpose of testing that is a problem to me.
 
Tim Perkuhn
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would it be appropriate to test that InitialDirContext fails to initialize if it receives the false configuration via the constructor that takes a Hashtable of environment entries? (i.e. test that your server is set up correctly)

That lead to another issue, that might be the root of my trouble.
I am reading a tree in the ldap directory. There is one object for each node.
Every class that produce one of these objects create its own DirContext. If i instead pass the DirContext as a parameter...
Thanks for your reply, Lasse.
Your counter question given me a idea of a better solution.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic