You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by David Beer <da...@gmail.com> on 2017/02/09 23:08:58 UTC
Test Page renders with Nested Panel
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;
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");
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);
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);
tester = getTester();
tester.startPage(adminViewPage);
}
@Test
public void renderSuccessfully() throws Exception {
tester.assertRenderedPage(AdminViewPage.class);
}
}
Any pointers would be great.
Thanks
David
Re: Test Page renders with Nested Panel
Posted by David Beer <da...@gmail.com>.
Hi
Thanks for the link I will look into this further separately. See if I can
do something Similar for Java EE and @EJB etc.
On 14 February 2017 at 09:12, Martin Grigorov <mg...@apache.org> wrote:
> Hi,
>
> I thought you want to use Spring (because the branch name mentions it).
> You can do the same with Java EE.
> If you use CDI then take a look at
> https://github.com/apache/wicket/tree/master/wicket-cdi-
> 1.1/src/test/java/org/apache/wicket/cdi
> I have no idea how to test @EJB and @Stateless. I haven't used those since
> very long time.
>
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
>
> On Mon, Feb 13, 2017 at 11:39 PM, David Beer <da...@gmail.com>
> wrote:
>
> > Hi Martin
> >
> > Thanks for the PR. So the solution is to remove JavaEE EJB references
> > rather than to use them and test them. Understand Spring doesn't care
> about
> > EJB but and vice versa. I am only using spring for the security layer and
> > JavaEE for everything else.
> >
> > So does @SpringBean just convert the EJB to a spring bean.
> >
> > So the only other way to test the EJB approach is to pass a mock value to
> > the constructor and have it check if the value is null as the container
> > will Inject the value.
> >
> > David
> >
> >
> > On 13 February 2017 at 21:20, Martin Grigorov <mg...@apache.org>
> > wrote:
> >
> > > https://github.com/dmbeer/wicket-7-spring-security/pull/1
> > > There you go!
> > >
> > > I've removed/commented out the Java EE stuff.
> > > Spring doesn't care about @EJB/@Stateless. As JavaEE doesn't care about
> > > @Component & Co.
> > >
> > > Martin Grigorov
> > > Wicket Training and Consulting
> > > https://twitter.com/mtgrigorov
> > >
> > > On Mon, Feb 13, 2017 at 10:05 PM, David Beer <da...@gmail.com>
> > > wrote:
> > >
> > > > Hi Martin
> > > >
> > > > It appears there was an error when I tried to push the code. I am
> > trying
> > > to
> > > > test AdminPage, and failing to inject the mock from the application
> > > > context.
> > > >
> > > > AdminPage
> > > > https://github.com/dmbeer/wicket-7-spring-security/blob/
> > > > wicket-7-test-spring-security/src/main/java/com/copperarrow/
> > > > pages/AdminPage.java
> > > > AdmingPageTest
> > > > https://github.com/dmbeer/wicket-7-spring-security/blob/
> > > > wicket-7-test-spring-security/src/test/java/com/copperarrow/
> > > > pages/AdminPageTest.java
> > > > UserAccountDataProvider
> > > > https://github.com/dmbeer/wicket-7-spring-security/blob/
> > > > wicket-7-test-spring-security/src/main/java/com/copperarrow/
> > > > model/dataproviders/UserAccountDataProvider.java
> > > >
> > > > This fails unable to attach container because UserDAO is always null
> > even
> > > > though I have added it to the applicationmock context.
> > > >
> > > >
> > > >
> > > > On 13 February 2017 at 19:57, Martin Grigorov <mg...@apache.org>
> > > > wrote:
> > > >
> > > > > Hi David,
> > > > >
> > > > > Please give more information what is not working.
> > > > > There are 3 tests and all pass.
> > > > > I have no idea where to look for a problem.
> > > > >
> > > > > Martin Grigorov
> > > > > Wicket Training and Consulting
> > > > > https://twitter.com/mtgrigorov
> > > > >
> > > > > On Sat, Feb 11, 2017 at 11:12 PM, David Beer <
> david.m.beer@gmail.com
> > >
> > > > > wrote:
> > > > >
> > > > > > 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 <
> > mgrigorov@apache.org>
> > > > > > wrote:
> > > > > >
> > > > > > > Hi,
> > > > > > >
> > > > > > >
> > > > > > > On Fri, Feb 10, 2017 at 12:08 AM, David Beer <
> > > david.m.beer@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
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
Re: Test Page renders with Nested Panel
Posted by Martin Grigorov <mg...@apache.org>.
Hi,
I thought you want to use Spring (because the branch name mentions it).
You can do the same with Java EE.
If you use CDI then take a look at
https://github.com/apache/wicket/tree/master/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi
I have no idea how to test @EJB and @Stateless. I haven't used those since
very long time.
Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov
On Mon, Feb 13, 2017 at 11:39 PM, David Beer <da...@gmail.com> wrote:
> Hi Martin
>
> Thanks for the PR. So the solution is to remove JavaEE EJB references
> rather than to use them and test them. Understand Spring doesn't care about
> EJB but and vice versa. I am only using spring for the security layer and
> JavaEE for everything else.
>
> So does @SpringBean just convert the EJB to a spring bean.
>
> So the only other way to test the EJB approach is to pass a mock value to
> the constructor and have it check if the value is null as the container
> will Inject the value.
>
> David
>
>
> On 13 February 2017 at 21:20, Martin Grigorov <mg...@apache.org>
> wrote:
>
> > https://github.com/dmbeer/wicket-7-spring-security/pull/1
> > There you go!
> >
> > I've removed/commented out the Java EE stuff.
> > Spring doesn't care about @EJB/@Stateless. As JavaEE doesn't care about
> > @Component & Co.
> >
> > Martin Grigorov
> > Wicket Training and Consulting
> > https://twitter.com/mtgrigorov
> >
> > On Mon, Feb 13, 2017 at 10:05 PM, David Beer <da...@gmail.com>
> > wrote:
> >
> > > Hi Martin
> > >
> > > It appears there was an error when I tried to push the code. I am
> trying
> > to
> > > test AdminPage, and failing to inject the mock from the application
> > > context.
> > >
> > > AdminPage
> > > https://github.com/dmbeer/wicket-7-spring-security/blob/
> > > wicket-7-test-spring-security/src/main/java/com/copperarrow/
> > > pages/AdminPage.java
> > > AdmingPageTest
> > > https://github.com/dmbeer/wicket-7-spring-security/blob/
> > > wicket-7-test-spring-security/src/test/java/com/copperarrow/
> > > pages/AdminPageTest.java
> > > UserAccountDataProvider
> > > https://github.com/dmbeer/wicket-7-spring-security/blob/
> > > wicket-7-test-spring-security/src/main/java/com/copperarrow/
> > > model/dataproviders/UserAccountDataProvider.java
> > >
> > > This fails unable to attach container because UserDAO is always null
> even
> > > though I have added it to the applicationmock context.
> > >
> > >
> > >
> > > On 13 February 2017 at 19:57, Martin Grigorov <mg...@apache.org>
> > > wrote:
> > >
> > > > Hi David,
> > > >
> > > > Please give more information what is not working.
> > > > There are 3 tests and all pass.
> > > > I have no idea where to look for a problem.
> > > >
> > > > Martin Grigorov
> > > > Wicket Training and Consulting
> > > > https://twitter.com/mtgrigorov
> > > >
> > > > On Sat, Feb 11, 2017 at 11:12 PM, David Beer <david.m.beer@gmail.com
> >
> > > > wrote:
> > > >
> > > > > 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 <
> mgrigorov@apache.org>
> > > > > wrote:
> > > > >
> > > > > > Hi,
> > > > > >
> > > > > >
> > > > > > On Fri, Feb 10, 2017 at 12:08 AM, David Beer <
> > david.m.beer@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
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
Re: Test Page renders with Nested Panel
Posted by David Beer <da...@gmail.com>.
Hi Martin
Thanks for the PR. So the solution is to remove JavaEE EJB references
rather than to use them and test them. Understand Spring doesn't care about
EJB but and vice versa. I am only using spring for the security layer and
JavaEE for everything else.
So does @SpringBean just convert the EJB to a spring bean.
So the only other way to test the EJB approach is to pass a mock value to
the constructor and have it check if the value is null as the container
will Inject the value.
David
On 13 February 2017 at 21:20, Martin Grigorov <mg...@apache.org> wrote:
> https://github.com/dmbeer/wicket-7-spring-security/pull/1
> There you go!
>
> I've removed/commented out the Java EE stuff.
> Spring doesn't care about @EJB/@Stateless. As JavaEE doesn't care about
> @Component & Co.
>
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
>
> On Mon, Feb 13, 2017 at 10:05 PM, David Beer <da...@gmail.com>
> wrote:
>
> > Hi Martin
> >
> > It appears there was an error when I tried to push the code. I am trying
> to
> > test AdminPage, and failing to inject the mock from the application
> > context.
> >
> > AdminPage
> > https://github.com/dmbeer/wicket-7-spring-security/blob/
> > wicket-7-test-spring-security/src/main/java/com/copperarrow/
> > pages/AdminPage.java
> > AdmingPageTest
> > https://github.com/dmbeer/wicket-7-spring-security/blob/
> > wicket-7-test-spring-security/src/test/java/com/copperarrow/
> > pages/AdminPageTest.java
> > UserAccountDataProvider
> > https://github.com/dmbeer/wicket-7-spring-security/blob/
> > wicket-7-test-spring-security/src/main/java/com/copperarrow/
> > model/dataproviders/UserAccountDataProvider.java
> >
> > This fails unable to attach container because UserDAO is always null even
> > though I have added it to the applicationmock context.
> >
> >
> >
> > On 13 February 2017 at 19:57, Martin Grigorov <mg...@apache.org>
> > wrote:
> >
> > > Hi David,
> > >
> > > Please give more information what is not working.
> > > There are 3 tests and all pass.
> > > I have no idea where to look for a problem.
> > >
> > > Martin Grigorov
> > > Wicket Training and Consulting
> > > https://twitter.com/mtgrigorov
> > >
> > > On Sat, Feb 11, 2017 at 11:12 PM, David Beer <da...@gmail.com>
> > > wrote:
> > >
> > > > 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 <mg...@apache.org>
> > > > wrote:
> > > >
> > > > > Hi,
> > > > >
> > > > >
> > > > > On Fri, Feb 10, 2017 at 12:08 AM, David Beer <
> david.m.beer@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
> > > > > >
> > > > >
> > > >
> > >
> >
>
Re: Test Page renders with Nested Panel
Posted by Martin Grigorov <mg...@apache.org>.
https://github.com/dmbeer/wicket-7-spring-security/pull/1
There you go!
I've removed/commented out the Java EE stuff.
Spring doesn't care about @EJB/@Stateless. As JavaEE doesn't care about
@Component & Co.
Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov
On Mon, Feb 13, 2017 at 10:05 PM, David Beer <da...@gmail.com> wrote:
> Hi Martin
>
> It appears there was an error when I tried to push the code. I am trying to
> test AdminPage, and failing to inject the mock from the application
> context.
>
> AdminPage
> https://github.com/dmbeer/wicket-7-spring-security/blob/
> wicket-7-test-spring-security/src/main/java/com/copperarrow/
> pages/AdminPage.java
> AdmingPageTest
> https://github.com/dmbeer/wicket-7-spring-security/blob/
> wicket-7-test-spring-security/src/test/java/com/copperarrow/
> pages/AdminPageTest.java
> UserAccountDataProvider
> https://github.com/dmbeer/wicket-7-spring-security/blob/
> wicket-7-test-spring-security/src/main/java/com/copperarrow/
> model/dataproviders/UserAccountDataProvider.java
>
> This fails unable to attach container because UserDAO is always null even
> though I have added it to the applicationmock context.
>
>
>
> On 13 February 2017 at 19:57, Martin Grigorov <mg...@apache.org>
> wrote:
>
> > Hi David,
> >
> > Please give more information what is not working.
> > There are 3 tests and all pass.
> > I have no idea where to look for a problem.
> >
> > Martin Grigorov
> > Wicket Training and Consulting
> > https://twitter.com/mtgrigorov
> >
> > On Sat, Feb 11, 2017 at 11:12 PM, David Beer <da...@gmail.com>
> > wrote:
> >
> > > 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 <mg...@apache.org>
> > > wrote:
> > >
> > > > Hi,
> > > >
> > > >
> > > > On Fri, Feb 10, 2017 at 12:08 AM, David Beer <david.m.beer@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
> > > > >
> > > >
> > >
> >
>
Re: Test Page renders with Nested Panel
Posted by David Beer <da...@gmail.com>.
Hi Martin
It appears there was an error when I tried to push the code. I am trying to
test AdminPage, and failing to inject the mock from the application context.
AdminPage
https://github.com/dmbeer/wicket-7-spring-security/blob/wicket-7-test-spring-security/src/main/java/com/copperarrow/pages/AdminPage.java
AdmingPageTest
https://github.com/dmbeer/wicket-7-spring-security/blob/wicket-7-test-spring-security/src/test/java/com/copperarrow/pages/AdminPageTest.java
UserAccountDataProvider
https://github.com/dmbeer/wicket-7-spring-security/blob/wicket-7-test-spring-security/src/main/java/com/copperarrow/model/dataproviders/UserAccountDataProvider.java
This fails unable to attach container because UserDAO is always null even
though I have added it to the applicationmock context.
On 13 February 2017 at 19:57, Martin Grigorov <mg...@apache.org> wrote:
> Hi David,
>
> Please give more information what is not working.
> There are 3 tests and all pass.
> I have no idea where to look for a problem.
>
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
>
> On Sat, Feb 11, 2017 at 11:12 PM, David Beer <da...@gmail.com>
> wrote:
>
> > 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 <mg...@apache.org>
> > wrote:
> >
> > > Hi,
> > >
> > >
> > > On Fri, Feb 10, 2017 at 12:08 AM, David Beer <da...@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
> > > >
> > >
> >
>
Re: Test Page renders with Nested Panel
Posted by Martin Grigorov <mg...@apache.org>.
Hi David,
Please give more information what is not working.
There are 3 tests and all pass.
I have no idea where to look for a problem.
Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov
On Sat, Feb 11, 2017 at 11:12 PM, David Beer <da...@gmail.com> wrote:
> 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 <mg...@apache.org>
> wrote:
>
> > Hi,
> >
> >
> > On Fri, Feb 10, 2017 at 12:08 AM, David Beer <da...@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
> > >
> >
>
Re: Test Page renders with Nested Panel
Posted by David Beer <da...@gmail.com>.
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 <mg...@apache.org> wrote:
> Hi,
>
>
> On Fri, Feb 10, 2017 at 12:08 AM, David Beer <da...@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
> >
>
Re: Test Page renders with Nested Panel
Posted by Martin Grigorov <mg...@apache.org>.
Hi,
On Fri, Feb 10, 2017 at 12:08 AM, David Beer <da...@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
>