Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dependency in the container due to context.lookup

 
avihai marchiano
Ranch Hand
Posts: 342
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

Ejb3 has a big step a head with the POJO idea.
its help a lot for decrease the dependency with the container.

i would like to consult with you how to write a test for a class that depend in statless (ejb3) and obtain it by using context.lookup

Thank you
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean you have a class that does something like this?


If that's the case, all you need to do is grab the MockContextFactory class from the MockEJB project and fake the JNDI tree. There's an example of this in the freely available online bonus chapter of my book.
 
avihai marchiano
Ranch Hand
Posts: 342
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.

I am actually in the middle of the book and i might need to start from the bonus chapter (i am working with JPA and Ejb3 with JBoss).

Do you have there a solution for injection.

I mean when you have in your ejb a resource injection like @Ejb and etc
I dont want to insert a IOVC framework for testing only.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by avihai marchiano:
I mean when you have in your ejb a resource injection like @Ejb and etc
I dont want to insert a IOVC framework for testing only.

Well, you don't need any frameworks/libraries if you make your @EJB/@Resource annotated fields visible (protected, package private, public) to the test code. If you don't want to do that, you can use Java's reflection API to forcibly assign a mock to the annotated field. That's a bit clunky, though, so it would probably be easier to use a library that does the nasty reflection stuff for you. If this is the way to go, I'd recommend BeanInject.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic