aspose file tools*
The moose likes Testing and the fly likes changes of jndi.propertie are not  reflected by DirContext Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "changes of jndi.propertie are not  reflected by DirContext" Watch "changes of jndi.propertie are not  reflected by DirContext" New topic
Author

changes of jndi.propertie are not reflected by DirContext

Tim Perkuhn
Greenhorn

Joined: Jan 31, 2003
Posts: 17
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

Joined: Jul 18, 2001
Posts: 2712
Moving to the Testing Forum...
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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)


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Tim Perkuhn
Greenhorn

Joined: Jan 31, 2003
Posts: 17
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

Joined: Jan 31, 2003
Posts: 17
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: changes of jndi.propertie are not reflected by DirContext