• 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

How to test persistence layer of a web based application?

 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
We have a web based application(packaged as ear) running in Weblogic 7.0.

I want to write a suite of tests to test our persistence operations.
The persistence layer is implemented as DAO's.
There are no EJB's in the application.

How can I invoke these DAO classes packaged in the EAR to test them?
What are the options(frameworks)?

Thanks in advance.
 
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As long as your DAO's are well-defined and all your persistence code is in DAO's, you should be able to use JUnit to test your persistence layer
 
Yan Lee
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jayesh,
Thanks for the respose. I do have the following additional question,
How can I invoke the DAO (a plain java class) that is in the .ear from outside of weblogic? The DAO is not in a session bean.

Any links to examples or resources to how this can he done will be highly helpful.

Thanks
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by p intelli:
How can I invoke the DAO (a plain java class) that is in the .ear from outside of weblogic? The DAO is not in a session bean.

You can't, unless you expose the DAO to the outside world using some kind of an adapter like RMI, EJB, web services, servlet, etc.
 
Jayesh Lalwani
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Personally, I would Unit test the DAO outside your web server. You are trying to make the DAO reuseable, right? This means that they should run in standalone apps too, right? So, If I were you I would test my persisitence layer in a standalone JUnit app
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a related question. I have a DAO with several methods. I want to write a suite of tests to test the success and failure of each of these methods. My DAO is written so that it is passed a DataSource object in its constuctor and it can create a Connection object from that DataSource.

i.e.


How do I create a DataSource in JUnit so that I can test the DAO? Would I have to use Cactus? How would I create the DS in cactus?
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since DataSource is an interface, you could pass in a mock datasource. This could use easyMock, jMock or even be a class you write yourself.

The mock datasource would return a connection using whatever mechanism you have for getting connections.
 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
looks like my question is also alike
i ahve an application with mvc desing pattern
Controller - > helper class - > Dao Implementaion
i was writing test cases for helper classes. but the helper class calls the dao implementaion and in the dao implementaion i am using the data source to get connection. when i run the test on my machine it fails since the daoimpl looks for the data source. Wondering how to write test cases for helper classes any help to any article will be appreciated.
Thanks
Rashid
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rashid,
When unit testing the helper class, you want to test just that class. So you would create a mock DAO. What does the helper class do? Think about what it is responsible for to figure out what you are trying to test.

If you were writing a test for the DAO, you would create a mock datasource.
 
Rashid Darvesh
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jeanne
my source code is organised as follows
src->com->eds->met->Helper->all Helper Classes example ValueHelper.java
src->com->eds->met->persistence->all Dao classes.
Now the thing is if i have to write a mock dao where should i write it
i have the following test folder structure in exact manner as the source from the root directory
test->com->eds->met->Helper->ValueHelperTest.java
In the ValueHelperTest i have all the test cases defined for ValueHelper class. In the setUp and teardown method i instantiate the valueHelper object and call the method. if i write my own mock Dao where should i write it.
Please let me know
Thanks...
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rashid,
I wouldn't actually advise writing a mock DAO. Just have your real DAO implement an interface. This interface goes in the same package as the original DAO.

Then you can use a framework like easyMock or jMock to mock it out. The framework does all the work.
 
reply
    Bookmark Topic Watch Topic
  • New Topic