Hi Dhanji, thanks for the answer. i think this kind of solution can help many developers, but does not fit my needs. i've developed a servletFilter, which call internally some classes. these classes depends on HttpServletRequest and httpSession objects in method parameters, but i don't want to depend on my servletFilter(called by guiceFilter) to test them. it seems the only solution would be to not use GuiceFilter and servletModule, but provide a mock request and session scope, and bind a mock HttpServletRequest and HttpSession (for example with spring- mock), to unit test them.
so, do you valid this option, and can you point to a mock implementation of request and session scopes? best regards, Charles. On 2 juil, 02:26, "Dhanji R. Prasanna" <[email protected]> wrote: > You could also check out the several EasyMock tests in GuiceServlet's own > test suite on our codesite. > > Dhanji. > > On Fri, Jul 2, 2010 at 7:21 AM, charles gay <[email protected]> wrote: > > Hi Kazimierz, > > can you post an example of unit testing an httpservlet or > > servletFilter, called by the GuiceFilter, like implied in your prevous > > post? > > > best regards, > > > Charles. > > > On 19 juin, 22:51, Kazimierz Pogoda <[email protected]> wrote: > > > On Thu, Jun 17, 2010 at 1:21 PM, yaniv kessler <[email protected]> wrote: > > > > I wanted to know if anyone tried to artificially induce scopes like > > Request > > > > or Session in unit tests and what is the best way to go about it. > > > > I tried with success, though my solution is specific to GWT RCP > > > testing. I have built abstraction around GuiceFilter which is > > > initialized on @BeforeClass together with Injector instance, and > > > destroyed on @AfterClass. The idea is to simply call doFilter on > > > GuiceFilter instance in every test, and pass FilterChain instance > > > which will call servlet's doGet or doPost method. I mock > > > ServletContext, HttpSession, HttpServletRequest, HttpServletResponse > > > with the help of spring-test library. In case of GWT RPC instead of > > > calling servlet's doPost method I just wrap service instance with > > > dynamic proxy which ensures that any method invocation is performed > > > inside GuiceFilter.doFilter method. This way I can test RPC service > > > and avoid any processing in the HTTP stack. > > > > > This question is being asked within the context of wicket pages > > testing. > > > > In case of wicket you would have to call WicketFilter instance in the > > > FilterChain in addition to GuiceFilter and construct appropriate > > > HttpServletRequest mock pointing to specific wicket page. > > > > -- > > > "Meaning is differential not referential" > > > > kazik 'morisil' pogodahttp://www.xemantic.com/http://blog.xemantic.com/ > > > -- > > You received this message because you are subscribed to the Google Groups > > "google-guice" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]<google-guice%[email protected]> > > . > > For more options, visit this group at > >http://groups.google.com/group/google-guice?hl=en. -- You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
