Hi, Additionally you need to : tester.executeBehavior() otherwise WicketTester is not used at all in your test.
On Thu, Nov 1, 2012 at 10:49 PM, vineet semwal <vineetsemwa...@gmail.com> wrote: > hi, > this is expected behavior, > AbortWithHttpErrorCodeException doesn't respond with > InternalErrorPage,it merely sets HTTP error code , > you can assert that by below code > > Assert.assertEquals( tester.getLastResponse().getStatus(), > HttpServletResponse.SC_NOT_FOUND); > Assert.assertEquals(tester.getLastResponse().getErrorMessage(), > "This is for testing") ; > > > On Thu, Nov 1, 2012 at 11:54 PM, Per Newgro <per.new...@gmx.ch> wrote: >> Hi, >> >> i try to unit test a custom behavior. But i was wondering what's the right >> way to test it. >> >> I provide some code to explain my mind mismatch. The behavior shall >> interrupt the rendering >> of a component. I would like to answer this with a 404. Calling the behavior >> method directly >> results in the expected exception. But if i render a using component it's >> not answered by the 404. >> >> How can i get a 404 within the usage testcase (see below). >> >> Thanks for helping me >> Per >> >> <code> >> public class TestHomePage { >> >> public static class MyBehavior extends Behavior { >> @Override >> public void beforeRender(Component component) { >> if (true) { >> throw new >> AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, "This is >> for testing"); >> } >> } >> } >> >> public static class MyTestHomePage extends WebPage implements >> IMarkupResourceStreamProvider { >> >> public MyTestHomePage() { >> add(new MyBehavior()); >> } >> >> @Override >> public IResourceStream getMarkupResourceStream( >> MarkupContainer container, Class<?> containerClass) { >> return Markup.of("<html></html>").getMarkupResourceStream(); >> } >> } >> >> private WicketTester tester; >> >> @Before >> public void setUp() { >> tester = new WicketTester(new WicketApplication()); >> } >> >> @Test >> public void abortRenderingOnUsage() { >> tester.startPage(MyTestHomePage.class); >> tester.assertRenderedPage(InternalErrorPage.class); >> } >> >> @Test(expected = AbortWithHttpErrorCodeException.class) >> public void abortRenderingOnUnitTesting() { >> MyBehavior behavior = new MyBehavior(); >> behavior.beforeRender(null); >> } >> } >> </code> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >> For additional commands, e-mail: users-h...@wicket.apache.org >> > > > > -- > regards, > > Vineet Semwal > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > -- Martin Grigorov jWeekend Training, Consulting, Development http://jWeekend.com --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org