mercredi 31 janvier 2018

How to JUnit Test a Wicket Page

I've got the following Wicket Page which serves a PDF:

public class TestPage extends WebPage {    
  public TestPage(PageParameters pageParameters) {
        String param1 = pageParameters.get("test").toString();
        String param2 = pageParameters.get("test1").toString();
        [..]
        try {       
            byte[] generatedPDF= generatePDF(param1, param2, pdfGenerationOptions);
                RequestCycle requestCycle = RequestCycle.get();
                HttpServletRequest request = (HttpServletRequest) requestCycle.getRequest().getContainerRequest();
                requestCycle.replaceAllRequestHandlers(new ResourceRequestHandler(new PDFResource("test.pdf", request.getHeader(USER_AGENT), true), null));
        } catch (PdfGenerationException | IOException e) {
            LOGGER.error("error", e);
            new PageProvider(ErrorPage.class);
        }
    }

    @Override
    public void renderPage() {
        // left blank
    }
}

How would it be possible to test if the page returns a byte array (pdf) or the ErrorPage.class since I can only call the constructor in this case?

thanks in advance

Aucun commentaire:

Enregistrer un commentaire