| 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
internet detective
Marshal
Joined: May 26, 2003
Posts: 26192
|
|
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.
|
 |
 |
|
|
subject: Problem: Apache Cactus + Servlet/ControllerTesting + EntityManagerFactory
|
|
|