aspose file tools*
The moose likes Testing and the fly likes Ejb3 unit testing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Ejb3 unit testing" Watch "Ejb3 unit testing" New topic
Author

Ejb3 unit testing

Harshana Dias
Ranch Hand

Joined: Jun 11, 2007
Posts: 327
Hi,

How can i resolve a scenario in ejb unit test where in service bean there is a persist for an object and later i need to get the persisted object back? The issue is ejb unit test does not really persist the object in the database where when it comes to get back the persisted object from the service class there is no such object persisted know?

Thank You.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29220
    
135

Harshana,
Is this a unit test (mock objects) or an integration test (database) ? For the former, you mock out what you expect to be returned. For the later, why wouldn't the object be there later?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Harshana Dias
Ranch Hand

Joined: Jun 11, 2007
Posts: 327
Jeanne Boyarsky wrote:Harshana,
Is this a unit test (mock objects) or an integration test (database) ? For the former, you mock out what you expect to be returned. For the later, why wouldn't the object be there later?


Its the Unit test (using eclipse)..well the methods returns a Dto with full of data..im assert that object(dto) not null(i guess that is what mock out means right?)
But the problem is inside the service class method body their is a scenario where it persist the object and after few lines it takes back the object.
So with Ejb unit test persist object doesn't really persist in the database.(may be its save somewhere until the time of unit test ).
But the problem arise when the method reach to the line where it retrieve the object back..where the test case fails saying no such entity found for query.
In the ejb unit framework looks for real database persist objects which are in the database when we retrieve the object (using a select query). you got the problem Jeanne?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

She's saying you mock it, like with MockEJB or something.
Harshana Dias
Ranch Hand

Joined: Jun 11, 2007
Posts: 327
David Newton wrote:She's saying you mock it, like with MockEJB or something.


No. I am uning Ejb3Unit. I extend the BaseSessionBeanFixture which is the base class for all JUnit test - testing stateless/statefull SessionBeans in my test class.
Harshana Dias
Ranch Hand

Joined: Jun 11, 2007
Posts: 327
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29220
    
135

No. I'm saying that I think you have a hybrid. You have the unit part where you expect the database will not be updated and the integration part where you expect the data to be in the database.
Amritendu De
author
Ranch Hand

Joined: Feb 21, 2009
Posts: 110
    
    6

Check this out for EJB unit testing: http://amritendude.blogspot.in/2012/07/unit-testing-ejb-30-and-jpa-20.html


Architect (SCEA 5, TOGAF 9, IBM OOAD, PMI certified)
[Book 1: Oracle Certified Master, Java EE Enterprise Architect Practice Guide]
[Book 2: Oracle Certified Associate Java SE-7 and SE-6: Exam IZO-803 and IZO-850 Practice Exams]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ejb3 unit testing
 
Similar Threads
Handle and HomeHandle
Stateful Session Bean question
ejbStore() and ejbLoad() in Entity Beans
How do you update a collection if some exist and some are new?
id is not set after getSession().save()