You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Alec Swan <al...@gmail.com> on 2012/06/06 19:09:05 UTC

Exception handling and testing

Hello,

I am creating a new set of pages that are a part of an old project but
have a different home page. It's kind of like a sub-site within a
site. The user is required to log in on the sub-site's home page to be
able to access any of those pages. If the user tries to access any of
these pages directly he should be redirected to the sub-site's home
page.

What's the best way to implement/configure the home page for this sub-site?
What kind of exception should each sub-site page throw to trigger
redirection to home page?
How can I verify that an exception was thrown in my test? (Currently I
have a test which calls startPanel(..) which logs an exception if the
user is not logged in, but returns with no errors. So, I have to
verify that the rendered page is what it should be.)

I am basically looking for best practices here.

Thanks,

Alec

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


Re: Exception handling and testing

Posted by Alec Swan <al...@gmail.com>.
Thanks, works great.

I just needed to convert IRequestParameters to PageParameters in
RequestHandler#onException() in order to "remember" the tab selection
made by the user throughout login. Is there a convenience method
somewhere in wicket to convert between IRequestParameters and
PageParameters?

Thanks,

Ale

On Thu, Sep 27, 2012 at 1:18 AM, Martin Grigorov <mg...@apache.org> wrote:
> Make the TabbedPanel stateless by using BookmarkablePageLink.
>
> P.S. Please start a new thread when you have new questions.
>
> On Wed, Sep 26, 2012 at 10:56 PM, Alec Swan <al...@gmail.com> wrote:
>> Thanks, that worked as advertised. Now I am wondering if it's possible
>> to get this to work when the user click on a tab in TabbedPanel?
>> RenderPageRequestHandler(new PageProvider(HomePage.class),
>> ALWAYS_REDIRECT) seems to lose the knowledge of the tab selected by
>> the user and redirects the user to the default tab after he logs in on
>> HomePage.
>>
>> Thoughts?
>>
>> Thanks,
>>
>> Alec
>>
>> On Wed, Sep 26, 2012 at 12:52 AM, Martin Grigorov <mg...@apache.org> wrote:
>>> You have to return a IRequestHandler. See RenderPageRequestHandler
>>>
>>> On Wed, Sep 26, 2012 at 1:45 AM, Alec Swan <al...@gmail.com> wrote:
>>>> I am trying to implement Martin's @SubSite annotation approach to
>>>> redirect the user to the sub-site's home page when
>>>> AuthenticationException is thrown in Wicket 1.5. However, apparently I
>>>> cannot throw a RestartResponseAtInterceptPageException(annotation.homePage())
>>>> from AbstractRequestCycleListener#onException. How else can I redirect
>>>> the user to the sub-site login page?
>>>>
>>>> The following RCH causes a 500 HTTP error page to be shown in the
>>>> browser when AuthenticationException is thrown.
>>>>
>>>> public class AuthenticationExceptionRequestCycleHandler extends
>>>> AbstractRequestCycleListener
>>>> {
>>>>     @Override
>>>>     public IRequestHandler onException(RequestCycle cycle, Exception ex) {
>>>>         if (ex instanceof WicketRuntimeException &&
>>>> ex.getCause().getCause() instanceof AuthenticationException) {
>>>>             IPageRequestHandler lastHandler =
>>>> PageRequestHandlerTracker.getLastHandler(cycle);
>>>>             Class<? extends IRequestablePage> pageClass = lastHandler
>>>> == null ? null : lastHandler.getPageClass();
>>>>             if (pageClass != null) {
>>>>                 SubSite annotation = pageClass.getAnnotation(SubSite.class);
>>>>                 if (annotation != null && annotation.homePage() != null) {
>>>>                     throw new
>>>> RestartResponseAtInterceptPageException(annotation.homePage());
>>>>                 }
>>>>             }
>>>>         }
>>>>         return super.onException(cycle, ex);
>>>>     }
>>>> }
>>>>
>>>> Thanks,
>>>>
>>>> Alec
>>>>
>>>> On Fri, Jun 8, 2012 at 2:54 PM, Alec Swan <al...@gmail.com> wrote:
>>>>> I also use this approach, but with authentication exceptions thrown by
>>>>> Wicket it's hard to tell if the user was redirected to Login page
>>>>> because of authentication or some other exceptions.
>>>>>
>>>>> On Fri, Jun 8, 2012 at 1:15 PM, Michal Margiel <mi...@gmail.com> wrote:
>>>>>> 2012/6/8 Alec Swan <al...@gmail.com>
>>>>>>
>>>>>>> That's clever. I will give it a try.
>>>>>>>
>>>>>>> What is the recommendation on verifying that an exception was thrown
>>>>>>> during page rendering using Wicket tester? I am not talking just about
>>>>>>> authentication here, but exceptions in general.
>>>>>>>
>>>>>>>
>>>>>> Hello,
>>>>>> Why you want to verify that exception was thrown in WicketTester? IMHO it
>>>>>> is not proper place to check that.
>>>>>> In my code I am verifying expcetions in services tests using
>>>>>> catch-exception library [1].
>>>>>>
>>>>>> And then while testing Page I am mocking my service to throw exception and
>>>>>> I am verifying behaviour on exception (e.g. redirecting to login page,
>>>>>> showing error message etc...)
>>>>>>
>>>>>> That makes not only clearer code but also simplify testing.
>>>>>> you can see example of services tests in [2] and page tests in [3]
>>>>>>
>>>>>> [1] http://code.google.com/p/catch-exception/
>>>>>> [2]
>>>>>> https://bitbucket.org/margielm/confitura/src/8599eae2ba00/src/test/java/jelatyna/services/UserServiceImplShould.java
>>>>>> [3]
>>>>>> https://bitbucket.org/margielm/confitura/src/8599eae2ba00/src/test/java/jelatyna/pages/admin/login/LoginPageShould.java
>>>>>> --
>>>>>> Pozdrawiam/Best regards
>>>>>> Michał Margiel
>>>>>>
>>>>>> http://www.confitura.pl (dawniej Javarsovia)
>>>>>> http://www.linkedin.com/in/MichalMargiel
>>>>>> http://www.margiel.eu
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>
>>>
>>>
>>>
>>> --
>>> Martin Grigorov
>>> jWeekend
>>> Training, Consulting, Development
>>> http://jWeekend.com
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>
>
>
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com
>
> ---------------------------------------------------------------------
> 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: Exception handling and testing

Posted by Martin Grigorov <mg...@apache.org>.
Make the TabbedPanel stateless by using BookmarkablePageLink.

P.S. Please start a new thread when you have new questions.

On Wed, Sep 26, 2012 at 10:56 PM, Alec Swan <al...@gmail.com> wrote:
> Thanks, that worked as advertised. Now I am wondering if it's possible
> to get this to work when the user click on a tab in TabbedPanel?
> RenderPageRequestHandler(new PageProvider(HomePage.class),
> ALWAYS_REDIRECT) seems to lose the knowledge of the tab selected by
> the user and redirects the user to the default tab after he logs in on
> HomePage.
>
> Thoughts?
>
> Thanks,
>
> Alec
>
> On Wed, Sep 26, 2012 at 12:52 AM, Martin Grigorov <mg...@apache.org> wrote:
>> You have to return a IRequestHandler. See RenderPageRequestHandler
>>
>> On Wed, Sep 26, 2012 at 1:45 AM, Alec Swan <al...@gmail.com> wrote:
>>> I am trying to implement Martin's @SubSite annotation approach to
>>> redirect the user to the sub-site's home page when
>>> AuthenticationException is thrown in Wicket 1.5. However, apparently I
>>> cannot throw a RestartResponseAtInterceptPageException(annotation.homePage())
>>> from AbstractRequestCycleListener#onException. How else can I redirect
>>> the user to the sub-site login page?
>>>
>>> The following RCH causes a 500 HTTP error page to be shown in the
>>> browser when AuthenticationException is thrown.
>>>
>>> public class AuthenticationExceptionRequestCycleHandler extends
>>> AbstractRequestCycleListener
>>> {
>>>     @Override
>>>     public IRequestHandler onException(RequestCycle cycle, Exception ex) {
>>>         if (ex instanceof WicketRuntimeException &&
>>> ex.getCause().getCause() instanceof AuthenticationException) {
>>>             IPageRequestHandler lastHandler =
>>> PageRequestHandlerTracker.getLastHandler(cycle);
>>>             Class<? extends IRequestablePage> pageClass = lastHandler
>>> == null ? null : lastHandler.getPageClass();
>>>             if (pageClass != null) {
>>>                 SubSite annotation = pageClass.getAnnotation(SubSite.class);
>>>                 if (annotation != null && annotation.homePage() != null) {
>>>                     throw new
>>> RestartResponseAtInterceptPageException(annotation.homePage());
>>>                 }
>>>             }
>>>         }
>>>         return super.onException(cycle, ex);
>>>     }
>>> }
>>>
>>> Thanks,
>>>
>>> Alec
>>>
>>> On Fri, Jun 8, 2012 at 2:54 PM, Alec Swan <al...@gmail.com> wrote:
>>>> I also use this approach, but with authentication exceptions thrown by
>>>> Wicket it's hard to tell if the user was redirected to Login page
>>>> because of authentication or some other exceptions.
>>>>
>>>> On Fri, Jun 8, 2012 at 1:15 PM, Michal Margiel <mi...@gmail.com> wrote:
>>>>> 2012/6/8 Alec Swan <al...@gmail.com>
>>>>>
>>>>>> That's clever. I will give it a try.
>>>>>>
>>>>>> What is the recommendation on verifying that an exception was thrown
>>>>>> during page rendering using Wicket tester? I am not talking just about
>>>>>> authentication here, but exceptions in general.
>>>>>>
>>>>>>
>>>>> Hello,
>>>>> Why you want to verify that exception was thrown in WicketTester? IMHO it
>>>>> is not proper place to check that.
>>>>> In my code I am verifying expcetions in services tests using
>>>>> catch-exception library [1].
>>>>>
>>>>> And then while testing Page I am mocking my service to throw exception and
>>>>> I am verifying behaviour on exception (e.g. redirecting to login page,
>>>>> showing error message etc...)
>>>>>
>>>>> That makes not only clearer code but also simplify testing.
>>>>> you can see example of services tests in [2] and page tests in [3]
>>>>>
>>>>> [1] http://code.google.com/p/catch-exception/
>>>>> [2]
>>>>> https://bitbucket.org/margielm/confitura/src/8599eae2ba00/src/test/java/jelatyna/services/UserServiceImplShould.java
>>>>> [3]
>>>>> https://bitbucket.org/margielm/confitura/src/8599eae2ba00/src/test/java/jelatyna/pages/admin/login/LoginPageShould.java
>>>>> --
>>>>> Pozdrawiam/Best regards
>>>>> Michał Margiel
>>>>>
>>>>> http://www.confitura.pl (dawniej Javarsovia)
>>>>> http://www.linkedin.com/in/MichalMargiel
>>>>> http://www.margiel.eu
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>
>>
>>
>> --
>> Martin Grigorov
>> jWeekend
>> Training, Consulting, Development
>> http://jWeekend.com
>>
>> ---------------------------------------------------------------------
>> 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
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

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


Re: Exception handling and testing

Posted by Alec Swan <al...@gmail.com>.
Thanks, that worked as advertised. Now I am wondering if it's possible
to get this to work when the user click on a tab in TabbedPanel?
RenderPageRequestHandler(new PageProvider(HomePage.class),
ALWAYS_REDIRECT) seems to lose the knowledge of the tab selected by
the user and redirects the user to the default tab after he logs in on
HomePage.

Thoughts?

Thanks,

Alec

On Wed, Sep 26, 2012 at 12:52 AM, Martin Grigorov <mg...@apache.org> wrote:
> You have to return a IRequestHandler. See RenderPageRequestHandler
>
> On Wed, Sep 26, 2012 at 1:45 AM, Alec Swan <al...@gmail.com> wrote:
>> I am trying to implement Martin's @SubSite annotation approach to
>> redirect the user to the sub-site's home page when
>> AuthenticationException is thrown in Wicket 1.5. However, apparently I
>> cannot throw a RestartResponseAtInterceptPageException(annotation.homePage())
>> from AbstractRequestCycleListener#onException. How else can I redirect
>> the user to the sub-site login page?
>>
>> The following RCH causes a 500 HTTP error page to be shown in the
>> browser when AuthenticationException is thrown.
>>
>> public class AuthenticationExceptionRequestCycleHandler extends
>> AbstractRequestCycleListener
>> {
>>     @Override
>>     public IRequestHandler onException(RequestCycle cycle, Exception ex) {
>>         if (ex instanceof WicketRuntimeException &&
>> ex.getCause().getCause() instanceof AuthenticationException) {
>>             IPageRequestHandler lastHandler =
>> PageRequestHandlerTracker.getLastHandler(cycle);
>>             Class<? extends IRequestablePage> pageClass = lastHandler
>> == null ? null : lastHandler.getPageClass();
>>             if (pageClass != null) {
>>                 SubSite annotation = pageClass.getAnnotation(SubSite.class);
>>                 if (annotation != null && annotation.homePage() != null) {
>>                     throw new
>> RestartResponseAtInterceptPageException(annotation.homePage());
>>                 }
>>             }
>>         }
>>         return super.onException(cycle, ex);
>>     }
>> }
>>
>> Thanks,
>>
>> Alec
>>
>> On Fri, Jun 8, 2012 at 2:54 PM, Alec Swan <al...@gmail.com> wrote:
>>> I also use this approach, but with authentication exceptions thrown by
>>> Wicket it's hard to tell if the user was redirected to Login page
>>> because of authentication or some other exceptions.
>>>
>>> On Fri, Jun 8, 2012 at 1:15 PM, Michal Margiel <mi...@gmail.com> wrote:
>>>> 2012/6/8 Alec Swan <al...@gmail.com>
>>>>
>>>>> That's clever. I will give it a try.
>>>>>
>>>>> What is the recommendation on verifying that an exception was thrown
>>>>> during page rendering using Wicket tester? I am not talking just about
>>>>> authentication here, but exceptions in general.
>>>>>
>>>>>
>>>> Hello,
>>>> Why you want to verify that exception was thrown in WicketTester? IMHO it
>>>> is not proper place to check that.
>>>> In my code I am verifying expcetions in services tests using
>>>> catch-exception library [1].
>>>>
>>>> And then while testing Page I am mocking my service to throw exception and
>>>> I am verifying behaviour on exception (e.g. redirecting to login page,
>>>> showing error message etc...)
>>>>
>>>> That makes not only clearer code but also simplify testing.
>>>> you can see example of services tests in [2] and page tests in [3]
>>>>
>>>> [1] http://code.google.com/p/catch-exception/
>>>> [2]
>>>> https://bitbucket.org/margielm/confitura/src/8599eae2ba00/src/test/java/jelatyna/services/UserServiceImplShould.java
>>>> [3]
>>>> https://bitbucket.org/margielm/confitura/src/8599eae2ba00/src/test/java/jelatyna/pages/admin/login/LoginPageShould.java
>>>> --
>>>> Pozdrawiam/Best regards
>>>> Michał Margiel
>>>>
>>>> http://www.confitura.pl (dawniej Javarsovia)
>>>> http://www.linkedin.com/in/MichalMargiel
>>>> http://www.margiel.eu
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>
>
>
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com
>
> ---------------------------------------------------------------------
> 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: Exception handling and testing

Posted by Martin Grigorov <mg...@apache.org>.
You have to return a IRequestHandler. See RenderPageRequestHandler

On Wed, Sep 26, 2012 at 1:45 AM, Alec Swan <al...@gmail.com> wrote:
> I am trying to implement Martin's @SubSite annotation approach to
> redirect the user to the sub-site's home page when
> AuthenticationException is thrown in Wicket 1.5. However, apparently I
> cannot throw a RestartResponseAtInterceptPageException(annotation.homePage())
> from AbstractRequestCycleListener#onException. How else can I redirect
> the user to the sub-site login page?
>
> The following RCH causes a 500 HTTP error page to be shown in the
> browser when AuthenticationException is thrown.
>
> public class AuthenticationExceptionRequestCycleHandler extends
> AbstractRequestCycleListener
> {
>     @Override
>     public IRequestHandler onException(RequestCycle cycle, Exception ex) {
>         if (ex instanceof WicketRuntimeException &&
> ex.getCause().getCause() instanceof AuthenticationException) {
>             IPageRequestHandler lastHandler =
> PageRequestHandlerTracker.getLastHandler(cycle);
>             Class<? extends IRequestablePage> pageClass = lastHandler
> == null ? null : lastHandler.getPageClass();
>             if (pageClass != null) {
>                 SubSite annotation = pageClass.getAnnotation(SubSite.class);
>                 if (annotation != null && annotation.homePage() != null) {
>                     throw new
> RestartResponseAtInterceptPageException(annotation.homePage());
>                 }
>             }
>         }
>         return super.onException(cycle, ex);
>     }
> }
>
> Thanks,
>
> Alec
>
> On Fri, Jun 8, 2012 at 2:54 PM, Alec Swan <al...@gmail.com> wrote:
>> I also use this approach, but with authentication exceptions thrown by
>> Wicket it's hard to tell if the user was redirected to Login page
>> because of authentication or some other exceptions.
>>
>> On Fri, Jun 8, 2012 at 1:15 PM, Michal Margiel <mi...@gmail.com> wrote:
>>> 2012/6/8 Alec Swan <al...@gmail.com>
>>>
>>>> That's clever. I will give it a try.
>>>>
>>>> What is the recommendation on verifying that an exception was thrown
>>>> during page rendering using Wicket tester? I am not talking just about
>>>> authentication here, but exceptions in general.
>>>>
>>>>
>>> Hello,
>>> Why you want to verify that exception was thrown in WicketTester? IMHO it
>>> is not proper place to check that.
>>> In my code I am verifying expcetions in services tests using
>>> catch-exception library [1].
>>>
>>> And then while testing Page I am mocking my service to throw exception and
>>> I am verifying behaviour on exception (e.g. redirecting to login page,
>>> showing error message etc...)
>>>
>>> That makes not only clearer code but also simplify testing.
>>> you can see example of services tests in [2] and page tests in [3]
>>>
>>> [1] http://code.google.com/p/catch-exception/
>>> [2]
>>> https://bitbucket.org/margielm/confitura/src/8599eae2ba00/src/test/java/jelatyna/services/UserServiceImplShould.java
>>> [3]
>>> https://bitbucket.org/margielm/confitura/src/8599eae2ba00/src/test/java/jelatyna/pages/admin/login/LoginPageShould.java
>>> --
>>> Pozdrawiam/Best regards
>>> Michał Margiel
>>>
>>> http://www.confitura.pl (dawniej Javarsovia)
>>> http://www.linkedin.com/in/MichalMargiel
>>> http://www.margiel.eu
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

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


Re: Exception handling and testing

Posted by Alec Swan <al...@gmail.com>.
I am trying to implement Martin's @SubSite annotation approach to
redirect the user to the sub-site's home page when
AuthenticationException is thrown in Wicket 1.5. However, apparently I
cannot throw a RestartResponseAtInterceptPageException(annotation.homePage())
from AbstractRequestCycleListener#onException. How else can I redirect
the user to the sub-site login page?

The following RCH causes a 500 HTTP error page to be shown in the
browser when AuthenticationException is thrown.

public class AuthenticationExceptionRequestCycleHandler extends
AbstractRequestCycleListener
{
    @Override
    public IRequestHandler onException(RequestCycle cycle, Exception ex) {
        if (ex instanceof WicketRuntimeException &&
ex.getCause().getCause() instanceof AuthenticationException) {
            IPageRequestHandler lastHandler =
PageRequestHandlerTracker.getLastHandler(cycle);
            Class<? extends IRequestablePage> pageClass = lastHandler
== null ? null : lastHandler.getPageClass();
            if (pageClass != null) {
                SubSite annotation = pageClass.getAnnotation(SubSite.class);
                if (annotation != null && annotation.homePage() != null) {
                    throw new
RestartResponseAtInterceptPageException(annotation.homePage());
                }
            }
        }
        return super.onException(cycle, ex);
    }
}

Thanks,

Alec

On Fri, Jun 8, 2012 at 2:54 PM, Alec Swan <al...@gmail.com> wrote:
> I also use this approach, but with authentication exceptions thrown by
> Wicket it's hard to tell if the user was redirected to Login page
> because of authentication or some other exceptions.
>
> On Fri, Jun 8, 2012 at 1:15 PM, Michal Margiel <mi...@gmail.com> wrote:
>> 2012/6/8 Alec Swan <al...@gmail.com>
>>
>>> That's clever. I will give it a try.
>>>
>>> What is the recommendation on verifying that an exception was thrown
>>> during page rendering using Wicket tester? I am not talking just about
>>> authentication here, but exceptions in general.
>>>
>>>
>> Hello,
>> Why you want to verify that exception was thrown in WicketTester? IMHO it
>> is not proper place to check that.
>> In my code I am verifying expcetions in services tests using
>> catch-exception library [1].
>>
>> And then while testing Page I am mocking my service to throw exception and
>> I am verifying behaviour on exception (e.g. redirecting to login page,
>> showing error message etc...)
>>
>> That makes not only clearer code but also simplify testing.
>> you can see example of services tests in [2] and page tests in [3]
>>
>> [1] http://code.google.com/p/catch-exception/
>> [2]
>> https://bitbucket.org/margielm/confitura/src/8599eae2ba00/src/test/java/jelatyna/services/UserServiceImplShould.java
>> [3]
>> https://bitbucket.org/margielm/confitura/src/8599eae2ba00/src/test/java/jelatyna/pages/admin/login/LoginPageShould.java
>> --
>> Pozdrawiam/Best regards
>> Michał Margiel
>>
>> http://www.confitura.pl (dawniej Javarsovia)
>> http://www.linkedin.com/in/MichalMargiel
>> http://www.margiel.eu

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


Re: Exception handling and testing

Posted by Alec Swan <al...@gmail.com>.
I also use this approach, but with authentication exceptions thrown by
Wicket it's hard to tell if the user was redirected to Login page
because of authentication or some other exceptions.

On Fri, Jun 8, 2012 at 1:15 PM, Michal Margiel <mi...@gmail.com> wrote:
> 2012/6/8 Alec Swan <al...@gmail.com>
>
>> That's clever. I will give it a try.
>>
>> What is the recommendation on verifying that an exception was thrown
>> during page rendering using Wicket tester? I am not talking just about
>> authentication here, but exceptions in general.
>>
>>
> Hello,
> Why you want to verify that exception was thrown in WicketTester? IMHO it
> is not proper place to check that.
> In my code I am verifying expcetions in services tests using
> catch-exception library [1].
>
> And then while testing Page I am mocking my service to throw exception and
> I am verifying behaviour on exception (e.g. redirecting to login page,
> showing error message etc...)
>
> That makes not only clearer code but also simplify testing.
> you can see example of services tests in [2] and page tests in [3]
>
> [1] http://code.google.com/p/catch-exception/
> [2]
> https://bitbucket.org/margielm/confitura/src/8599eae2ba00/src/test/java/jelatyna/services/UserServiceImplShould.java
> [3]
> https://bitbucket.org/margielm/confitura/src/8599eae2ba00/src/test/java/jelatyna/pages/admin/login/LoginPageShould.java
> --
> Pozdrawiam/Best regards
> Michał Margiel
>
> http://www.confitura.pl (dawniej Javarsovia)
> http://www.linkedin.com/in/MichalMargiel
> http://www.margiel.eu

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


Re: Exception handling and testing

Posted by Michal Margiel <mi...@gmail.com>.
2012/6/8 Alec Swan <al...@gmail.com>

> That's clever. I will give it a try.
>
> What is the recommendation on verifying that an exception was thrown
> during page rendering using Wicket tester? I am not talking just about
> authentication here, but exceptions in general.
>
>
Hello,
Why you want to verify that exception was thrown in WicketTester? IMHO it
is not proper place to check that.
In my code I am verifying expcetions in services tests using
catch-exception library [1].

And then while testing Page I am mocking my service to throw exception and
I am verifying behaviour on exception (e.g. redirecting to login page,
showing error message etc...)

That makes not only clearer code but also simplify testing.
you can see example of services tests in [2] and page tests in [3]

[1] http://code.google.com/p/catch-exception/
[2]
https://bitbucket.org/margielm/confitura/src/8599eae2ba00/src/test/java/jelatyna/services/UserServiceImplShould.java
[3]
https://bitbucket.org/margielm/confitura/src/8599eae2ba00/src/test/java/jelatyna/pages/admin/login/LoginPageShould.java
-- 
Pozdrawiam/Best regards
Michał Margiel

http://www.confitura.pl (dawniej Javarsovia)
http://www.linkedin.com/in/MichalMargiel
http://www.margiel.eu

Re: Exception handling and testing

Posted by Alec Swan <al...@gmail.com>.
That's clever. I will give it a try.

What is the recommendation on verifying that an exception was thrown
during page rendering using Wicket tester? I am not talking just about
authentication here, but exceptions in general.

Thanks,

Alec

On Thu, Jun 7, 2012 at 6:18 PM, Martin Grigorov <mg...@apache.org> wrote:
> On Fri, Jun 8, 2012 at 12:37 AM, Alec Swan <al...@gmail.com> wrote:
>> I am also asking how to redirect to sub-site's home page when the user
>> is not authenticated and tries to access on of those sub-site pages.
>
> Use a custom IAuthenticationStrategy that knows which pages are part
> of this sub-site (e.g. you can annotate them with a special @SubSite)
> and
> if the user is not logged in then redirect to @SubSite.homePage class.
> This way even every page can it have its own home page.
>
>>
>> On Thu, Jun 7, 2012 at 3:35 PM, Alec Swan <al...@gmail.com> wrote:
>>> The problem is that I cannot verify this exception in tests. I am
>>> basically asking for best practices.
>>>
>>> Thanks!
>>>
>>> On Thu, Jun 7, 2012 at 1:30 AM, Martin Grigorov <mg...@apache.org> wrote:
>>>> Hi,
>>>>
>>>> You can use IAuthenticationStrategy and throw
>>>> RestartResponseAtInterceptException.
>>>>
>>>> On Wed, Jun 6, 2012 at 8:09 PM, Alec Swan <al...@gmail.com> wrote:
>>>>> Hello,
>>>>>
>>>>> I am creating a new set of pages that are a part of an old project but
>>>>> have a different home page. It's kind of like a sub-site within a
>>>>> site. The user is required to log in on the sub-site's home page to be
>>>>> able to access any of those pages. If the user tries to access any of
>>>>> these pages directly he should be redirected to the sub-site's home
>>>>> page.
>>>>>
>>>>> What's the best way to implement/configure the home page for this sub-site?
>>>>> What kind of exception should each sub-site page throw to trigger
>>>>> redirection to home page?
>>>>> How can I verify that an exception was thrown in my test? (Currently I
>>>>> have a test which calls startPanel(..) which logs an exception if the
>>>>> user is not logged in, but returns with no errors. So, I have to
>>>>> verify that the rendered page is what it should be.)
>>>>>
>>>>> I am basically looking for best practices here.
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Alec
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Martin Grigorov
>>>> jWeekend
>>>> Training, Consulting, Development
>>>> http://jWeekend.com
>>>>
>>>> ---------------------------------------------------------------------
>>>> 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
>>
>
>
>
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com
>
> ---------------------------------------------------------------------
> 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: Exception handling and testing

Posted by Martin Grigorov <mg...@apache.org>.
On Fri, Jun 8, 2012 at 12:37 AM, Alec Swan <al...@gmail.com> wrote:
> I am also asking how to redirect to sub-site's home page when the user
> is not authenticated and tries to access on of those sub-site pages.

Use a custom IAuthenticationStrategy that knows which pages are part
of this sub-site (e.g. you can annotate them with a special @SubSite)
and
if the user is not logged in then redirect to @SubSite.homePage class.
This way even every page can it have its own home page.

>
> On Thu, Jun 7, 2012 at 3:35 PM, Alec Swan <al...@gmail.com> wrote:
>> The problem is that I cannot verify this exception in tests. I am
>> basically asking for best practices.
>>
>> Thanks!
>>
>> On Thu, Jun 7, 2012 at 1:30 AM, Martin Grigorov <mg...@apache.org> wrote:
>>> Hi,
>>>
>>> You can use IAuthenticationStrategy and throw
>>> RestartResponseAtInterceptException.
>>>
>>> On Wed, Jun 6, 2012 at 8:09 PM, Alec Swan <al...@gmail.com> wrote:
>>>> Hello,
>>>>
>>>> I am creating a new set of pages that are a part of an old project but
>>>> have a different home page. It's kind of like a sub-site within a
>>>> site. The user is required to log in on the sub-site's home page to be
>>>> able to access any of those pages. If the user tries to access any of
>>>> these pages directly he should be redirected to the sub-site's home
>>>> page.
>>>>
>>>> What's the best way to implement/configure the home page for this sub-site?
>>>> What kind of exception should each sub-site page throw to trigger
>>>> redirection to home page?
>>>> How can I verify that an exception was thrown in my test? (Currently I
>>>> have a test which calls startPanel(..) which logs an exception if the
>>>> user is not logged in, but returns with no errors. So, I have to
>>>> verify that the rendered page is what it should be.)
>>>>
>>>> I am basically looking for best practices here.
>>>>
>>>> Thanks,
>>>>
>>>> Alec
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>
>>>
>>>
>>>
>>> --
>>> Martin Grigorov
>>> jWeekend
>>> Training, Consulting, Development
>>> http://jWeekend.com
>>>
>>> ---------------------------------------------------------------------
>>> 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
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

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


Re: Exception handling and testing

Posted by Alec Swan <al...@gmail.com>.
I am also asking how to redirect to sub-site's home page when the user
is not authenticated and tries to access on of those sub-site pages.

On Thu, Jun 7, 2012 at 3:35 PM, Alec Swan <al...@gmail.com> wrote:
> The problem is that I cannot verify this exception in tests. I am
> basically asking for best practices.
>
> Thanks!
>
> On Thu, Jun 7, 2012 at 1:30 AM, Martin Grigorov <mg...@apache.org> wrote:
>> Hi,
>>
>> You can use IAuthenticationStrategy and throw
>> RestartResponseAtInterceptException.
>>
>> On Wed, Jun 6, 2012 at 8:09 PM, Alec Swan <al...@gmail.com> wrote:
>>> Hello,
>>>
>>> I am creating a new set of pages that are a part of an old project but
>>> have a different home page. It's kind of like a sub-site within a
>>> site. The user is required to log in on the sub-site's home page to be
>>> able to access any of those pages. If the user tries to access any of
>>> these pages directly he should be redirected to the sub-site's home
>>> page.
>>>
>>> What's the best way to implement/configure the home page for this sub-site?
>>> What kind of exception should each sub-site page throw to trigger
>>> redirection to home page?
>>> How can I verify that an exception was thrown in my test? (Currently I
>>> have a test which calls startPanel(..) which logs an exception if the
>>> user is not logged in, but returns with no errors. So, I have to
>>> verify that the rendered page is what it should be.)
>>>
>>> I am basically looking for best practices here.
>>>
>>> Thanks,
>>>
>>> Alec
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>
>>
>>
>> --
>> Martin Grigorov
>> jWeekend
>> Training, Consulting, Development
>> http://jWeekend.com
>>
>> ---------------------------------------------------------------------
>> 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: Exception handling and testing

Posted by Alec Swan <al...@gmail.com>.
The problem is that I cannot verify this exception in tests. I am
basically asking for best practices.

Thanks!

On Thu, Jun 7, 2012 at 1:30 AM, Martin Grigorov <mg...@apache.org> wrote:
> Hi,
>
> You can use IAuthenticationStrategy and throw
> RestartResponseAtInterceptException.
>
> On Wed, Jun 6, 2012 at 8:09 PM, Alec Swan <al...@gmail.com> wrote:
>> Hello,
>>
>> I am creating a new set of pages that are a part of an old project but
>> have a different home page. It's kind of like a sub-site within a
>> site. The user is required to log in on the sub-site's home page to be
>> able to access any of those pages. If the user tries to access any of
>> these pages directly he should be redirected to the sub-site's home
>> page.
>>
>> What's the best way to implement/configure the home page for this sub-site?
>> What kind of exception should each sub-site page throw to trigger
>> redirection to home page?
>> How can I verify that an exception was thrown in my test? (Currently I
>> have a test which calls startPanel(..) which logs an exception if the
>> user is not logged in, but returns with no errors. So, I have to
>> verify that the rendered page is what it should be.)
>>
>> I am basically looking for best practices here.
>>
>> Thanks,
>>
>> Alec
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>
>
>
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com
>
> ---------------------------------------------------------------------
> 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: Exception handling and testing

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

You can use IAuthenticationStrategy and throw
RestartResponseAtInterceptException.

On Wed, Jun 6, 2012 at 8:09 PM, Alec Swan <al...@gmail.com> wrote:
> Hello,
>
> I am creating a new set of pages that are a part of an old project but
> have a different home page. It's kind of like a sub-site within a
> site. The user is required to log in on the sub-site's home page to be
> able to access any of those pages. If the user tries to access any of
> these pages directly he should be redirected to the sub-site's home
> page.
>
> What's the best way to implement/configure the home page for this sub-site?
> What kind of exception should each sub-site page throw to trigger
> redirection to home page?
> How can I verify that an exception was thrown in my test? (Currently I
> have a test which calls startPanel(..) which logs an exception if the
> user is not logged in, but returns with no errors. So, I have to
> verify that the rendered page is what it should be.)
>
> I am basically looking for best practices here.
>
> Thanks,
>
> Alec
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

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