Re: unit testing cookies after redirect
hej, SO it seems that errors I got was because of my bad testing. I created simple test in new project and it now works. the only problem is that 1. wicket tester process request twice after startPage - the first time the page is rendered and cookies are saved into AddCookieAction. then request is processed second time and this time all actions are invoked and cookie is finally added to second response. Is this because wicket is always redirecting browser with render request?? 2. after request is fully processed the original request and response are saved as lastRequest and lastResonse (llok at recordRequestResponse in WicketBaseTester). cookies are in tester.getLastResponse().getCookies() 3. the thing which is not intuitive is the fact that after one request is fully processed the new request (and response) is created but cookies from last response are not rewritten to it. cookies will be added when new request will be processed by tester on next startPage. I think that's it, hope I got this right this time ;] and it may help someone pozdrawiam Paweł Kamiński kami...@gmail.com pkaminski@gmail.com __ - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: unit testing cookies after redirect
On Fri, Dec 30, 2011 at 2:02 PM, kamiseq kami...@gmail.com wrote: hej, SO it seems that errors I got was because of my bad testing. I created simple test in new project and it now works. the only problem is that 1. wicket tester process request twice after startPage - the first time the page is rendered and cookies are saved into AddCookieAction. then request is processed second time and this time all actions are invoked and cookie is finally added to second response. Is this because wicket is always redirecting browser with render request?? 2. after request is fully processed the original request and response are saved as lastRequest and lastResonse (llok at recordRequestResponse in WicketBaseTester). cookies are in tester.getLastResponse().getCookies() 3. the thing which is not intuitive is the fact that after one request is fully processed the new request (and response) is created but cookies from last response are not rewritten to it. cookies will be added when new request will be processed by tester on next startPage. this is fixed in 1.5-snapshot I think that's it, hope I got this right this time ;] and it may help someone pozdrawiam Paweł Kamiński kami...@gmail.com pkaminski@gmail.com __ - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org -- Martin Grigorov jWeekend Training, Consulting, Development http://jWeekend.com - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: unit testing cookies after redirect
Hi, Have you verified that the cookie value is correct? In Cookie javadocs [1] it reads: With Version 0 cookies, values should not contain white space, brackets, parentheses, equals signs, commas, double quotes, slashes, question marks, at signs, colons, and semicolons. Empty values may not behave the same way on all browsers. I've had a similar issue to yours and it turned out that the value I was setting contained a semicolon, so setting the cookie always failed silently. best, Piotr [1] http://docs.oracle.com/javaee/6/api/javax/servlet/http/Cookie.html#setValue(java.lang.String) http://docs.oracle.com/javaee/6/api/javax/servlet/http/Cookie.html#setValue(java.lang.String) -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/unit-testing-cookies-after-redirect-tp3995764p4214036.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: unit testing cookies after redirect
Hi, I have also noticed that once but didn't have time to investigate it further and later I forgot about it ... Can you create a simple quickstart and attach it to Jira. On Sun, Nov 20, 2011 at 10:41 PM, kamiseq kami...@gmail.com wrote: hej, well I tried to follow the cookies in wicket tester. starting from the beginning I have page A that while constructing adds new cookie to response and throws (as Martin advised) ReplaceHandlerException pointing to page B. everything goes well and cookies are carried inside original response until BaseWicketTester.processRequest(forcedRequest, forcedRequestHandler, redirect) - setupNextRequestCycle() were new request and new response is created and my cookies info is gone :/ I guess that cookies from last response should be rewritten to new request, right?? I a bit confused how this works here, I have problems with cooking when Im testing it inside jetty so maybe this is something on my side only :/ any ideas? pozdrawiam Paweł Kamiński kami...@gmail.com pkaminski@gmail.com __ On 9 November 2011 15:01, kamiseq kami...@gmail.com wrote: so if this is the last line in my code those two approaches are pretty the same pozdrawiam Paweł Kamiński kami...@gmail.com pkaminski@gmail.com __ -- Martin Grigorov jWeekend Training, Consulting, Development http://jWeekend.com - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: unit testing cookies after redirect
ok I ll do it this week thanks pozdrawiam Paweł Kamiński kami...@gmail.com pkaminski@gmail.com __ On 21 November 2011 09:52, Martin Grigorov mgrigo...@apache.org wrote: Hi, I have also noticed that once but didn't have time to investigate it further and later I forgot about it ... Can you create a simple quickstart and attach it to Jira. On Sun, Nov 20, 2011 at 10:41 PM, kamiseq kami...@gmail.com wrote: hej, well I tried to follow the cookies in wicket tester. starting from the beginning I have page A that while constructing adds new cookie to response and throws (as Martin advised) ReplaceHandlerException pointing to page B. everything goes well and cookies are carried inside original response until BaseWicketTester.processRequest(forcedRequest, forcedRequestHandler, redirect) - setupNextRequestCycle() were new request and new response is created and my cookies info is gone :/ I guess that cookies from last response should be rewritten to new request, right?? I a bit confused how this works here, I have problems with cooking when Im testing it inside jetty so maybe this is something on my side only :/ any ideas? pozdrawiam Paweł Kamiński kami...@gmail.com pkaminski@gmail.com __ On 9 November 2011 15:01, kamiseq kami...@gmail.com wrote: so if this is the last line in my code those two approaches are pretty the same pozdrawiam Paweł Kamiński kami...@gmail.com pkaminski@gmail.com __ -- Martin Grigorov jWeekend Training, Consulting, Development http://jWeekend.com - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: unit testing cookies after redirect
hej, well I tried to follow the cookies in wicket tester. starting from the beginning I have page A that while constructing adds new cookie to response and throws (as Martin advised) ReplaceHandlerException pointing to page B. everything goes well and cookies are carried inside original response until BaseWicketTester.processRequest(forcedRequest, forcedRequestHandler, redirect) - setupNextRequestCycle() were new request and new response is created and my cookies info is gone :/ I guess that cookies from last response should be rewritten to new request, right?? I a bit confused how this works here, I have problems with cooking when Im testing it inside jetty so maybe this is something on my side only :/ any ideas? pozdrawiam Paweł Kamiński kami...@gmail.com pkaminski@gmail.com __ On 9 November 2011 15:01, kamiseq kami...@gmail.com wrote: so if this is the last line in my code those two approaches are pretty the same pozdrawiam Paweł Kamiński kami...@gmail.com pkaminski@gmail.com __
Re: unit testing cookies after redirect
so if this is the last line in my code those two approaches are pretty the same pozdrawiam Paweł Kamiński kami...@gmail.com pkaminski@gmail.com __ - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: unit testing cookies after redirect
ok, thanks for that. I have one small question that is bugging me for a while. What would be the difference between throwing exception or setResponsePage(pageClass);?? I ve found somewhere that I should always throw RestartException, but I see setResponsePage so many times that Im confused. pozdrawiam Paweł Kamiński kami...@gmail.com pkaminski@gmail.com __ - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: unit testing cookies after redirect
On Wed, Nov 9, 2011 at 12:42 AM, kamiseq kami...@gmail.com wrote: ok, thanks for that. I have one small question that is bugging me for a while. What would be the difference between throwing exception or setResponsePage(pageClass);?? I ve found somewhere that I should always throw RestartException, but I see setResponsePage so many times that Im confused. The exception stops the execution of your code and immediately replaces the current IRequestHandler while setResponsePage() just schedules another IRequestHandler to be executed after the current one and continues executing your code. pozdrawiam Paweł Kamiński kami...@gmail.com pkaminski@gmail.com __ - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org -- Martin Grigorov jWeekend Training, Consulting, Development http://jWeekend.com - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: unit testing cookies after redirect
Hi, On Sun, Nov 6, 2011 at 3:53 PM, kamiseq kami...@gmail.com wrote: hej, I ve found this http://apache-wicket.1842946.n4.nabble.com/Wickettester-cookies-and-redirects-in-Wicket-1-4-15-td3250792.html but im developing on 1.5.2 and ticket is closed. I believe it is the same case. this is description: I have a page ValidationPage that accepts request, checks parameters and sets cookie on response object ((WebResponse)getRequestCycle().getResponse()).addCookie(new Cookie(mycookie, VAL)); then on certain condition I want to redirect to original destination or to some set page if (!continueToOriginalDestination()) { log.warning(redirect failed redirecting to original destination); throw new RestartResponseException(new MyOtherPage()); RestartResponseException extends ResetResponseException which _resets_ the response, i.e. removes all the collected response body and headers and starts from a clean state. Use this instead: public class NonResettingRestartException extends ReplaceHandlerException { public NonResettingRestartException(final Class? extends Page? pageClass, final PageParameters params, final RequestCycle cycle) { super(createRequestHandler(pageClass, params), true); Response response = cycle.getResponse(); if (response instanceof IMetaDataBufferingWebResponse) { IMetaDataBufferingWebResponse bufferingWebResponse = (IMetaDataBufferingWebResponse) response; bufferingWebResponse.writeMetaData((WebResponse) cycle.getOriginalResponse()); } } private static IRequestHandler createRequestHandler(Class? extends Page? pageClass, PageParameters params) { return new RenderPageRequestHandler(new PageProvider(pageClass, params)); } } } so in test tester.startPage(ValidationPage.class, pageParameters); tester.assertRenderedPage(MyOtherPage.class); final Cookie[] cookies = tester.getRequest().getCookies(); assertNotNull(cookies); - fail and I get null, I tried Reponse object but no luck. I thought cookies should be resend in next request back to server right? pozdrawiam Paweł Kamiński kami...@gmail.com pkaminski@gmail.com __ - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org -- Martin Grigorov jWeekend Training, Consulting, Development http://jWeekend.com - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
unit testing cookies after redirect
hej, I ve found this http://apache-wicket.1842946.n4.nabble.com/Wickettester-cookies-and-redirects-in-Wicket-1-4-15-td3250792.html but im developing on 1.5.2 and ticket is closed. I believe it is the same case. this is description: I have a page ValidationPage that accepts request, checks parameters and sets cookie on response object ((WebResponse)getRequestCycle().getResponse()).addCookie(new Cookie(mycookie, VAL)); then on certain condition I want to redirect to original destination or to some set page if (!continueToOriginalDestination()) { log.warning(redirect failed redirecting to original destination); throw new RestartResponseException(new MyOtherPage()); } so in test tester.startPage(ValidationPage.class, pageParameters); tester.assertRenderedPage(MyOtherPage.class); final Cookie[] cookies = tester.getRequest().getCookies(); assertNotNull(cookies); - fail and I get null, I tried Reponse object but no luck. I thought cookies should be resend in next request back to server right? pozdrawiam Paweł Kamiński kami...@gmail.com pkaminski@gmail.com __ - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org