Re: [Wicket-user] Unit testing - updating a DropDownChoice with Ajax
I tried with formTester.submit() and the test went OK with that. Anyway, thanks for informing about the fix (WICKET-254), I will take it into use. Regards, Richard. Jean-Baptiste Quenot-3 wrote: > > * Jean-Baptiste Quenot: >> * glr: >> > >> > FormTester formTester = >> this.tester.newFormTester("articleEditorForm", false); >> > formTester.select("rscTypesList", 0); >> > this.tester.executeAjaxEvent("articleEditorForm:rscTypesList", >> "onchange"); >> >> Can you please try with: >> >> formTester.submit(); >> >> instead of: >> >> this.tester.executeAjaxEvent("articleEditorForm:rscTypesList", >> "onchange"); >> >> To see if it's not the ajax behavior that causes problems? > > Indeed WicketTester was overwriting field values in two places > when submitting via Ajax. I just fixed this, you can safely use > executeAjaxEvent() now. > > The related JIRA issue is: > > Allow to set field values before submitting a form with Ajax in > WicketTester > https://issues.apache.org/jira/browse/WICKET-254 > -- > Jean-Baptiste Quenot > aka John Banana Qwerty > http://caraldi.com/jbq/ > > - > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > ___ > Wicket-user mailing list > Wicket-user@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/wicket-user > > -- View this message in context: http://www.nabble.com/Unit-testing---updating-a-DropDownChoice-with-Ajax-tf3946499.html#a11305654 Sent from the Wicket - User mailing list archive at Nabble.com. - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ ___ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user
Re: [Wicket-user] Unit testing - updating a DropDownChoice with Ajax
Hi Here is the code for the test-case. I tried to use FormTester.select(...): public void testSelectResources() { // Set expectations to the mock content store final String title1 = "MyArticle-1"; List editorials = new ArrayList(); editorials.add(title1); // Expectations for the editor display expect(this.mockArticleStore.listEditorials()).andReturn(editorials); // Expectations for listing the resources (uploaded files). List fileNames = new ArrayList(); fileNames.add("rsc-1.bin"); fileNames.add("rsc-2.bin"); expect(this.mockResourceStore.getFilenames((String)anyObject())).andReturn(fileNames); // Replay recorded expectations replay(this.mockArticleStore); replay(this.mockResourceStore); this.tester.startPage(ArticleEditor.class); // Check if the editor page is shown. this.tester.assertRenderedPage(ArticleEditor.class); // Test resource selection DropDownChoice rscValuesChoice = (DropDownChoice)this.tester.getLastRenderedPage().get( "articleEditorForm:rscValuesList"); List rscValues = rscValuesChoice.getChoices(); assertTrue(rscValues.size() == 0); FormTester formTester = this.tester.newFormTester("articleEditorForm", false); formTester.select("rscTypesList", 0); this.tester.executeAjaxEvent("articleEditorForm:rscTypesList", "onchange"); rscValuesChoice = (DropDownChoice)this.tester.getLastRenderedPage().get( "articleEditorForm:rscValuesList"); rscValues = rscValuesChoice.getChoices(); assertTrue(rscValues.size() == 2); verify(this.mockResourceStore); verify(this.mockArticleStore); } mockResourceStore and mockArticleStore are two mock objects used to interact with at unit-testing time. The AJAX event fires correctly, but the component that it would update does not have its model in the expected state. (The production code does work correctly as integration testing can verify it.) Richard. Jean-Baptiste Quenot-3 wrote: > > * glr: > >> I tried using WicketTester with FormTester but I cannot have the >> model of the first DropDownChoice updated as a response to >> making a selection in it. As a result, when the OnEvent handler >> of the AjaxFormComponentUpdatingBehavior fires, it looks as if >> there was no selection in the first DropDownChoice. > > Can you please provide a sample code for your test? Did you make > use of FormTester.select(String, int)? > -- > Jean-Baptiste Quenot > aka John Banana Qwerty > http://caraldi.com/jbq/ > > - > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > ___ > Wicket-user mailing list > Wicket-user@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/wicket-user > > -- View this message in context: http://www.nabble.com/Unit-testing---updating-a-DropDownChoice-with-Ajax-tf3946499.html#a11283509 Sent from the Wicket - User mailing list archive at Nabble.com. - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ ___ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user
[Wicket-user] Unit testing - updating a DropDownChoice with Ajax
Hi I have 2 DropDownChoice's on a form. When making a choice in the first, the choices in the second are updated using AjaxFormComponentUpdatingBehavior. (Just like in the Drop Down Choice Example of the "live action" Wicket Examples (http://www.wicket-library.com/wicket-examples/ajax?wicket:bookmarkablePage=:wicket.examples.ajax.builtin.ChoicePage)). Could anyone tell me what the recommended way is to unit-test the above case? I tried using WicketTester with FormTester but I cannot have the model of the first DropDownChoice updated as a response to making a selection in it. As a result, when the OnEvent handler of the AjaxFormComponentUpdatingBehavior fires, it looks as if there was no selection in the first DropDownChoice. Thanks for your answer in advance, Richard. -- View this message in context: http://www.nabble.com/Unit-testing---updating-a-DropDownChoice-with-Ajax-tf3946499.html#a11195046 Sent from the Wicket - User mailing list archive at Nabble.com. - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ ___ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user