• 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
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

EJB3 unit tesing for session beans

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
author & internet detective
Posts: 40537
825
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
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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 40537
825
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
Moving to our EJB forum. Since one works, the test itself is fine.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic