Test safely:

https://cwiki.apache.org/WICKET/type-safe-testing-in-wicket.html

2012/4/21 mmuk...@gmail.com <mmuk...@gmail.com>:
> I have several wicket tests that target a sortable DataTable, specifically
> ajax-clicking the sortable column headers and asserting the contents of the
> rendered body rows. Now the component hierarchy of the table component's
> descendants is auto generated by the wicket framework, and results in paths
> to the sorting links (ajax) similar to:
>
>    table:topToolbars:toolbars:0:headers:1:header:orderByLink
>
> However, when the DataTable gets re-rendered across tests, the index of the
> toolbars component is incremented each time i.e similar to:
>
>    table:topToolbars:toolbars:1:headers:1:header:orderByLink
>
> which then breaks the hard-coded paths of the succeeding tests as they will
> no longer match.
>
> The code fragment for the datatable construction is as follows:
>
>                final PayeesProvider dataProvider = new PayeesProvider();
>                table = new DataTable<ResponsePayeeDetails>("payees", columns,
> dataProvider, rowsPerPage);
>                table.setOutputMarkupId(true);
>                table.addTopToolbar(new AjaxFallbackHeadersToolbar(table, 
> dataProvider) {
>
>                        private static final long serialVersionUID = 
> -3509487788284410429L;
>
>                        @Override
>                        protected WebMarkupContainer newSortableHeader(final 
> String borderId,
> final String property, final ISortStateLocator locator) {
>                                return new AjaxFallbackOrderByBorder(borderId, 
> property, locator,
> getAjaxCallDecorator()) {
>
>                                        @Override
>                                        protected void onRender() {
>                                                System.out.printf("Path: 
> %s\n", this.getPageRelativePath());
>                                                super.onRender();
>                                        }
>
>                                        private static final long 
> serialVersionUID = -6399737639959498915L;
>
>                                        @Override
>                                        protected void onAjaxClick(final 
> AjaxRequestTarget target) {
>                                                target.add(getTable(), 
> navigator, navigatorInfoContainer);
>                                        }
>
>                                        @Override
>                                        protected void onSortChanged() {
>                                                super.onSortChanged();
>                                                getTable().setCurrentPage(0);
>                                        }
>                                };
>                        }
>                });
>                table.addBottomToolbar(new NoRecordsToolbar(table));
>                add(table);
>
> To be precise, when I run my tests, the above System.out.printf statement
> prints:
>
> (1st test)
>
>    Path: payees:topToolbars:toolbars:0:headers:1:header
>    Path: payees:topToolbars:toolbars:0:headers:2:header
>
> (2nd test)
>
>    Path: payees:topToolbars:toolbars:2:headers:1:header
>    Path: payees:topToolbars:toolbars:2:headers:2:header
>
> (3rd test)
>
>    Path: payees:topToolbars:toolbars:4:headers:1:header
>    Path: payees:topToolbars:toolbars:4:headers:2:header
>
> (4th test)
>
>    Path: payees:topToolbars:toolbars:6:headers:1:header
>    Path: payees:topToolbars:toolbars:6:headers:2:header
>    Path: payees:topToolbars:toolbars:6:headers:1:header
>    Path: payees:topToolbars:toolbars:6:headers:2:header
>    Path: payees:topToolbars:toolbars:6:headers:1:header
>    Path: payees:topToolbars:toolbars:6:headers:2:header
>
> (5th test)
>
>    Path: payees:topToolbars:toolbars:8:headers:1:header
>    Path: payees:topToolbars:toolbars:8:headers:2:header
>
> Does anyone know how I can force the index generation to be more
> deterministic / repeatable. Alternatively, is there a way of wild-carding or
> otherwise generalising the path, so as to make them immune to these
> increments?
>
> Any help will be greatly appreciated chaps!
>
>
> --
> View this message in context: 
> http://apache-wicket.1842946.n4.nabble.com/How-do-I-keep-component-paths-constant-across-unit-tests-when-using-Wicket-Tester-tp4577030p4577030.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>

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

Reply via email to