title: Wicket (Java) : How to use wickettester to test if 404 redirected to correct page
body: <p>With the wicketframework it's possible to use wickettester and see lastrenderedpage.
  I want to test if my wicketapplication redirects the user to my custom ErrorPage on
  runtimeexceptions and missing resources (404).</p>
  
  <p>For the first case i set the redirect to my custom errorpage and verified it works. Basically,
  "   <code>settings.setInternalErrorPage(ErrorPage.class);</code>"
  and having a unittest that basically goes:</p>
  
  <pre><code> tester = new WicketTester(webApplication);
          APage aPage = new APage();
          tester.startPage(aPage);
          tester.assertRenderedPage(APage.class);
          tester.setExposeExceptions(false);
  
          //Page rendered ok, now throw an exception at a button submit
          when(aPage.getServiceFacade()).thenThrow(new RuntimeException("DummyException"));
          tester.submitForm("searchPanel:searchForm");
          tester.assertRenderedPage(ErrorPage.class);//YES, we got redirected to deploymode
  </code></pre>
  
  <p>So the test for runtimeexecptions -> errorpage works fine.
  Now to testing for missing resources. 
  Basically i set up the web.xml with "</p>
  
  <pre><code> &lt;error-page&gt; 
      &lt;error-code&gt;404&lt;/error-code&gt;
      &lt;location&gt;/error404&lt;/location&gt;
      &lt;/error-page&gt;
  </code></pre>
  
  <p>which i then also mounted in wicket.
  This works fine for real usage. But when testing.. i tried this..</p>
  
  <pre><code> MockHttpServletRequest request = tester.getRequest();
           String contextPath = request.getContextPath();
           String filterPrefix = request.getFilterPrefix();
           tester.setExposeExceptions(false);
           tester.executeUrl(contextPath + "/" + filterPrefix + "/"+ "startpage" + "/MyStrangeurlToNothing);
           tester.assertRenderedPage(ErrorPage.class);
  </code></pre>
  
  <p>But, lastrenderedpage on tester object doesn't work in this case and gives me null. I guess WicketTester doesn't read the web.xml for example, and so, wouldn't know how to map this error. Any hints on how to test this?</p>