Hi Martin

Thanks for the pointers some left over code from refactoring. I have
created an example project located here
<https://github.com/dmbeer/wicket-7-spring-security/tree/wicket-7-test-spring-security>
under branch wicket-7-test-spring-security. I am still struggling to get
the mocked DAO injected. Any pointers welcome or even a PR if not too much
trouble or example somewhere.

Thanks

David

On 10 February 2017 at 07:46, Martin Grigorov <mgrigo...@apache.org> wrote:

> Hi,
>
>
> On Fri, Feb 10, 2017 at 12:08 AM, David Beer <david.m.b...@gmail.com>
> wrote:
>
> > Hi Guys
> >
> > I am new to WicketTester and testing pages here. I am also getting back
> > into wicket slowly.
> >
> > I have a page which currently simply adds a panel (more to come), the
> panel
> > contains a DataTable. I am not interested in the content of the table
> just
> > that the page renders with an empty table.
> >
> > MyPage -> MyPanel -> Adds a DataTable, using dataproviders.
> >
> > The problem is that when I do tester.startPage(MyPage.class) it tries to
> > add the data table and fails unless data provider size is set to 0.
> >
> > MyPage Code
> >
> > public class MyPage extends BasePage<AdminViewPage> {
> >
> > private NotificationPanel notificationPanel;
> > private BootstrapDefaultDataTable<UserAccount, String> userTable;
> >
>
> This is not used/needed.
>
>
> >
> > public MyPage() {
> > notificationPanel = new NotificationPanel("notification");
> > notificationPanel.setOutputMarkupId(true);
> > notificationPanel.hideAfter(Duration.seconds(2));
> > add(notificationPanel);
> > add(new MyPanel("users-table-panel"));
> > }
> > }
> >
> > MyPanel code
> >
> > public class MyPanel extends Panel {
> >
> >     private NotificationPanel notificationPanel;
> >     private BootstrapDefaultDataTable<UserAccount, String> userTable;
> >
> >
> >     public UsersTablePanel(String id) {
> >         super(id);
> >         notificationPanel = new NotificationPanel("notification");
>
>
> This looks the same as in the page. Maybe one should be removed ?!
>
>
> >         notificationPanel.setOutputMarkupId(true);
> >         notificationPanel.hideAfter(Duration.seconds(2));
> >         add(notificationPanel);
> >         usersTable();
> >     }
> >
> >     private void usersTable() {
> >         List<IColumn<UserAccount, String>> columns = new ArrayList<>();
> >         columns.add(new PropertyColumn<>(Model.of("First Name"),
> > "firstName", "firstName"));
> >         columns.add(new PropertyColumn<>(Model.of("Last Name"),
> > "lastName"));
> >         columns.add(new PropertyColumn<>(Model.of("Email Address"),
> > "email"));
> >         columns.add(new PropertyColumn<>(Model.of("Username"),
> > "userName"));
> >
> >         userTable = new BootstrapDefaultDataTable<>("users-table",
> > columns,
> > new DataProvider(), 20);
> >
>
> Here you create a new DataProvider.
> Does it use some service (Spring, EJB, Guice,...) to load the items ?!
>
>
> >         userTable.add(new TableBehavior().hover().bordered());
> >         add(userTable);
> >     }
> > }
> >
> > MyPageTest Code
> >
> > public class AdminViewPageTest extends WicketApplicationTest {
> >
> > private WicketTester tester;
> >
> > private UsersDataProvider usersDataProvider;
> >
> > private AdminViewPage adminViewPage;
> >
> > @Before
> > public void setUp() throws Exception {
> > super.setUp();
> > usersDataProvider = mock(UsersDataProvider.class);
> > adminViewPage = new AdminViewPage();
> > doNothing().when(usersDataProvider).checkDAO();
> > when(usersDataProvider.size()).thenReturn(0L);
> >
>
> This usersDataProvider is not really used by UsersTablePanel.java because
> it creates its own one (new DataProvider()). So the mocking doesn't really
> help.
>
>
> > tester = getTester();
> > tester.startPage(adminViewPage);
> > }
> >
> > @Test
> > public void renderSuccessfully() throws Exception {
> > tester.assertRenderedPage(AdminViewPage.class);
> > }
> >
> > }
> >
> > Any pointers would be great.
> >
>
> Usually the DataProviders use some service to load the items and this
> service is injected (Spring, CDI, ...).
> Then in your tests you need to provide Dependency Injection context that
> provides mocked service. This way Wicket will used the mock for the tests
> and the real service when running the application.
>
>
> >
> > Thanks
> >
> > David
> >
>

Reply via email to