You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Mathilde Pellerin <ma...@statlife.fr> on 2011/08/19 14:21:22 UTC

how to test what radio is checked in a radiogroup?

Hi all,

I have a form with a Radiogroup :

In my form, I have a radiogroup like this :
        RadioGroup<String> genre = new
RadioGroup<String>("genreDestinataire");
        genre.setRequired(true);
        genre.setLabel(new Model<String>("Genre destinataire"));
        genre.add(new Radio<String>("femme", new Model<String>("f")));
        genre.add(new Radio<String>("homme", new Model<String>("h")));
        genre.add(new Radio<String>("mixte", new Model<String>("b")));
        form.add(genre);

This radiogroup match the genreDestinataire field in Questionnaire Entity
(with a CompoundPropertyModel).

In my unit test, I try to check what radio is selected, but I don't find
how...
I can get Model Object from radioGroup like this :
        String genreObtenu =
((RadioGroup<String>)form.get("genreDestinataire")).getDefaultModelObjectAsString();

but it works even if none of radio is checked. It happen when I fill the
form with existant Questionnaire : radiogroup model is ok, but none of radio
is checked.
Before correct this bug, I want to reproduce it in test, but I didn't find
how to see if a radio is checked or not : I didn't find any method like
"isChecked" or "isSelected" on Radio Component.

Is there any way to check that ?

Thanks.
M.

-- 
*Mathilde Pellerin*
Ingénieur en développement de logiciel

STATLIFE
tel : 01.42.11.64.88
mail : mathilde.pellerin@statlife.fr

Re: how to test what radio is checked in a radiogroup?

Posted by Mike Mander <wi...@gmx.de>.
Am 19.08.2011 15:35, schrieb Mathilde Pellerin:
> Thank you for your answer Mike.
>
> I didn't find out how could I try with Radio.onComponentTag, so I tried with
> tagTester.
>
> I think it could be a good solution, so I did that :
>          TagTester tagFemme =
> tester.getTagByWicketId("formCreationQuestionnaire:genre:femme");
>          TagTester tagHomme =
> tester.getTagByWicketId("formCreationQuestionnaire:genre:homme");
>          TagTester tagMixte =
> tester.getTagByWicketId("formCreationQuestionnaire:genre:mixte");
>          Assert.assertNotNull(tagFemme);
>          Assert.assertTrue(tagFemme.hasAttribute("checked"));
>          Assert.assertFalse(tagHomme.hasAttribute("checked"));
>          Assert.assertFalse(tagMixte.hasAttribute("checked"));
>
> but my tagTester are always null ! I checked path many times, and I tried
> other way to instantiate tagTester, but without success.
> I already used TagTester in other test before without problem, and I really
> don't understand why it is always null here...
>
Can you provide output from WicketTester.debugComponentTree()?

Mike

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


Re: how to test what radio is checked in a radiogroup?

Posted by Mike Mander <wi...@gmx.de>.
Am 22.08.2011 13:27, schrieb Mike Mander:
> Am 22.08.2011 09:45, schrieb Mathilde Pellerin:
>> Hi all,
>>
>> thanks for your answers.
>> So, Ajax can be a problem with tagTester. Ok, so I don't use Ajax 
>> response
>> anymore to render my page :
>>
>>      public void 
>> testStory23_TA21_VerificationInitialisationBoutonsRadio(){
>>          Questionnaire questionnaire =
>> serviceQuestionnaire.findBytitre("Questionnaire pour Femme").get(0);
>>          CreationQuestionnairePage creationQuestionnairePage = new
>> CreationQuestionnairePage(
>>                  new PageParameters("p=2"), questionnaire);
>>          tester.startPage(creationQuestionnairePage);
>>          tester.assertRenderedPage(CreationQuestionnairePage.class);
>>
>> then, I checked my markup by tester.dumpPage() :
>> <h2>Questionnaires</h2>
>> <p>
>> <a href="#" wicket:id="retourRecapitulatif"
>> id="retourRecapitulatif3" onclick="var
>> wcall=wicketAjaxGet('?wicket:interface=:0:retourRecapitulatif::IBehaviorListener:0:',function() 
>>
>> { }.bind(this),function() { }.bind(this), function() {return
>> Wicket.$('retourRecapitulatif3') != null;}.bind(this));return
>> !wcall;">Retour à la liste
>>                      des questionnaires</a>
>> </p>
>> <h3>Création d'un nouveau questionnaire :</h3>
>> <div>
>> <form wicket:id="formCreationQuestionnaire" method="post"
>> id="formCreationQuestionnaire4"
>> action="?wicket:interface=:0:formCreationQuestionnaire::IFormSubmitListener::" 
>>
>> enctype="multipart/form-data"><div
>> style="width:0px;height:0px;position:absolute;left:-100px;top:-100px;overflow:hidden"><input 
>>
>> type="hidden" name="formCreationQuestionnaire4_hf_0"
>> id="formCreationQuestionnaire4_hf_0" /></div>
>> <table>
>> <tr>
>> <td colspan="2" style="border-bottom:
>> none;"><span wicket:id="feedback" id="feedback5"><wicket:panel>
>>
>> </wicket:panel></span>
>> </td>
>> </tr>
>> <tr>
>> <td><h4>Titre du nouveau questionnaire
>> :</h4></td>
>> <td><input type="text" wicket:id="titre"
>> style="width: 100%;" value="Questionnaire pour Femme" name="titre"/>
>> </td>
>> </tr>
>> <tr>
>> <td><h4>Numéro :</h4></td>
>> <td><input type="text" wicket:id="numero"
>> style="width: 100px;" value="Q2" name="numero"/>
>> </td>
>> </tr>
>> <tr>
>> <td><h4>Genre des destinataires :</h4></td>
>> <td>
>> &nbsp;&nbsp;<input type="radio"
>> wicket:id="femme" id="femme6" name="genre" value="radio0" 
>> checked="checked"
>> class="wicket-genre7"/>&nbsp; Femme
>> &nbsp;&nbsp;<input type="radio"
>> wicket:id="homme" id="homme8" name="genre" value="radio1"
>> class="wicket-genre7"/>&nbsp; Homme
>> &nbsp;&nbsp;<input type="radio"
>> wicket:id="mixte" id="mixte9" name="genre" value="radio2"
>> class="wicket-genre7"/>&nbsp; Mixte
>>
>> </td>
>> </tr>
>>
>> we can see that radio button with wicket:id="femme" have tag "checked".
>> But in my test :
>>          TagTester tagFemme =
>> tester.getTagByWicketId("formCreationQuestionnaire:genre:femme");
>>          TagTester tagHomme =
>> tester.getTagByWicketId("formCreationQuestionnaire:genre:homme");
>>          TagTester tagMixte =
>> tester.getTagByWicketId("formCreationQuestionnaire:genre:mixte");
>>          //tester.debugComponentTrees();
>>          tester.dumpPage();
>>          Assert.assertNotNull(tagFemme);
>>
>> tagFemme is still null.
>>
>> I checked my path for this radio button with 
>> tester.debugComponentTrees() :
>> INFO  - BaseWicketTester           - path    
>> formCreationQuestionnaire:genre
>>      org.apache.wicket.markup.html.form.RadioGroup     [f]
>> INFO  - BaseWicketTester           - path
>> formCreationQuestionnaire:genre:femme
>> org.apache.wicket.markup.html.form.Radio     [f]
>> INFO  - BaseWicketTester           - path
>> formCreationQuestionnaire:genre:homme
>> org.apache.wicket.markup.html.form.Radio     [h]
>> INFO  - BaseWicketTester           - path
>> formCreationQuestionnaire:genre:mixte
>> org.apache.wicket.markup.html.form.Radio     [b]
>>
>> I really don't understand what am I doing wrong...
>>
> Where is genre? Try
>
> formCreationQuestionnaire:homme
>
> . Did that help?
> Mike
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Ähm sorry for my stupidity but i didn't used this for a long time.
Try to use homme (and other radios) only!!! TagTester is searching for 
the wicket:id. Parent components are not relevant. So you don't have to 
provide the complete path.

Sorry,
Mike

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


Re: how to test what radio is checked in a radiogroup?

Posted by Mike Mander <wi...@gmx.de>.
Am 22.08.2011 09:45, schrieb Mathilde Pellerin:
> Hi all,
>
> thanks for your answers.
> So, Ajax can be a problem with tagTester. Ok, so I don't use Ajax response
> anymore to render my page :
>
>      public void testStory23_TA21_VerificationInitialisationBoutonsRadio(){
>          Questionnaire questionnaire =
> serviceQuestionnaire.findBytitre("Questionnaire pour Femme").get(0);
>          CreationQuestionnairePage creationQuestionnairePage = new
> CreationQuestionnairePage(
>                  new PageParameters("p=2"), questionnaire);
>          tester.startPage(creationQuestionnairePage);
>          tester.assertRenderedPage(CreationQuestionnairePage.class);
>
> then, I checked my markup by tester.dumpPage() :
> <h2>Questionnaires</h2>
>              <p>
>                  <a href="#" wicket:id="retourRecapitulatif"
> id="retourRecapitulatif3" onclick="var
> wcall=wicketAjaxGet('?wicket:interface=:0:retourRecapitulatif::IBehaviorListener:0:',function()
> { }.bind(this),function() { }.bind(this), function() {return
> Wicket.$('retourRecapitulatif3') != null;}.bind(this));return
> !wcall;">Retour à la liste
>                      des questionnaires</a>
>              </p>
>              <h3>Création d'un nouveau questionnaire :</h3>
>              <div>
>                  <form wicket:id="formCreationQuestionnaire" method="post"
> id="formCreationQuestionnaire4"
> action="?wicket:interface=:0:formCreationQuestionnaire::IFormSubmitListener::"
> enctype="multipart/form-data"><div
> style="width:0px;height:0px;position:absolute;left:-100px;top:-100px;overflow:hidden"><input
> type="hidden" name="formCreationQuestionnaire4_hf_0"
> id="formCreationQuestionnaire4_hf_0" /></div>
>                      <table>
>                          <tr>
>                              <td colspan="2" style="border-bottom:
> none;"><span wicket:id="feedback" id="feedback5"><wicket:panel>
>
> </wicket:panel></span>
>                              </td>
>                          </tr>
>                          <tr>
>                              <td><h4>Titre du nouveau questionnaire
> :</h4></td>
>                              <td><input type="text" wicket:id="titre"
> style="width: 100%;" value="Questionnaire pour Femme" name="titre"/>
>                              </td>
>                          </tr>
>                          <tr>
>                              <td><h4>Numéro :</h4></td>
>                              <td><input type="text" wicket:id="numero"
> style="width: 100px;" value="Q2" name="numero"/>
>                              </td>
>                          </tr>
>                          <tr>
>                              <td><h4>Genre des destinataires :</h4></td>
>                              <td>
>                                  &nbsp;&nbsp;<input type="radio"
> wicket:id="femme" id="femme6" name="genre" value="radio0" checked="checked"
> class="wicket-genre7"/>&nbsp; Femme
>                                  &nbsp;&nbsp;<input type="radio"
> wicket:id="homme" id="homme8" name="genre" value="radio1"
> class="wicket-genre7"/>&nbsp; Homme
>                                  &nbsp;&nbsp;<input type="radio"
> wicket:id="mixte" id="mixte9" name="genre" value="radio2"
> class="wicket-genre7"/>&nbsp; Mixte
>
>                              </td>
>                          </tr>
>
> we can see that radio button with wicket:id="femme" have tag "checked".
> But in my test :
>          TagTester tagFemme =
> tester.getTagByWicketId("formCreationQuestionnaire:genre:femme");
>          TagTester tagHomme =
> tester.getTagByWicketId("formCreationQuestionnaire:genre:homme");
>          TagTester tagMixte =
> tester.getTagByWicketId("formCreationQuestionnaire:genre:mixte");
>          //tester.debugComponentTrees();
>          tester.dumpPage();
>          Assert.assertNotNull(tagFemme);
>
> tagFemme is still null.
>
> I checked my path for this radio button with tester.debugComponentTrees() :
> INFO  - BaseWicketTester           - path    formCreationQuestionnaire:genre
>      org.apache.wicket.markup.html.form.RadioGroup     [f]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:genre:femme
> org.apache.wicket.markup.html.form.Radio     [f]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:genre:homme
> org.apache.wicket.markup.html.form.Radio     [h]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:genre:mixte
> org.apache.wicket.markup.html.form.Radio     [b]
>
> I really don't understand what am I doing wrong...
>
Where is genre? Try

formCreationQuestionnaire:homme

. Did that help?
Mike

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


Re: how to test what radio is checked in a radiogroup?

Posted by Mathilde Pellerin <ma...@statlife.fr>.
It works well when I don't provide the complete path !

Thank you a lot Mike !

Re: how to test what radio is checked in a radiogroup?

Posted by Mathilde Pellerin <ma...@statlife.fr>.
Hi all,

thanks for your answers.
So, Ajax can be a problem with tagTester. Ok, so I don't use Ajax response
anymore to render my page :

    public void testStory23_TA21_VerificationInitialisationBoutonsRadio(){
        Questionnaire questionnaire =
serviceQuestionnaire.findBytitre("Questionnaire pour Femme").get(0);
        CreationQuestionnairePage creationQuestionnairePage = new
CreationQuestionnairePage(
                new PageParameters("p=2"), questionnaire);
        tester.startPage(creationQuestionnairePage);
        tester.assertRenderedPage(CreationQuestionnairePage.class);

then, I checked my markup by tester.dumpPage() :
<h2>Questionnaires</h2>
            <p>
                <a href="#" wicket:id="retourRecapitulatif"
id="retourRecapitulatif3" onclick="var
wcall=wicketAjaxGet('?wicket:interface=:0:retourRecapitulatif::IBehaviorListener:0:',function()
{ }.bind(this),function() { }.bind(this), function() {return
Wicket.$('retourRecapitulatif3') != null;}.bind(this));return
!wcall;">Retour à la liste
                    des questionnaires</a>
            </p>
            <h3>Création d'un nouveau questionnaire :</h3>
            <div>
                <form wicket:id="formCreationQuestionnaire" method="post"
id="formCreationQuestionnaire4"
action="?wicket:interface=:0:formCreationQuestionnaire::IFormSubmitListener::"
enctype="multipart/form-data"><div
style="width:0px;height:0px;position:absolute;left:-100px;top:-100px;overflow:hidden"><input
type="hidden" name="formCreationQuestionnaire4_hf_0"
id="formCreationQuestionnaire4_hf_0" /></div>
                    <table>
                        <tr>
                            <td colspan="2" style="border-bottom:
none;"><span wicket:id="feedback" id="feedback5"><wicket:panel>

</wicket:panel></span>
                            </td>
                        </tr>
                        <tr>
                            <td><h4>Titre du nouveau questionnaire
:</h4></td>
                            <td><input type="text" wicket:id="titre"
style="width: 100%;" value="Questionnaire pour Femme" name="titre"/>
                            </td>
                        </tr>
                        <tr>
                            <td><h4>Numéro :</h4></td>
                            <td><input type="text" wicket:id="numero"
style="width: 100px;" value="Q2" name="numero"/>
                            </td>
                        </tr>
                        <tr>
                            <td><h4>Genre des destinataires :</h4></td>
                            <td>
                                &nbsp;&nbsp; <input type="radio"
wicket:id="femme" id="femme6" name="genre" value="radio0" checked="checked"
class="wicket-genre7"/>&nbsp; Femme
                                &nbsp;&nbsp; <input type="radio"
wicket:id="homme" id="homme8" name="genre" value="radio1"
class="wicket-genre7"/>&nbsp; Homme
                                &nbsp;&nbsp; <input type="radio"
wicket:id="mixte" id="mixte9" name="genre" value="radio2"
class="wicket-genre7"/>&nbsp; Mixte

                            </td>
                        </tr>

we can see that radio button with wicket:id="femme" have tag "checked".
But in my test :
        TagTester tagFemme =
tester.getTagByWicketId("formCreationQuestionnaire:genre:femme");
        TagTester tagHomme =
tester.getTagByWicketId("formCreationQuestionnaire:genre:homme");
        TagTester tagMixte =
tester.getTagByWicketId("formCreationQuestionnaire:genre:mixte");
        //tester.debugComponentTrees();
        tester.dumpPage();
        Assert.assertNotNull(tagFemme);

tagFemme is still null.

I checked my path for this radio button with tester.debugComponentTrees() :
INFO  - BaseWicketTester           - path    formCreationQuestionnaire:genre
    org.apache.wicket.markup.html.form.RadioGroup     [f]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:genre:femme
org.apache.wicket.markup.html.form.Radio     [f]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:genre:homme
org.apache.wicket.markup.html.form.Radio     [h]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:genre:mixte
org.apache.wicket.markup.html.form.Radio     [b]

I really don't understand what am I doing wrong...

Re: how to test what radio is checked in a radiogroup?

Posted by Per Newgro <pe...@gmx.ch>.
Welcome to wicket Shunmuga

Did you check the website http://wicket.apache.org already. It's all there.
Check the wiki, component examples and books section.

Hope you have fun with wicket

Cheers
Per

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


Re: how to test what radio is checked in a radiogroup?

Posted by Shunmuga Raj <sh...@gmail.com>.
Hi all,

          I'm new to Wicket. Can you help me to know what is wicket & how it
works? pls ppl's mail me the links for it's tutorials and learning path. Now
i'm using Netbeans 6.9,7.0 so pls share the plugins for it too, Thanks in
advance

On Fri, Aug 19, 2011 at 11:28 PM, "Mike Müller" <wi...@gmx.de> wrote:

> If i'm not completely wrong is tester.clickLink(path) a wrapper for
> tester.clickLink(path, isAjax = true). So you get an ajax response.
> You can check that by calling tester.dumpPage().
>
> The problem is that wicket tester only works on page markup. It is not
> working on ajax response markup (at least i didn't get it to work.
> Once i've wrote an extractor. Maybe that helps you to.
>
> <code>
> package de.frontend.wicket.testtools;
>
> public final class AjaxResponseComponentMarkup {
>
>        private final String _ajaxResponseMarkup;
>        private final int _componentTagStartPosition;
>        private final int _componentTagEndPosition;
>
>        public AjaxResponseComponentMarkup(String ajaxResponseMarkup) {
>                _ajaxResponseMarkup = ajaxResponseMarkup;
>                _componentTagStartPosition =
> _ajaxResponseMarkup.indexOf("<component");
>                _componentTagEndPosition =
> _ajaxResponseMarkup.indexOf("</component>");
>        }
>
>        public String extract() {
>                StringBuilder result = new StringBuilder();
>                if (hasComponentTag()) {
>
>  result.append(_ajaxResponseMarkup.substring(startOfAjaxResponseComponentMarkup(),
> endOfAjaxResponseComponentMarkup()));
>                }
>                return result.toString();
>        }
>
>        private int startOfAjaxResponseComponentMarkup() {
>                String cdataTag = "<![CDATA[";
>                return _ajaxResponseMarkup.indexOf(cdataTag,
> _componentTagStartPosition) + cdataTag.length();
>        }
>
>        private int endOfAjaxResponseComponentMarkup() {
>                String cdataTag = "]]>";
>                return
> _ajaxResponseMarkup.substring(_componentTagStartPosition,
> _componentTagEndPosition).lastIndexOf(cdataTag) +
> _componentTagStartPosition;
>        }
>
>        private boolean hasComponentTag() {
>                return _componentTagStartPosition != -1;
>        }
> }
> </code>
> This is only extracting the markup in CDATA of ajax response.
> Use it this way:
>
> <code>
>
>        private void assertExpandedNodeAt(int row) {
>                List<TagTester> t = TagTester.createTagsByAttribute(new
> AjaxResponseComponentMarkup(_tester.getServletResponse().getDocument()).extract(),
> "wicketpath",
>                                "brdPage_availability_tariffTable_rows_" +
> row + "_cells_1_cell_junction", true);
>                Assert.assertTrue("Node " + row + " is collapsed",
> t.get(0).getAttributeIs("class", "tree-junction-expanded"));
>        }
> </code>
>
> Please see TagTester.createTagsByAttribute for concrete parameters
> required.
>
> Maybe someone else has a better approach. But for me this was working.
>
> Hth
> Mike
>
> -------- Original-Nachricht --------
> > Datum: Fri, 19 Aug 2011 18:38:43 +0200
> > Von: Mathilde Pellerin <ma...@statlife.fr>
> > An: users@wicket.apache.org
> > Betreff: Re: how to test what radio is checked in a radiogroup?
>
> > hum, yes and no... I mean, page is loaded by an ajax response (AjaxLink),
> > but then there is no Ajax.
> > This is the entire test, maybe it can help :
> >
> >     @SuppressWarnings("unchecked")
> >     @Test @Transactional @Rollback
> >     public void
> testStory23_TA21_VerificationInitialisationBoutonsRadio(){
> >         tester.startPage(RecapitulatifQuestionnairePage.class);
> >         tester.assertRenderedPage(RecapitulatifQuestionnairePage.class);
> >         tester.clickLink("questionnaireEnCours:1:modifier");
> >         tester.assertRenderedPage(CreationQuestionnairePage.class);
> >
> >         Form<Questionnaire> form = (Form<Questionnaire>)
> > tester.getComponentFromLastRenderedPage(
> >         "formCreationQuestionnaire");
> >
> >         //On vérifie que le formulaire est préremplie avec le
> > questionnaire
> > sélectionné
> >         Questionnaire qObtenu = form.getModelObject();
> >         Assert.assertNotNull(qObtenu);
> >
> >         //Vérification du sexe des destinataires
> >         String genreAttendu = qObtenu.getSexeDestinataire().toString();
> >         String genreObtenu =
> > ((RadioGroup<String>)form.get("genre")).getDefaultModelObjectAsString();
> >         Assert.assertEquals(genreAttendu, genreObtenu);
> >
> >         TagTester tagFemme =
> > tester.getTagByWicketId("formCreationQuestionnaire:genre:femme");
> >         TagTester tagHomme =
> > tester.getTagByWicketId("formCreationQuestionnaire:genre:homme");
> >         TagTester tagMixte =
> > tester.getTagByWicketId("formCreationQuestionnaire:genre:mixte");
> >         tester.debugComponentTrees();
> >         Assert.assertNotNull(tagFemme);
> >
> >         Assert.assertTrue(tagFemme.hasAttribute("checked"));
> >         Assert.assertFalse(tagHomme.hasAttribute("checked"));
> >         Assert.assertFalse(tagMixte.hasAttribute("checked"));
> >     }
>
> --
> Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
> belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: how to test what radio is checked in a radiogroup?

Posted by Mike Müller <wi...@gmx.de>.
If i'm not completely wrong is tester.clickLink(path) a wrapper for tester.clickLink(path, isAjax = true). So you get an ajax response.
You can check that by calling tester.dumpPage().

The problem is that wicket tester only works on page markup. It is not
working on ajax response markup (at least i didn't get it to work.
Once i've wrote an extractor. Maybe that helps you to.

<code>
package de.frontend.wicket.testtools;

public final class AjaxResponseComponentMarkup {

	private final String _ajaxResponseMarkup;
	private final int _componentTagStartPosition;
	private final int _componentTagEndPosition;
	
	public AjaxResponseComponentMarkup(String ajaxResponseMarkup) {
		_ajaxResponseMarkup = ajaxResponseMarkup;
		_componentTagStartPosition = _ajaxResponseMarkup.indexOf("<component");
		_componentTagEndPosition = _ajaxResponseMarkup.indexOf("</component>");
	}
	
	public String extract() {
		StringBuilder result = new StringBuilder();
		if (hasComponentTag()) {
			result.append(_ajaxResponseMarkup.substring(startOfAjaxResponseComponentMarkup(), endOfAjaxResponseComponentMarkup()));
		}
		return result.toString();
	}

	private int startOfAjaxResponseComponentMarkup() {
		String cdataTag = "<![CDATA[";
		return _ajaxResponseMarkup.indexOf(cdataTag, _componentTagStartPosition) + cdataTag.length();
	}

	private int endOfAjaxResponseComponentMarkup() {
		String cdataTag = "]]>";
		return _ajaxResponseMarkup.substring(_componentTagStartPosition, _componentTagEndPosition).lastIndexOf(cdataTag) + _componentTagStartPosition;
	}

	private boolean hasComponentTag() {
		return _componentTagStartPosition != -1;
	}
}
</code> 
This is only extracting the markup in CDATA of ajax response.
Use it this way:

<code>

	private void assertExpandedNodeAt(int row) {
		List<TagTester> t = TagTester.createTagsByAttribute(new AjaxResponseComponentMarkup(_tester.getServletResponse().getDocument()).extract(), "wicketpath",
				"brdPage_availability_tariffTable_rows_" + row + "_cells_1_cell_junction", true);
		Assert.assertTrue("Node " + row + " is collapsed", t.get(0).getAttributeIs("class", "tree-junction-expanded"));
	}
</code>

Please see TagTester.createTagsByAttribute for concrete parameters required.

Maybe someone else has a better approach. But for me this was working.

Hth
Mike

-------- Original-Nachricht --------
> Datum: Fri, 19 Aug 2011 18:38:43 +0200
> Von: Mathilde Pellerin <ma...@statlife.fr>
> An: users@wicket.apache.org
> Betreff: Re: how to test what radio is checked in a radiogroup?

> hum, yes and no... I mean, page is loaded by an ajax response (AjaxLink),
> but then there is no Ajax.
> This is the entire test, maybe it can help :
> 
>     @SuppressWarnings("unchecked")
>     @Test @Transactional @Rollback
>     public void testStory23_TA21_VerificationInitialisationBoutonsRadio(){
>         tester.startPage(RecapitulatifQuestionnairePage.class);
>         tester.assertRenderedPage(RecapitulatifQuestionnairePage.class);
>         tester.clickLink("questionnaireEnCours:1:modifier");
>         tester.assertRenderedPage(CreationQuestionnairePage.class);
> 
>         Form<Questionnaire> form = (Form<Questionnaire>)
> tester.getComponentFromLastRenderedPage(
>         "formCreationQuestionnaire");
> 
>         //On vérifie que le formulaire est préremplie avec le
> questionnaire
> sélectionné
>         Questionnaire qObtenu = form.getModelObject();
>         Assert.assertNotNull(qObtenu);
> 
>         //Vérification du sexe des destinataires
>         String genreAttendu = qObtenu.getSexeDestinataire().toString();
>         String genreObtenu =
> ((RadioGroup<String>)form.get("genre")).getDefaultModelObjectAsString();
>         Assert.assertEquals(genreAttendu, genreObtenu);
> 
>         TagTester tagFemme =
> tester.getTagByWicketId("formCreationQuestionnaire:genre:femme");
>         TagTester tagHomme =
> tester.getTagByWicketId("formCreationQuestionnaire:genre:homme");
>         TagTester tagMixte =
> tester.getTagByWicketId("formCreationQuestionnaire:genre:mixte");
>         tester.debugComponentTrees();
>         Assert.assertNotNull(tagFemme);
> 
>         Assert.assertTrue(tagFemme.hasAttribute("checked"));
>         Assert.assertFalse(tagHomme.hasAttribute("checked"));
>         Assert.assertFalse(tagMixte.hasAttribute("checked"));
>     }

-- 
Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de

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


Re: how to test what radio is checked in a radiogroup?

Posted by Mathilde Pellerin <ma...@statlife.fr>.
hum, yes and no... I mean, page is loaded by an ajax response (AjaxLink),
but then there is no Ajax.
This is the entire test, maybe it can help :

    @SuppressWarnings("unchecked")
    @Test @Transactional @Rollback
    public void testStory23_TA21_VerificationInitialisationBoutonsRadio(){
        tester.startPage(RecapitulatifQuestionnairePage.class);
        tester.assertRenderedPage(RecapitulatifQuestionnairePage.class);
        tester.clickLink("questionnaireEnCours:1:modifier");
        tester.assertRenderedPage(CreationQuestionnairePage.class);

        Form<Questionnaire> form = (Form<Questionnaire>)
tester.getComponentFromLastRenderedPage(
        "formCreationQuestionnaire");

        //On vérifie que le formulaire est préremplie avec le questionnaire
sélectionné
        Questionnaire qObtenu = form.getModelObject();
        Assert.assertNotNull(qObtenu);

        //Vérification du sexe des destinataires
        String genreAttendu = qObtenu.getSexeDestinataire().toString();
        String genreObtenu =
((RadioGroup<String>)form.get("genre")).getDefaultModelObjectAsString();
        Assert.assertEquals(genreAttendu, genreObtenu);

        TagTester tagFemme =
tester.getTagByWicketId("formCreationQuestionnaire:genre:femme");
        TagTester tagHomme =
tester.getTagByWicketId("formCreationQuestionnaire:genre:homme");
        TagTester tagMixte =
tester.getTagByWicketId("formCreationQuestionnaire:genre:mixte");
        tester.debugComponentTrees();
        Assert.assertNotNull(tagFemme);

        Assert.assertTrue(tagFemme.hasAttribute("checked"));
        Assert.assertFalse(tagHomme.hasAttribute("checked"));
        Assert.assertFalse(tagMixte.hasAttribute("checked"));
    }

Re: how to test what radio is checked in a radiogroup?

Posted by Mike Mander <wi...@gmx.de>.
Am 19.08.2011 16:38, schrieb Mathilde Pellerin:
>   I add WicketTester.debugComponentTrees() in my test juste before
> assertNotNull which failed like this :
>
>          TagTester tagFemme =
> tester.getTagByWicketId("formCreationQuestionnaire:genre:femme");
>          TagTester tagHomme =
> tester.getTagByWicketId("formCreationQuestionnaire:genre:homme");
>          TagTester tagMixte =
> tester.getTagByWicketId("formCreationQuestionnaire:genre:mixte");
>          tester.debugComponentTrees();
>          Assert.assertNotNull(tagFemme);
>
> and this is the output (lines relatives to radiogroup are in bold) :
>
> INFO  - BaseWicketTester           - debugging
> ----------------------------------------------
> INFO  - BaseWicketTester           - path    logo
> org.apache.wicket.markup.html.link.BookmarkablePageLink     []
> INFO  - BaseWicketTester           - path    deconnexion
> org.apache.wicket.markup.html.link.Link     []
> INFO  - BaseWicketTester           - path    tableaubord
> org.apache.wicket.markup.html.link.BookmarkablePageLink     []
> INFO  - BaseWicketTester           - path    recapitulatifQuestionnaire
> org.apache.wicket.markup.html.link.BookmarkablePageLink     []
> INFO  - BaseWicketTester           - path    retourRecapitulatif
> org.apache.wicket.ajax.markup.html.AjaxLink     []
> INFO  - BaseWicketTester           - path    fenetreModale
> fr.statlife.protoE4N.pages.ModalWindowE4N     []
> INFO  - BaseWicketTester           - path    fenetreModale:content
> fr.statlife.protoE4N.pages.questionnaire.QuestionnaireContentPanel     []
> INFO  - BaseWicketTester           - path    fenetreModale:content:qForm
> org.apache.wicket.markup.html.form.Form     []
> INFO  - BaseWicketTester           - path
> fenetreModale:content:qForm:qErrorMsg
> org.apache.wicket.markup.html.panel.FeedbackPanel     []
> INFO  - BaseWicketTester           - path
> fenetreModale:content:qForm:qErrorMsg:feedbackul
> org.apache.wicket.markup.html.WebMarkupContainer     []
> INFO  - BaseWicketTester           - path
> fenetreModale:content:qForm:qErrorMsg:feedbackul:messages
> org.apache.wicket.markup.html.list.ListView     [[]]
> INFO  - BaseWicketTester           - path
> fenetreModale:content:qForm:qRepeating
> org.apache.wicket.markup.repeater.RepeatingView     []
> INFO  - BaseWicketTester           - path
> fenetreModale:content:qForm:qRepeating:1
> org.apache.wicket.markup.html.WebMarkupContainer     []
> INFO  - BaseWicketTester           - path
> fenetreModale:content:qForm:qRepeating:1:question
> org.apache.wicket.markup.html.basic.Label     [vide :(]
> INFO  - BaseWicketTester           - path
> fenetreModale:content:qForm:ajaxSubmitQuestionnaire
> org.apache.wicket.ajax.markup.html.form.AjaxButton     [Fermer]
> INFO  - BaseWicketTester           - path
> fenetreModale:content:qForm:qCancelbutton
> org.apache.wicket.ajax.markup.html.form.AjaxButton     []
> INFO  - BaseWicketTester           - path    formCreationQuestionnaire
> org.apache.wicket.markup.html.form.Form     [Questionnaire
> [idQuestionnaire=26, numero=Q2, titre=Questionnaire pour Femme,
> sexeDestinataire=f, publie=null, listeQuestionnaires=[],
> listeQuestions=[Question [idQuestion=27, numQuestion=1, question=Type liste
> :, typeReponse=LISTE, legende=null,
> reponsesPossibles=0g,30g,60g,90g,120g,150g,200g,250g et +,
> idQuestionnaire=26], Question [idQuestion=28, numQuestion=2, question=Type
> champsTexte :, typeReponse=TEXTE, legende=null, reponsesPossibles=null,
> idQuestionnaire=26], Question [idQuestion=29, numQuestion=3, question=Type
> date :, typeReponse=DATE, legende=null, reponsesPossibles=null,
> idQuestionnaire=26], Question [idQuestion=30, numQuestion=4, question=Type
> radio :, typeReponse=RADIO, legende=null,
> reponsesPossibles=rouge,vert,jaune,bleu, idQuestionnaire=26], Question
> [idQuestion=31, numQuestion=5, question=Type checkbox :,
> typeReponse=CHECKBOX, legende=null, reponsesPossibles=rouge,vert,jaune,bleu,
> idQuestionnaire=26]], listeReponses=[]]]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:feedback
> org.apache.wicket.markup.html.panel.FeedbackPanel     [No get method defined
> for class: class fr.statlife.protoE4N.data.entites.Questionnaire expression:
> feedback]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:feedback:feedbackul
> org.apache.wicket.markup.html.WebMarkupContainer     [No get method defined
> for class: class fr.statlife.protoE4N.data.entites.Questionnaire expression:
> feedbackul]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:feedback:feedbackul:messages
> org.apache.wicket.markup.html.list.ListView     [[]]
> INFO  - BaseWicketTester           - path    formCreationQuestionnaire:titre
>      org.apache.wicket.markup.html.form.TextField     [Questionnaire pour
> Femme]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:numero
> org.apache.wicket.markup.html.form.TextField     [Q2]
> *INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:genre
> org.apache.wicket.markup.html.form.RadioGroup     [f]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:genre:femme
> org.apache.wicket.markup.html.form.Radio     [f]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:genre:homme
> org.apache.wicket.markup.html.form.Radio     [h]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:genre:mixte
> org.apache.wicket.markup.html.form.Radio     [b]*
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:nbQuestions
> org.apache.wicket.markup.html.form.DropDownChoice     [5]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions
> org.apache.wicket.markup.html.WebMarkupContainer     [No get method defined
> for class: class fr.statlife.protoE4N.data.entites.Questionnaire expression:
> conteneurQuestions]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question
> org.apache.wicket.markup.repeater.RepeatingView     [No get method defined
> for class: class fr.statlife.protoE4N.data.entites.Questionnaire expression:
> question]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:1
> org.apache.wicket.markup.html.WebMarkupContainer     [No get method defined
> for class: class fr.statlife.protoE4N.data.entites.Questionnaire expression:
> 1]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:1:labelQuestion
> org.apache.wicket.markup.html.basic.Label     [Question 1]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:1:texteQuestion
> org.apache.wicket.markup.html.form.TextField     [Type liste :]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:1:legende
> org.apache.wicket.markup.html.form.TextField     []
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:1:reponses
> org.apache.wicket.markup.html.WebMarkupContainer     [No get method defined
> for class: class fr.statlife.protoE4N.data.entites.Questionnaire expression:
> reponses]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:1:reponses:reponsesPossible
>      org.apache.wicket.markup.html.form.TextField
> [0g,30g,60g,90g,120g,150g,200g,250g et +]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:1:typeReponse
> org.apache.wicket.markup.html.form.DropDownChoice     [LISTE]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:1:uploadImage
> org.apache.wicket.markup.html.form.upload.FileUploadField     []
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:2
> org.apache.wicket.markup.html.WebMarkupContainer     [No get method defined
> for class: class fr.statlife.protoE4N.data.entites.Questionnaire expression:
> 2]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:2:labelQuestion
> org.apache.wicket.markup.html.basic.Label     [Question 2]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:2:texteQuestion
> org.apache.wicket.markup.html.form.TextField     [Type champsTexte :]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:2:legende
> org.apache.wicket.markup.html.form.TextField     []
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:2:reponses
> org.apache.wicket.markup.html.WebMarkupContainer     [No get method defined
> for class: class fr.statlife.protoE4N.data.entites.Questionnaire expression:
> reponses]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:2:reponses:reponsesPossible
>      org.apache.wicket.markup.html.form.TextField     []
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:2:typeReponse
> org.apache.wicket.markup.html.form.DropDownChoice     [TEXTE]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:2:uploadImage
> org.apache.wicket.markup.html.form.upload.FileUploadField     []
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:3
> org.apache.wicket.markup.html.WebMarkupContainer     [No get method defined
> for class: class fr.statlife.protoE4N.data.entites.Questionnaire expression:
> 3]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:3:labelQuestion
> org.apache.wicket.markup.html.basic.Label     [Question 3]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:3:texteQuestion
> org.apache.wicket.markup.html.form.TextField     [Type date :]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:3:legende
> org.apache.wicket.markup.html.form.TextField     []
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:3:reponses
> org.apache.wicket.markup.html.WebMarkupContainer     [No get method defined
> for class: class fr.statlife.protoE4N.data.entites.Questionnaire expression:
> reponses]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:3:reponses:reponsesPossible
>      org.apache.wicket.markup.html.form.TextField     []
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:3:typeReponse
> org.apache.wicket.markup.html.form.DropDownChoice     [DATE]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:3:uploadImage
> org.apache.wicket.markup.html.form.upload.FileUploadField     []
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:4
> org.apache.wicket.markup.html.WebMarkupContainer     [No get method defined
> for class: class fr.statlife.protoE4N.data.entites.Questionnaire expression:
> 4]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:4:labelQuestion
> org.apache.wicket.markup.html.basic.Label     [Question 4]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:4:texteQuestion
> org.apache.wicket.markup.html.form.TextField     [Type radio :]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:4:legende
> org.apache.wicket.markup.html.form.TextField     []
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:4:reponses
> org.apache.wicket.markup.html.WebMarkupContainer     [No get method defined
> for class: class fr.statlife.protoE4N.data.entites.Questionnaire expression:
> reponses]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:4:reponses:reponsesPossible
>      org.apache.wicket.markup.html.form.TextField     [rouge,vert,jaune,bleu]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:4:typeReponse
> org.apache.wicket.markup.html.form.DropDownChoice     [RADIO]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:4:uploadImage
> org.apache.wicket.markup.html.form.upload.FileUploadField     []
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:5
> org.apache.wicket.markup.html.WebMarkupContainer     [No get method defined
> for class: class fr.statlife.protoE4N.data.entites.Questionnaire expression:
> 5]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:5:labelQuestion
> org.apache.wicket.markup.html.basic.Label     [Question 5]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:5:texteQuestion
> org.apache.wicket.markup.html.form.TextField     [Type checkbox :]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:5:legende
> org.apache.wicket.markup.html.form.TextField     []
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:5:reponses
> org.apache.wicket.markup.html.WebMarkupContainer     [No get method defined
> for class: class fr.statlife.protoE4N.data.entites.Questionnaire expression:
> reponses]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:5:reponses:reponsesPossible
>      org.apache.wicket.markup.html.form.TextField     [rouge,vert,jaune,bleu]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:5:typeReponse
> org.apache.wicket.markup.html.form.DropDownChoice     [CHECKBOX]
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:conteneurQuestions:question:5:uploadImage
> org.apache.wicket.markup.html.form.upload.FileUploadField     []
> INFO  - BaseWicketTester           - path
> formCreationQuestionnaire:visualiser
> org.apache.wicket.ajax.markup.html.AjaxLink     [No get method defined for
> class: class fr.statlife.protoE4N.data.entites.Questionnaire expression:
> visualiser]
> INFO  - ionalTestExecutionListener - Rolled back transaction after test
> execution for test context [[TestContext@43a30706 testClass =
> TestStory23_CreationQuestionnaire, locations =
> array<String>['classpath:/applicationContext.xml'], testInstance =
> fr.statlife.protoE4N.wicket.TestStory23_CreationQuestionnaire@4223d9b,
> testMethod =
> testStory23_TA21_VerificationInitialisationBoutonsRadio@TestStory23_CreationQuestionnaire,
> testException = junit.framework.AssertionFailedError: null]]
> INFO  - GenericApplicationContext  - Closing
> org.springframework.context.support.GenericApplicationContext@220ca470:
> startup date [Fri Aug 19 16:32:03 CEST 2011]; root of context hierarchy
> INFO  - DefaultListableBeanFactory - Destroying singletons in
> org.springframework.beans.factory.support.DefaultListableBeanFactory@105691e:
> defining beans
> [entityManagerFactory,transactionManager,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,administrateurDaoImpl,lienBaseE4NDaoImpl,listeQuestionnaireDaoImpl,membreDaoImpl,questionDaoImpl,questionnaireDaoImpl,reponseDaoImpl,serviceAdministrateurImpl,serviceIdentificationImpl,serviceInscriptionImpl,serviceLienBaseE4NImpl,serviceListeQuestionnaireImpl,serviceMailImpl,serviceMembreImpl,serviceNutritionImpl,serviceQuestionnaireImpl,initData];
> root of factory hierarchy
> INFO  - alEntityManagerFactoryBean - Closing JPA EntityManagerFactory for
> persistence unit 'jpaUnitProtoE4N'
> INFO  - SessionFactoryImpl         - closing
> INFO  - rManagerConnectionProvider - cleaning up connection pool:
> jdbc:postgresql://localhost:5432/protoE4N
>
Is this on an ajax response?


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


Re: how to test what radio is checked in a radiogroup?

Posted by Mathilde Pellerin <ma...@statlife.fr>.
 I add WicketTester.debugComponentTrees() in my test juste before
assertNotNull which failed like this :

        TagTester tagFemme =
tester.getTagByWicketId("formCreationQuestionnaire:genre:femme");
        TagTester tagHomme =
tester.getTagByWicketId("formCreationQuestionnaire:genre:homme");
        TagTester tagMixte =
tester.getTagByWicketId("formCreationQuestionnaire:genre:mixte");
        tester.debugComponentTrees();
        Assert.assertNotNull(tagFemme);

and this is the output (lines relatives to radiogroup are in bold) :

INFO  - BaseWicketTester           - debugging
----------------------------------------------
INFO  - BaseWicketTester           - path    logo
org.apache.wicket.markup.html.link.BookmarkablePageLink     []
INFO  - BaseWicketTester           - path    deconnexion
org.apache.wicket.markup.html.link.Link     []
INFO  - BaseWicketTester           - path    tableaubord
org.apache.wicket.markup.html.link.BookmarkablePageLink     []
INFO  - BaseWicketTester           - path    recapitulatifQuestionnaire
org.apache.wicket.markup.html.link.BookmarkablePageLink     []
INFO  - BaseWicketTester           - path    retourRecapitulatif
org.apache.wicket.ajax.markup.html.AjaxLink     []
INFO  - BaseWicketTester           - path    fenetreModale
fr.statlife.protoE4N.pages.ModalWindowE4N     []
INFO  - BaseWicketTester           - path    fenetreModale:content
fr.statlife.protoE4N.pages.questionnaire.QuestionnaireContentPanel     []
INFO  - BaseWicketTester           - path    fenetreModale:content:qForm
org.apache.wicket.markup.html.form.Form     []
INFO  - BaseWicketTester           - path
fenetreModale:content:qForm:qErrorMsg
org.apache.wicket.markup.html.panel.FeedbackPanel     []
INFO  - BaseWicketTester           - path
fenetreModale:content:qForm:qErrorMsg:feedbackul
org.apache.wicket.markup.html.WebMarkupContainer     []
INFO  - BaseWicketTester           - path
fenetreModale:content:qForm:qErrorMsg:feedbackul:messages
org.apache.wicket.markup.html.list.ListView     [[]]
INFO  - BaseWicketTester           - path
fenetreModale:content:qForm:qRepeating
org.apache.wicket.markup.repeater.RepeatingView     []
INFO  - BaseWicketTester           - path
fenetreModale:content:qForm:qRepeating:1
org.apache.wicket.markup.html.WebMarkupContainer     []
INFO  - BaseWicketTester           - path
fenetreModale:content:qForm:qRepeating:1:question
org.apache.wicket.markup.html.basic.Label     [vide :(]
INFO  - BaseWicketTester           - path
fenetreModale:content:qForm:ajaxSubmitQuestionnaire
org.apache.wicket.ajax.markup.html.form.AjaxButton     [Fermer]
INFO  - BaseWicketTester           - path
fenetreModale:content:qForm:qCancelbutton
org.apache.wicket.ajax.markup.html.form.AjaxButton     []
INFO  - BaseWicketTester           - path    formCreationQuestionnaire
org.apache.wicket.markup.html.form.Form     [Questionnaire
[idQuestionnaire=26, numero=Q2, titre=Questionnaire pour Femme,
sexeDestinataire=f, publie=null, listeQuestionnaires=[],
listeQuestions=[Question [idQuestion=27, numQuestion=1, question=Type liste
:, typeReponse=LISTE, legende=null,
reponsesPossibles=0g,30g,60g,90g,120g,150g,200g,250g et +,
idQuestionnaire=26], Question [idQuestion=28, numQuestion=2, question=Type
champsTexte :, typeReponse=TEXTE, legende=null, reponsesPossibles=null,
idQuestionnaire=26], Question [idQuestion=29, numQuestion=3, question=Type
date :, typeReponse=DATE, legende=null, reponsesPossibles=null,
idQuestionnaire=26], Question [idQuestion=30, numQuestion=4, question=Type
radio :, typeReponse=RADIO, legende=null,
reponsesPossibles=rouge,vert,jaune,bleu, idQuestionnaire=26], Question
[idQuestion=31, numQuestion=5, question=Type checkbox :,
typeReponse=CHECKBOX, legende=null, reponsesPossibles=rouge,vert,jaune,bleu,
idQuestionnaire=26]], listeReponses=[]]]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:feedback
org.apache.wicket.markup.html.panel.FeedbackPanel     [No get method defined
for class: class fr.statlife.protoE4N.data.entites.Questionnaire expression:
feedback]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:feedback:feedbackul
org.apache.wicket.markup.html.WebMarkupContainer     [No get method defined
for class: class fr.statlife.protoE4N.data.entites.Questionnaire expression:
feedbackul]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:feedback:feedbackul:messages
org.apache.wicket.markup.html.list.ListView     [[]]
INFO  - BaseWicketTester           - path    formCreationQuestionnaire:titre
    org.apache.wicket.markup.html.form.TextField     [Questionnaire pour
Femme]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:numero
org.apache.wicket.markup.html.form.TextField     [Q2]
*INFO  - BaseWicketTester           - path
formCreationQuestionnaire:genre
org.apache.wicket.markup.html.form.RadioGroup     [f]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:genre:femme
org.apache.wicket.markup.html.form.Radio     [f]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:genre:homme
org.apache.wicket.markup.html.form.Radio     [h]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:genre:mixte
org.apache.wicket.markup.html.form.Radio     [b]*
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:nbQuestions
org.apache.wicket.markup.html.form.DropDownChoice     [5]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions
org.apache.wicket.markup.html.WebMarkupContainer     [No get method defined
for class: class fr.statlife.protoE4N.data.entites.Questionnaire expression:
conteneurQuestions]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question
org.apache.wicket.markup.repeater.RepeatingView     [No get method defined
for class: class fr.statlife.protoE4N.data.entites.Questionnaire expression:
question]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:1
org.apache.wicket.markup.html.WebMarkupContainer     [No get method defined
for class: class fr.statlife.protoE4N.data.entites.Questionnaire expression:
1]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:1:labelQuestion
org.apache.wicket.markup.html.basic.Label     [Question 1]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:1:texteQuestion
org.apache.wicket.markup.html.form.TextField     [Type liste :]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:1:legende
org.apache.wicket.markup.html.form.TextField     []
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:1:reponses
org.apache.wicket.markup.html.WebMarkupContainer     [No get method defined
for class: class fr.statlife.protoE4N.data.entites.Questionnaire expression:
reponses]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:1:reponses:reponsesPossible
    org.apache.wicket.markup.html.form.TextField
[0g,30g,60g,90g,120g,150g,200g,250g et +]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:1:typeReponse
org.apache.wicket.markup.html.form.DropDownChoice     [LISTE]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:1:uploadImage
org.apache.wicket.markup.html.form.upload.FileUploadField     []
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:2
org.apache.wicket.markup.html.WebMarkupContainer     [No get method defined
for class: class fr.statlife.protoE4N.data.entites.Questionnaire expression:
2]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:2:labelQuestion
org.apache.wicket.markup.html.basic.Label     [Question 2]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:2:texteQuestion
org.apache.wicket.markup.html.form.TextField     [Type champsTexte :]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:2:legende
org.apache.wicket.markup.html.form.TextField     []
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:2:reponses
org.apache.wicket.markup.html.WebMarkupContainer     [No get method defined
for class: class fr.statlife.protoE4N.data.entites.Questionnaire expression:
reponses]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:2:reponses:reponsesPossible
    org.apache.wicket.markup.html.form.TextField     []
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:2:typeReponse
org.apache.wicket.markup.html.form.DropDownChoice     [TEXTE]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:2:uploadImage
org.apache.wicket.markup.html.form.upload.FileUploadField     []
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:3
org.apache.wicket.markup.html.WebMarkupContainer     [No get method defined
for class: class fr.statlife.protoE4N.data.entites.Questionnaire expression:
3]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:3:labelQuestion
org.apache.wicket.markup.html.basic.Label     [Question 3]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:3:texteQuestion
org.apache.wicket.markup.html.form.TextField     [Type date :]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:3:legende
org.apache.wicket.markup.html.form.TextField     []
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:3:reponses
org.apache.wicket.markup.html.WebMarkupContainer     [No get method defined
for class: class fr.statlife.protoE4N.data.entites.Questionnaire expression:
reponses]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:3:reponses:reponsesPossible
    org.apache.wicket.markup.html.form.TextField     []
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:3:typeReponse
org.apache.wicket.markup.html.form.DropDownChoice     [DATE]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:3:uploadImage
org.apache.wicket.markup.html.form.upload.FileUploadField     []
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:4
org.apache.wicket.markup.html.WebMarkupContainer     [No get method defined
for class: class fr.statlife.protoE4N.data.entites.Questionnaire expression:
4]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:4:labelQuestion
org.apache.wicket.markup.html.basic.Label     [Question 4]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:4:texteQuestion
org.apache.wicket.markup.html.form.TextField     [Type radio :]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:4:legende
org.apache.wicket.markup.html.form.TextField     []
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:4:reponses
org.apache.wicket.markup.html.WebMarkupContainer     [No get method defined
for class: class fr.statlife.protoE4N.data.entites.Questionnaire expression:
reponses]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:4:reponses:reponsesPossible
    org.apache.wicket.markup.html.form.TextField     [rouge,vert,jaune,bleu]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:4:typeReponse
org.apache.wicket.markup.html.form.DropDownChoice     [RADIO]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:4:uploadImage
org.apache.wicket.markup.html.form.upload.FileUploadField     []
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:5
org.apache.wicket.markup.html.WebMarkupContainer     [No get method defined
for class: class fr.statlife.protoE4N.data.entites.Questionnaire expression:
5]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:5:labelQuestion
org.apache.wicket.markup.html.basic.Label     [Question 5]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:5:texteQuestion
org.apache.wicket.markup.html.form.TextField     [Type checkbox :]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:5:legende
org.apache.wicket.markup.html.form.TextField     []
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:5:reponses
org.apache.wicket.markup.html.WebMarkupContainer     [No get method defined
for class: class fr.statlife.protoE4N.data.entites.Questionnaire expression:
reponses]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:5:reponses:reponsesPossible
    org.apache.wicket.markup.html.form.TextField     [rouge,vert,jaune,bleu]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:5:typeReponse
org.apache.wicket.markup.html.form.DropDownChoice     [CHECKBOX]
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:conteneurQuestions:question:5:uploadImage
org.apache.wicket.markup.html.form.upload.FileUploadField     []
INFO  - BaseWicketTester           - path
formCreationQuestionnaire:visualiser
org.apache.wicket.ajax.markup.html.AjaxLink     [No get method defined for
class: class fr.statlife.protoE4N.data.entites.Questionnaire expression:
visualiser]
INFO  - ionalTestExecutionListener - Rolled back transaction after test
execution for test context [[TestContext@43a30706 testClass =
TestStory23_CreationQuestionnaire, locations =
array<String>['classpath:/applicationContext.xml'], testInstance =
fr.statlife.protoE4N.wicket.TestStory23_CreationQuestionnaire@4223d9b,
testMethod =
testStory23_TA21_VerificationInitialisationBoutonsRadio@TestStory23_CreationQuestionnaire,
testException = junit.framework.AssertionFailedError: null]]
INFO  - GenericApplicationContext  - Closing
org.springframework.context.support.GenericApplicationContext@220ca470:
startup date [Fri Aug 19 16:32:03 CEST 2011]; root of context hierarchy
INFO  - DefaultListableBeanFactory - Destroying singletons in
org.springframework.beans.factory.support.DefaultListableBeanFactory@105691e:
defining beans
[entityManagerFactory,transactionManager,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,administrateurDaoImpl,lienBaseE4NDaoImpl,listeQuestionnaireDaoImpl,membreDaoImpl,questionDaoImpl,questionnaireDaoImpl,reponseDaoImpl,serviceAdministrateurImpl,serviceIdentificationImpl,serviceInscriptionImpl,serviceLienBaseE4NImpl,serviceListeQuestionnaireImpl,serviceMailImpl,serviceMembreImpl,serviceNutritionImpl,serviceQuestionnaireImpl,initData];
root of factory hierarchy
INFO  - alEntityManagerFactoryBean - Closing JPA EntityManagerFactory for
persistence unit 'jpaUnitProtoE4N'
INFO  - SessionFactoryImpl         - closing
INFO  - rManagerConnectionProvider - cleaning up connection pool:
jdbc:postgresql://localhost:5432/protoE4N

Re: how to test what radio is checked in a radiogroup?

Posted by Mathilde Pellerin <ma...@statlife.fr>.
Thank you for your answer Mike.

I didn't find out how could I try with Radio.onComponentTag, so I tried with
tagTester.

I think it could be a good solution, so I did that :
        TagTester tagFemme =
tester.getTagByWicketId("formCreationQuestionnaire:genre:femme");
        TagTester tagHomme =
tester.getTagByWicketId("formCreationQuestionnaire:genre:homme");
        TagTester tagMixte =
tester.getTagByWicketId("formCreationQuestionnaire:genre:mixte");
        Assert.assertNotNull(tagFemme);
        Assert.assertTrue(tagFemme.hasAttribute("checked"));
        Assert.assertFalse(tagHomme.hasAttribute("checked"));
        Assert.assertFalse(tagMixte.hasAttribute("checked"));

but my tagTester are always null ! I checked path many times, and I tried
other way to instantiate tagTester, but without success.
I already used TagTester in other test before without problem, and I really
don't understand why it is always null here...

Re: how to test what radio is checked in a radiogroup?

Posted by Mike Mander <wi...@gmx.de>.
Am 19.08.2011 14:21, schrieb Mathilde Pellerin:
> Hi all,
>
> I have a form with a Radiogroup :
>
> In my form, I have a radiogroup like this :
>          RadioGroup<String>  genre = new
> RadioGroup<String>("genreDestinataire");
>          genre.setRequired(true);
>          genre.setLabel(new Model<String>("Genre destinataire"));
>          genre.add(new Radio<String>("femme", new Model<String>("f")));
>          genre.add(new Radio<String>("homme", new Model<String>("h")));
>          genre.add(new Radio<String>("mixte", new Model<String>("b")));
>          form.add(genre);
>
> This radiogroup match the genreDestinataire field in Questionnaire Entity
> (with a CompoundPropertyModel).
>
> In my unit test, I try to check what radio is selected, but I don't find
> how...
> I can get Model Object from radioGroup like this :
>          String genreObtenu =
> ((RadioGroup<String>)form.get("genreDestinataire")).getDefaultModelObjectAsString();
>
> but it works even if none of radio is checked. It happen when I fill the
> form with existant Questionnaire : radiogroup model is ok, but none of radio
> is checked.
> Before correct this bug, I want to reproduce it in test, but I didn't find
> how to see if a radio is checked or not : I didn't find any method like
> "isChecked" or "isSelected" on Radio Component.
>
> Is there any way to check that ?
>
> Thanks.
> M.
>
Maybe you can get the component from last renderered page (by path to 
component) and cast it to radio.
Then you can compare raw input of group with the radio value (see 
Radio.onComponentTag).

Other option would be to use the tag tester provided by WicketTester. See

     /**
      * Modified version of BaseWicketTester#getTagByWicketId(String) 
that returns all matching tags
      * instead of just the first.
      *
      * @see BaseWicketTester#getTagByWicketId(String)
      */
     public static List<TagTester> getTagsByWicketId(WicketTester 
tester, String wicketId)
     {
         return 
TagTester.createTagsByAttribute(tester.getServletResponse().getDocument(),
             "wicket:id", wicketId, false);
     }

Hth
Mike

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