aspose file tools*
The moose likes Testing and the fly likes Problem: Apache Cactus + Servlet/ControllerTesting + EntityManagerFactory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Problem: Apache Cactus + Servlet/ControllerTesting + EntityManagerFactory " Watch "Problem: Apache Cactus + Servlet/ControllerTesting + EntityManagerFactory " New topic
Author

Problem: Apache Cactus + Servlet/ControllerTesting + EntityManagerFactory

shyam shridhar
Ranch Hand

Joined: Sep 15, 2006
Posts: 31
Hi all,

We are developing an web application (jsp/some controller)(JPA+GlassfishV2).
This is an existing project, in this we have an existing light weighted mvc framework.

we have DispatcherServlet entry in web.xml,We have write controller by extending an abstract classes.

Now i need to write testcase(ServletTestCase) for controller but i'm not able to get entity manger instance when i'm running test cases.

Controller code is like following
- an request processing method
- inside this method getting parameter from request.
- now getting or saving data with the help of another project (DataLayer)
- we pass 'entity manager factory' instance and 'transaction instance' to DataLayer that work as Dao.

We are instantiating entity manager factory and usertransaction in DispatcherServlet.

sample test controller :-

public class AbcControllerTest extends ServletTestCase {


public void beginProcessRequest(WebRequest request) {

request.addParameter("userid", "13499");
request.addParameter("password", "robinson");
}

public void testProcessRequest() throws Exception {
System.out.println("request processing");
AbcController instance = new AbcController();
ModelAndView expResult = new ModelAndView("/login.jsp");
ModelAndView result = instance.processRequest(request, response);
assertEquals(expResult.getPage(), result.getPage());
}
}


Please suggest me how i get the emf or if any other way i write the case to achive the same.

I'm new to servlet testing but i have some experience of junit testing.

Thanks in adavance
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30918
    
158

Shyam,
Normally you would create a mock object if the real object isn't available. If you post the relevant parts of AbcController, you might get some more specific comments.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
shyam shridhar
Ranch Hand

Joined: Sep 15, 2006
Posts: 31
Thanks Jeanne,

I have solved the issue.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem: Apache Cactus + Servlet/ControllerTesting + EntityManagerFactory