You can simulate a request by instantiating GuiceFilter() and passing it a
mock request and response. If you have previously installed a configured
ServletModule, it will execute the servlets + filters registered in the GS2
pipeline.
Dhanji.

On Sat, Jun 13, 2009 at 5:12 AM, naaka <[email protected]> wrote:

>
> thanks dhanji.
>
> but what other ways do i have for testing ?
>
> i wanted to do some integration testing and i need to have everything
> injected by the container.
>
>
> nicola
>
>
>
> On Jun 12, 6:32 pm, "Dhanji R. Prasanna" <[email protected]> wrote:
> > You should bind @RequestScoped and @SessionScoped to your own mock Scope
> > implementation. Then Guice will use this instead of its default HTTP
> scopes.
> > In this case you want to omit the ServletModule in your test.
> > MockRequestScope myMockScope = new MockRequestScope();
> > bindScope(RequestScoped.class, myMockScope);
> >
> > //after tests
> > myMockScope.assertThatThingsWereScoped();
> >
> > Btw, this is a very heavyweight way of testing, so I assume this is not
> > something you need to do often.
> > good luck!
> >
> > Dhanji.
> >
> > On Fri, Jun 12, 2009 at 9:18 AM, naaka <[email protected]> wrote:
> >
> > > hi,
> > > i tried out google guice and it looks great.
> >
> > > i have tdd-ed a small spike with persistence and singleton/no scopes
> > > and every worked fine.
> >
> > > now i have added the servlet-guice extension, and changed a class to
> > > session scope, but my test complaint:
> >
> > > com.google.inject.ProvisionException: Guice provision errors:
> >
> > > 1) Error in custom provider, com.google.inject.OutOfScopeException:
> > > Cannot access scoped object. Either we are not currently inside an
> > > HTTP Servlet request, or you may have forgotten to apply
> > > com.google.inject.servlet.GuiceFilter as a servlet filter for this
> > > request.
> > >  while locating com.naaka.spikes.domain.User
> > >    for field at com.naaka.spikes.domain.UserTest.defaultUser
> > > (UserTest.java:24)
> > >  while locating com.naaka.spikes.domain.UserTest
> >
> > > i already added the servlet module in the setup method:
> >
> > > @BeforeClass
> > > public void setupInjection() {
> > >  ...
> > >  modules.add(declarePersistence);
> > >  modules.add(configPersistence);
> > >  modules.add(new ServletModule());
> > >  injector = Guice.createInjector(modules);
> > >  ...
> > > }
> >
> > > how i can setup a test to work with session modules ?
> >
> > > do i have to mock something (servlet request/response/filter) ?
> >
> > > is there a base test class or a test i can copy from ?
> >
> > > THANKS !
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to