O'Reilly logo

JSF 2.0 Cookbook by Anghel Leonard

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

JSFUnit API

This recipe comes to amplify the previous two recipes with more details regarding JSFUnit API. You will see a set of snapshots that cover the main questions about writing JSFUnit test classes.

How to do it...

You can integrate the following code snippets into your JSFUnit test classes just by simple copy-pasting and then replacing the […] sections accordingly to your needs:

  • Start a JSFUnit session by getting a page:
    WebClientSpec webClientSpec = new WebClientSpec("/[PAGE_NAME]");
    HtmlPage htmlPage = (HtmlPage)webClientSpec.doInitialRequest();
    
  • Get the FacesContext instance:
    FacesContext facesContext =
    FacesContextBridge.getCurrentInstance();
    
  • Get the key to all state as of the last request:
    UIViewRoot uiViewRoot = facesContext.getViewRoot(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required