This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

EJB3 testing with JUnit4

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
How can we get EntityManager in JUnit test class.I am trying to get it using the below code, but it returning null.

When I run the above as JUnit test, it fails throwing :

Please help.javascript:emoticon:cry:
 
author & internet detective
Posts: 40913
840
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
First of all, you are using a mix of JUnit 3.8 and 4.0. This may cause you problems. The only line in your code that is 3.8 is this one. You might want to remove the "extends."


Now on to your problem - you are running your JUnit test a standalone program, not an EJB. This means it isn't a session bean even though you have the annotation. Which in tern means things aren't injected.

What are you actually trying to test? A session bean? Something else?
 
bhama kumaran
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to test session bean. I am trying to get entitymanager in a stateless session bean.How do I do it?
 
bhama kumaran
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to do JuNite testing on session bean. I am trying to get entitymanager.How do I do it?
 
Jeanne Boyarsky
author & internet detective
Posts: 40913
840
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
How are you running your test? If you use a server side framework, like Cactus, it can access the EJB.
 
bhama kumaran
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No I am not using any server side framework. I am working on RAD 7.5 with WAS 7. Can unit test my DAO classes using Junit here.
I was trying to get the entitymanager in a junit test class. I tried also injecting the entitymanager and making the test class as session. But I still get entitymanager as null. Is there is any way I can unit test ejb's from inside the container.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As per my knowlege junit can't be used to test applications...

You will need
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could also use "Cactus" to test your enterprise components.

http://jakarta.apache.org/cactus/


 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic