Re: wicket-guice HttpServletRequest

2013-06-10 Thread Martin Grigorov
Hi,

To be able to do this you have to know Guice internals.
HttpServletRequest is @Request scoped and since there is no http request in
unit/wicketTester tests Guice cannot provide it for you.

I guess that you can bind it manually in your TestModule so it will have a
global scope as workaround.

But your question is not for Wicket but Guice forums (if there are such,
because Guice is not very well maintained lately).



On Tue, Jun 4, 2013 at 1:01 AM, Watrous, Daniel daniel.t.watr...@hp.comwrote:

 I'm having some trouble getting my unittests to work when I use Guice to
 get an instance of the HttpServletRequest object. The page works fine when
 running in jetty, but in the unittests I get these errors.

 org.apache.wicket.WicketRuntimeException: Can't instantiate page using
 constructor 'public
 com.hp.honeybadger.console.HomePage(org.apache.wicket.request.mapper.parameter.PageParameters)'
 and argument ''. Might be it doesn't exist, may be it is not visible
 (public).

 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.
   at
 com.google.inject.servlet.InternalServletModule.provideHttpServletRequest(InternalServletModule.java:95)
   while locating javax.servlet.http.HttpServletRequest

 Caused by: 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.

 This is my page

 public class HomePage extends WebPage {

 private static final long serialVersionUID = 1L;
 @Inject private HttpServletRequest request;

 public HomePage(final PageParameters parameters) {
 super(parameters);

 add(new Label(version,
 getApplication().getFrameworkSettings().getVersion()));

 // TODO Add your page's components here
 add(new Label(method, request.getMethod()));

 }
 }

 QUESTION

 How can I get around this issue or make use of a mock object to enable
 unittests?



wicket-guice HttpServletRequest

2013-06-03 Thread Watrous, Daniel
I'm having some trouble getting my unittests to work when I use Guice to get an 
instance of the HttpServletRequest object. The page works fine when running in 
jetty, but in the unittests I get these errors.

org.apache.wicket.WicketRuntimeException: Can't instantiate page using 
constructor 'public 
com.hp.honeybadger.console.HomePage(org.apache.wicket.request.mapper.parameter.PageParameters)'
 and argument ''. Might be it doesn't exist, may be it is not visible (public).

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.
  at 
com.google.inject.servlet.InternalServletModule.provideHttpServletRequest(InternalServletModule.java:95)
  while locating javax.servlet.http.HttpServletRequest

Caused by: 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.

This is my page

public class HomePage extends WebPage {

private static final long serialVersionUID = 1L;
@Inject private HttpServletRequest request;

public HomePage(final PageParameters parameters) {
super(parameters);

add(new Label(version, 
getApplication().getFrameworkSettings().getVersion()));

// TODO Add your page's components here
add(new Label(method, request.getMethod()));

}
}

QUESTION

How can I get around this issue or make use of a mock object to enable 
unittests?