• Post Reply Bookmark Topic Watch Topic
  • New Topic

EJB3 unit tesing for session beans  RSS feed

 
sam ghaisas
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am using session beans(EJB3) in my application.
I have created two inner classes as Local and Remote interfaces in the same parent Interface.
I am injecting the bean into another bean as shown below

@EJB(beanInterface = AccountingService.AccountingServiceLocal.class)
private AccountingService accountingService;

I am using ejb3unit with mocking for testing the session beans. i am usning MockedSessionBeanFixture for mocking the beans

But its not able to mock the injected bean. its giving me NullPointerException.

Does anyone know how to fix it.


 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37256
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam,
Welcome to JavaRanch! What line is the null pointer occurring on? Where do you inject the mock bean?
 
sam ghaisas
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:Sam,
Welcome to JavaRanch! What line is the null pointer occurring on? Where do you inject the mock bean?


I am injecting the bean into another bean. and writen junit of that bean. when i use normal injection i.e. without specifying the beanInterface it works fine. but if i give argument beanInterface in EJB annotation it fails to populate that bean.

Say I have BusinessBean and i have injected AccountingServiceBean as shown below

@EJB(beanInterface = AccountingService.AccountingServiceLocal.class)
private AccountingService accountingService;

And when i run junit it fails to inject this AccountingService into BusinessBean. but if i inject it like beow i.e. without specifying the local interface for the bean like

@EJB
private AccountingService accountingService;

it works.

Any idea why this is happening? please provide your inputs.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37256
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to our EJB forum. Since one works, the test itself is fine.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!