package mzClasses;

import java.io.IOException;

import org.jboss.jsfunit.jsfsession.JSFClientSession;
import org.jboss.jsfunit.jsfsession.JSFServerSession;
import org.jboss.jsfunit.jsfsession.JSFSession;

import junit.framework.Test;
import junit.framework.TestSuite;

public class JSFUnitTest extends org.apache.cactus.ServletTestCase{
   public static Test suite(){
      return new TestSuite( JSFUnitTest.class );
   }
   
   public void testInitialPage() throws IOException{
      // Send an HTTP request for the initial page
      JSFSession jsfSession = new JSFSession("/index.faces");
      
      // A JSFClientSession emulates the browser and lets you test HTML
      JSFClientSession client = jsfSession.getJSFClientSession();
      
      // A JSFServerSession gives you access to JSF state      
      JSFServerSession server = jsfSession.getJSFServerSession();

      // Test navigation to initial viewID
      assertEquals("/index.faces", server.getCurrentViewID());

      // Assert that the current value of username is guest
      assertEquals("guest", server.getManagedBeanValue("#{bean.name}"));  
      
      // set values and hit login
      
      client.setValue("form1:username", "john");
      client.setValue("form1:password", "ripple");
      client.click("login");
      // Test navigation 
      assertEquals("/welcome.jsp", server.getCurrentViewID());
      
   }
}
