• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ejb3 unit testing

 
Harshana Dias
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34669
366
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Harshana Dias
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
She's saying you mock it, like with MockEJB or something.
 
Harshana Dias
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34669
366
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 188
11
Java Oracle
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic