You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Nick Pratt <nb...@gmail.com> on 2014/10/30 21:08:10 UTC

Unit testing RadioChoice with AjaxFormComponentUpdatingBehavior

Wicket 6.17.0

I have a RadioChoice (in a Form) that has an attached
AjaxFormComponentUpdatingBehavior.

The onUpdate() method of the Behavior fires an event for other components
on the page to update (change visibility depending on user selection in
radio choice).

Im trying to unit test it using:

formTester.selectRadioChoice( "propertyType", 2 );

and then I'm trying to trigger the behavior to fire so that I can
check that the various components are visible/invisible:

Component component = baseTester.getComponentFromLastRenderedPage(
"form:propertyType" );
for ( Behavior b : component.getBehaviors() )
{
   if ( b instanceof AjaxFormComponentUpdatingBehavior )
   {
      baseTester.executeBehavior( (AbstractAjaxBehavior) b );
   }
}

However, I'm running in to this when the behavior is executed:

org.apache.wicket.core.request.handler.ListenerInvocationNotAllowedException:
Behavior rejected interface invocation.

Is it possible to unit test this specific behavior, and am I going
about this the right way?

I've verified that the application works as expected in a browser.

Re: Unit testing RadioChoice with AjaxFormComponentUpdatingBehavior

Posted by Nick Pratt <nb...@gmail.com>.
That was a typo - apologies.  I'm using a
AjaxFormChoiceComponentUpdatingBehavior

As for the tester, its the EnhancedFormTester - its a thin wrapper that
invokes: formTester.select( path, index ); (where formTester is the Wicket
FormTester)

On Thu, Oct 30, 2014 at 4:27 PM, Andrea Del Bene <an...@gmail.com>
wrote:

> On 30/10/14 21:08, Nick Pratt wrote:
>
>> Wicket 6.17.0
>>
>> I have a RadioChoice (in a Form) that has an attached
>> AjaxFormComponentUpdatingBehavior.
>>
>> The onUpdate() method of the Behavior fires an event for other components
>> on the page to update (change visibility depending on user selection in
>> radio choice).
>>
>> Im trying to unit test it using:
>>
>> formTester.selectRadioChoice( "propertyType", 2 );
>>
> I guess that's a typo :) or are you using a custom formTester?
>
>>
>> and then I'm trying to trigger the behavior to fire so that I can
>> check that the various components are visible/invisible:
>>
>> Component component = baseTester.getComponentFromLastRenderedPage(
>> "form:propertyType" );
>> for ( Behavior b : component.getBehaviors() )
>> {
>>     if ( b instanceof AjaxFormComponentUpdatingBehavior )
>>     {
>>        baseTester.executeBehavior( (AbstractAjaxBehavior) b );
>>     }
>> }
>>
>> However, I'm running in to this when the behavior is executed:
>>
>> org.apache.wicket.core.request.handler.ListenerInvocationNotAllowedEx
>> ception:
>> Behavior rejected interface invocation.
>>
>> Is it possible to unit test this specific behavior, and am I going
>> about this the right way?
>>
>> I've verified that the application works as expected in a browser.
>>
> BTW, multiple-choice component should use AjaxFormChoiceComponentUpdatingBehavior
> instead of AjaxFormComponentUpdatingBehavior.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Unit testing RadioChoice with AjaxFormComponentUpdatingBehavior

Posted by Nick Pratt <nb...@gmail.com>.
I reproduced this in a simple quickstart using this unit test:

@Test
public void testAjaxEventFired() throws Exception
{
   HomePage homePage = new HomePage( new PageParameters() );
   tester.startPage( homePage );

   FormTester formTester = tester.newFormTester( "form" );
   formTester.select( "radioChoice", 2 );

   Component component = tester.getComponentFromLastRenderedPage(
"form:radioChoice" );
   List<? extends Behavior> behaviors = component.getBehaviors();
   for( Behavior behavior : behaviors )
   {
      if( behavior instanceof AjaxFormChoiceComponentUpdatingBehavior )
      {
         AjaxFormChoiceComponentUpdatingBehavior afccub =
(AjaxFormChoiceComponentUpdatingBehavior) behavior;
         tester.executeBehavior( afccub );
      }
   }

   assertEquals( true, homePage.eventFired );
   assertEquals( "C", homePage.chosen );
}


This is working as expected.  HomePage has a RadioChoice with a
List<String> of choices, A,B,C,D,E.


There must be something in our application that's causing the
invocation to be rejected which Ill dig in to.


On Thu, Oct 30, 2014 at 4:27 PM, Andrea Del Bene <an...@gmail.com>
wrote:

> On 30/10/14 21:08, Nick Pratt wrote:
>
>> Wicket 6.17.0
>>
>> I have a RadioChoice (in a Form) that has an attached
>> AjaxFormComponentUpdatingBehavior.
>>
>> The onUpdate() method of the Behavior fires an event for other components
>> on the page to update (change visibility depending on user selection in
>> radio choice).
>>
>> Im trying to unit test it using:
>>
>> formTester.selectRadioChoice( "propertyType", 2 );
>>
> I guess that's a typo :) or are you using a custom formTester?
>
>>
>> and then I'm trying to trigger the behavior to fire so that I can
>> check that the various components are visible/invisible:
>>
>> Component component = baseTester.getComponentFromLastRenderedPage(
>> "form:propertyType" );
>> for ( Behavior b : component.getBehaviors() )
>> {
>>     if ( b instanceof AjaxFormComponentUpdatingBehavior )
>>     {
>>        baseTester.executeBehavior( (AbstractAjaxBehavior) b );
>>     }
>> }
>>
>> However, I'm running in to this when the behavior is executed:
>>
>> org.apache.wicket.core.request.handler.ListenerInvocationNotAllowedEx
>> ception:
>> Behavior rejected interface invocation.
>>
>> Is it possible to unit test this specific behavior, and am I going
>> about this the right way?
>>
>> I've verified that the application works as expected in a browser.
>>
> BTW, multiple-choice component should use AjaxFormChoiceComponentUpdatingBehavior
> instead of AjaxFormComponentUpdatingBehavior.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Unit testing RadioChoice with AjaxFormComponentUpdatingBehavior

Posted by Nick Pratt <nb...@gmail.com>.
Thanks Paul

 I read that before posting, and tried a couple of things.  Is there
anything specific in that section other than:

tester.executeAjaxEvent("label", "click");

If this is what is needed, how do I simulate a click on a specific
item from a RadioChoice? Do I set the value using the normal
formTester methods and then fire a generic click event?


On Thu, Oct 30, 2014 at 4:31 PM, Paul Bors <pa...@bors.ws> wrote:

> Since you want to test a AjaxFormComponentUpdatingBehav
> ior and not a standard form component (non-ajax) you don't use
> formTester.selectRadioChoice( "propertyType", 2 ) you have to create the
> AjaxTarget and etc.
>
> See "Testing AJAX behaviors" section at:
> http://wicket.apache.org/guide/guide/testing.html
>
> On Thu, Oct 30, 2014 at 4:27 PM, Andrea Del Bene <an...@gmail.com>
> wrote:
>
> > On 30/10/14 21:08, Nick Pratt wrote:
> >
> >> Wicket 6.17.0
> >>
> >> I have a RadioChoice (in a Form) that has an attached
> >> AjaxFormComponentUpdatingBehavior.
> >>
> >> The onUpdate() method of the Behavior fires an event for other
> components
> >> on the page to update (change visibility depending on user selection in
> >> radio choice).
> >>
> >> Im trying to unit test it using:
> >>
> >> formTester.selectRadioChoice( "propertyType", 2 );
> >>
> > I guess that's a typo :) or are you using a custom formTester?
> >
> >>
> >> and then I'm trying to trigger the behavior to fire so that I can
> >> check that the various components are visible/invisible:
> >>
> >> Component component = baseTester.getComponentFromLastRenderedPage(
> >> "form:propertyType" );
> >> for ( Behavior b : component.getBehaviors() )
> >> {
> >>     if ( b instanceof AjaxFormComponentUpdatingBehavior )
> >>     {
> >>        baseTester.executeBehavior( (AbstractAjaxBehavior) b );
> >>     }
> >> }
> >>
> >> However, I'm running in to this when the behavior is executed:
> >>
> >> org.apache.wicket.core.request.handler.ListenerInvocationNotAllowedEx
> >> ception:
> >> Behavior rejected interface invocation.
> >>
> >> Is it possible to unit test this specific behavior, and am I going
> >> about this the right way?
> >>
> >> I've verified that the application works as expected in a browser.
> >>
> > BTW, multiple-choice component should use
> AjaxFormChoiceComponentUpdatingBehavior
> > instead of AjaxFormComponentUpdatingBehavior.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
>

Re: Unit testing RadioChoice with AjaxFormComponentUpdatingBehavior

Posted by Paul Bors <pa...@bors.ws>.
Since you want to test a AjaxFormComponentUpdatingBehav
ior and not a standard form component (non-ajax) you don't use
formTester.selectRadioChoice( "propertyType", 2 ) you have to create the
AjaxTarget and etc.

See "Testing AJAX behaviors" section at:
http://wicket.apache.org/guide/guide/testing.html

On Thu, Oct 30, 2014 at 4:27 PM, Andrea Del Bene <an...@gmail.com>
wrote:

> On 30/10/14 21:08, Nick Pratt wrote:
>
>> Wicket 6.17.0
>>
>> I have a RadioChoice (in a Form) that has an attached
>> AjaxFormComponentUpdatingBehavior.
>>
>> The onUpdate() method of the Behavior fires an event for other components
>> on the page to update (change visibility depending on user selection in
>> radio choice).
>>
>> Im trying to unit test it using:
>>
>> formTester.selectRadioChoice( "propertyType", 2 );
>>
> I guess that's a typo :) or are you using a custom formTester?
>
>>
>> and then I'm trying to trigger the behavior to fire so that I can
>> check that the various components are visible/invisible:
>>
>> Component component = baseTester.getComponentFromLastRenderedPage(
>> "form:propertyType" );
>> for ( Behavior b : component.getBehaviors() )
>> {
>>     if ( b instanceof AjaxFormComponentUpdatingBehavior )
>>     {
>>        baseTester.executeBehavior( (AbstractAjaxBehavior) b );
>>     }
>> }
>>
>> However, I'm running in to this when the behavior is executed:
>>
>> org.apache.wicket.core.request.handler.ListenerInvocationNotAllowedEx
>> ception:
>> Behavior rejected interface invocation.
>>
>> Is it possible to unit test this specific behavior, and am I going
>> about this the right way?
>>
>> I've verified that the application works as expected in a browser.
>>
> BTW, multiple-choice component should use AjaxFormChoiceComponentUpdatingBehavior
> instead of AjaxFormComponentUpdatingBehavior.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Unit testing RadioChoice with AjaxFormComponentUpdatingBehavior

Posted by Andrea Del Bene <an...@gmail.com>.
On 30/10/14 21:08, Nick Pratt wrote:
> Wicket 6.17.0
>
> I have a RadioChoice (in a Form) that has an attached
> AjaxFormComponentUpdatingBehavior.
>
> The onUpdate() method of the Behavior fires an event for other components
> on the page to update (change visibility depending on user selection in
> radio choice).
>
> Im trying to unit test it using:
>
> formTester.selectRadioChoice( "propertyType", 2 );
I guess that's a typo :) or are you using a custom formTester?
>
> and then I'm trying to trigger the behavior to fire so that I can
> check that the various components are visible/invisible:
>
> Component component = baseTester.getComponentFromLastRenderedPage(
> "form:propertyType" );
> for ( Behavior b : component.getBehaviors() )
> {
>     if ( b instanceof AjaxFormComponentUpdatingBehavior )
>     {
>        baseTester.executeBehavior( (AbstractAjaxBehavior) b );
>     }
> }
>
> However, I'm running in to this when the behavior is executed:
>
> org.apache.wicket.core.request.handler.ListenerInvocationNotAllowedException:
> Behavior rejected interface invocation.
>
> Is it possible to unit test this specific behavior, and am I going
> about this the right way?
>
> I've verified that the application works as expected in a browser.
BTW, multiple-choice component should use 
AjaxFormChoiceComponentUpdatingBehavior instead of 
AjaxFormComponentUpdatingBehavior.


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