aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Mockrunner Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Mockrunner" Watch "Mockrunner" New topic
Author

Mockrunner

shrenik jain
Greenhorn

Joined: Apr 22, 2013
Posts: 1
I am using mockrunner,i am new at this.my problem started when i began testing a web dynamic project which includes(structs,ejbs,servlet). i have a servlet called SetupServlet , which calls a class called Dispenser. In Dispenser we load all the EJB Refrences.
I started testing SetupServlet. I created a junit test case called TestservletTest as:

in the setUp() method i given this
Dispenser code:

while creating ctx i get this error:
22/04 12:47:18:148 ERROR [ ] Dispenser <init>() NamingException : javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]

i belive since i am extending my testclass as BasicServletTestCaseAdapter and ctx is for loading ejbs is for loading ejbs.is the problem.please give me solution on how to overcome this problem while testing setupservlet.
Amir Keibi
Ranch Hand

Joined: Apr 23, 2012
Posts: 49

"i belive since i am extending my testclass as BasicServletTestCaseAdapter and ctx is for loading ejbs is for loading ejbs.is the problem"


Understanding the problem is half of the solution. You're right.

InitialContext class is considered an entry point to a naming system. In order to access application server's JNDI, an object of that class has to be created (as your code does). While your code is trying to create that object, it encounters "NamingContextFactory" class. It'll be available to an application if one of the following is correct:

  • Application runs in a container.
  • Application server provides a Java RMI client (typically a jar file) that can be added to the application's class path.


  • If you are writing unit tests, then application server is considered an external dependency. That is, you have to use Mocking techniques.
    If you are writing integration tests that involve an actual application server, then either your test code has to run in an application container or you ought to have the Java RMI client in your class path. I prefer the later.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Mockrunner
     
    Similar Threads
    WSAD InitialContext stalls
    Cannot Access EJB on Weblogic ???
    accesing ejb deployed in weblogic from tomcat
    Accessing a datasource from outside JBoss
    JMS and JNDI