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<String> editorials = new ArrayList<String>();
editorials.add(title1);
// Expectations for the editor display
expect(this.mockArticleStore.listEditorials()).andReturn(editorials);
// Expectations for listing the resources (uploaded files).
List<String> 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
> [email protected]
> 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
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user