0

So my application runs on JSF 1.2 and uses the Spring Beans IOC to inject classes into Backing Beans based on the Spring Context XML configuration.

I am using JSFUnit for testing, and I can navigate through pages and assert on my Backing Bean values, however I am unable yet to access any of the injected beans.

I know JSFUnit has been advertized to do white-box testing, but so far I could only do stuff similar to the in-container testing made with Arquilian.

Can anyone help me with accessing the Business Object I have (injected by Spring) once I open the page related to the Backing Bean ? Thanks !

abdelrahman-sinno
  • 1,157
  • 1
  • 12
  • 33

1 Answers1

0

I found the answer, once you navigate to your page, you can call this method in your test case which simply returns the bean by bean name, it's so neat:

@SuppressWarnings("unchecked")
public static <T> T findBean(String beanName) {
    FacesContext context = FacesContext.getCurrentInstance();
    return (T) context.getApplication().evaluateExpressionGet(context, "#{"+beanName+"}", Object.class);
}

Now JSFUnit became much more useful !

abdelrahman-sinno
  • 1,157
  • 1
  • 12
  • 33