Ramesh Kotha
Ramesh Kotha

Reputation: 8322

Unit Testing with JUnit in JNDI datasource Hibernate with weblogic environment?

i am using datasource in weblogic server and, using the datasource in Hibernate. With HibernateUtil class am getting the SessionFactory, now i want write test cases for my DAO layer by using JUnit.

  1. How to get the SessionFactory in my Test class.
  2. I am able to get the datasource by jndi lookup in setUp method in my Test Class

is there any better way of writing test classes in this environment?

Upvotes: 1

Views: 1599

Answers (1)

RicardoS
RicardoS

Reputation: 2118

You can get the datasource JNDI, using javax.naming.InitialContext. But I think wouldn't be a good idea make the test dependent on container (weblogic).

I had only 2 ideas:

  • You could use Mock, getting a fake conection to DB.
  • Or you could use a diferent hibernate configuration file for tests. This way, you can specify the connection directly, without JNDI.

Loading this test-file-configuration can be done using reflection or a mock.

Upvotes: 1

Related Questions