2 Replies Latest reply on May 14, 2008 3:27 PM by Francois Eric

    Testing question

    Francois Eric Novice


      I'm quite new with Seam and although I love what I'm seeing, I have a few questions concerning the tests.

      First off, I am building a test application and in it I have a AuthenticationAction that calls a AuthenticationFacade.  I call the action with this:

      (AuthenticationFacade) Component.getInstance("authenticationFacade");

      Now in my test case, I want to test that the AuthenticationAction works by calling the authenticationFacade (therefore it is a integration test since it tests more than merely a class).  So far my test looks like this:

          public void unitTestAuthenticationOK() throws Exception {
              new ComponentTest() {
                  protected void testComponents() throws Exception {
                      AuthenticationAction authenticationAction = new AuthenticationAction();
                      Identity identity = new Identity();
                      setField(authenticationAction, "identity", identity);
                      assert authenticationAction.authenticate();

      And here is the code in the AuthenticationAction:

           private Identity identity;
           public boolean authenticate() {
                try {
                     LoginUser user = Component.getInstance("authenticationFacade").login(identity.getUsername(), identity.getPassword(), null);
                     if(user != null) {
                          for(LoginRole userRole: user.getLoginRoles()) {
                          for(LoginRole groupRole: user.getGroup().getRoles()) {
                     return true;
                } catch (SystemException e) {
                     return false;
                } catch (LoginFailureException e) {
                     return false;

      I get a NullPointerException when the AuthenticationAction calls the Component.getInstance() method.  I can understand it since I haven't told the test case where to look for the facade but I don't know how to do this.

      More precisely my questions are:
      1- How can I tell my test case that authenticationAction will call a authenticationFacade?
      2- Am I using the correct way for a service to call another service by using Component.getInstance().

      Thanks for your help,