Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem: Apache Cactus + Servlet/ControllerTesting + EntityManagerFactory

 
shyam shridhar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34672
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
shyam shridhar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeanne,

I have solved the issue.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic