You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Jason Anderson <jl...@gmail.com> on 2007/11/26 16:32:13 UTC

NPE in FormTester.submit

Am i doing something wrong here? i couldn't find much docs on testing
besides the javadoc and a page on the wiki...




tester = new WicketTester(new MyApplication());



    public void testLogin() throws Exception {
        tester.startPage(HomePage.class);
        tester.assertRenderedPage(LoginPage.class);

        FormTester form = tester.newFormTester("form");
        form.setValue("username", "******");
        form.setValue("password, "******");
        form.submit();

        tester.assertRenderedPage(HomePage.class);
    }


this gives the following exception:

java.lang.NullPointerException
	at org.apache.wicket.protocol.http.MockHttpServletResponse.sendRedirect(MockHttpServletResponse.java:534)
	at org.apache.wicket.protocol.http.WebResponse.redirect(WebResponse.java:232)
	at org.apache.wicket.protocol.http.BufferedWebResponse.close(BufferedWebResponse.java:66)
	at org.apache.wicket.protocol.http.MockWebApplication.processRequestCycle(MockWebApplication.java:386)
	at org.apache.wicket.util.tester.FormTester.submit(FormTester.java:588)

(wicket 1.3.0-rc1)

 from a quick peek thru the code it looks like the request cycle is
detaching the threadlocal before the response uses it in close()

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: NPE in FormTester.submit

Posted by Jason Anderson <xd...@maxexp.com>.
i made a quickstart and attached it to the following issue

https://issues.apache.org/jira/browse/WICKET-1187

thanks for the help

On Nov 26, 2007 8:57 PM, Timo Rantalaiho <Ti...@ri.fi> wrote:
> On Mon, 26 Nov 2007, Jason Anderson wrote:
> > and the code for MockHttpServletResponse:
> >
> >       public void sendRedirect(String location) throws IOException
> >       {
> >               // If the location starts with ../
> >               if (location.startsWith("../"))
> >               {
> >                       // Test if the current url has a / in it. (a mount)
> >                       String url = RequestCycle.get().getRequest().getURL();
> >
> >
> > I really can't see any way the threadlocal can possibly live long
> > enough to exist in this method.
>
> OK, so maybe it's just that WicketTester cannot handle these
> redirects.
>
> Maybe you could create a minimal quickstart reproducing
> this, or better yet a patch with a crashing WicketTester
> test, and attach it to Jira.
>
>
> Best wishes,
> Timo
>
> --
> Timo Rantalaiho
> Reaktor Innovations Oy    <URL: http://www.ri.fi/ >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: NPE in FormTester.submit

Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Mon, 26 Nov 2007, Jason Anderson wrote:
> and the code for MockHttpServletResponse:
> 
> 	public void sendRedirect(String location) throws IOException
> 	{
> 		// If the location starts with ../
> 		if (location.startsWith("../"))
> 		{
> 			// Test if the current url has a / in it. (a mount)
> 			String url = RequestCycle.get().getRequest().getURL();
> 
> 
> I really can't see any way the threadlocal can possibly live long
> enough to exist in this method.

OK, so maybe it's just that WicketTester cannot handle these
redirects.

Maybe you could create a minimal quickstart reproducing 
this, or better yet a patch with a crashing WicketTester
test, and attach it to Jira.

Best wishes,
Timo

-- 
Timo Rantalaiho           
Reaktor Innovations Oy    <URL: http://www.ri.fi/ >

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: NPE in FormTester.submit

Posted by Jason Anderson <xd...@maxexp.com>.
the form is not ajax, its pretty much a standard form with just login
and password fields and an onsubmit callback to send the page back to
the originally requested url or homepage much like you would find in
the login page included with the wicket-auth-roles classes

i'm not sure that storing the request would help as it is bound before
entering the submit();

here is the code in MockWebApplication.java

	public void processRequestCycle(WebRequestCycle cycle)
	{
		try
		{
			cycle.request();           //  <- RequestCycle exists and is
unbound at the end of this method after all the steps() have run in
threadDetach();
		}
		finally
		{
			cycle.getResponse().close();  // <-
MockHttpServletResponse.sendRedirect is called by this which calls
RequestCycle.get() after the above has already detached the
threadlocal
		}
		postProcessRequestCycle(cycle);
	}


and the code for MockHttpServletResponse:

	public void sendRedirect(String location) throws IOException
	{
		// If the location starts with ../
		if (location.startsWith("../"))
		{
			// Test if the current url has a / in it. (a mount)
			String url = RequestCycle.get().getRequest().getURL();


I really can't see any way the threadlocal can possibly live long
enough to exist in this method.





On Nov 26, 2007 7:58 PM, Timo Rantalaiho <Ti...@ri.fi> wrote:
> On Mon, 26 Nov 2007, Jason Anderson wrote:
> >         tester.startPage(HomePage.class);
>
> I'm not sure if it changes anything here, but we've
> typically done tester.startPage(new ITestPageSource()...
> instead.
>
> >  from a quick peek thru the code it looks like the request cycle is
> > detaching the threadlocal before the response uses it in close()
>
> Your code seems straight forward. But in more complex cases
> this sometimes comes up with WicketTester, and at times,
> WicketTester.setupRequestAndResponse() helps. You might also
> try storing RequestCycle.get() earlier and putting it back
> with RequestCycle.set() just before submit.
>
> Your form isn't ajax, is it? I think that ajax submits
> typically have to be submitted with WicketTester.executeAjaxEvent()
> instead of FOrmTester.submit().
>
> Best wishes,
> Timo
>
> --
> Timo Rantalaiho
> Reaktor Innovations Oy    <URL: http://www.ri.fi/ >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: NPE in FormTester.submit

Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Mon, 26 Nov 2007, Jason Anderson wrote:
>         tester.startPage(HomePage.class);

I'm not sure if it changes anything here, but we've 
typically done tester.startPage(new ITestPageSource()...
instead.

>  from a quick peek thru the code it looks like the request cycle is
> detaching the threadlocal before the response uses it in close()

Your code seems straight forward. But in more complex cases
this sometimes comes up with WicketTester, and at times,
WicketTester.setupRequestAndResponse() helps. You might also
try storing RequestCycle.get() earlier and putting it back 
with RequestCycle.set() just before submit.

Your form isn't ajax, is it? I think that ajax submits 
typically have to be submitted with WicketTester.executeAjaxEvent() 
instead of FOrmTester.submit().

Best wishes,
Timo

-- 
Timo Rantalaiho           
Reaktor Innovations Oy    <URL: http://www.ri.fi/ >

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org