[jboss-cvs] jboss-seam/src/test/unit/org/jboss/seam/test/unit ...

Peter Muir peter at bleepbleep.org.uk
Mon Oct 8 14:15:48 EDT 2007


  User: pmuir   
  Date: 07/10/08 14:15:47

  Added:       src/test/unit/org/jboss/seam/test/unit                                     
                        PhaseListenerTest.java MailTest.java Bar.java
                        SeamTextTest.txt People.java
                        SeamMockELResolverTest.java PageflowTest.java
                        TestActions.java DependencyTest.java
                        TimeZoneTest.java SecurityTest.java ELTest.java
                        EjbBean.java Person.java BrokenAction.java
                        DataModelTest.java Widget.java testng.xml
                        InitializationTest.java HomeTest.java Ejb.java
                        RemotingTest.java SimpleEntity.java
                        SeamTestTest.java SeamTextTest.java
                        PageActionsTest.java Foo.java ContextTest.java
                        Action.java CoreTest.java Factory.java
                        PageflowConfigurationTest.java
                        MockInvocationContext.java InterpolatorTest.java
                        InterceptorTest.java ComponentTest.java
                        LocaleTest.java
  Log:
  JBSEAM-2028
  
  Revision  Changes    Path
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/PhaseListenerTest.java
  
  Index: PhaseListenerTest.java
  ===================================================================
  //$Id: PhaseListenerTest.java,v 1.1 2007/10/08 18:15:47 pmuir Exp $
  package org.jboss.seam.test.unit;
  
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Map;
  
  import javax.faces.context.ExternalContext;
  import javax.faces.event.PhaseEvent;
  import javax.faces.event.PhaseId;
  import javax.servlet.http.HttpServletRequest;
  
  import org.jboss.seam.Component;
  import org.jboss.seam.ScopeType;
  import org.jboss.seam.Seam;
  import org.jboss.seam.contexts.ApplicationContext;
  import org.jboss.seam.contexts.Context;
  import org.jboss.seam.contexts.Contexts;
  import org.jboss.seam.contexts.SessionContext;
  import org.jboss.seam.core.Conversation;
  import org.jboss.seam.core.ConversationEntries;
  import org.jboss.seam.core.ConversationPropagation;
  import org.jboss.seam.core.Events;
  import org.jboss.seam.core.Init;
  import org.jboss.seam.core.Manager;
  import org.jboss.seam.core.ResourceLoader;
  import org.jboss.seam.faces.FacesManager;
  import org.jboss.seam.faces.FacesMessages;
  import org.jboss.seam.faces.FacesPage;
  import org.jboss.seam.faces.Validation;
  import org.jboss.seam.jsf.SeamPhaseListener;
  import org.jboss.seam.jsf.SeamStateManager;
  import org.jboss.seam.mock.MockApplication;
  import org.jboss.seam.mock.MockExternalContext;
  import org.jboss.seam.mock.MockFacesContext;
  import org.jboss.seam.mock.MockLifecycle;
  import org.jboss.seam.navigation.Pages;
  import org.jboss.seam.servlet.ServletRequestSessionMap;
  import org.jboss.seam.web.Session;
  import org.testng.annotations.Test;
  
  public class PhaseListenerTest
  {
     private void installComponents(Context appContext)
     {
        Init init = new Init();
        init.setTransactionManagementEnabled(false);
        appContext.set( Seam.getComponentName(Init.class), init );
        installComponent(appContext, FacesManager.class);
        installComponent(appContext, ConversationEntries.class);
        installComponent(appContext, FacesPage.class);
        installComponent(appContext, Conversation.class);
        installComponent(appContext, FacesMessages.class);
        installComponent(appContext, Pages.class);
        installComponent(appContext, Events.class);
        installComponent(appContext, Validation.class);
        installComponent(appContext, Session.class);
        installComponent(appContext, ConversationPropagation.class);
        installComponent(appContext, ResourceLoader.class);
     }
     
     private void installComponent(Context appContext, Class clazz)
     {
        appContext.set( Seam.getComponentName(clazz) + ".component", new Component(clazz) );
     }
     
     private MockFacesContext createFacesContext()
     {
        ExternalContext externalContext = new MockExternalContext();
        MockFacesContext facesContext = new MockFacesContext( externalContext, new MockApplication() );
        facesContext.setCurrent().createViewRoot();
        facesContext.getApplication().setStateManager( new SeamStateManager( facesContext.getApplication().getStateManager() ) );
        
        Context appContext = new ApplicationContext( externalContext.getApplicationMap() );
        installComponents(appContext);
        return facesContext;
     }
     
     @Test
     public void testSeamPhaseListener()
     {
        MockFacesContext facesContext = createFacesContext();
        SeamPhaseListener phases = new SeamPhaseListener();
  
        assert !Contexts.isEventContextActive();
        assert !Contexts.isSessionContextActive();
        assert !Contexts.isApplicationContextActive();
        assert !Contexts.isConversationContextActive();
  
        phases.beforePhase( new PhaseEvent(facesContext, PhaseId.RESTORE_VIEW, MockLifecycle.INSTANCE ) );
        
        assert Contexts.isEventContextActive();
        assert Contexts.isSessionContextActive();
        assert Contexts.isApplicationContextActive();
        assert !Contexts.isConversationContextActive();
        
        phases.afterPhase( new PhaseEvent(facesContext, PhaseId.RESTORE_VIEW, MockLifecycle.INSTANCE ) );
        
        assert Contexts.isConversationContextActive();
        assert !Manager.instance().isLongRunningConversation();
        
        phases.beforePhase( new PhaseEvent(facesContext, PhaseId.APPLY_REQUEST_VALUES, MockLifecycle.INSTANCE ) );
        phases.afterPhase( new PhaseEvent(facesContext, PhaseId.APPLY_REQUEST_VALUES, MockLifecycle.INSTANCE ) );
        phases.beforePhase( new PhaseEvent(facesContext, PhaseId.PROCESS_VALIDATIONS, MockLifecycle.INSTANCE ) );
        phases.afterPhase( new PhaseEvent(facesContext, PhaseId.PROCESS_VALIDATIONS, MockLifecycle.INSTANCE ) );
        phases.beforePhase( new PhaseEvent(facesContext, PhaseId.UPDATE_MODEL_VALUES, MockLifecycle.INSTANCE ) );
        phases.afterPhase( new PhaseEvent(facesContext, PhaseId.UPDATE_MODEL_VALUES, MockLifecycle.INSTANCE ) );
              
        phases.beforePhase( new PhaseEvent(facesContext, PhaseId.INVOKE_APPLICATION, MockLifecycle.INSTANCE ) );
              
        phases.afterPhase( new PhaseEvent(facesContext, PhaseId.INVOKE_APPLICATION, MockLifecycle.INSTANCE ) );
        
        assert !Manager.instance().isLongRunningConversation();
        
        phases.beforePhase( new PhaseEvent(facesContext, PhaseId.RENDER_RESPONSE, MockLifecycle.INSTANCE ) );
        
        assert facesContext.getViewRoot().getAttributes().size()==1;
        assert ( (FacesPage) getPageMap(facesContext).get( getPrefix() + Seam.getComponentName(FacesPage.class) ) ).getConversationId()==null;
        assert Contexts.isEventContextActive();
        assert Contexts.isSessionContextActive();
        assert Contexts.isApplicationContextActive();
        assert Contexts.isConversationContextActive();
        
        facesContext.getApplication().getStateManager().saveView(facesContext);
        
        phases.afterPhase( new PhaseEvent(facesContext, PhaseId.RENDER_RESPONSE, MockLifecycle.INSTANCE ) );
  
        assert !Contexts.isEventContextActive();
        assert !Contexts.isSessionContextActive();
        assert !Contexts.isApplicationContextActive();
        assert !Contexts.isConversationContextActive();
     }
  
     private String getPrefix()
     {
        return ScopeType.PAGE.getPrefix() + '$';
     }
  
     @SuppressWarnings("serial")
     @Test
     public void testSeamPhaseListenerLongRunning()
     {
        MockFacesContext facesContext = createFacesContext();
        
        getPageMap(facesContext).put( getPrefix() + Seam.getComponentName(FacesPage.class), new FacesPage() { @Override public String getConversationId() { return "2"; } });
        
        List<String> conversationIdStack = new ArrayList<String>();
        conversationIdStack.add("2");
        ConversationEntries entries = new ConversationEntries();
        entries.createConversationEntry("2", conversationIdStack);
        SessionContext sessionContext = new SessionContext( new ServletRequestSessionMap( (HttpServletRequest) facesContext.getExternalContext().getRequest() ) );
        sessionContext.set( Seam.getComponentName(ConversationEntries.class), entries );
        
        SeamPhaseListener phases = new SeamPhaseListener();
  
        assert !Contexts.isEventContextActive();
        assert !Contexts.isSessionContextActive();
        assert !Contexts.isApplicationContextActive();
        assert !Contexts.isConversationContextActive();
  
        phases.beforePhase( new PhaseEvent(facesContext, PhaseId.RESTORE_VIEW, MockLifecycle.INSTANCE ) );
        
        assert Contexts.isEventContextActive();
        assert Contexts.isSessionContextActive();
        assert Contexts.isApplicationContextActive();
        assert !Contexts.isConversationContextActive();
        
        phases.afterPhase( new PhaseEvent(facesContext, PhaseId.RESTORE_VIEW, MockLifecycle.INSTANCE ) );
        
        assert Contexts.isConversationContextActive();
        assert Manager.instance().isLongRunningConversation();
        
        phases.beforePhase( new PhaseEvent(facesContext, PhaseId.APPLY_REQUEST_VALUES, MockLifecycle.INSTANCE ) );
        phases.afterPhase( new PhaseEvent(facesContext, PhaseId.APPLY_REQUEST_VALUES, MockLifecycle.INSTANCE ) );
        phases.beforePhase( new PhaseEvent(facesContext, PhaseId.PROCESS_VALIDATIONS, MockLifecycle.INSTANCE ) );
        phases.afterPhase( new PhaseEvent(facesContext, PhaseId.PROCESS_VALIDATIONS, MockLifecycle.INSTANCE ) );
        phases.beforePhase( new PhaseEvent(facesContext, PhaseId.UPDATE_MODEL_VALUES, MockLifecycle.INSTANCE ) );
        phases.afterPhase( new PhaseEvent(facesContext, PhaseId.UPDATE_MODEL_VALUES, MockLifecycle.INSTANCE ) );
        
        phases.beforePhase( new PhaseEvent(facesContext, PhaseId.INVOKE_APPLICATION, MockLifecycle.INSTANCE ) );
        
        phases.afterPhase( new PhaseEvent(facesContext, PhaseId.INVOKE_APPLICATION, MockLifecycle.INSTANCE ) );
        
        assert Manager.instance().isLongRunningConversation();
        
        facesContext.getViewRoot().getAttributes().clear();
        
        phases.beforePhase( new PhaseEvent(facesContext, PhaseId.RENDER_RESPONSE, MockLifecycle.INSTANCE ) );
  
        assert Contexts.isEventContextActive();
        assert Contexts.isSessionContextActive();
        assert Contexts.isApplicationContextActive();
        assert Contexts.isConversationContextActive();
        
        facesContext.getApplication().getStateManager().saveView(facesContext);
        
        phases.afterPhase( new PhaseEvent(facesContext, PhaseId.RENDER_RESPONSE, MockLifecycle.INSTANCE ) );
        
        assert ( (FacesPage) getPageMap(facesContext).get( getPrefix() + Seam.getComponentName(FacesPage.class) ) ).getConversationId().equals("2");
  
        assert !Contexts.isEventContextActive();
        assert !Contexts.isSessionContextActive();
        assert !Contexts.isApplicationContextActive();
        assert !Contexts.isConversationContextActive();
     }
  
     private Map getPageMap(MockFacesContext facesContext)
     {
        return facesContext.getViewRoot().getAttributes();
     }
  
     @Test
     public void testSeamPhaseListenerNewLongRunning()
     {
        MockFacesContext facesContext = createFacesContext();
  
        SeamPhaseListener phases = new SeamPhaseListener();
  
        assert !Contexts.isEventContextActive();
        assert !Contexts.isSessionContextActive();
        assert !Contexts.isApplicationContextActive();
        assert !Contexts.isConversationContextActive();
  
        phases.beforePhase( new PhaseEvent(facesContext, PhaseId.RESTORE_VIEW, MockLifecycle.INSTANCE ) );
        
        assert Contexts.isEventContextActive();
        assert Contexts.isSessionContextActive();
        assert Contexts.isApplicationContextActive();
        assert !Contexts.isConversationContextActive();
        
        phases.afterPhase( new PhaseEvent(facesContext, PhaseId.RESTORE_VIEW, MockLifecycle.INSTANCE ) );
        
        assert Contexts.isConversationContextActive();
        assert !Manager.instance().isLongRunningConversation();
        
        phases.beforePhase( new PhaseEvent(facesContext, PhaseId.APPLY_REQUEST_VALUES, MockLifecycle.INSTANCE ) );
        phases.afterPhase( new PhaseEvent(facesContext, PhaseId.APPLY_REQUEST_VALUES, MockLifecycle.INSTANCE ) );
        phases.beforePhase( new PhaseEvent(facesContext, PhaseId.PROCESS_VALIDATIONS, MockLifecycle.INSTANCE ) );
        phases.afterPhase( new PhaseEvent(facesContext, PhaseId.PROCESS_VALIDATIONS, MockLifecycle.INSTANCE ) );
        phases.beforePhase( new PhaseEvent(facesContext, PhaseId.UPDATE_MODEL_VALUES, MockLifecycle.INSTANCE ) );
        phases.afterPhase( new PhaseEvent(facesContext, PhaseId.UPDATE_MODEL_VALUES, MockLifecycle.INSTANCE ) );
        
        phases.beforePhase( new PhaseEvent(facesContext, PhaseId.INVOKE_APPLICATION, MockLifecycle.INSTANCE ) );
        
        Manager.instance().beginConversation();
        
        phases.afterPhase( new PhaseEvent(facesContext, PhaseId.INVOKE_APPLICATION, MockLifecycle.INSTANCE ) );
        
        assert Manager.instance().isLongRunningConversation();
        
        phases.beforePhase( new PhaseEvent(facesContext, PhaseId.RENDER_RESPONSE, MockLifecycle.INSTANCE ) );
        
        assert Contexts.isEventContextActive();
        assert Contexts.isSessionContextActive();
        assert Contexts.isApplicationContextActive();
        assert Contexts.isConversationContextActive();
        
        facesContext.getApplication().getStateManager().saveView(facesContext);
        
        assert facesContext.getViewRoot().getAttributes().size()==1;
  
        phases.afterPhase( new PhaseEvent(facesContext, PhaseId.RENDER_RESPONSE, MockLifecycle.INSTANCE ) );
  
        assert !Contexts.isEventContextActive();
        assert !Contexts.isSessionContextActive();
        assert !Contexts.isApplicationContextActive();
        assert !Contexts.isConversationContextActive();
     }
  
     @Test
     public void testSeamPhaseListenerRedirect()
     {
        MockFacesContext facesContext = createFacesContext();
        SeamPhaseListener phases = new SeamPhaseListener();
  
        assert !Contexts.isEventContextActive();
        assert !Contexts.isSessionContextActive();
        assert !Contexts.isApplicationContextActive();
        assert !Contexts.isConversationContextActive();
  
        phases.beforePhase( new PhaseEvent(facesContext, PhaseId.RESTORE_VIEW, MockLifecycle.INSTANCE ) );
        
        assert Contexts.isEventContextActive();
        assert Contexts.isSessionContextActive();
        assert Contexts.isApplicationContextActive();
        assert !Contexts.isConversationContextActive();
        
        phases.afterPhase( new PhaseEvent(facesContext, PhaseId.RESTORE_VIEW, MockLifecycle.INSTANCE ) );
        
        assert Contexts.isConversationContextActive();
        assert !Manager.instance().isLongRunningConversation();
        
        phases.beforePhase( new PhaseEvent(facesContext, PhaseId.APPLY_REQUEST_VALUES, MockLifecycle.INSTANCE ) );
        phases.afterPhase( new PhaseEvent(facesContext, PhaseId.APPLY_REQUEST_VALUES, MockLifecycle.INSTANCE ) );
        phases.beforePhase( new PhaseEvent(facesContext, PhaseId.PROCESS_VALIDATIONS, MockLifecycle.INSTANCE ) );
        phases.afterPhase( new PhaseEvent(facesContext, PhaseId.PROCESS_VALIDATIONS, MockLifecycle.INSTANCE ) );
        phases.beforePhase( new PhaseEvent(facesContext, PhaseId.UPDATE_MODEL_VALUES, MockLifecycle.INSTANCE ) );
        phases.afterPhase( new PhaseEvent(facesContext, PhaseId.UPDATE_MODEL_VALUES, MockLifecycle.INSTANCE ) );
              
        phases.beforePhase( new PhaseEvent(facesContext, PhaseId.INVOKE_APPLICATION, MockLifecycle.INSTANCE ) );
        
        facesContext.responseComplete();
              
        phases.afterPhase( new PhaseEvent(facesContext, PhaseId.INVOKE_APPLICATION, MockLifecycle.INSTANCE ) );
        
        assert !Contexts.isEventContextActive();
        assert !Contexts.isSessionContextActive();
        assert !Contexts.isApplicationContextActive();
        assert !Contexts.isConversationContextActive();
     }
  
     @Test
     public void testSeamPhaseListenerNonFacesRequest()
     {
        MockFacesContext facesContext = createFacesContext();
        SeamPhaseListener phases = new SeamPhaseListener();
  
        assert !Contexts.isEventContextActive();
        assert !Contexts.isSessionContextActive();
        assert !Contexts.isApplicationContextActive();
        assert !Contexts.isConversationContextActive();
  
        phases.beforePhase( new PhaseEvent(facesContext, PhaseId.RESTORE_VIEW, MockLifecycle.INSTANCE ) );
        
        assert Contexts.isEventContextActive();
        assert Contexts.isSessionContextActive();
        assert Contexts.isApplicationContextActive();
        assert !Contexts.isConversationContextActive();
        
        phases.afterPhase( new PhaseEvent(facesContext, PhaseId.RESTORE_VIEW, MockLifecycle.INSTANCE ) );
        
        assert Contexts.isConversationContextActive();
        assert !Manager.instance().isLongRunningConversation();
        
        phases.beforePhase( new PhaseEvent(facesContext, PhaseId.RENDER_RESPONSE, MockLifecycle.INSTANCE ) );
        
        assert facesContext.getViewRoot().getAttributes().size()==1;
        assert ( (FacesPage) getPageMap(facesContext).get( getPrefix() + Seam.getComponentName(FacesPage.class) ) ).getConversationId()==null;
        assert Contexts.isEventContextActive();
        assert Contexts.isSessionContextActive();
        assert Contexts.isApplicationContextActive();
        assert Contexts.isConversationContextActive();
        
        facesContext.getApplication().getStateManager().saveView(facesContext);
        
        phases.afterPhase( new PhaseEvent(facesContext, PhaseId.RENDER_RESPONSE, MockLifecycle.INSTANCE ) );
        
        assert !Contexts.isEventContextActive();
        assert !Contexts.isSessionContextActive();
        assert !Contexts.isApplicationContextActive();
        assert !Contexts.isConversationContextActive();
     }
  
  }
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/MailTest.java
  
  Index: MailTest.java
  ===================================================================
  package org.jboss.seam.test.unit;
  
  import java.util.ArrayList;
  
  import javax.mail.NoSuchProviderException;
  import javax.mail.Session;
  import javax.naming.NamingException;
  
  import org.jboss.seam.mail.MailSession;
  import org.jboss.seam.mail.MeldwareUser;
  import org.testng.annotations.Test;
  
  import com.sun.mail.smtp.SMTPSSLTransport;
  import com.sun.mail.smtp.SMTPTransport;
  
  public class MailTest
  {
  
     private static final String HOST = "smtp.jboss.org";
     
     private static final String DEFAULT_HOST = "localhost";
  
     private static final int PORT = 666;
     
     private static final int DEFAULT_PORT = 25;
     
     private static final int DEFAULT_SSL_PORT = 465;
  
     private static final String USERNAME = "pmuir";
  
     private static final String PASSWORD = "letmein";
     
     private static final String EMAIL = "pete.muir at jboss.org";
  
     @Test
     public void testBasicMailSession()
     {
  
        MailSession mailSession = new MailSession();
  
        mailSession.create();
  
        Session session = null;
  
        try
        {
           session = mailSession.getSession();
        }
        catch (NamingException e)
        {
           assert false;
           // Naming exception can't occur if we aren't getting the Session from
           // JNDI
        }
  
        assert DEFAULT_HOST.equals(session.getProperty("mail.smtp.host"));
  
        int port = 0;
  
        try
        {
           port = Integer.parseInt(session.getProperty("mail.smtp.port"));
        }
        catch (NumberFormatException e)
        {
           assert false;
        }
  
        assert port == DEFAULT_PORT;
  
        assert "smtp".equals(session.getProperty("mail.transport.protocol"));
        
        SMTPTransport transport = null;
  
        try
        {
           assert session.getTransport() instanceof SMTPTransport;
           transport = (SMTPTransport) session.getTransport();
        }
        catch (NoSuchProviderException e)
        {
           assert false;
        }
  
        assert !session.getDebug();
  
        assert transport.getStartTLS();
  
     }
  
     @Test
     public void testMailSession()
     {
  
        MailSession mailSession = new MailSession();
        mailSession.setHost(HOST);
        mailSession.setPort(PORT);
        mailSession.setDebug(true);
  
        mailSession.create();
  
        Session session = null;
  
        try
        {
           session = mailSession.getSession();
        }
        catch (NamingException e)
        {
           assert false;
           // Naming exception can't occur if we aren't getting the Session from
           // JNDI
        }
  
        assert HOST.equals(session.getProperty("mail.smtp.host"));
  
        int port = 0;
  
        try
        {
           port = Integer.parseInt(session.getProperty("mail.smtp.port"));
        }
        catch (NumberFormatException e)
        {
           assert false;
        }
  
        assert port == PORT;
  
        try
        {
           assert session.getTransport() instanceof SMTPTransport;
        }
        catch (NoSuchProviderException e)
        {
           assert false;
        }
  
        assert session.getDebug();
  
     }
  
     @Test
     public void testAuthenticatedMailSession()
     {
        MailSession mailSession = new MailSession();
        mailSession.setUsername(USERNAME);
        mailSession.setPassword(PASSWORD);
  
        mailSession.create();
  
        Session session = null;
  
        try
        {
           session = mailSession.getSession();
        }
        catch (NamingException e)
        {
           assert false;
           // Naming exception can't occur if we aren't getting the Session from
           // JNDI
        }
  
        assert "true".equals(session.getProperty("mail.smtp.auth"));
  
        // TODO Check authentication
  
     }
     
     @Test
     public void testMissingPasswordMailSession()
     {
        MailSession mailSession = new MailSession();
        mailSession.setUsername(USERNAME);
  
        mailSession.create();
  
        Session session = null;
  
        try
        {
           session = mailSession.getSession();
        }
        catch (NamingException e)
        {
           assert false;
           // Naming exception can't occur if we aren't getting the Session from
           // JNDI
        }
  
        assert null == session.getProperty("mail.smtp.auth");
  
     }
     
     @Test
     public void testMissingUsernameMailSession()
     {
        MailSession mailSession = new MailSession();
        mailSession.setPassword(PASSWORD);
  
        mailSession.create();
  
        Session session = null;
  
        try
        {
           session = mailSession.getSession();
        }
        catch (NamingException e)
        {
           assert false;
           // Naming exception can't occur if we aren't getting the Session from
           // JNDI
        }
  
        assert null == session.getProperty("mail.smtp.auth");
  
     }
  
     @Test
     public void testBasicSslMailSession()
     {
        MailSession mailSession = new MailSession();
        
        mailSession.setSsl(true);
  
        mailSession.create();
  
        Session session = null;
  
        try
        {
           session = mailSession.getSession();
        }
        catch (NamingException e)
        {
           assert false;
           // Naming exception can't occur if we aren't getting the Session from
           // JNDI
        }
  
        assert "smtps".equals(session.getProperty("mail.transport.protocol"));
        
        SMTPSSLTransport transport = null;
  
        try
        {
           assert session.getTransport() instanceof SMTPSSLTransport;
           transport = (SMTPSSLTransport) session.getTransport();
        }
        catch (NoSuchProviderException e)
        {
           assert false;
        }
       
        int port = 0;
        
        try
        {
           port = Integer.parseInt(session.getProperty("mail.smtps.port"));
        }
        catch (NumberFormatException e)
        {
           assert false;
        }
  
        assert port == DEFAULT_SSL_PORT;
        
        assert DEFAULT_HOST.equals(session.getProperty("mail.smtps.host"));
        
        assert !session.getDebug();
        
        // TLS not used over SSL
        assert !transport.getStartTLS();
  
     }
     
     @Test
     public void testSslMailSession()
     {
        MailSession mailSession = new MailSession();
        mailSession.setHost(HOST);
        mailSession.setSsl(true);
        mailSession.setPort(PORT);
  
        mailSession.create();
  
        Session session = null;
  
        try
        {
           session = mailSession.getSession();
        }
        catch (NamingException e)
        {
           assert false;
           // Naming exception can't occur if we aren't getting the Session from
           // JNDI
        }
       
        int port = 0;
        
        try
        {
           port = Integer.parseInt(session.getProperty("mail.smtps.port"));
        }
        catch (NumberFormatException e)
        {
           assert false;
        }
  
        assert port == PORT;
  
     }
     
     @Test
     public void testAuthenticatedSslMailSession()
     {
        MailSession mailSession = new MailSession();
        mailSession.setUsername(USERNAME);
        mailSession.setPassword(PASSWORD);
        mailSession.setSsl(true);
  
        mailSession.create();
  
        Session session = null;
  
        try
        {
           session = mailSession.getSession();
        }
        catch (NamingException e)
        {
           assert false;
           // Naming exception can't occur if we aren't getting the Session from
           // JNDI
        }
  
        assert "true".equals(session.getProperty("mail.smtps.auth"));
        assert session.getProperty("mail.smtp.auth") == null;
  
        // TODO Check authentication
  
     }
     
     @Test
     public void testJndiMailSession()
     {
        MailSession mailSession = new MailSession();
        mailSession.setSessionJndiName("java:/Mail");
        
        mailSession.create();
        
        boolean failure = false;
        
        // We can't get a Session from JNDI without a full container.
        try
        {
           mailSession.getSession();
        }
        catch (Exception e)
        {
          failure = true;
        }
        
        assert failure;
     }
     
     @Test
     public void testMeldwareUser()
     {
        MeldwareUser meldwareUser = new MeldwareUser();
        meldwareUser.setUsername(USERNAME);
        meldwareUser.setPassword(PASSWORD);
        meldwareUser.getAliases().add(EMAIL);
        
        assert USERNAME.equals(meldwareUser.getUsername());
        assert PASSWORD.equals(meldwareUser.getPassword());
        assert meldwareUser.getAliases() != null;
        assert meldwareUser.getAliases().contains(EMAIL);
        assert meldwareUser.getRoles().contains("calendaruser");
        assert !meldwareUser.getRoles().contains("adminuser");
        
        meldwareUser.setAliases(new ArrayList<String>());
        assert meldwareUser.getAliases().isEmpty();
     }
     
     @Test
     public void testAdminMeldwareUser()
     {
        MeldwareUser meldwareUser = new MeldwareUser();
        meldwareUser.setAdministrator(true);
        
        assert meldwareUser.getRoles().contains("calendaruser");
        assert meldwareUser.getRoles().contains("adminuser");
     }
     
     // TODO Write tests for Meldware
  
  }
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/Bar.java
  
  Index: Bar.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.seam.test.unit;
  
  import java.io.Serializable;
  
  import org.jboss.seam.ScopeType;
  import org.jboss.seam.annotations.Begin;
  import org.jboss.seam.annotations.Conversational;
  import org.jboss.seam.annotations.Create;
  import org.jboss.seam.annotations.Destroy;
  import org.jboss.seam.annotations.End;
  import org.jboss.seam.annotations.In;
  import org.jboss.seam.annotations.Name;
  import org.jboss.seam.annotations.Out;
  import org.jboss.seam.annotations.Scope;
  
  /**
   * @author <a href="mailto:theute at jboss.org">Thomas Heute </a>
   */
  @Name("bar")
  @Scope(ScopeType.CONVERSATION)
  @Conversational
  public class Bar implements Serializable
  {
     private static final long serialVersionUID = -5325217160542604204L;
  
     @In(required=true)
     Foo otherFoo;
     
     @In(create=true)
     Foo foo;
     
     @Out(required=false)
     String string;
     
     @Out(required=false, scope=ScopeType.EVENT)
     String otherString;
     
     @Begin
     public String begin()
     {
        return "begun";
     }
     
     public String foo()
     {
        string = "out";
        otherString = "outAgain";
        return "foo";
     }
     
     @End
     public String end()
     {
        return "ended";
     }
     
     @Destroy
     public void destroy(){}
     @Create
     public void create(){}
     
  }
  
  
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/SeamTextTest.txt
  
  Index: SeamTextTest.txt
  ===================================================================
  +Seam Text!
  This page demonstrates Seam Text.
  
  ++Some examples:
  
  Here is some wiki text: 
  *bold* |mono| ~deleted~ _underline_ /italic/ ^super^
  
  This is a new paragraph. (Just leave a blank line.)
  
  */_Multiple ~tags~ styles_ can be nested!/*
  
  Special characters can be escaped: \| \* \_ 
  
  This is especially useful for HTML: \<notatag\> \&notanentity;
  
  But if we don't want to use escapes in our preformatted
  text, we can wrap it in backwards quotes, and special 
  characters get escaped automagically:
  
  `//This is some code:
  
  <some-tag/>
  "a string" 
  a_variable_name 
  a||b 
  x=y*z/2`
  
  We wrap quoted text in double quotes:
  
  "This is a block quote with /formatting/. The quote can cross multiple 
  lines, but a blank line does not start a new paragraph. If you
  need multiple paragraphs in a quote, you have to use \<p\>."
  
  You can even have "a quote", or `some code` inside
  a regular paragraph!
  
  We use ordinary old HTML for tables: 
  
  <table>
     <tr><td>foo</td><td>*bar*</td><td>baz</td></tr><tr>
     <td>fee</td>
     <td>fi</td>
     <td>/fo/</td>
     </tr>
  </table>
  
  And we can use HTML for lists: 
  
  <ol>
     <li>foo</li>
     <li>*bar*</li>
     <li>/baz/</li>
  </ol>
  
  <ul><li>foo</li><li>*bar*</li><li>/baz/</li></ul>
  
  But if the items fit on a line, we can use \#
  for ordered lists:
  
  # item 1
  # item 2
  # item 3
  
  And \= for unordered lists:
  
  = item 1
  = item 2
  = item 3
  
  We use HTML for <a href="http://www.hibernate.org/">links</a>.
  
  Or we can use [a special syntax=>http://jboss.com/products/seam] to
  link to [=>http://jboss.com/products/seam].
  
  And for images: <img src="http://www.hibernate.org/tpl/jboss/img/01_oben_logo.gif"/>
  
  And even for more exotic formatting, for example:
  
  <q>This is a /HTML/ quote with a <a href="http://jboss.org/">link</a>, 
  and a "nested quote" and even `some code` in it.</q>
  
  <p>
  This is a HTML paragraph with some lists:
  
  # item 1
  # item 2
  
  = an item
  = another item
  
  And "a quote" in it.
  </p>
  
  Oh, and one last thing:
  
  "This is a block quote with
  
  = a list,
  = with 2 items
  
  and <i>some HTML</i> formatting and `some code` and
  and <a href="http://jboss.com/products/seam"><i>yet 
  another</i> link</a>."
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/People.java
  
  Index: People.java
  ===================================================================
  package org.jboss.seam.test.unit;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import org.jboss.seam.ScopeType;
  import org.jboss.seam.annotations.Factory;
  import org.jboss.seam.annotations.Name;
  import org.jboss.seam.annotations.datamodel.DataModelSelection;
  
  @Name("people")
  public class People
  {
     @org.jboss.seam.annotations.datamodel.DataModel(scope=ScopeType.PAGE)
     private List<Person> peopleList;
     
     @DataModelSelection
     private Person selectedPerson;
     
     @Factory("peopleList")
     public void peopleFactory()
     {
        peopleList = new ArrayList<Person>();
        peopleList.add(new Person("Gavin"));
        peopleList.add(new Person("Pete"));
        peopleList.add(new Person("Shane"));
        peopleList.add(new Person("Norman"));
     }
     
     public Person getSelectedPerson()
     {
        return selectedPerson;
     }
  
  }
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/SeamMockELResolverTest.java
  
  Index: SeamMockELResolverTest.java
  ===================================================================
  package org.jboss.seam.test.unit;
  
  import java.beans.FeatureDescriptor;
  import java.util.Iterator;
  
  import javax.el.ELContext;
  import javax.el.ELException;
  import javax.el.ELResolver;
  import javax.el.PropertyNotFoundException;
  import javax.el.PropertyNotWritableException;
  
  import org.jboss.seam.mock.SeamTest;
  import org.testng.annotations.Test;
  
  /**
   * Test for adding EL resolvers to Seam MockFacesContext
   * 
   * @author Pete Muir
   * 
   */
  public class SeamMockELResolverTest extends SeamTest
  {
     
     private static final String property = "customELResolverTest";
  
     @Override
     protected void startJbossEmbeddedIfNecessary()
              throws org.jboss.deployers.spi.DeploymentException, java.io.IOException
     {
     }
  
     @Override
     protected ELResolver[] getELResolvers()
     {
        ELResolver[] resolvers = new ELResolver[1];
        resolvers[0] = new ELResolver()
        {
  
           @Override
           public Class<?> getCommonPropertyType(ELContext arg0, Object arg1)
           {
              return null;
           }
  
           @Override
           public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext arg0, Object arg1)
           {
              return null;
           }
  
           @Override
           public Class<?> getType(ELContext arg0, Object base, Object property)
                    throws NullPointerException, PropertyNotFoundException, ELException
           {
              return null;
           }
  
           @Override
           public Object getValue(ELContext context, Object base, Object property)
                    throws NullPointerException, PropertyNotFoundException, ELException
           {
              if (SeamMockELResolverTest.property.equals(property))
              {
                 context.setPropertyResolved(true);
                 return "found";
              }
              return null;
           }
  
           @Override
           public boolean isReadOnly(ELContext arg0, Object base, Object property)
                    throws NullPointerException, PropertyNotFoundException, ELException
           {
              if (SeamMockELResolverTest.property.equals(property))
              {
                 return false;
              }
              return false;
           }
  
           @Override
           public void setValue(ELContext context, Object base, Object property, Object value)
                    throws NullPointerException, PropertyNotFoundException,
                    PropertyNotWritableException, ELException
           {
              if (SeamMockELResolverTest.property.equals(property))
              {
                 throw new PropertyNotWritableException();
              }
           }
  
        };
        return resolvers;
     }
  
     @Test
     public void testCustomELResolver() throws Exception
     {
        new FacesRequest()
        {
           @Override
           protected void invokeApplication() throws Exception
           {
              assert "found".equals(getValue("#{" + property + "}"));
           }
        }.run();
     }
  
  }
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/PageflowTest.java
  
  Index: PageflowTest.java
  ===================================================================
  package org.jboss.seam.test.unit;
  
  import java.io.StringReader;
  
  import org.jboss.seam.bpm.PageflowParser;
  import org.jboss.seam.pageflow.Page;
  import org.jbpm.JbpmConfiguration;
  import org.jbpm.JbpmContext;
  import org.jbpm.graph.def.ProcessDefinition;
  import org.jbpm.graph.exe.ProcessInstance;
  import org.jbpm.graph.exe.Token;
  import org.jbpm.graph.node.StartState;
  import org.testng.annotations.Test;
  
  public class PageflowTest 
  {
    
    JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString(
      "<jbpm-configuration />"
    );
  
    @Test
    public void testPageflowWithStartState() {
      JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
      
      StringReader stringReader = new StringReader(
        "<pageflow-definition name='hoepla'>" +
        "  <start-state name='start' />" +
        "</pageflow-definition>"
      );
      PageflowParser pageflowParser = new PageflowParser(stringReader);
      ProcessDefinition processDefinition = pageflowParser.readProcessDefinition();
      assert "start".equals(processDefinition.getStartState().getName());
      
      jbpmContext.close();
    }
    
    @Test
    public void testPageflowWithStartPage() {
      JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();    
      StringReader stringReader = new StringReader(
      "<pageflow-definition name='hoepla'>" +
      "  <start-page name='start' view-id='/start.xhtml'/>" +
      "</pageflow-definition>");
      PageflowParser pageflowParser = new PageflowParser(stringReader);
      ProcessDefinition processDefinition = pageflowParser.readProcessDefinition();
      
      assert "start".equals(processDefinition.getStartState().getName());
      
      jbpmContext.close();
    }
    
    @Test
    public void testPageflowWithStartPageAttribute() {
      JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
      
      StringReader stringReader = new StringReader(
        "<pageflow-definition name='hoepla' start-page='start'>" +
        "  <page name='start' view-id='/start.xhtml'/>" +
        "</pageflow-definition>"
      );
      PageflowParser pageflowParser = new PageflowParser(stringReader);
      ProcessDefinition processDefinition = pageflowParser.readProcessDefinition();
      assert "start".equals(processDefinition.getStartState().getName());
      
      jbpmContext.close();
    }
    
    @Test
    public void testOrderPageflow() {
       StringReader stringReader = new StringReader(
        "<pageflow-definition name='checkout'>" +
        "  <start-state name='start'>" +
        "    <transition to='confirm'/>" +
        "  </start-state>" +
        "  <page name='confirm' view-id='/confirm.xhtml'>" +
        "    <redirect/>" +
        "    <transition name='update'   to='continue'/>" + 
        "    <transition name='purchase' to='complete'>" +
        "      <action expression='#{checkout.submitOrder}' />" +
        "    </transition>" +
        "  </page>" +
        "  <page name='complete' view-id='/complete.xhtml'>" +
        "    <redirect/>" +
        "    <end-conversation/>" +
        "  </page>" +    
        "  <page name='continue' view-id='/browse.xhtml'>" +
        "    <end-conversation/>" +
        "  </page>" +
        "</pageflow-definition>"
      );
      PageflowParser pageflowParser = new PageflowParser(stringReader);
      ProcessDefinition processDefinition = pageflowParser.readProcessDefinition();
      
      StartState start = (StartState) processDefinition.getStartState();
      Page confirm = (Page) processDefinition.getNode("confirm");
      Page complete = (Page) processDefinition.getNode("complete");
      Page cont = (Page) processDefinition.getNode("continue");
      assert confirm!=null;
      assert complete!=null;
      assert cont!=null;
      
      ProcessInstance processInstance = new ProcessInstance(processDefinition);
      Token token = processInstance.getRootToken();
      assert start.equals(token.getNode());
      
      processInstance.signal();
    }
    
  }
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/TestActions.java
  
  Index: TestActions.java
  ===================================================================
  package org.jboss.seam.test.unit;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import org.jboss.seam.Component;
  import org.jboss.seam.annotations.Name;
  
  /**
   * A bunch of test actions to be used in unit tests.
   */
  @Name("testActions")
  public class TestActions
  {
     private List<String> actionsCalled = new ArrayList<String>();
     
     public String nonNullActionA() {
        actionsCalled.add("nonNullActionA");
        return "outcomeA";
     }
     
     public String nonNullActionB() {
        actionsCalled.add("nonNullActionB");
        return "outcomeB";
     }
     
     public String nonNullActionC() {
        actionsCalled.add("nonNullActionC");
        return "outcomeC";
     }
     
     public void nullActionA() {
        actionsCalled.add("nullActionA");
     }
     
     public void nullActionB() {
        actionsCalled.add("nullActionB");
     }
     
     public void nullActionC() {
        actionsCalled.add("nullActionC");
     }
     
     public List<String> getActionsCalled() {
        return actionsCalled;
     }
     
     public static TestActions instance() {
        return (TestActions) Component.getInstance(TestActions.class);
     }
  }
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/DependencyTest.java
  
  Index: DependencyTest.java
  ===================================================================
  package org.jboss.seam.test.unit;
  
  import java.util.HashMap;
  import java.util.Map;
  import java.util.Set;
  import java.util.TreeSet;
  
  import org.jboss.seam.ScopeType;
  import org.jboss.seam.annotations.Install;
  import org.jboss.seam.init.ComponentDescriptor;
  import org.jboss.seam.init.DependencyManager;
  import org.testng.Assert;
  import org.testng.annotations.Test;
  
  public class DependencyTest {
      @Test
      public void testNoComponents() 
      {
          Assert.assertEquals(0, installSet().size());
      }
      
      @Test
      public void testNoDependencies() {
          MockDescriptor desc1 = new MockDescriptor("foo", SomeClass.class);
          
          Set<ComponentDescriptor> installed = installSet(desc1);
          Assert.assertEquals(installed.size(), 1);        
      }
      
      
      @Test
      public void testNotInstalled() {
          MockDescriptor desc1 = new MockDescriptor("foo", SomeClass.class);
          desc1.setInstalled(false);
  
          Assert.assertEquals(installSet(desc1).size(), 0);        
      }
      
      
      @Test
      public void testOverride() {
          MockDescriptor desc1 = new MockDescriptor("foo", SomeClass.class);
          desc1.setPrecedence(Install.APPLICATION);
          MockDescriptor desc2 = new MockDescriptor("foo", SomeClass.class);
          desc2.setPrecedence(Install.DEPLOYMENT);
          MockDescriptor desc3 = new MockDescriptor("foo", SomeClass.class);
          desc3.setPrecedence(Install.BUILT_IN);      
                  
          Set<ComponentDescriptor> installed = installSet(desc1, desc2, desc3);
          Assert.assertEquals(installed.size(), 1);                
          Assert.assertEquals(installed.iterator().next().getPrecedence(),Install.DEPLOYMENT);              
      }
      
      
      @Test
      public void testOverride2() {
          MockDescriptor desc1 = new MockDescriptor("foo", SomeClass.class);
          desc1.setDependencies(new String[] {"bar"});
          MockDescriptor desc2 = new MockDescriptor("bar", SomeClass.class);
          desc2.setPrecedence(Install.FRAMEWORK);
          MockDescriptor desc3 = new MockDescriptor("bar", SomeOtherClass.class);
          desc3.setPrecedence(Install.APPLICATION);
          desc3.setClassDependencies(new String[] {"SomeClassThatDoesntExist"});
  
                  
          Set<ComponentDescriptor> installed = installSet(desc1, desc2, desc3);        
          Assert.assertEquals(installed.size(), 2);                
          Assert.assertTrue(installed.contains(desc1), "contains desc1");
          Assert.assertTrue(installed.contains(desc2), "contains desc2");
                
      }
      
      @Test
      public void testClassDependency() {
          MockDescriptor desc1 = new MockDescriptor("foo", SomeClass.class);
          desc1.setClassDependencies(new String[] {"SomeClassThatDoesntExist"});
                     
          Set<ComponentDescriptor> installed = installSet(desc1);
          Assert.assertEquals(installed.size(), 0);      
          
          desc1.setClassDependencies(new String[] {"SomeClassThatDoesntExist", SomeClass.class.getName()});       
          installed = installSet(desc1);
          Assert.assertEquals(installed.size(), 0);                 
          
          desc1.setClassDependencies(new String[] {SomeClass.class.getName()});       
          installed = installSet(desc1);
          Assert.assertEquals(installed.size(), 1);      
      }
      
      @Test
      public void testDependency() {
          MockDescriptor desc1 = new MockDescriptor("foo", SomeClass.class);
          desc1.setDependencies(new String[] {"bar"});
          MockDescriptor desc2 = new MockDescriptor("bar", SomeClass.class);
          desc2.setDependencies(new String[] {"baz"});
          MockDescriptor desc3 = new MockDescriptor("baz", SomeClass.class);
          
          Assert.assertEquals(installSet(desc1).size(), 0);    
          Assert.assertEquals(installSet(desc1,desc2).size(), 0);  
          Assert.assertEquals(installSet(desc1,desc2,desc3).size(), 3);           
      }
      
      @Test
      public void testCircularDependency() {
          MockDescriptor desc1 = new MockDescriptor("foo", SomeClass.class);
          desc1.setDependencies(new String[] {"bar"});
          MockDescriptor desc2 = new MockDescriptor("bar", SomeClass.class);
          desc2.setDependencies(new String[] {"foo"});
                  
          Assert.assertEquals(installSet(desc1).size(), 0);    
          Assert.assertEquals(installSet(desc2).size(), 0);  
          Assert.assertEquals(installSet(desc1,desc2).size(), 2);     
          
          // just to make sure
          desc1.setDependencies(new String[] {"foo"});        
          Assert.assertEquals(installSet(desc1).size(), 1);  
      }
      
      
      @Test
      public void testComponentByClassDependency() {
          MockDescriptor desc1 = new MockDescriptor("foo", SomeClass.class);
          desc1.setGenericDependencies(new Class[] {SomeOtherClass.class});
          MockDescriptor desc2 = new MockDescriptor("bar", SomeOtherClass.class);
                  
          Assert.assertEquals(installSet(desc1).size(), 0);        
          Assert.assertEquals(installSet(desc2).size(), 1);
          Assert.assertEquals(installSet(desc1,desc2).size(), 2);           
      }
      
      
      @Test
      public void testUnmetDueToOverride() {
          MockDescriptor desc1 = new MockDescriptor("foo", SomeClass.class);
          desc1.setGenericDependencies(new Class[] {SomeOtherClass.class});
          MockDescriptor desc2 = new MockDescriptor("bar", SomeOtherClass.class);
          desc2.setPrecedence(Install.FRAMEWORK);
          MockDescriptor desc3 = new MockDescriptor("bar", SomeUnrelatedClass.class);        
          
          Set<ComponentDescriptor> installed = installSet(desc1,desc2);
          Assert.assertEquals(installed.size(), 2);
                  
          installed = installSet(desc1,desc2,desc3);        
          Assert.assertEquals(installed.size(), 1);
          Assert.assertEquals(installed.iterator().next().getName(), "bar");
          Assert.assertEquals(installed.iterator().next().getPrecedence(), Install.APPLICATION);      
      }
      // ------------------------------------------------------
      
      
      private Map<String,Set<ComponentDescriptor>> componentSet(ComponentDescriptor... descriptors) {
          Map<String,Set<ComponentDescriptor>> map = new HashMap<String, Set<ComponentDescriptor>>();
          
          for (ComponentDescriptor descriptor: descriptors) {
              addDependency(map, descriptor);
          }
          return map;        
      }
      
      private Set<ComponentDescriptor> installSet(ComponentDescriptor... descriptors) {
          DependencyManager manager = new DependencyManager(componentSet(descriptors));
          return manager.installedSet();
      }
      
      private void addDependency(Map<String,Set<ComponentDescriptor>> dependencies, 
                                 ComponentDescriptor descriptor) 
      {
          Set<ComponentDescriptor> descriptors = dependencies.get(descriptor.getName());
          if (descriptors == null) 
          {
              descriptors = new TreeSet<ComponentDescriptor>(new ComponentDescriptor.PrecedenceComparator());
              dependencies.put(descriptor.getName(), descriptors);
          }
           
          descriptors.add(descriptor);
      }             
      
      static class MockDescriptor
          extends ComponentDescriptor 
      {        
          private String[] classDependencies;
          private String[] dependencies;
          private Class[] genericDependencies;
  
          public MockDescriptor(String name, Class<?> componentClass) {
              super(name, componentClass, ScopeType.SESSION);        
          }
  
          public void setInstalled(boolean installed) {
              this.installed = installed;
          }
          
          public void setPrecedence(int precedence) {
              this.precedence = precedence;
          }
          
          public void setClassDependencies(String[] classDependencies) {
              this.classDependencies = classDependencies;
          }
  
          @Override
          public String[] getClassDependencies() {
              return (classDependencies != null) ?   
                     classDependencies : super.getClassDependencies();
          }
          
          public void setDependencies(String[] dependencies) {
              this.dependencies = dependencies;
          }
  
          @Override
          public String[] getDependencies() {
              return (dependencies != null) ?   
                      dependencies : super.getDependencies();
          }
  
          public void setGenericDependencies(Class[] genericDependencies) {
              this.genericDependencies = genericDependencies;
          }
          
          @Override
          public Class[] getGenericDependencies() {
              return (genericDependencies != null) ?
                      genericDependencies : super.getGenericDependencies();
          }       
      }
      
      
      static class SomeClass {
      }    
      
      static class SomeOtherClass {
      }    
      
      static class SomeUnrelatedClass {        
      }
  }
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/TimeZoneTest.java
  
  Index: TimeZoneTest.java
  ===================================================================
  package org.jboss.seam.test.unit;
  
  import java.io.IOException;
  import java.util.TimeZone;
  
  import javax.faces.component.UIOutput;
  import javax.faces.event.ValueChangeEvent;
  
  import org.jboss.deployers.spi.DeploymentException;
  import org.jboss.seam.international.TimeZoneSelector;
  import org.jboss.seam.mock.SeamTest;
  import org.testng.annotations.Test;
  
  public class TimeZoneTest extends SeamTest
  {
  
     @Override
     protected void startJbossEmbeddedIfNecessary() throws DeploymentException, IOException {}
     
     @Test
     public void timeZoneTest() throws Exception
     {
        new FacesRequest()
        {
           @Override
           protected void invokeApplication() throws Exception
           {
              assert org.jboss.seam.international.TimeZone.instance().equals(java.util.TimeZone.getDefault());
              
              TimeZone cet = TimeZone.getTimeZone("CET");
              TimeZoneSelector.instance().setTimeZone(cet);
              
              assert org.jboss.seam.international.TimeZone.instance().equals(cet);
            
              TimeZoneSelector.instance().setTimeZoneId("CET");
              
              assert org.jboss.seam.international.TimeZone.instance().equals(cet);
              
              TimeZoneSelector.instance().selectTimeZone("GMT");
              assert org.jboss.seam.international.TimeZone.instance().getID().equals("GMT");
              
              ValueChangeEvent valueChangeEvent = new ValueChangeEvent(new UIOutput(), "GMT", "PST");
              TimeZoneSelector.instance().select(valueChangeEvent);
              assert org.jboss.seam.international.TimeZone.instance().getID().equals("PST");
              
              // TODO Test cookie stuff (need to extend Mocks for this)
              
           }
        }.run();
     }
  }
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/SecurityTest.java
  
  Index: SecurityTest.java
  ===================================================================
  package org.jboss.seam.test.unit;
  
  
  public class SecurityTest
  {
    /*@Name("mock")
    class MockSecureEntityMethodId {
      private Integer id;
      public MockSecureEntityMethodId(Integer id) { this.id = id; }
      @Id public Integer getId() { return id; }
    }
  
    @Name("mock")
    class MockSecureEntityFieldId {
      @Id private Integer id;
      public MockSecureEntityFieldId(Integer id) { this.id = id; }
    }
  
    class MockCompositeId implements Serializable {
      private int fieldA;
      private String fieldB;
      @Override
      public String toString() {
        return String.format("%s,%s", fieldA, fieldB);
      }
      public MockCompositeId(int fieldA, String fieldB) {
        this.fieldA = fieldA;
        this.fieldB = fieldB;
      }
    }
  
    @Name("mock")
    class MockSecureEntityCompositeId {
      @Id private MockCompositeId id;
      public MockSecureEntityCompositeId(MockCompositeId id) { this.id = id; }
    }
  
    @Test
    public void testJPAIdentityGenerator()
    {
      JPAIdentityGenerator gen = new JPAIdentityGenerator();
      assert("mock:1234".equals(gen.generateIdentity(new MockSecureEntityMethodId(1234))));
      assert("mock:1234".equals(gen.generateIdentity(new MockSecureEntityFieldId(1234))));
      assert(null == gen.generateIdentity(new MockSecureEntityMethodId(null)));
      assert("mock:1234,abc".equals(gen.generateIdentity(new MockSecureEntityCompositeId(
        new MockCompositeId(1234, "abc")))));
    }
  
    @Test
    public void testPersistentAcls()
    {
      Ejb3Configuration ac = new Ejb3Configuration();
      System.setProperty("java.naming.factory.initial", "org.jnp.interfaces.LocalOnlyContextFactory");
  
      ac.setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver");
      ac.setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:aname");
      ac.setProperty("hibernate.connection.username", "sa");
      ac.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
      ac.setProperty("hibernate.hbm2ddl.auto", "create");
      //ac.setProperty("hibernate.show_sql", "true");
      ac.setProperty("hibernate.cache.use_second_level_cache", "false");
  
      ac.addAnnotatedClass(MockAclPermission.class);
      ac.addAnnotatedClass(MockAclObjectIdentity.class);
      ac.addAnnotatedClass(MockSecureEntity.class);
  
      EntityManagerFactory factory = ac.createEntityManagerFactory();
  
      EntityManager em = factory.createEntityManager();
      em.getTransaction().begin();
  
      // Create our mock entity
      MockSecureEntity ent = new MockSecureEntity();
      ent.setId(123);
      em.persist(ent);
  
      // Now create an identity for it
      MockAclObjectIdentity ident = new MockAclObjectIdentity();
      ident.setId(1);
      ident.setObjectIdentity(new JPAIdentityGenerator().generateIdentity(ent));
      em.persist(ident);
  
      // And now create some permissions
      //@todo This step should eventually be done using SeamSecurityManager.grantPermission()
      MockAclPermission perm = new MockAclPermission();
      perm.setId(1);
      perm.setIdentity(ident);
      perm.setRecipient("testUser");
      perm.setRecipientType(RecipientType.user);
      perm.setMask(0x01 | 0x02);  // read/delete permission only
      em.persist(perm);
      em.flush();
      em.getTransaction().commit();
  
      MockServletContext ctx = new MockServletContext();
      MockExternalContext eCtx = new MockExternalContext(ctx);
  
      new Initialization(ctx).init();
  
      Lifecycle.beginRequest(eCtx);
  
      // Create an Authentication object in session scope
      Contexts.getSessionContext().set("org.jboss.seam.security.authentication",
                                       new UsernamePasswordToken("testUser", "",
                                       new String[] {}));
  
      Component aclProviderComp = new Component(PersistentAclManager.class,
                                                "persistentAclProvider");
      PersistentAclManager aclProvider = (PersistentAclManager) aclProviderComp.newInstance();
      aclProvider.setPersistenceContextManager(factory);
      aclProvider.setAclQuery("select p.mask, p.recipient, p.recipientType from MockAclPermission p " +
          "where p.identity.objectIdentity = :identity");
  
      MockSecureEntity e2 = em.find(MockSecureEntity.class, 123);
  
      // This check should pass
  
      // --> will reinstate once PersistentAclProvider.convertToPermissions() works
      //SeamSecurityManager.instance().checkPermission(e2, "read");
  
      // This check should fail
      //try
      //{
        //SeamSecurityManager.instance().checkPermission(e2, "special");
        //assert(false);
      //}
      //catch (SecurityException ex) { }
  
      Lifecycle.endRequest();
    }*/
  }
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/ELTest.java
  
  Index: ELTest.java
  ===================================================================
  package org.jboss.seam.test.unit;
  
  import javax.el.ELException;
  import javax.faces.el.MethodBinding;
  import javax.faces.el.ValueBinding;
  
  import org.jboss.seam.jsf.UnifiedELMethodBinding;
  import org.jboss.seam.jsf.UnifiedELValueBinding;
  import org.jboss.seam.mock.SeamTest;
  import org.testng.annotations.Test;
  
  public class ELTest extends SeamTest
  {
     
     @Override
     protected void startJbossEmbeddedIfNecessary() 
     throws org.jboss.deployers.spi.DeploymentException ,java.io.IOException {}
     
     @Test
     public void testUnifiedELMethodBinding() throws Exception
     {
        new FacesRequest() 
        {
           @Override
           protected void invokeApplication() throws Exception
           {
              MethodBinding methodBinding = new UnifiedELMethodBinding("#{action.go}", new Class[0]);
              
              assert "#{action.go}".equals(methodBinding.getExpressionString());
              
              assert String.class.equals(methodBinding.getType(getFacesContext()));
              
              Object result = methodBinding.invoke(getFacesContext(), new Object[0]);
              
              assert result instanceof String;
              assert "success".equals(result);
           }
        }.run();
     }
     
     @Test
     public void testUnifiedELMethodBindingWithNull() throws Exception
     {
        new FacesRequest() 
        {
           @Override
           protected void invokeApplication() throws Exception
           {
  
              MethodBinding methodBinding = new UnifiedELMethodBinding("#{action.go}", null);
              
              assert String.class.equals(methodBinding.getType(getFacesContext()));
              
              Object result = methodBinding.invoke(getFacesContext(), null);
              
              assert result instanceof String;
              assert "success".equals(result);
           }
        }.run();
     }
     
     @Test
     public void testEmptyUnifiedELMethodBinding() throws Exception
     {
        new FacesRequest() 
        {
           @Override
           protected void invokeApplication() throws Exception
           {
  
              MethodBinding methodBinding = new UnifiedELMethodBinding();
              boolean failed = false;
              try
              {
                 Object result = methodBinding.invoke(getFacesContext(), null);
              }
              catch (ELException e) {
                 failed = true;
              }
              assert failed;
           }
        }.run();
     }
     
     @Test
     public void testUnifiedELValueBinding() throws Exception
     {
        new FacesRequest()
        {
           @Override
           protected void invokeApplication() throws Exception
           {
              ValueBinding valueBinding = new UnifiedELValueBinding("#{person.name}");
              
              assert "#{person.name}".equals(valueBinding.getExpressionString());
              
              assert !valueBinding.isReadOnly(getFacesContext());
              
              assert String.class.equals(valueBinding.getType(getFacesContext()));
              
              valueBinding.setValue(getFacesContext(), "Pete");
              
              assert "Pete".equals(valueBinding.getValue(getFacesContext()));
           }
        }.run();
     }
     
     @Test
     public void testEmptyUnifiedELValueBinding() throws Exception
     {
        new FacesRequest() 
        {
           @Override
           protected void invokeApplication() throws Exception
           {
  
              ValueBinding valueBinding = new UnifiedELValueBinding();
              boolean failed = false;
              try
              {
                 valueBinding.setValue(getFacesContext(), "Pete");
                 valueBinding.getValue(getFacesContext());
              }
              catch (ELException e) {
                 failed = true;
              }
              assert failed;
           }
        }.run();
     }
  
  }
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/EjbBean.java
  
  Index: EjbBean.java
  ===================================================================
  //$Id: EjbBean.java,v 1.1 2007/10/08 18:15:47 pmuir Exp $
  package org.jboss.seam.test.unit;
  
  import javax.ejb.Remove;
  import javax.ejb.Stateful;
  
  import org.jboss.seam.ScopeType;
  import org.jboss.seam.annotations.Destroy;
  import org.jboss.seam.annotations.JndiName;
  import org.jboss.seam.annotations.Name;
  import org.jboss.seam.annotations.Scope;
  
  @Stateful
  @Name("ejb")
  @Scope(ScopeType.EVENT)
  @JndiName("x")
  public class EjbBean implements Ejb
  {
     public void foo() {}
     @Remove @Destroy
     public void destroy() {}
  }
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/Person.java
  
  Index: Person.java
  ===================================================================
  package org.jboss.seam.test.unit;
  
  import java.io.Serializable;
  
  import org.jboss.seam.annotations.Name;
  
  
  @Name("person")
  public class Person implements Serializable
  {
     
     public Person(String name)
     {
        this.name = name;
     }
     
     public Person() {}
     
     private String name;
     
     public String getName()
     {
        return name;
     }
     
      public void setName(String name)
     {
        this.name = name;
     }
      
      @Override
     public boolean equals(Object other)
     {
        if (other instanceof Person)
        {
           Person that = (Person) other;
           return (this.name == null && that.name == null) || (this.name != null && this.name.equals(that.name));     
        }
        else
        {
           return false;
        }
     }
  
  }
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/BrokenAction.java
  
  Index: BrokenAction.java
  ===================================================================
  package org.jboss.seam.test.unit;
  
  import org.jboss.seam.annotations.In;
  import org.jboss.seam.annotations.Name;
  
  @Name("brokenAction")
  public class BrokenAction {
     
     @In String name;
     
     public String go() {
        return "success";
     }
  
  }
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/DataModelTest.java
  
  Index: DataModelTest.java
  ===================================================================
  package org.jboss.seam.test.unit;
  
  import java.io.ByteArrayInputStream;
  import java.io.ByteArrayOutputStream;
  import java.io.IOException;
  import java.io.NotSerializableException;
  import java.io.ObjectInputStream;
  import java.io.ObjectOutputStream;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.List;
  import java.util.Map;
  import java.util.Set;
  
  import javax.faces.model.DataModel;
  import javax.faces.model.ListDataModel;
  
  import org.jboss.deployers.spi.DeploymentException;
  import org.jboss.seam.faces.DataModels;
  import org.jboss.seam.jsf.ArrayDataModel;
  import org.jboss.seam.jsf.MapDataModel;
  import org.jboss.seam.jsf.SetDataModel;
  import org.jboss.seam.mock.SeamTest;
  import org.testng.annotations.Test;
  
  public class DataModelTest extends SeamTest
  {
     
     @Override
     protected void startJbossEmbeddedIfNecessary() throws DeploymentException, IOException {}
     
     @Test
     public void testDataModels() throws Exception
     {
      
        new FacesRequest()
        {
           @Override
           protected void invokeApplication() throws Exception
           {
              DataModels dataModels = DataModels.instance();
              
              assert dataModels.getDataModel(new ArrayList()) instanceof ListDataModel;
              assert dataModels.getDataModel(new HashMap()) instanceof MapDataModel;
              assert dataModels.getDataModel(new HashSet()) instanceof SetDataModel;
              assert dataModels.getDataModel(new Object[0]) instanceof ArrayDataModel;
              // TODO assert dataModels.getDataModel(query) instanceof ListDataModel;
              
              boolean failed = false;
              try
              {
                 dataModels.getDataModel(new Foo());
              }
              catch (IllegalArgumentException e)
              {
                 failed = true;
              }
              assert failed;
           }
        }.run();
     }
     
     @Test
     public void testArrayDataModelSerialization() throws Exception
     {
        String[] array = {"Seam", "Hibernate"};
        javax.faces.model.ArrayDataModel arrayDataModel = new ArrayDataModel(array);
        arrayDataModel.setRowIndex(1);
        
        Object object = null;
        try
        {
           object = serialize(arrayDataModel);
        }
        catch (NotSerializableException e) 
        {
           assert false;
        }
        assert object instanceof javax.faces.model.ArrayDataModel;
        
        javax.faces.model.ArrayDataModel serializedArrayDataModel = (javax.faces.model.ArrayDataModel) object;
        
        assert serializedArrayDataModel.getRowIndex() == 1;
        
        String[] serializedArray = (String[]) serializedArrayDataModel.getWrappedData();
        
        assert array[0].equals(serializedArray[0]);
        
        assert array[1].equals(serializedArray[1]);
     }
     
     // Utility to serialize an object
     private Object serialize(Object object) throws Exception
     {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(object);  
        ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
        ObjectInputStream ois = new ObjectInputStream(bis);
        return ois.readObject();
     }
     
     @Test
     public void testListDataModelSerialization() throws Exception
     {
        
        List<String> list = Arrays.asList("Seam", "Hibernate");
        javax.faces.model.ListDataModel listDataModel = new org.jboss.seam.jsf.ListDataModel(list);
        listDataModel.setRowIndex(1);
        
        Object object = null;
        try
        {
           object = serialize(listDataModel);
        }
        catch (NotSerializableException e) 
        {
           assert false;
        }
        
        assert object instanceof javax.faces.model.ListDataModel;
        javax.faces.model.ListDataModel serializedListDataModel = (javax.faces.model.ListDataModel) object;
        List<String> serializedList = (List<String>) serializedListDataModel.getWrappedData();
        
        assert serializedListDataModel.getRowIndex() == 1;
        assert list.get(0).equals(serializedList.get(0)); 
        assert list.get(1).equals(serializedList.get(1));
     }
     
     @Test
     public void testMapDataModel() throws IOException, ClassNotFoundException
     {
        Map<String, Person> map = new HashMap<String, Person>();
        map.put("0", new Person("Gavin"));
        map.put("1", new Person("Tom"));
        
        javax.faces.model.DataModel mapDataModel = new MapDataModel();
        
        assert mapDataModel.getRowCount() == -1;
        assert mapDataModel.getRowData() == null;
        assert !mapDataModel.isRowAvailable();
        
        mapDataModel = new MapDataModel(map);
        
        assert mapDataModel.getWrappedData() instanceof Map;
        
        assert map.get("0").equals(((Map) mapDataModel.getWrappedData()).get("0"));
        assert map.get("1").equals(((Map) mapDataModel.getWrappedData()).get("1"));
        
        mapDataModel.setRowIndex(10);
        
        assert !mapDataModel.isRowAvailable();
        
        boolean failed = false;
        try
        {
           mapDataModel.getRowData();
        }
        catch (IllegalArgumentException e) 
        {
           failed = true;
        }
        
        assert failed;
        
        mapDataModel.setRowIndex(1);
        
        assert mapDataModel.isRowAvailable();
        assert mapDataModel.getRowIndex() == 1;
        assert mapDataModel.getRowCount() == 2;
        
        // JBSEAM-1660
        /*try 
        {
           mapDataModel.setWrappedData(null);
        }
        catch (NullPointerException e) 
        {
           // Spec allows passing null
           assert false;
        }*/
     }
     
     //JBSEAM-1659
     
     /*@Test
     public void testMapDataModelSerialization() throws Exception
     {
        
        Map<String, Person> map = new HashMap<String, Person>();
        map.put("0", new Person("Gavin"));
        map.put("1", new Person("Tom"));
        
        javax.faces.model.DataModel mapDataModel = new MapDataModel(map);    
        mapDataModel.setRowIndex(1);
  
        Object object = null;
        try
        {
           object = serialize(mapDataModel);
        }
        catch (NotSerializableException e) 
        {
           assert false;
        }
        
        
        assert object instanceof javax.faces.model.DataModel;
        javax.faces.model.DataModel serializedMapDataModel = (javax.faces.model.DataModel) object;
        Map<String, Person> serializedMap = (Map<String, Person>) serializedMapDataModel.getWrappedData();
        
        assert serializedMapDataModel.getRowIndex() == 1;
        assert map.get("0").equals(serializedMap.get("0")); 
        assert map.get("1").equals(serializedMap.get("1"));
     }*/
     
     @Test
     public void testSetDataModel() throws IOException, ClassNotFoundException
     {
        Person gavin = new Person("Gavin");
        Person tom = new Person("Tom");
        
        Set<Person> set = new HashSet<Person>();
        set.add(gavin);
        set.add(tom);
        
        javax.faces.model.DataModel setDataModel = new SetDataModel();
        
        assert setDataModel.getRowCount() == -1;
        assert setDataModel.getRowData() == null;
        assert !setDataModel.isRowAvailable();
        
        setDataModel = new SetDataModel(set);
        
        assert setDataModel.getWrappedData() instanceof Set;
        
        assert set.contains(gavin);
        assert set.contains(tom);
        
        setDataModel.setRowIndex(10);
        
        assert !setDataModel.isRowAvailable();
        
        boolean failed = false;
        try
        {
           setDataModel.getRowData();
        }
        catch (IllegalArgumentException e) 
        {
           failed = true;
        }
        
        assert failed;
        
        setDataModel.setRowIndex(1);
        
        assert setDataModel.isRowAvailable();
        assert setDataModel.getRowIndex() == 1;
        assert setDataModel.getRowCount() == 2;
        
        // JBSEAM-1660
        /*try 
        {
           setDataModel.setWrappedData(null);
        }
        catch (NullPointerException e) 
        {
           // Spec allows passing null
           assert false;
        }*/
     }
     
     @Test
     public void testSetDataModelSerialization() throws Exception
     {
        
        Person gavin = new Person("Gavin");
        Person tom = new Person("Tom");
        
        Set<Person> set = new HashSet<Person>();
        set.add(gavin);
        set.add(tom);
        
        javax.faces.model.DataModel setDataModel = new SetDataModel(set);    
        setDataModel.setRowIndex(1);
  
        Object object = null;
        try
        {
           object = serialize(setDataModel);
        }
        catch (NotSerializableException e) 
        {
           assert false;
        }
        
        
        assert object instanceof javax.faces.model.DataModel;
        javax.faces.model.DataModel serializedSetDataModel = (javax.faces.model.DataModel) object;
        Set<Person> serializedSet = (Set<Person>) serializedSetDataModel.getWrappedData();
        
        assert serializedSetDataModel.getRowIndex() == 1;
        assert serializedSet.contains(gavin);
        assert serializedSet.contains(tom);
     }
     
     @Test
     public void testDataModelOutjection() throws Exception
     {
        new FacesRequest()
        {
           
           @Override
           protected void renderResponse() throws Exception
           {
              Object people = getValue("#{peopleList}");
              assert people instanceof DataModel;
              DataModel dataModel = (DataModel) people;
              assert dataModel.getRowCount() == 4;
              dataModel.setRowIndex(1);
           }     
           
        }.run();
        
     }
  
  }
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/Widget.java
  
  Index: Widget.java
  ===================================================================
  package org.jboss.seam.test.unit;
  
  import java.util.Map;
  import java.util.List;
  
  /**
   * Used for remoting unit tests to test a variety of constraint combinations.
   *
   * @author Shane Bryzak
   */
  public class Widget
  {
    private String value;
    private String secret;
    private Widget child;
    private Map<String,Widget> widgetMap;
    private List<Widget> widgetList;
  
    public String getValue()
    {
      return value;
    }
  
    public void setValue(String value)
    {
      this.value = value;
    }
  
    public String getSecret()
    {
      return secret;
    }
  
    public void setSecret(String secret)
    {
      this.secret = secret;
    }
  
    public Widget getChild()
    {
      return child;
    }
  
    public void setChild(Widget child)
    {
      this.child = child;
    }
  
    public Map<String,Widget> getWidgetMap()
    {
      return widgetMap;
    }
  
    public void setWidgetMap(Map<String,Widget> widgetMap)
    {
      this.widgetMap = widgetMap;
    }
  
    public List<Widget> getWidgetList()
    {
      return widgetList;
    }
  
    public void setWidgetList(List<Widget> widgetList)
    {
      this.widgetList = widgetList;
    }
  }
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/testng.xml
  
  Index: testng.xml
  ===================================================================
  <!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
  
  <suite name="Seam Core Tests" verbose="2" parallel="false">
     <test name="Unit">
       <classes>
         <class name="org.jboss.seam.test.unit.CoreTest"/>
         <class name="org.jboss.seam.test.unit.InitializationTest"/>
         <class name="org.jboss.seam.test.unit.PhaseListenerTest"/>
         <class name="org.jboss.seam.test.unit.InterceptorTest"/>
         <class name="org.jboss.seam.test.unit.ComponentTest"/>
         <class name="org.jboss.seam.test.unit.ContextTest"/>
         <class name="org.jboss.seam.test.unit.PhaseListenerTest"/>
         <class name="org.jboss.seam.test.unit.RemotingTest"/>
         <class name="org.jboss.seam.test.unit.SecurityTest"/>
         <class name="org.jboss.seam.test.unit.InterpolatorTest"/>
         <class name="org.jboss.seam.test.unit.DependencyTest"/>
         <class name="org.jboss.seam.test.unit.SeamTestTest"/>
         <class name="org.jboss.seam.test.unit.MailTest"/>
         <class name="org.jboss.seam.test.unit.ELTest"/>
         <class name="org.jboss.seam.test.unit.DataModelTest"/>
         <class name="org.jboss.seam.test.unit.TimeZoneTest"/>
         <class name="org.jboss.seam.test.unit.LocaleTest"/>
         <class name="org.jboss.seam.test.unit.PageflowTest"/>
         <class name="org.jboss.seam.test.unit.SeamMockELResolverTest" />
         <class name="org.jboss.seam.test.unit.PageActionsTest" />
         <class name="org.jboss.seam.test.unit.HomeTest" />
       </classes>
     </test>
  </suite>
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/InitializationTest.java
  
  Index: InitializationTest.java
  ===================================================================
  //$Id: InitializationTest.java,v 1.1 2007/10/08 18:15:47 pmuir Exp $
  package org.jboss.seam.test.unit;
  
  import org.jboss.seam.Seam;
  import org.jboss.seam.contexts.Contexts;
  import org.jboss.seam.contexts.ServletLifecycle;
  import org.jboss.seam.core.Manager;
  import org.jboss.seam.init.Initialization;
  import org.jboss.seam.mock.MockServletContext;
  import org.testng.annotations.Test;
  
  public class InitializationTest
  {
     @Test
     public void testInitialization()
     {
        MockServletContext servletContext = new MockServletContext();
        ServletLifecycle.beginApplication(servletContext);
        new Initialization(servletContext).init();
  
        assert !servletContext.getAttributes().isEmpty();
        assert servletContext.getAttributes().containsKey( Seam.getComponentName(Manager.class) + ".component" );
        assert servletContext.getAttributes().containsKey( Seam.getComponentName(Foo.class) + ".component" );
        assert !Contexts.isApplicationContextActive();
     }
  
     //TODO: write a test for components.xml
  }
  
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/HomeTest.java
  
  Index: HomeTest.java
  ===================================================================
  package org.jboss.seam.test.unit;
  
  import javax.persistence.EntityManager;
  
  import org.jboss.seam.faces.FacesMessages;
  import org.jboss.seam.framework.Home;
  import org.testng.annotations.Test;
  
  public class HomeTest
  {
     /**
      * Ensure that the add message methods do not trigger a null
      * pointer exception if the getEntityClass() method is overridden.
      */
     @Test
     public void testGetEntityClassOverride() {
        TestHome1 home = new TestHome1();
        // emulate @Create method
        home.create();
        home.triggerCreatedMessage();
     }
     
     /**
      * Ensure that an instance can be created when getEntityClass()
      * method is overridden.
      */
     @Test
     public void testCreateInstance() {
        TestHome1 home = new TestHome1();
        // emulate @Create method
        home.create();
        SimpleEntity entity = home.getInstance();
        assert entity != null : "Excepting a non-null instance";
        assert entity.getClass().equals(SimpleEntity.class) : "Expecting entity class to be " + SimpleEntity.class + " but got " + entity.getClass();
     }
     
     class TestHome1 extends Home<EntityManager, SimpleEntity> {
  
        private FacesMessages facesMessages;
  
        public TestHome1() {
           facesMessages = new FacesMessages();
        }
        
        public void triggerCreatedMessage() {
           createdMessage();
        }
        
        @Override
        protected void debug(Object object, Object... params)
        {
           // ignore
        }
        
        @Override
        protected FacesMessages getFacesMessages()
        {
           return facesMessages;
        }
  
        @Override
        public Class<SimpleEntity> getEntityClass()
        {
           return SimpleEntity.class;
        }
  
        @Override
        protected String getEntityName()
        {
           return "SimpleEntity";
        }
  
        @Override
        protected String getPersistenceContextName()
        {
           return "entityManager";
        }
        
     }
  }
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/Ejb.java
  
  Index: Ejb.java
  ===================================================================
  //$Id: Ejb.java,v 1.1 2007/10/08 18:15:47 pmuir Exp $
  package org.jboss.seam.test.unit;
  
  import javax.ejb.Local;
  
  @Local
  public interface Ejb
  {
     public void foo();
     public void destroy();
  }
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/RemotingTest.java
  
  Index: RemotingTest.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.seam.test.unit;
  
  import static org.testng.Assert.assertEquals;
  
  import java.io.ByteArrayOutputStream;
  import java.io.IOException;
  import java.io.OutputStream;
  import java.io.StringReader;
  import java.io.UnsupportedEncodingException;
  import java.lang.reflect.Type;
  import java.net.URLEncoder;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.Calendar;
  import java.util.Collection;
  import java.util.Date;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  import java.util.Queue;
  import java.util.Set;
  
  import org.dom4j.Document;
  import org.dom4j.DocumentFactory;
  import org.dom4j.Element;
  import org.dom4j.io.SAXReader;
  import org.jboss.seam.contexts.Lifecycle;
  import org.jboss.seam.contexts.ServletLifecycle;
  import org.jboss.seam.init.Initialization;
  import org.jboss.seam.mock.MockServletContext;
  import org.jboss.seam.remoting.CallContext;
  import org.jboss.seam.remoting.MarshalUtils;
  import org.jboss.seam.remoting.client.ParserUtils;
  import org.jboss.seam.remoting.wrapper.BagWrapper;
  import org.jboss.seam.remoting.wrapper.BaseWrapper;
  import org.jboss.seam.remoting.wrapper.BeanWrapper;
  import org.jboss.seam.remoting.wrapper.BooleanWrapper;
  import org.jboss.seam.remoting.wrapper.ConversionException;
  import org.jboss.seam.remoting.wrapper.ConversionScore;
  import org.jboss.seam.remoting.wrapper.DateWrapper;
  import org.jboss.seam.remoting.wrapper.MapWrapper;
  import org.jboss.seam.remoting.wrapper.NullWrapper;
  import org.jboss.seam.remoting.wrapper.NumberWrapper;
  import org.jboss.seam.remoting.wrapper.StringWrapper;
  import org.jboss.seam.remoting.wrapper.WrapperFactory;
  import org.testng.annotations.Test;
  import org.jboss.seam.remoting.InterfaceGenerator;
  import java.math.BigInteger;
  import java.math.BigDecimal;
  
  /**
   * Unit tests for Seam Remoting
   * 
   * @author Shane Bryzak
   */
  public class RemotingTest
  {
     private class InvalidClass
     {
     }
  
     public Element createElement(String name, String value)
           throws UnsupportedEncodingException
     {
        Element e = DocumentFactory.getInstance().createElement(name);
        if (value != null)
           e.addText(URLEncoder.encode(value, StringWrapper.DEFAULT_ENCODING));
        return e;
     }
  
     private enum TestEnum
     {
        red, green, blue
     }
  
     @Test
     public void testBooleanWrapper() throws Exception
     {
        BooleanWrapper wrapper = new BooleanWrapper();
        wrapper.setElement(createElement("bool", Boolean.toString(true)));
  
        assert (Boolean) wrapper.convert(Boolean.class);
        assert (Boolean) wrapper.convert(Boolean.TYPE);
  
        try
        {
           // Try an invalid conversion
           wrapper.convert(InvalidClass.class);
           assert false;
        }
        catch (ConversionException ex)
        {
        }
  
        // test the marshal() method
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        wrapper.marshal(out);
        byte[] expected = ("<bool>" + Boolean.toString(true) + "</bool>")
              .getBytes();
        assertEquals(expected, out.toByteArray());
  
        // test the conversionScore() method
        assert ConversionScore.exact == wrapper.conversionScore(Boolean.class);
        assert ConversionScore.exact == wrapper.conversionScore(Boolean.TYPE);
        assert ConversionScore.compatible == wrapper
              .conversionScore(Object.class);
        assert ConversionScore.nomatch == wrapper
              .conversionScore(InvalidClass.class);
     }
  
     @Test
     public void testDateWrapper() throws Exception
     {
        DateWrapper wrapper = new DateWrapper();
        String value = "20061231123045150";
        wrapper.setElement(createElement("date", value));
  
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, 2006);
        cal.set(Calendar.MONTH, Calendar.DECEMBER);
        cal.set(Calendar.DATE, 31);
        cal.set(Calendar.HOUR_OF_DAY, 12);
        cal.set(Calendar.MINUTE, 30);
        cal.set(Calendar.SECOND, 45);
        cal.set(Calendar.MILLISECOND, 150);
  
        assertEquals(cal.getTime(), wrapper.convert(Date.class));
  
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        wrapper.marshal(out);
  
        byte[] expected = ("<date>" + value + "</date>").getBytes();
        assertEquals(expected, out.toByteArray());
  
        try
        {
           // this should throw an exception
           wrapper.convert(InvalidClass.class);
           assert false;
        }
        catch (ConversionException ex)
        {
        }
  
        try
        {
           // this should throw an exception
           wrapper.setElement(createElement("date", "foobar"));
           wrapper.convert(Date.class);
           assert false;
        }
        catch (ConversionException ex)
        {
        }
  
        // test conversionScore() method
        assert ConversionScore.exact == wrapper.conversionScore(Date.class);
        assert ConversionScore.exact == wrapper
              .conversionScore(java.sql.Date.class);
        assert ConversionScore.compatible == wrapper
              .conversionScore(Object.class);
        assert ConversionScore.nomatch == wrapper
              .conversionScore(InvalidClass.class);
     }
  
     @Test
     public void testStringWrapper() throws Exception
     {
        String value = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
              + "!@#$%^&*()_+-=`~[]{}|;:\"',./<>?\\ ";
        StringWrapper wrapper = new StringWrapper();
        wrapper.setElement(createElement("str", value));
  
        assert value.equals(wrapper.convert(String.class));
        assert value
              .equals(((StringBuilder) wrapper.convert(StringBuilder.class))
                    .toString());
        assert value.equals(((StringBuffer) wrapper.convert(StringBuffer.class))
              .toString());
  
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        wrapper.marshal(out);
        byte[] expected = ("<str>"
              + URLEncoder.encode(value, StringWrapper.DEFAULT_ENCODING) + "</str>")
              .replace("+", "%20").getBytes();
  
        assertEquals(expected, out.toByteArray());
  
        value = "123";
        wrapper.setElement(createElement("str", value));
  
        assert Integer.valueOf(value).equals(wrapper.convert(Integer.class));
        assert Integer.valueOf(value).equals(wrapper.convert(Integer.TYPE));
        assert Long.valueOf(value).equals(wrapper.convert(Long.class));
        assert Long.valueOf(value).equals(wrapper.convert(Long.TYPE));
        assert Short.valueOf(value).equals(wrapper.convert(Short.class));
        assert Short.valueOf(value).equals(wrapper.convert(Short.TYPE));
        assert Byte.valueOf(value).equals(wrapper.convert(Byte.class));
        assert Byte.valueOf(value).equals(wrapper.convert(Byte.TYPE));
  
        value = "123.4567";
        wrapper.setElement(createElement("str", value));
  
        assert Double.valueOf(value).equals(wrapper.convert(Double.class));
        assert Double.valueOf(value).equals(wrapper.convert(Double.TYPE));
        assert Float.valueOf(value).equals(wrapper.convert(Float.class));
        assert Float.valueOf(value).equals(wrapper.convert(Float.TYPE));
  
        wrapper.setElement(createElement("str", Boolean.toString(true)));
        assert (Boolean) wrapper.convert(Boolean.class);
        assert (Boolean) wrapper.convert(Boolean.TYPE);
  
        wrapper.setElement(createElement("str", Boolean.toString(false)));
        assert !(Boolean) wrapper.convert(Boolean.class);
        assert !(Boolean) wrapper.convert(Boolean.TYPE);
  
        try
        {
           // Attempt an invalid conversion
           wrapper.convert(Integer.class);
           assert false;
        }
        catch (ConversionException ex)
        {
        }
  
        value = "A";
        wrapper.setElement(createElement("str", value));
  
        assert Character.valueOf(value.charAt(0)).equals(
              wrapper.convert(Character.class));
        assert Character.valueOf(value.charAt(0)).equals(
              wrapper.convert(Character.TYPE));
  
        value = "green";
        wrapper.setElement(createElement("str", value));
  
        assert TestEnum.valueOf(value).equals(wrapper.convert(TestEnum.class));
  
        try
        {
           wrapper.setElement(createElement("str", "foo"));
           // Attempt an invalid conversion
           wrapper.convert(InvalidClass.class);
           assert false;
        }
        catch (ConversionException ex)
        {
        }
  
        // Test conversionScore() method
        wrapper = new StringWrapper();
  
        assert ConversionScore.exact == wrapper.conversionScore(String.class);
        assert ConversionScore.exact == wrapper
              .conversionScore(StringBuffer.class);
        assert ConversionScore.exact == wrapper
              .conversionScore(StringBuffer.class);
        assert ConversionScore.compatible == wrapper
              .conversionScore(Integer.class);
        assert ConversionScore.compatible == wrapper
              .conversionScore(Integer.TYPE);
        assert ConversionScore.compatible == wrapper.conversionScore(Long.class);
        assert ConversionScore.compatible == wrapper.conversionScore(Long.TYPE);
        assert ConversionScore.compatible == wrapper.conversionScore(Short.class);
        assert ConversionScore.compatible == wrapper.conversionScore(Short.TYPE);
        assert ConversionScore.compatible == wrapper
              .conversionScore(Boolean.class);
        assert ConversionScore.compatible == wrapper
              .conversionScore(Boolean.TYPE);
        assert ConversionScore.compatible == wrapper.conversionScore(Float.class);
        assert ConversionScore.compatible == wrapper.conversionScore(Float.TYPE);
        assert ConversionScore.compatible == wrapper
              .conversionScore(Character.class);
        assert ConversionScore.compatible == wrapper
              .conversionScore(Character.TYPE);
        assert ConversionScore.compatible == wrapper.conversionScore(Byte.class);
        assert ConversionScore.compatible == wrapper.conversionScore(Byte.TYPE);
  
        wrapper.setElement(createElement("str", "green"));
        assert ConversionScore.compatible == wrapper
              .conversionScore(TestEnum.class);
        wrapper.setElement(createElement("str", "foo"));
        assert ConversionScore.nomatch == wrapper.conversionScore(TestEnum.class);
  
        assert ConversionScore.nomatch == wrapper
              .conversionScore(InvalidClass.class);
     }
  
     @Test
     public void testNumberWrapper() throws Exception
     {
        String value = "123";
  
        NumberWrapper wrapper = new NumberWrapper();
        wrapper.setElement(createElement("number", value));
  
        assert new Short(value).equals(wrapper.convert(Short.class));
        assert wrapper.convert(Short.TYPE).equals(Short.parseShort(value));
  
        assert new Integer(value).equals(wrapper.convert(Integer.class));
        assert wrapper.convert(Integer.TYPE).equals(Integer.parseInt(value));
  
        assert new Long(value).equals(wrapper.convert(Long.class));
        assert wrapper.convert(Long.TYPE).equals(Long.parseLong(value));
  
        assert new Byte(value).equals(wrapper.convert(Byte.class));
        assert wrapper.convert(Byte.TYPE).equals(Byte.parseByte(value));
  
        assert value.equals(wrapper.convert(String.class));
  
        value = "123.456";
        wrapper.setElement(createElement("number", value));
  
        assert new Double(value).equals(wrapper.convert(Double.class));
        assert Double.valueOf(value).equals(wrapper.convert(Double.TYPE));
  
        assert new Float(value).equals(wrapper.convert(Float.class));
        assert Float.valueOf(value).equals(wrapper.convert(Float.TYPE));
  
        value = "";
        wrapper.setElement(createElement("number", value));
  
        assert null == wrapper.convert(Short.class);
        assert null == wrapper.convert(Integer.class);
        assert null == wrapper.convert(Long.class);
        assert null == wrapper.convert(Float.class);
        assert null == wrapper.convert(Double.class);
        assert null == wrapper.convert(Byte.class);
  
        try
        {
           // Attempt an invalid conversion
           wrapper.convert(InvalidClass.class);
           assert false;
        }
        catch (ConversionException ex)
        {
        }
  
        assert ConversionScore.exact == wrapper.conversionScore(Integer.class);
        assert ConversionScore.exact == wrapper.conversionScore(Integer.TYPE);
  
        assert ConversionScore.compatible == wrapper
              .conversionScore(String.class);
        assert ConversionScore.compatible == wrapper
              .conversionScore(Object.class);
  
        assert ConversionScore.nomatch == wrapper
              .conversionScore(InvalidClass.class);
     }
  
     /**
      * Dummy method used in testBagWrapper()
      * 
      * @return List
      */
     public List<String> dummy()
     {
        return null;
     }
  
     public InvalidList<String> dummyInvalid()
     {
        return null;
     }
  
     /**
      * Used in testBagWrapper()
      */
     @SuppressWarnings("serial")
     private class InvalidList<E> extends ArrayList<E>
     {
        public InvalidList()
        {
           throw new InstantiationError();
        }
     }
  
     @Test
     public void testBagWrapper() throws Exception
     {
        BagWrapper wrapper = new BagWrapper();
        wrapper.setCallContext(new CallContext());
  
        String[] values = new String[2];
        values[0] = "foo";
        values[1] = "bar";
  
        Element e = createElement("bag", null);
        e.addElement("element").addElement("str").addText(values[0]);
        e.addElement("element").addElement("str").addText(values[1]);
        wrapper.setElement(e);
  
        // String Array
        String[] converted = (String[]) wrapper.convert(String[].class);
        assert values.length == converted.length;
        assertEquals(values[0], converted[0]);
        assertEquals(values[1], converted[1]);
  
        // List
        List convertedList = (List) wrapper.convert(List.class);
        assert values.length == convertedList.size();
        assertEquals(values[0], convertedList.get(0));
        assertEquals(values[1], convertedList.get(1));
  
        // List<String> (Generic type)
  
        // Isn't there an easier way of getting a generic type than this??
        Type t = RemotingTest.class.getMethod("dummy").getGenericReturnType();
  
        List<String> stringList = (List<String>) wrapper.convert(t);
        assert values.length == stringList.size();
        assertEquals(values[0], stringList.get(0));
        assertEquals(values[1], stringList.get(1));
  
        // Set
        Set s = (Set) wrapper.convert(Set.class);
        assert values.length == s.size();
        assert s.contains(values[0]);
        assert s.contains(values[1]);
  
        // Queue
        Queue q = (Queue) wrapper.convert(Queue.class);
        assert values.length == q.size();
        assert q.contains(values[0]);
        assert q.contains(values[1]);
  
        // Concrete class
        ArrayList l = (ArrayList) wrapper.convert(ArrayList.class);
        assert values.length == l.size();
        assertEquals(values[0], l.get(0));
        assertEquals(values[1], l.get(1));
  
        try
        {
           // This should throw a ConversionException
           wrapper.convert(InvalidList.class);
           assert false;
        }
        catch (ConversionException ex)
        {
        }
  
        t = RemotingTest.class.getMethod("dummyInvalid").getGenericReturnType();
        try
        {
           // This should throw a ConversionException also
           wrapper.convert(t);
           assert false;
        }
        catch (ConversionException ex)
        {
        }
  
        int[] intValues = new int[2];
        intValues[0] = 44444;
        intValues[1] = 55555;
  
        e = createElement("bag", null);
        e.addElement("element").addElement("number").addText("" + intValues[0]);
        e.addElement("element").addElement("number").addText("" + intValues[1]);
        wrapper.setElement(e);
  
        // int Array
        int[] convertedInts = (int[]) wrapper.convert(int[].class);
        assert intValues.length == convertedInts.length;
        assertEquals(intValues[0], convertedInts[0]);
        assertEquals(intValues[1], convertedInts[1]);
  
        // Test marshal()
  
        byte[] expected = ("<bag><element><number>" + intValues[0]
              + "</number></element>" + "<element><number>" + intValues[1] + "</number></element></bag>")
              .getBytes();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        wrapper.marshal(out);
        assertEquals(expected, out.toByteArray());
  
        List intList = new ArrayList();
        intList.add(intValues[0]);
        intList.add(intValues[1]);
        wrapper.setValue(intList);
        out.reset();
        wrapper.marshal(out);
        assertEquals(expected, out.toByteArray());
  
        try
        {
           // This should throw a RuntimeException
           wrapper.setValue(new InvalidClass());
           wrapper.marshal(out);
           assert false;
        }
        catch (RuntimeException ex)
        {
        }
  
        // test conversionScore() method
        assert ConversionScore.compatible == wrapper
              .conversionScore(String[].class);
        assert ConversionScore.compatible == wrapper
              .conversionScore(Object.class);
        assert ConversionScore.compatible == wrapper
              .conversionScore(Collection.class);
        assert ConversionScore.nomatch == wrapper
              .conversionScore(InvalidClass.class);
     }
  
     @Test
     public void testBeanWrapper()
     {
        // BeanWrapper wrapper = new BeanWrapper();
  
        /** @todo Write tests for BeanWrapper */
     }
  
     /**
      * Used in testMapWrapper()
      */
     public Map<String, String> dummyMap()
     {
        return null;
     }
  
     /**
      * Used in testMapWrapper()
      */
     @SuppressWarnings("serial")
     private class InvalidMap extends HashMap
     {
        public InvalidMap()
        {
           throw new InstantiationError();
        }
     }
  
     @Test
     public void testMapWrapper() throws Exception
     {
        MapWrapper wrapper = new MapWrapper();
        wrapper.setCallContext(new CallContext());
  
        // Construct a map with two elements, foo:aaaaa and bar:zzzzz
        Element e = DocumentFactory.getInstance().createElement("map");
        Element child = e.addElement("element");
        child.addElement("k").addElement("str").addText("foo");
        child.addElement("v").addElement("str").addText("aaaaa");
        child = e.addElement("element");
        child.addElement("k").addElement("str").addText("bar");
        child.addElement("v").addElement("str").addText("zzzzz");
  
        wrapper.setElement(e);
  
        // Conversion tests
        Map m = (Map) wrapper.convert(Map.class);
        assert m.containsKey("foo");
        assert m.containsKey("bar");
        assert "aaaaa".equals(m.get("foo"));
        assert "zzzzz".equals(m.get("bar"));
  
        m = (Map) wrapper.convert(HashMap.class);
        assert m.containsKey("foo");
        assert m.containsKey("bar");
        assert "aaaaa".equals(m.get("foo"));
        assert "zzzzz".equals(m.get("bar"));
  
        Type t = RemotingTest.class.getMethod("dummyMap").getGenericReturnType();
        m = (Map) wrapper.convert(t);
        assert m.containsKey("foo");
        assert m.containsKey("bar");
        assert "aaaaa".equals(m.get("foo"));
        assert "zzzzz".equals(m.get("bar"));
  
        try
        {
           // This should throw a ConversionException
           wrapper.convert(InvalidClass.class);
           assert false;
        }
        catch (ConversionException ex)
        {
        }
  
        try
        {
           // This should throw a ConversionException also
           wrapper.convert(InvalidMap.class);
           assert false;
        }
        catch (ConversionException ex)
        {
        }
  
        byte[] expected = ("<map><element><k><str>foo</str></k><v><str>aaaaa</str></v></element>"
              + "<element><k><str>bar</str></k><v><str>zzzzz</str></v></element></map>")
              .getBytes();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        wrapper.marshal(out);
        assertEquals(expected, out.toByteArray());
  
        // test conversionScore() method
        assert ConversionScore.exact == wrapper.conversionScore(Map.class);
        assert ConversionScore.exact == wrapper.conversionScore(HashMap.class);
        assert ConversionScore.compatible == wrapper
              .conversionScore(Object.class);
        assert ConversionScore.nomatch == wrapper
              .conversionScore(InvalidClass.class);
     }
  
     @Test
     public void testNullWrapper() throws Exception
     {
        NullWrapper wrapper = new NullWrapper();
        assert wrapper.convert(null) == null;
  
        byte[] expected = "<null/>".getBytes();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        wrapper.marshal(out);
        assertEquals(expected, out.toByteArray());
  
        assert ConversionScore.compatible == wrapper.conversionScore(null);
        assert ConversionScore.compatible == wrapper
              .conversionScore(Object.class);
     }
  
     @Test
     public void testBaseWrapper()
     {
        BaseWrapper wrapper = new BaseWrapper()
        {
           public ConversionScore conversionScore(Class cls)
           {
              return ConversionScore.nomatch;
           }
  
           public void marshal(OutputStream out)
           {
           }
  
           public Object convert(Type type)
           {
              return null;
           }
        };
  
        Object value = new Object();
        wrapper.setValue(value);
  
        assert value.equals(wrapper.getValue());
  
        // For code-coverage completeness
        wrapper.unmarshal();
        wrapper.setCallContext(null);
        try
        {
           wrapper.serialize(null);
        }
        catch (IOException ex)
        {
        }
     }
  
     @Test
     public void testWrapperFactory()
     {
        try
        {
           // This should throw a RuntimeException
           WrapperFactory.getInstance().createWrapper("invalid");
           assert false;
        }
        catch (RuntimeException ex)
        {
        }
  
        assert WrapperFactory.getInstance().getWrapperForObject(null) instanceof NullWrapper;
        assert WrapperFactory.getInstance().getWrapperForObject(new HashMap()) instanceof MapWrapper;
        assert WrapperFactory.getInstance().getWrapperForObject(new String[2]) instanceof BagWrapper;
        assert WrapperFactory.getInstance().getWrapperForObject(new ArrayList()) instanceof BagWrapper;
        assert WrapperFactory.getInstance()
              .getWrapperForObject(new Boolean(true)) instanceof BooleanWrapper;
        assert WrapperFactory.getInstance().getWrapperForObject(true) instanceof BooleanWrapper;
        assert WrapperFactory.getInstance().getWrapperForObject(TestEnum.blue) instanceof StringWrapper;
        assert WrapperFactory.getInstance().getWrapperForObject(new Date()) instanceof DateWrapper;
        assert WrapperFactory.getInstance().getWrapperForObject(new Object()) instanceof BeanWrapper;
  
        // All the String types
        assert WrapperFactory.getInstance().getWrapperForObject("foo") instanceof StringWrapper;
        assert WrapperFactory.getInstance().getWrapperForObject(
              new StringBuffer("foo")) instanceof StringWrapper;
        assert WrapperFactory.getInstance().getWrapperForObject(
              new StringBuilder("foo")) instanceof StringWrapper;
        assert WrapperFactory.getInstance().getWrapperForObject(
              new Character('a')) instanceof StringWrapper;
  
        // All the number types
        assert WrapperFactory.getInstance().getWrapperForObject(111) instanceof NumberWrapper;
        assert WrapperFactory.getInstance().getWrapperForObject(111) instanceof NumberWrapper;
        assert WrapperFactory.getInstance().getWrapperForObject(111) instanceof NumberWrapper;
        assert WrapperFactory.getInstance().getWrapperForObject(123.456) instanceof NumberWrapper;
        assert WrapperFactory.getInstance().getWrapperForObject(123.456) instanceof NumberWrapper;
        assert WrapperFactory.getInstance().getWrapperForObject(111) instanceof NumberWrapper;
  
     }
  
     @Test
     public void testConversionScore()
     {
        // For code-coverage completeness
        assert 0 == ConversionScore.nomatch.getScore();
        assert 1 == ConversionScore.compatible.getScore();
        assert 2 == ConversionScore.exact.getScore();
        ConversionScore.valueOf("exact");
     }
  
     @Test
     public void testConstraints() throws Exception
     {
        // Initialize Seam
        MockServletContext servletContext = new MockServletContext();
        ServletLifecycle.beginApplication(servletContext);
        new Initialization(servletContext).init();
  
        try
        {
           Lifecycle.beginCall();
  
           // Create our object graph
           Widget result = new Widget();
           result.setValue("foo");
           result.setSecret("bar");
  
           ByteArrayOutputStream out = new ByteArrayOutputStream();
  
           // Constrain a single field of the result
           List<String> constraints = Arrays.asList(new String[] { "secret" });
           MarshalUtils.marshalResult(null, new CallContext(), out, result,
                 constraints);
  
           SAXReader xmlReader = new SAXReader();
           Document doc = xmlReader.read(new StringReader(new String(out
                 .toByteArray())));
  
           Widget widget = (Widget) ParserUtils.unmarshalResult(doc
                 .getRootElement());
  
           // value field should equal "foo"
           assert "foo".equals(widget.getValue());
  
           // secret field should be null
           assert widget.getSecret() == null;
  
           // Now extend our object graph a little further
           result.setChild(new Widget());
           result.getChild().setValue("foo");
           result.getChild().setSecret("bar");
  
           // Reset our output stream so we can re-use it
           out.reset();
  
           // Now we're going to constrain result.child's secret field
           constraints = Arrays.asList(new String[] { "child.secret" });
           MarshalUtils.marshalResult(null, new CallContext(), out, result,
                 constraints);
  
           doc = xmlReader.read(new StringReader(new String(out.toByteArray())));
           widget = (Widget) ParserUtils.unmarshalResult(doc.getRootElement());
           assert "foo".equals(widget.getValue());
           assert "bar".equals(widget.getSecret());
           assert "foo".equals(widget.getChild().getValue());
           assert widget.getChild().getSecret() == null;
  
           // Add a map to our result
           result.setWidgetMap(new HashMap<String, Widget>());
           Widget val = new Widget();
           val.setValue("foo");
           val.setSecret("bar");
           result.getWidgetMap().put("foo", val);
  
           // Reset our output stream again
           out.reset();
  
           // Constrain the "secret" field of the widgetMap map's values (sounds
           // confusing, I know...)
           constraints = Arrays
                 .asList(new String[] { "widgetMap[value].secret" });
           MarshalUtils.marshalResult(null, new CallContext(), out, result,
                 constraints);
  
           doc = xmlReader.read(new StringReader(new String(out.toByteArray())));
           widget = (Widget) ParserUtils.unmarshalResult(doc.getRootElement());
           val = widget.getWidgetMap().get("foo");
           assert val != null;
           assert "foo".equals(val.getValue());
           assert val.getSecret() == null;
  
           // Reset our output stream
           out.reset();
  
           // Add a list to our result
           result.setWidgetList(new ArrayList<Widget>());
           Widget item = new Widget();
           item.setValue("foo");
           item.setSecret("bar");
           result.getWidgetList().add(item);
  
           // Constraint the "secret" field of widgetList
           constraints = Arrays.asList(new String[] { "widgetList.secret" });
           MarshalUtils.marshalResult(null, new CallContext(), out, result,
                 constraints);
  
           doc = xmlReader.read(new StringReader(new String(out.toByteArray())));
           widget = (Widget) ParserUtils.unmarshalResult(doc.getRootElement());
           item = widget.getWidgetList().get(0);
           assert item != null;
           assert "foo".equals(item.getValue());
           assert item.getSecret() == null;
  
           // Reset our output stream
           out.reset();
  
           // Now constrain all secrets
           constraints = Arrays
                 .asList(new String[] { "[org.jboss.seam.test.Widget].secret" });
           MarshalUtils.marshalResult(null, new CallContext(), out, result,
                 constraints);
  
           doc = xmlReader.read(new StringReader(new String(out.toByteArray())));
           widget = (Widget) ParserUtils.unmarshalResult(doc.getRootElement());
  
           val = widget.getWidgetMap().get("foo");
           item = widget.getWidgetList().get(0);
  
           assert "foo".equals(widget.getValue());
           assert "foo".equals(widget.getChild().getValue());
           assert "foo".equals(val.getValue());
           assert "foo".equals(item.getValue());
  
           assert widget.getSecret() == null;
           assert widget.getChild().getSecret() == null;
           assert val.getSecret() == null;
           assert item.getSecret() == null;
        }
        finally
        {
           Lifecycle.endCall();
        }
     }
  
     class ProxyInterfaceGenerator extends InterfaceGenerator
     {
        @Override
        public String getFieldType(Type type)
        {
           return super.getFieldType(type);
        }
     }
  
     static class Dummy
     {
        enum TestEnum
        {
           foo, bar
        }
  
        public String getString()
        {
           return null;
        }
  
        public TestEnum getEnum()
        {
           return null;
        }
  
        public BigInteger getBigInteger()
        {
           return null;
        }
  
        public BigDecimal getBigDecimal()
        {
           return null;
        }
  
        public Boolean getBoolean()
        {
           return null;
        }
  
        public boolean getBool()
        {
           return false;
        }
  
        public Short getShort()
        {
           return null;
        }
  
        public short getSht()
        {
           return 0;
        }
  
        public Integer getInteger()
        {
           return null;
        }
  
        public int getInt()
        {
           return 0;
        }
  
        public Long getLong()
        {
           return null;
        }
  
        public long getLng()
        {
           return 0;
        }
  
        public Float getFloat()
        {
           return null;
        }
  
        public float getFlt()
        {
           return 0;
        }
  
        public Double getDouble()
        {
           return null;
        }
  
        public double getDbl()
        {
           return 0;
        }
  
        public Byte getByte()
        {
           return null;
        }
  
        public byte getByt()
        {
           return 0;
        }
  
        public Date getDate()
        {
           return null;
        }
  
        public int[] getIntArray()
        {
           return null;
        }
  
        public Map getMap()
        {
           return null;
        }
  
        public Collection getCollection()
        {
           return null;
        }
  
        public Map<String, String> getGenericMap()
        {
           return null;
        }
  
        public Collection<String> getGenericCollection()
        {
           return null;
        }
     }
  
     private Type getDummyReturnType(String methodName)
     {
        try
        {
           return Dummy.class.getMethod(methodName).getGenericReturnType();
        }
        catch (NoSuchMethodException ex)
        {
           return null;
        }
     }
  
     /**
      * Test that the correct remoting type is returned for various Java types
      */
     @Test
     public void testInterfaceGenerator()
     {
        ProxyInterfaceGenerator gen = new ProxyInterfaceGenerator();
        assert ("str".equals(gen.getFieldType(getDummyReturnType("getString"))));
        assert ("str".equals(gen.getFieldType(getDummyReturnType("getEnum"))));
        assert ("str".equals(gen
              .getFieldType(getDummyReturnType("getBigInteger"))));
        assert ("str".equals(gen
              .getFieldType(getDummyReturnType("getBigDecimal"))));
        assert ("bool".equals(gen.getFieldType(getDummyReturnType("getBoolean"))));
        assert ("bool".equals(gen.getFieldType(getDummyReturnType("getBool"))));
        assert ("number".equals(gen.getFieldType(getDummyReturnType("getShort"))));
        assert ("number".equals(gen.getFieldType(getDummyReturnType("getSht"))));
        assert ("number".equals(gen
              .getFieldType(getDummyReturnType("getInteger"))));
        assert ("number".equals(gen.getFieldType(getDummyReturnType("getInt"))));
        assert ("number".equals(gen.getFieldType(getDummyReturnType("getLong"))));
        assert ("number".equals(gen.getFieldType(getDummyReturnType("getLng"))));
        assert ("number".equals(gen.getFieldType(getDummyReturnType("getFloat"))));
        assert ("number".equals(gen.getFieldType(getDummyReturnType("getFlt"))));
        assert ("number"
              .equals(gen.getFieldType(getDummyReturnType("getDouble"))));
        assert ("number".equals(gen.getFieldType(getDummyReturnType("getDbl"))));
        assert ("number".equals(gen.getFieldType(getDummyReturnType("getByte"))));
        assert ("number".equals(gen.getFieldType(getDummyReturnType("getByt"))));
        assert ("date".equals(gen.getFieldType(getDummyReturnType("getDate"))));
        assert ("bag".equals(gen.getFieldType(getDummyReturnType("getIntArray"))));
        assert ("map".equals(gen.getFieldType(getDummyReturnType("getMap"))));
        assert ("bag".equals(gen
              .getFieldType(getDummyReturnType("getCollection"))));
        assert ("map".equals(gen
              .getFieldType(getDummyReturnType("getGenericMap"))));
        assert ("bag".equals(gen
              .getFieldType(getDummyReturnType("getGenericCollection"))));
     }
  }
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/SimpleEntity.java
  
  Index: SimpleEntity.java
  ===================================================================
  package org.jboss.seam.test.unit;
  
  import java.io.Serializable;
  
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  
  /**
   * A simple entity class that can be used in tests.
   */
  @Entity
  public class SimpleEntity implements Serializable
  {
     private Long id;
  
     private String name;
  
     @Id @GeneratedValue
     public Long getId()
     {
        return id;
     }
  
     public String getName()
     {
        return name;
     }
  
     public void setId(Long id)
     {
        this.id = id;
     }
  
     public void setName(String name)
     {
        this.name = name;
     }
  }
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/SeamTestTest.java
  
  Index: SeamTestTest.java
  ===================================================================
  package org.jboss.seam.test.unit;
  
  import org.jboss.seam.mock.SeamTest;
  import org.testng.annotations.Test;
  
  public class SeamTestTest extends SeamTest
  {
     
     @Override
     protected void startJbossEmbeddedIfNecessary() 
     throws org.jboss.deployers.spi.DeploymentException ,java.io.IOException {}
     
     private static final String PETER_NAME = "Pete Muir";
     private static final String PETER_USERNAME = "pmuir";
     
     @Test
     public void testEl() throws Exception
     {
        new FacesRequest() 
        {  
           
           @Override
           protected void updateModelValues() throws Exception
           {
              setValue("#{person.name}", PETER_NAME);
           }
           
           @Override
           protected void renderResponse() throws Exception
           {
              assert getValue("#{person.name}").equals(PETER_NAME);
           }
           
           @Override
           protected void invokeApplication() throws Exception
           {
              invokeAction("#{action.go}");
              String result = getOutcome();
              assert "success".equals(result);
           }
        }.run();
     }
     
     @Test
     public void testSeamSecurity() throws Exception
     {
        new FacesRequest() 
        {  
           
           @Override
           protected void updateModelValues() throws Exception
           {
              setValue("#{identity.username}", PETER_USERNAME);
           }
           
           @Override
           protected void renderResponse() throws Exception
           {
              assert getValue("#{identity.username}").equals(PETER_USERNAME);
           }
        }.run();
     }
  
  }
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/SeamTextTest.java
  
  Index: SeamTextTest.java
  ===================================================================
  package org.jboss.seam.test.unit;
  
  import java.io.InputStreamReader;
  import java.io.Reader;
  
  import org.jboss.seam.text.SeamTextLexer;
  import org.jboss.seam.text.SeamTextParser;
  
  public class SeamTextTest
  {
      public static void main(String[] args) throws Exception {
          Reader r = new InputStreamReader( SeamTextTest.class.getResourceAsStream("SeamTextTest.txt") );
          SeamTextLexer lexer = new SeamTextLexer(r);
          SeamTextParser parser = new SeamTextParser(lexer);
          parser.startRule();
          System.out.println(parser);
      }
  }
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/PageActionsTest.java
  
  Index: PageActionsTest.java
  ===================================================================
  package org.jboss.seam.test.unit;
  
  import org.jboss.seam.Component;
  import org.jboss.seam.ScopeType;
  import org.jboss.seam.Seam;
  import org.jboss.seam.annotations.Name;
  import org.jboss.seam.annotations.Scope;
  import org.jboss.seam.annotations.intercept.BypassInterceptors;
  import org.jboss.seam.contexts.Context;
  import org.jboss.seam.contexts.Contexts;
  import org.jboss.seam.contexts.FacesLifecycle;
  import org.jboss.seam.contexts.Lifecycle;
  import org.jboss.seam.core.Expressions;
  import org.jboss.seam.core.Init;
  import org.jboss.seam.core.ResourceLoader;
  import org.jboss.seam.faces.FacesManager;
  import org.jboss.seam.mock.MockApplication;
  import org.jboss.seam.mock.MockExternalContext;
  import org.jboss.seam.mock.MockFacesContext;
  import org.jboss.seam.navigation.Pages;
  import org.jboss.seam.util.Conversions;
  import org.testng.annotations.AfterMethod;
  import org.testng.annotations.BeforeMethod;
  import org.testng.annotations.Test;
  
  import javax.faces.context.FacesContext;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  
  /**
   * The purpose of this test is to verify the way that page actions are handled. Once
   * a page action triggers a navigation event, subsequent page actions in the chain
   * should be short circuited.
   */
  public class PageActionsTest
  {
     @BeforeMethod
     public void setup()
     {
        // create main application map
        Lifecycle.beginApplication(new HashMap<String, Object>());
  
        // start all the contexts
        Lifecycle.beginCall();
  
        // establish the FacesContext
        new MockFacesContext(new MockExternalContext(), new MockApplication()).setCurrent().createViewRoot();
        FacesLifecycle.resumePage();
  
        // install key components
        installComponents(Contexts.getApplicationContext());
  
        // initialize pages from WEB-INF/pages.xml
        Pages.instance();
  
        // mark the application as started
        Lifecycle.mockApplication();
     }
  
     @AfterMethod
     public void tearDown()
     {
        Lifecycle.endApplication();
        Lifecycle.unmockApplication();
     }
  
     /**
      * This test verifies that a non-null outcome will short-circuit the page
      * actions. It tests two difference variations. The first variation includes
      * both actions as nested elements of the page node. The second variation has
      * the first action in the action attribute of the page node and the second
      * action as a nested element. Aside from the placement of the actions, the
      * two parts of the test are equivalent.
      */
     @Test(enabled = true)
     public void testShortCircuitOnNonNullOutcome()
     {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        TestActions testActions = TestActions.instance();
  
        facesContext.getViewRoot().setViewId("/action-test01a.xhtml");
        Pages.instance().preRender(facesContext);
        assertViewId(facesContext, "/pageA.xhtml");
        assertActionCalls(testActions, new String[] { "nonNullActionA" });
  
        testActions = TestActions.instance();
  
        facesContext.getViewRoot().setViewId("/action-test01b.xhtml");
        Pages.instance().preRender(facesContext);
        assertViewId(facesContext, "/pageA.xhtml");
        assertActionCalls(testActions, new String[] { "nonNullActionA" });
     }
  
     /**
      * This test verifies that because the first action does not result in a
      * navigation, the second action is executed. However, the third action is
      * not called because of the navigation on the second action.
      */
     @Test(enabled = true)
     public void testShortCircuitInMiddle()
     {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        TestActions testActions = TestActions.instance();
  
        facesContext.getViewRoot().setViewId("/action-test02.xhtml");
        Pages.instance().preRender(facesContext);
        assertViewId(facesContext, "/pageB.xhtml");
        assertActionCalls(testActions, new String[] { "nonNullActionA", "nonNullActionB" });
     }
  
     @Test(enabled = true)
     public void testShortCircuitOnNullOutcome()
     {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        TestActions testActions = TestActions.instance();
  
        facesContext.getViewRoot().setViewId("/action-test03.xhtml");
        Pages.instance().preRender(facesContext);
        assertViewId(facesContext, "/pageA.xhtml");
        assertActionCalls(testActions, new String[] { "nullActionA" });
     }
  
     /**
      * Verify that the first non-null outcome, even if it is to the same view id,
      * will short circuit the action calls.
      */
     @Test(enabled = true)
     public void testShortCircuitOnFirstNonNullOutcome()
     {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        TestActions testActions = TestActions.instance();
  
        facesContext.getViewRoot().setViewId("/action-test04.xhtml");
        Pages.instance().preRender(facesContext);
        assertViewId(facesContext, "/action-test04.xhtml");
        assertActionCalls(testActions, new String[] { "nullActionA", "nonNullActionB" });
     }
  
     /**
      * Same as testShortCircuitOnNonNullOutcome except that the navigation rules
      * are redirects rather than renders.
      */
     @Test(enabled = true)
     public void testShortCircuitOnNonNullOutcomeWithRedirect()
     {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        TestActions testActions = TestActions.instance();
  
        facesContext.getViewRoot().setViewId("/action-test05.xhtml");
        Pages.instance().preRender(facesContext);
        assertViewId(facesContext, "/action-test05.xhtml");
        assertActionCalls(testActions, new String[] { "nonNullActionA" });
        assert Contexts.getEventContext().get("lastRedirectViewId").equals("/pageA.xhtml") : 
           "Expecting a redirect to /pageA.xhtml but redirected to " + Contexts.getEventContext().get("lastRedirectViewId");
        assert facesContext.getResponseComplete() == true : "The response should have been marked as complete";
     }
     
     /**
      * This test is here (and disabled) to demonstrate the old behavior. All page
      * actions would be executed regardless and navigations could cross page
      * declaration boundaries since the view id is changing mid-run (hence
      * resulting in different navigation rule matches)
      */
     @Test(enabled = false)
     public void oldBehaviorTest()
     {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        TestActions testActions = TestActions.instance();
  
        facesContext.getViewRoot().setViewId("/action-test99a.xhtml");
        Pages.instance().preRender(facesContext);
        assertViewId(facesContext, "/pageB.xhtml");
        assertActionCalls(testActions, new String[] { "nonNullActionA", "nonNullActionB" });
     }
  
     private void assertViewId(FacesContext facesContext, String expectedViewId)
     {
        String actualViewId = facesContext.getViewRoot().getViewId();
        assert expectedViewId.equals(actualViewId) :
           "Expected viewId to be " + expectedViewId + ", but got " + actualViewId;
     }
  
     private void assertActionCalls(TestActions testActions, String[] methodNames)
     {
        List<String> actionsCalled = testActions.getActionsCalled();
        assert actionsCalled.size() == methodNames.length :
           "Expected " + methodNames.length + " action(s) to be called, but executed " + actionsCalled.size() + " action(s) instead";
        String expectedMethodCalls = "";
        for (int i = 0, len = methodNames.length; i < len; i++)
        {
           if (i > 0)
           {
              expectedMethodCalls += ", ";
           }
           expectedMethodCalls += methodNames[i];
        }
        String actualMethodCalls = "";
        for (int i = 0, len = actionsCalled.size(); i < len; i++)
        {
           if (i > 0)
           {
              actualMethodCalls += ", ";
           }
           actualMethodCalls += actionsCalled.get(i);
        }
  
        assert expectedMethodCalls.equals(actualMethodCalls) :
           "Expected actions to be called: " + expectedMethodCalls + "; actions actually called: " + actualMethodCalls;
  
        Contexts.getEventContext().remove(Component.getComponentName(TestActions.class));
     }
  
     private void installComponents(Context appContext)
     {
        Init init = new Init();
        init.setTransactionManagementEnabled(false);
        appContext.set(Seam.getComponentName(Init.class), init);
        Map<String, Conversions.PropertyValue> properties = new HashMap<String, Conversions.PropertyValue>();
        appContext.set(Component.PROPERTIES, properties);
        properties.put(Seam.getComponentName(Pages.class) + ".resources", new Conversions.FlatPropertyValue("/META-INF/pagesForPageActionsTest.xml"));
  
        installComponent(appContext, NoRedirectFacesManager.class);
        installComponent(appContext, ResourceLoader.class);
        installComponent(appContext, Expressions.class);
        installComponent(appContext, Pages.class);
  
        installComponent(appContext, TestActions.class);
     }
  
     private void installComponent(Context appContext, Class clazz)
     {
        appContext.set(Seam.getComponentName(clazz) + ".component", new Component(clazz));
     }
  
     @Scope(ScopeType.EVENT)
     @Name("org.jboss.seam.core.manager")
     @BypassInterceptors
     public static class NoRedirectFacesManager extends FacesManager {
  
        @Override
        public void redirect(String viewId, Map<String, Object> parameters, boolean includeConversationId)
        {
           Contexts.getEventContext().set("lastRedirectViewId", viewId);
           // a lot of shit happens we don't need; the important part is that the
           // viewId is not changed on FacesContext, but the response is marked complete
           FacesContext.getCurrentInstance().responseComplete();
        }
        
     }
  
  }
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/Foo.java
  
  Index: Foo.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.seam.test.unit;
  
  import java.io.Serializable;
  
  import javax.ejb.Remove;
  
  import org.hibernate.validator.NotNull;
  import org.jboss.seam.ScopeType;
  import org.jboss.seam.annotations.Begin;
  import org.jboss.seam.annotations.End;
  import org.jboss.seam.annotations.Name;
  import org.jboss.seam.annotations.Scope;
  
  /**
   * @author <a href="mailto:theute at jboss.org">Thomas Heute </a>
   * @version $Revision: 1.1 $
   */
  @Name("foo")
  @Scope(ScopeType.SESSION)
  @SuppressWarnings("deprecation")
  public class Foo implements Serializable
  {
     private static final long serialVersionUID = -5448030633067107049L;
     
     private String value;
     
     public String foo() { return "foo"; }
  
     @Remove
     public void destroy() {}
  
     @NotNull
     public String getValue()
     {
        return value;
     }
  
     public void setValue(String value)
     {
        this.value = value;
     }
     
     public String bar()
     {
        return "bar";
     }
     
     @Begin
     public String begin()
     {
        return "begun";
     }
     @End
     public String end()
     {
        return "ended";
     }
     
     @Begin
     public String beginNull()
     {
        return null;
     }
     @End
     public String endNull()
     {
        return null;
     }
     
     @Begin
     public void beginVoid() { }
     @End
     public void endVoid() { }
     
     @Begin(ifOutcome="success")
     public String beginIf()
     {
        return "success";
     }
     @End(ifOutcome="success")
     public String endIf()
     {
        return "success";
     }
     
  }
  
  
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/ContextTest.java
  
  Index: ContextTest.java
  ===================================================================
  //$Id: ContextTest.java,v 1.1 2007/10/08 18:15:47 pmuir Exp $
  package org.jboss.seam.test.unit;
  
  import java.util.Map;
  
  import javax.faces.context.ExternalContext;
  import javax.servlet.http.HttpServletRequest;
  
  import org.jboss.seam.Component;
  import org.jboss.seam.Seam;
  import org.jboss.seam.contexts.ApplicationContext;
  import org.jboss.seam.contexts.Context;
  import org.jboss.seam.contexts.Contexts;
  import org.jboss.seam.contexts.EventContext;
  import org.jboss.seam.contexts.FacesLifecycle;
  import org.jboss.seam.contexts.ServerConversationContext;
  import org.jboss.seam.contexts.ServletLifecycle;
  import org.jboss.seam.contexts.SessionContext;
  import org.jboss.seam.core.ConversationEntries;
  import org.jboss.seam.core.Init;
  import org.jboss.seam.core.Manager;
  import org.jboss.seam.el.EL;
  import org.jboss.seam.el.SeamELResolver;
  import org.jboss.seam.mock.MockExternalContext;
  import org.jboss.seam.mock.MockHttpServletRequest;
  import org.jboss.seam.mock.MockHttpSession;
  import org.jboss.seam.mock.MockServletContext;
  import org.jboss.seam.servlet.ServletRequestMap;
  import org.jboss.seam.servlet.ServletRequestSessionMap;
  import org.jboss.seam.web.Parameters;
  import org.jboss.seam.web.ServletContexts;
  import org.jboss.seam.web.Session;
  import org.testng.annotations.Test;
  
  public class ContextTest
  {
     private void installComponent(Context appContext, Class clazz)
     {
        appContext.set( Seam.getComponentName(clazz) + ".component", new Component(clazz) );
     }
     
     @Test
     public void testContextManagement() throws Exception
     {
        SeamELResolver seamVariableResolver = new SeamELResolver();
        //org.jboss.seam.bpm.SeamVariableResolver jbpmVariableResolver = new org.jboss.seam.bpm.SeamVariableResolver();
        
        MockServletContext servletContext = new MockServletContext();
        ServletLifecycle.beginApplication(servletContext);
        MockExternalContext externalContext = new MockExternalContext(servletContext);
        Context appContext = new ApplicationContext( externalContext.getApplicationMap() );
        //appContext.set( Seam.getComponentName(Init.class), new Init() );
        installComponent(appContext, ConversationEntries.class);
        installComponent(appContext, Manager.class);
        installComponent(appContext, Session.class);
        installComponent(appContext, ServletContexts.class);
        installComponent(appContext, Parameters.class);
        appContext.set( Seam.getComponentName(Init.class), new Init() );
        
        installComponent(appContext, Bar.class);
        installComponent(appContext, Foo.class);
        appContext.set("otherFoo", new Foo());
        
        assert !Contexts.isEventContextActive();
        assert !Contexts.isSessionContextActive();
        assert !Contexts.isConversationContextActive();
        assert !Contexts.isApplicationContextActive();
        
        FacesLifecycle.beginRequest(externalContext);
        
        assert Contexts.isEventContextActive();
        assert Contexts.isSessionContextActive();
        assert !Contexts.isConversationContextActive();
        assert Contexts.isApplicationContextActive();
        
        Manager.instance().setCurrentConversationId("3");
        FacesLifecycle.resumeConversation(externalContext);
        Manager.instance().setLongRunningConversation(true);
        
        assert Contexts.isEventContextActive();
        assert Contexts.isSessionContextActive();
        assert Contexts.isConversationContextActive();
        assert Contexts.isApplicationContextActive();
        assert !Contexts.isPageContextActive();
        
        assert Contexts.getEventContext()!=null;
        assert Contexts.getSessionContext()!=null;
        assert Contexts.getConversationContext()!=null;
        assert Contexts.getApplicationContext()!=null;
        assert Contexts.getEventContext() instanceof EventContext;
        assert Contexts.getSessionContext() instanceof SessionContext;
        assert Contexts.getConversationContext() instanceof ServerConversationContext;
        assert Contexts.getApplicationContext() instanceof ApplicationContext;
        
        Contexts.getSessionContext().set("zzz", "bar");
        Contexts.getApplicationContext().set("zzz", "bar");
        Contexts.getConversationContext().set("xxx", "yyy");
        
        Object bar = seamVariableResolver.getValue(EL.EL_CONTEXT, null, "bar");
        assert bar!=null;
        assert bar instanceof Bar;
        assert Contexts.getConversationContext().get("bar")==bar;
        Object foo = Contexts.getSessionContext().get("foo");
        assert foo!=null;
        assert foo instanceof Foo;
        
        FacesLifecycle.endRequest(externalContext);
        
        assert !Contexts.isEventContextActive();
        assert !Contexts.isSessionContextActive();
        assert !Contexts.isConversationContextActive();
        assert !Contexts.isApplicationContextActive();
        assert ((MockHttpSession)externalContext.getSession(false)).getAttributes().size()==4;
        assert ((MockServletContext)externalContext.getContext()).getAttributes().size()==10;
        
        FacesLifecycle.beginRequest(externalContext);
        
        assert Contexts.isEventContextActive();
        assert Contexts.isSessionContextActive();
        assert !Contexts.isConversationContextActive();
        assert Contexts.isApplicationContextActive();
        
        Manager.instance().setCurrentConversationId("3");
        FacesLifecycle.resumeConversation(externalContext);
        
        assert Contexts.isEventContextActive();
        assert Contexts.isSessionContextActive();
        assert Contexts.isConversationContextActive();
        assert Contexts.isApplicationContextActive();
        
        assert Contexts.getEventContext()!=null;
        assert Contexts.getSessionContext()!=null;
        assert Contexts.getConversationContext()!=null;
        assert Contexts.getApplicationContext()!=null;
        assert Contexts.getEventContext() instanceof EventContext;
        assert Contexts.getSessionContext() instanceof SessionContext;
        assert Contexts.getConversationContext() instanceof ServerConversationContext;
        assert Contexts.getApplicationContext() instanceof ApplicationContext;
        
        assert Contexts.getSessionContext().get("zzz").equals("bar");
        assert Contexts.getApplicationContext().get("zzz").equals("bar");
        assert Contexts.getConversationContext().get("xxx").equals("yyy");
        assert Contexts.getConversationContext().get("bar")==bar;
        assert Contexts.getSessionContext().get("foo")==foo;
        
        assert Contexts.getConversationContext().getNames().length==2;
        assert Contexts.getApplicationContext().getNames().length==10;
        assert Contexts.getSessionContext().getNames().length==2;
        
        assert seamVariableResolver.getValue(EL.EL_CONTEXT, null, "zzz").equals("bar");
        assert seamVariableResolver.getValue(EL.EL_CONTEXT, null, "xxx").equals("yyy");
        assert seamVariableResolver.getValue(EL.EL_CONTEXT, null, "bar")==bar;
        assert seamVariableResolver.getValue(EL.EL_CONTEXT, null, "foo")==foo;
        
        /*assert jbpmVariableResolver.resolveVariable("zzz").equals("bar");
        assert jbpmVariableResolver.resolveVariable("xxx").equals("yyy");
        assert jbpmVariableResolver.resolveVariable("bar")==bar;
        assert jbpmVariableResolver.resolveVariable("foo")==foo;*/
  
        Manager.instance().setLongRunningConversation(false);
        FacesLifecycle.endRequest(externalContext);
        
        assert !Contexts.isEventContextActive();
        assert !Contexts.isSessionContextActive();
        assert !Contexts.isConversationContextActive();
        assert !Contexts.isApplicationContextActive();
        assert ((MockHttpSession)externalContext.getSession(false)).getAttributes().size()==2;
        assert ((MockServletContext)externalContext.getContext()).getAttributes().size()==10;
        
        ServletLifecycle.endSession( ( (HttpServletRequest) externalContext.getRequest() ).getSession() );
              
        ServletLifecycle.endApplication();
        
     }
     
     @Test
     public void testContexts()
     {
        MockServletContext servletContext = new MockServletContext();
        ServletLifecycle.beginApplication(servletContext);
        MockHttpSession session = new MockHttpSession(servletContext);
        MockHttpServletRequest request = new MockHttpServletRequest(session);
        ExternalContext externalContext = new MockExternalContext(servletContext, request);
        Map sessionAdaptor = new ServletRequestSessionMap(request);
        Map requestAdaptor = new ServletRequestMap(request);
        Context appContext = new ApplicationContext( externalContext.getApplicationMap() );
        installComponent(appContext, ConversationEntries.class);
        installComponent(appContext, Manager.class);
        appContext.set( Seam.getComponentName(Init.class), new Init() );
        FacesLifecycle.beginRequest(externalContext);
        Manager.instance().setLongRunningConversation(true);
        testContext( new ApplicationContext( externalContext.getApplicationMap() ) );
        testContext( new SessionContext(sessionAdaptor) );
        testContext( new EventContext(requestAdaptor) );
        testContext( new ServerConversationContext(sessionAdaptor, "1") );
        testEquivalence( new ServerConversationContext(sessionAdaptor, "1"), new ServerConversationContext(sessionAdaptor, "1") );
        testEquivalence( new SessionContext(sessionAdaptor), new SessionContext(sessionAdaptor) );
        testEquivalence( new ApplicationContext( externalContext.getApplicationMap() ), new ApplicationContext( externalContext.getApplicationMap() ) );
        testIsolation( new ServerConversationContext(sessionAdaptor, "1"), new ServerConversationContext(sessionAdaptor, "2") );
        // testIsolation( new WebSessionContext(externalContext), new WebSessionContext( new MockExternalContext()) );
        
        ServletLifecycle.endApplication();
     }
     
     private void testEquivalence(Context ctx, Context cty)
     {
        ctx.set("foo", "bar");
        ctx.flush();
        assert cty.get("foo").equals("bar");
        ctx.remove("foo");
        ctx.flush();
        assert !cty.isSet("foo");
     }
     
     private void testIsolation(Context ctx, Context cty)
     {
        ctx.set("foo", "bar");
        ctx.flush();
        assert !cty.isSet("foo");
        cty.set("foo", "bar");
        ctx.remove("foo");
        ctx.flush();
        assert cty.get("foo").equals("bar");
     }
     
     private void testContext(Context ctx)
     {
        assert !ctx.isSet("foo");
        ctx.set("foo", "bar");
        assert ctx.isSet("foo");
        assert ctx.get("foo").equals("bar");
        ctx.remove("foo");
        assert !ctx.isSet("foo");
     }
  }
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/Action.java
  
  Index: Action.java
  ===================================================================
  package org.jboss.seam.test.unit;
  
  import org.jboss.seam.annotations.In;
  import org.jboss.seam.annotations.Name;
  
  @Name("action")
  public class Action {
     
     @In(create=true) String name;
     
     public String go() {
        return "success";
     }
  }
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/CoreTest.java
  
  Index: CoreTest.java
  ===================================================================
  //$Id: CoreTest.java,v 1.1 2007/10/08 18:15:47 pmuir Exp $
  package org.jboss.seam.test.unit;
  
  
  public class CoreTest
  {
  
  }
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/Factory.java
  
  Index: Factory.java
  ===================================================================
  package org.jboss.seam.test.unit;
  
  import org.jboss.seam.ScopeType;
  import org.jboss.seam.annotations.Name;
  import org.jboss.seam.annotations.Out;
  
  @Name("factory")
  public class Factory 
  {
     @Out(scope=ScopeType.CONVERSATION, required=true) 
     String name;
     
     @org.jboss.seam.annotations.Factory("name")
     public void createName()
     {
        name="Gavin King";
     }
  }
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/PageflowConfigurationTest.java
  
  Index: PageflowConfigurationTest.java
  ===================================================================
  package org.jboss.seam.test.unit;
  
  import org.jbpm.JbpmConfiguration;
  import org.jbpm.JbpmContext;
  import org.jbpm.graph.def.ProcessDefinition;
  import org.jbpm.graph.exe.ProcessInstance;
  import org.testng.annotations.Test;
  
  public class PageflowConfigurationTest{
  
    static JbpmConfiguration pageflowConfiguration = JbpmConfiguration.parseResource("org/jbpm/pageflow/jbpm.pageflow.cfg.xml");
    
    @Test
    public void testOne() {
      JbpmContext jbpmContext = pageflowConfiguration.createJbpmContext();
      ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
        "<process-definition name='navigation'>" +
        "  <start-state name='start'>" +
        "    <transition to='a' />" +
        "  </start-state>" +
        "  <state name='a'>" +
        "    <transition to='end' />" +
        "  </state>" +
        "  <end-state name='end' />" +
        "</process-definition>"
      );
      
      ProcessInstance processInstance = processDefinition.createProcessInstance();
  
      processInstance.signal();
      processInstance.signal();
      
      assert processInstance.hasEnded();
      
      jbpmContext.close();
    }
  
  }
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/MockInvocationContext.java
  
  Index: MockInvocationContext.java
  ===================================================================
  //$Id: MockInvocationContext.java,v 1.1 2007/10/08 18:15:47 pmuir Exp $
  package org.jboss.seam.test.unit;
  
  import java.lang.reflect.Method;
  import java.util.Map;
  
  import org.jboss.seam.intercept.InvocationContext;
  
  public class MockInvocationContext implements InvocationContext
  {
  
     public Object getTarget()
     {
        //TODO
        return null;
     }
  
     public Map getContextData()
     {
        //TODO
        return null;
     }
  
     public Method getMethod()
     {
        //TODO
        return null;
     }
  
     public Object[] getParameters()
     {
        //TODO
        return null;
     }
  
     public Object proceed() throws Exception
     {
        return null;
     }
  
     public void setParameters(Object[] params)
     {
        //TODO
        
     }
  
  }
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/InterpolatorTest.java
  
  Index: InterpolatorTest.java
  ===================================================================
  package org.jboss.seam.test.unit;
  
  import java.text.SimpleDateFormat;
  import java.util.Date;
  
  import org.jboss.seam.core.Interpolator;
  import org.testng.Assert;
  import org.testng.annotations.Test;
  
  
  public class InterpolatorTest
  {
      
      static final String CHOICE_EXPR = "There {0,choice,0#are no files|1#is one file|1<are {0,number,integer} files}.";
      @Test
      public void testInterpolation() 
      {
          Interpolator interpolator = Interpolator.instance();
  
          Assert.assertEquals("3 5 7", interpolator.interpolate("#0 #1 #2", 3, 5, 7));
          Assert.assertEquals("3 5 7", interpolator.interpolate("{0} {1} {2}", 3, 5, 7));
  
          // this tests that the result of an expression evaluation is not evaluated again
          Assert.assertEquals("{0}", interpolator.interpolate("{1}", "bad", "{0}"));
          
          // this tests that embedded {} expressions are parsed correctly.
          Assert.assertEquals("There are no files.", interpolator.interpolate(CHOICE_EXPR, 0));
          Assert.assertEquals("There is one file.", interpolator.interpolate(CHOICE_EXPR, 1));
          Assert.assertEquals("There are 2 files.", interpolator.interpolate(CHOICE_EXPR, 2));
          
          Date date = new Date(0);
                  
          Assert.assertEquals(new SimpleDateFormat("M/d/y").format(date), interpolator.interpolate("{0,date,short}", date));
   
          
          // test that a messageformat error doesn't blow up
          Assert.assertEquals("{nosuchmessage}", interpolator.interpolate("{nosuchmessage}"));
          
          try {
              interpolator.interpolate("hello #{", (Object) null);
          } catch (Throwable t) {
              Assert.fail("interpolator raised an exception");
          }
      }
  
  }
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/InterceptorTest.java
  
  Index: InterceptorTest.java
  ===================================================================
  //$Id: InterceptorTest.java,v 1.1 2007/10/08 18:15:47 pmuir Exp $
  package org.jboss.seam.test.unit;
  
  import java.lang.reflect.Method;
  
  import javax.faces.context.ExternalContext;
  import javax.faces.event.PhaseId;
  
  import org.jboss.seam.Component;
  import org.jboss.seam.NoConversationException;
  import org.jboss.seam.RequiredException;
  import org.jboss.seam.Seam;
  import org.jboss.seam.contexts.ApplicationContext;
  import org.jboss.seam.contexts.Context;
  import org.jboss.seam.contexts.Contexts;
  import org.jboss.seam.contexts.FacesLifecycle;
  import org.jboss.seam.contexts.ServletLifecycle;
  import org.jboss.seam.core.BijectionInterceptor;
  import org.jboss.seam.core.ConversationEntries;
  import org.jboss.seam.core.ConversationInterceptor;
  import org.jboss.seam.core.ConversationalInterceptor;
  import org.jboss.seam.core.Events;
  import org.jboss.seam.core.Init;
  import org.jboss.seam.core.Interpolator;
  import org.jboss.seam.core.Manager;
  import org.jboss.seam.ejb.RemoveInterceptor;
  import org.jboss.seam.faces.FacesMessages;
  import org.jboss.seam.mock.MockApplication;
  import org.jboss.seam.mock.MockExternalContext;
  import org.jboss.seam.mock.MockFacesContext;
  import org.jboss.seam.mock.MockServletContext;
  import org.jboss.seam.persistence.PersistenceContexts;
  import org.testng.annotations.Test;
  
  public class InterceptorTest
  {
     
     @Test
     public void testBijectionInterceptor() throws Exception
     {
        MockServletContext servletContext = new MockServletContext();
        ServletLifecycle.beginApplication(servletContext);
        MockExternalContext externalContext = new MockExternalContext(servletContext);
        Context appContext = new ApplicationContext( externalContext.getApplicationMap() );
        appContext.set( Seam.getComponentName(Init.class), new Init() );
        appContext.set( 
              Seam.getComponentName(ConversationEntries.class) + ".component", 
              new Component(ConversationEntries.class, appContext) 
           );
        appContext.set( 
              Seam.getComponentName(Manager.class) + ".component", 
              new Component(Manager.class, appContext) 
           );
        appContext.set( 
              Seam.getComponentName(Foo.class) + ".component", 
              new Component(Foo.class, appContext) 
           );
        appContext.set( 
              Seam.getComponentName(Factory.class) + ".component", 
              new Component(Factory.class, appContext) 
           );
  
        FacesLifecycle.beginRequest(externalContext);
        Manager.instance().setCurrentConversationId("1");
        FacesLifecycle.resumeConversation(externalContext);
        FacesLifecycle.setPhaseId(PhaseId.RENDER_RESPONSE);
        
        final Bar bar = new Bar();
        final Foo foo = new Foo();
        Contexts.getSessionContext().set("otherFoo", foo);
        
        BijectionInterceptor bi = new BijectionInterceptor();
        bi.setComponent( new Component(Bar.class, appContext) );
        String result = (String) bi.aroundInvoke( new MockInvocationContext() {
           @Override
           public Object getTarget()
           {
              return bar;
           }
  
           @Override
           public Object proceed() throws Exception
           {
              assert bar.otherFoo==foo;
              assert bar.foo!=null;
              return bar.foo();
           }
        });
        assert "foo".equals(result);
        assert Contexts.getEventContext().get("otherString").equals("outAgain");
        assert Contexts.getConversationContext().get("string").equals("out");
        assert Contexts.getSessionContext().isSet("foo");
        assert bar.foo==null;
        assert bar.otherFoo==null;
        
        final Method method;
        try
        {
           method = Bar.class.getMethod("foo");
        }
        catch (Exception e) 
        {
           throw new RuntimeException(e);
        }
  
        bi.aroundInvoke( new MockInvocationContext() {
           @Override
           public Object getTarget()
           {
              return bar;
           }
  
           @Override
           public Object proceed() throws Exception
           {
              assert bar.otherFoo==foo;
              assert bar.foo!=null;
              return bar.foo();
           }
           @Override
           public Method getMethod()
           {
              return method;
           }
        });
        assert bar.foo==null;
        assert bar.otherFoo==null;
        
        try 
        {
           Contexts.getSessionContext().remove("otherFoo");
           bi.aroundInvoke( new MockInvocationContext() {
              @Override
              public Object getTarget()
              {
                 return bar;
              }
              @Override
              public Object proceed() throws Exception
              {
                 assert false;
                 return null;
              }
              @Override
              public Method getMethod()
              {
                 return method;
              }
           });
           assert false;
        }
        catch (Exception e)
        {
           assert e instanceof RequiredException;
        }
        
        final Method method2;
        try
        {
           method2 = BrokenAction.class.getMethod("go");
        }
        catch (Exception e) 
        {
           throw new RuntimeException(e);
        }
  
        final BrokenAction brokenAction = new BrokenAction();
        BijectionInterceptor biba = new BijectionInterceptor();
        biba.setComponent( new Component(BrokenAction.class, appContext) );
        try
        {
           biba.aroundInvoke( new MockInvocationContext() {
     
              @Override
              public Object getTarget() {
                 return brokenAction;
              }   
              @Override
              public Object proceed() throws Exception {
                 assert false;
                 return null;
              }
              
              @Override
              public Method getMethod()
              {
                 return method2;
              }
            
           } );
           assert false;
        }
        catch (Exception e)
        {
           assert e instanceof RequiredException;
        }
        
        final Method method3;
        try
        {
           method3 = Action.class.getMethod("go");
        }
        catch (Exception e) 
        {
           throw new RuntimeException(e);
        }
  
        final Action action = new Action();
        BijectionInterceptor bia = new BijectionInterceptor();
        bia.setComponent( new Component(Action.class, appContext) );
        result = (String) bia.aroundInvoke( new MockInvocationContext() {
  
           @Override
           public Object getTarget() {
              return action;
           }
  
           @Override
           public Object proceed() throws Exception {
              assert "Gavin King".equals(action.name);
              return action.go();
           }
           
           @Override
           public Method getMethod()
           {
              return method3;
           }
         
        } );
        assert "success".equals(result);
        assert Contexts.getConversationContext().get("name").equals("Gavin King");
  
        ServletLifecycle.endApplication();
     }
     
     @Test
     public void testConversationInterceptor() throws Exception
     {
        MockServletContext servletContext = new MockServletContext();
        ServletLifecycle.beginApplication(servletContext);
        MockExternalContext externalContext = new MockExternalContext(servletContext);
        Context appContext = new ApplicationContext( externalContext.getApplicationMap() );
        appContext.set( Seam.getComponentName(Init.class), new Init() );
        appContext.set( 
              Seam.getComponentName(ConversationEntries.class) + ".component", 
              new Component(ConversationEntries.class, appContext) 
           );
        appContext.set( 
              Seam.getComponentName(PersistenceContexts.class) + ".component", 
              new Component(PersistenceContexts.class, appContext) 
           );
        appContext.set( 
              Seam.getComponentName(Manager.class) + ".component", 
              new Component(Manager.class, appContext) 
           );
        FacesLifecycle.beginRequest( externalContext );
        Manager.instance().setCurrentConversationId("1");
        FacesLifecycle.resumeConversation(externalContext);
  
        ConversationInterceptor ci = new ConversationInterceptor();
        ci.setComponent( new Component(Foo.class, appContext) );
        
        assert !Manager.instance().isLongRunningConversation();
  
        String result = (String) ci.aroundInvoke( new MockInvocationContext() {
           @Override
           public Method getMethod()
           {
              return InterceptorTest.getMethod("foo");
           }
           @Override
           public Object proceed() throws Exception
           {
              return "foo";
           }
        });
        
        assert !Manager.instance().isLongRunningConversation();
        assert "foo".equals(result);
        
        Manager.instance().initializeTemporaryConversation();
        
        result = (String) ci.aroundInvoke( new MockInvocationContext() {
           @Override
           public Method getMethod()
           {
              return InterceptorTest.getMethod("begin");
           }
           @Override
           public Object proceed() throws Exception
           {
              return "begun";
           }
        });
        
        assert Manager.instance().isLongRunningConversation();
        assert "begun".equals(result);
  
        result = (String) ci.aroundInvoke( new MockInvocationContext() {
           @Override
           public Method getMethod()
           {
              return InterceptorTest.getMethod("foo");
           }
           @Override
           public Object proceed() throws Exception
           {
              return "foo";
           }
        });
        
        assert Manager.instance().isLongRunningConversation();
        assert "foo".equals(result);
  
        result = (String) ci.aroundInvoke( new MockInvocationContext() {
           @Override
           public Method getMethod()
           {
              return InterceptorTest.getMethod("end");
           }
           @Override
           public Object proceed() throws Exception
           {
              return "ended";
           }
        });
        
        assert !Manager.instance().isLongRunningConversation();
        assert "ended".equals(result);
        
        result = (String) ci.aroundInvoke( new MockInvocationContext() {
           @Override
           public Method getMethod()
           {
              return InterceptorTest.getMethod("beginNull");
           }
           @Override
           public Object proceed() throws Exception
           {
              return null;
           }
        });
        
        assert !Manager.instance().isLongRunningConversation();
        assert result==null;
  
        result = (String) ci.aroundInvoke( new MockInvocationContext() {
           @Override
           public Method getMethod()
           {
              return InterceptorTest.getMethod("beginVoid");
           }
           @Override
           public Object proceed() throws Exception
           {
              return null;
           }
        });
        
        assert Manager.instance().isLongRunningConversation();
        assert result==null;
  
        result = (String) ci.aroundInvoke( new MockInvocationContext() {
           @Override
           public Method getMethod()
           {
              return InterceptorTest.getMethod("foo");
           }
           @Override
           public Object proceed() throws Exception
           {
              return "foo";
           }
        });
        
        assert Manager.instance().isLongRunningConversation();
        assert "foo".equals(result);
  
        result = (String) ci.aroundInvoke( new MockInvocationContext() {
           @Override
           public Method getMethod()
           {
              return InterceptorTest.getMethod("endNull");
           }
           @Override
           public Object proceed() throws Exception
           {
              return null;
           }
        });
        
        assert Manager.instance().isLongRunningConversation();
        assert result==null;
  
        result = (String) ci.aroundInvoke( new MockInvocationContext() {
           @Override
           public Method getMethod()
           {
              return InterceptorTest.getMethod("endVoid");
           }
           @Override
           public Object proceed() throws Exception
           {
              return null;
           }
        });
        
        assert !Manager.instance().isLongRunningConversation();
        assert result==null;
        
        result = (String) ci.aroundInvoke( new MockInvocationContext() {
           @Override
           public Method getMethod()
           {
              return InterceptorTest.getMethod("beginIf");
           }
           @Override
           public Object proceed() throws Exception
           {
              return "failure";
           }
        });
        
        assert !Manager.instance().isLongRunningConversation();
        assert "failure".equals(result);
  
        result = (String) ci.aroundInvoke( new MockInvocationContext() {
           @Override
           public Method getMethod()
           {
              return InterceptorTest.getMethod("beginIf");
           }
           @Override
           public Object proceed() throws Exception
           {
              return "success";
           }
        });
        
        assert Manager.instance().isLongRunningConversation();
        assert "success".equals(result);
  
        result = (String) ci.aroundInvoke( new MockInvocationContext() {
           @Override
           public Method getMethod()
           {
              return InterceptorTest.getMethod("foo");
           }
           @Override
           public Object proceed() throws Exception
           {
              return "foo";
           }
        });
        
        assert Manager.instance().isLongRunningConversation();
        assert "foo".equals(result);
  
        result = (String) ci.aroundInvoke( new MockInvocationContext() {
           @Override
           public Method getMethod()
           {
              return InterceptorTest.getMethod("endIf");
           }
           @Override
           public Object proceed() throws Exception
           {
              return "failure";
           }
        });
        
        assert Manager.instance().isLongRunningConversation();
        assert "failure".equals(result);
  
        result = (String) ci.aroundInvoke( new MockInvocationContext() {
           @Override
           public Method getMethod()
           {
              return InterceptorTest.getMethod("endIf");
           }
           @Override
           public Object proceed() throws Exception
           {
              return "success";
           }
        });
        
        assert !Manager.instance().isLongRunningConversation();
        assert "success".equals(result);
  
        ServletLifecycle.endApplication();
     }
     
     @Test
     public void testConversationalInterceptor() throws Exception
     {
        MockServletContext servletContext = new MockServletContext();
        ServletLifecycle.beginApplication(servletContext);
        MockExternalContext externalContext = new MockExternalContext(servletContext);
        Context appContext = new ApplicationContext( externalContext.getApplicationMap() );
        appContext.set( Seam.getComponentName(Init.class), new Init() );
        appContext.set( 
              Seam.getComponentName(ConversationEntries.class) + ".component", 
              new Component(ConversationEntries.class, appContext) 
           );
        appContext.set( 
              Seam.getComponentName(Manager.class) + ".component", 
              new Component(Manager.class, appContext) 
           );
        appContext.set( 
              Seam.getComponentName(FacesMessages.class) + ".component", 
              new Component(FacesMessages.class, appContext) 
           );
        appContext.set( 
                 Seam.getComponentName(Events.class) + ".component", 
                 new Component(Events.class, appContext) 
              );
        FacesLifecycle.setPhaseId(PhaseId.INVOKE_APPLICATION);
        FacesLifecycle.beginRequest( externalContext );
        Manager.instance().setCurrentConversationId("1");
        FacesLifecycle.resumeConversation(externalContext);
        
        ConversationalInterceptor ci = new ConversationalInterceptor();
        ci.setComponent( new Component(Bar.class, appContext) );
        
        assert !Manager.instance().isLongRunningConversation();
        
        try
        {
  
           ci.aroundInvoke( new MockInvocationContext() {
              @Override
              public Method getMethod()
              {
                 return InterceptorTest.getMethod("foo");
              }
              @Override
              public Object proceed() throws Exception
              {
                 assert false;
                 return null;
              }
           });
           
           assert false;
           
        }
        catch (Exception e)
        {
           assert e instanceof NoConversationException;
        }
        
        assert !Manager.instance().isLongRunningConversation();
        
        String result = (String) ci.aroundInvoke( new MockInvocationContext() {
           @Override
           public Method getMethod()
           {
              return InterceptorTest.getMethod("begin");
           }
           @Override
           public Object proceed() throws Exception
           {
              return "begun";
           }
        });
        
        Manager.instance().initializeTemporaryConversation();
        Manager.instance().beginConversation();
        
        //assert Manager.instance().isLongRunningConversation();
        assert "begun".equals(result);
  
        result = (String) ci.aroundInvoke( new MockInvocationContext() {
           @Override
           public Method getMethod()
           {
              return InterceptorTest.getMethod("foo");
           }
           @Override
           public Object proceed() throws Exception
           {
              return "foo";
           }
        });
        
        //assert Manager.instance().isLongRunningConversation();
        assert "foo".equals(result);
  
        result = (String) ci.aroundInvoke( new MockInvocationContext() {
           @Override
           public Method getMethod()
           {
              return InterceptorTest.getMethod("end");
           }
           @Override
           public Object proceed() throws Exception
           {
              return "ended";
           }
        });
        
        Manager.instance().endConversation(false);
        
        //assert !Manager.instance().isLongRunningConversation();
        assert "ended".equals(result);
        
        ServletLifecycle.endApplication();
        
     }
     
     @Test
     public void testValidationInterceptor() throws Exception
     {
        MockServletContext servletContext = new MockServletContext();
        ServletLifecycle.beginApplication(servletContext);
        ExternalContext externalContext = new MockExternalContext(servletContext);
        new MockFacesContext( externalContext, new MockApplication() ).setCurrent().createViewRoot();
        
        Context appContext = new ApplicationContext( externalContext.getApplicationMap() );
        appContext.set( Seam.getComponentName(Init.class), new Init() );
        appContext.set( 
              Seam.getComponentName(ConversationEntries.class) + ".component", 
              new Component(ConversationEntries.class, appContext) 
           );
        appContext.set( 
              Seam.getComponentName(Manager.class) + ".component", 
              new Component(Manager.class, appContext) 
           );
        appContext.set( 
              Seam.getComponentName(FacesMessages.class) + ".component", 
              new Component(FacesMessages.class, appContext) 
           );
        appContext.set(
              Seam.getComponentName(Interpolator.class) + ".component", 
              new Component(Interpolator.class, appContext)
           );
        FacesLifecycle.setPhaseId(PhaseId.INVOKE_APPLICATION);
        FacesLifecycle.beginRequest(externalContext);
        Manager.instance().setCurrentConversationId("1");
        FacesLifecycle.resumeConversation(externalContext);
        
        ServletLifecycle.endApplication();
     }
     
     @Test 
     public void testRemoveInterceptor() throws Exception
     {
        MockServletContext servletContext = new MockServletContext();
        ServletLifecycle.beginApplication(servletContext);
        MockExternalContext externalContext = new MockExternalContext(servletContext);
        Context appContext = new ApplicationContext( externalContext.getApplicationMap() );
        appContext.set( Seam.getComponentName(Init.class), new Init() );
        appContext.set( 
              Seam.getComponentName(ConversationEntries.class) + ".component", 
              new Component(ConversationEntries.class, appContext) 
           );
        appContext.set( 
              Seam.getComponentName(Manager.class) + ".component", 
              new Component(Manager.class, appContext) 
           );
  
        FacesLifecycle.beginRequest( externalContext );
        Contexts.getSessionContext().set( "foo", new Foo() );
        
        RemoveInterceptor ri = new RemoveInterceptor();
        ri.setComponent( new Component(Foo.class, appContext) );
        
        ri.aroundInvoke( new MockInvocationContext() {
           @Override
           public Method getMethod()
           {
              return InterceptorTest.getMethod("foo");
           }
        } );
        
        assert Contexts.getSessionContext().isSet("foo");
        
        ri.aroundInvoke( new MockInvocationContext() {
           @Override
           public Method getMethod()
           {
              return InterceptorTest.getMethod("destroy");
           }
        } );
        
        assert !Contexts.getSessionContext().isSet("foo");
        
        ServletLifecycle.endApplication();
     }
  
     static Method getMethod(String name)
     {
        try
        {
           return Foo.class.getMethod(name);
        }
        catch (Exception e)
        {
           assert false;
           return null;
        }
     }
  }
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/ComponentTest.java
  
  Index: ComponentTest.java
  ===================================================================
  //$Id: ComponentTest.java,v 1.1 2007/10/08 18:15:47 pmuir Exp $
  package org.jboss.seam.test.unit;
  
  import org.jboss.seam.Component;
  import org.jboss.seam.ComponentType;
  import org.jboss.seam.ScopeType;
  import org.jboss.seam.Seam;
  import org.jboss.seam.core.Init;
  import org.jboss.seam.core.Manager;
  import org.jboss.seam.persistence.ManagedHibernateSession;
  import org.jboss.seam.persistence.ManagedPersistenceContext;
  import org.testng.annotations.Test;
  
  public class ComponentTest
  {
     @Test
     public void testStaticMethods()
     {
        assert Seam.getComponentName(Bar.class).equals("bar");
        assert Seam.getComponentType(Bar.class)==ComponentType.JAVA_BEAN;
        assert Seam.getComponentScope(Bar.class)==ScopeType.CONVERSATION;
        assert Seam.getComponentName(Foo.class).equals("foo");
        assert Seam.getComponentType(Foo.class)==ComponentType.JAVA_BEAN;
        assert Seam.getComponentScope(Foo.class)==ScopeType.SESSION;
        //assert Seam.getBeanClass(Foo.class)==Foo.class;
        assert Seam.getEjbName(EjbBean.class).equals("EjbBean");
        assert Seam.getEjbName(Foo.class)==null;
        assert Seam.isInterceptionEnabled(Foo.class)==true;
     }
     
     @Test
     public void testComponent()
     {
        Component c = new Component(Bar.class);
        assert c.getName().equals("bar");
        assert c.getBeanClass()==Bar.class;
        assert c.getType()==ComponentType.JAVA_BEAN;
        assert c.getScope()==ScopeType.CONVERSATION;
        assert c.hasDestroyMethod();
        assert c.hasCreateMethod();
        assert c.getCreateMethod().getName().equals("create");
        assert c.getDestroyMethod().getName().equals("destroy");
        assert c.getInAttributes().size()==2;
        assert c.getUnwrapMethod()==null;
        assert c.getOutAttributes().size()==2;
        assert c.getRemoveMethods().size()==0;
        assert c.isInstance( new Bar() );
  
        c = new Component(Foo.class);
        assert c.getName().equals("foo");
        assert c.getBeanClass()==Foo.class;
        assert c.getType()==ComponentType.JAVA_BEAN;
        assert c.getScope()==ScopeType.SESSION;
        assert !c.hasDestroyMethod();
        assert !c.hasCreateMethod();
        assert c.getCreateMethod()==null;
        assert c.getDestroyMethod()==null;
        assert c.getInAttributes().size()==0;
        assert c.getUnwrapMethod()==null;
        assert c.getOutAttributes().size()==0;
        assert c.getRemoveMethods().size()==1;
        assert c.isInstance( new Foo() );
        
        c = new Component(EjbBean.class);
        assert c.getName().equals("ejb");
        assert c.getBeanClass()==EjbBean.class;
        assert c.getType()==ComponentType.STATEFUL_SESSION_BEAN;
        assert c.getScope()==ScopeType.EVENT;
        assert c.hasDestroyMethod();
        assert !c.hasDefaultRemoveMethod();
        assert !c.hasCreateMethod();
        assert c.getCreateMethod()==null;
        assert c.getDestroyMethod()!=null;
        assert c.getDefaultRemoveMethod()==null;
        assert c.getInAttributes().size()==0;
        assert c.getUnwrapMethod()==null;
        assert c.getOutAttributes().size()==0;
        assert c.getRemoveMethods().size()==1;
        assert c.isInstance( new Ejb() {
           public void destroy() {}
           public void foo() {} 
        } );
     }
     
     public void testBuiltInComponents()
     {
        Component c = new Component(Manager.class);
        assert c.getName().equals("org.jboss.seam.conversationManager");
        assert c.getBeanClass()==Manager.class;
        assert c.getType()==ComponentType.JAVA_BEAN;
        assert c.getScope()==ScopeType.EVENT;
        assert c.hasDestroyMethod();
        assert !c.hasCreateMethod();
        assert c.getCreateMethod()==null;
        assert c.getDestroyMethod().getName().equals("destroy");
        assert c.getInAttributes().size()==0;
        assert c.getUnwrapMethod()==null;
        assert c.getOutAttributes().size()==0;
        assert c.getRemoveMethods().size()==0;
  
        c = new Component(Init.class);
        assert c.getName().equals("org.jboss.seam.settings");
        assert c.getBeanClass()==Init.class;
        assert c.getType()==ComponentType.JAVA_BEAN;
        assert c.getScope()==ScopeType.APPLICATION;
        assert !c.hasDestroyMethod();
        assert !c.hasCreateMethod();
        assert c.getCreateMethod()==null;
        assert c.getDestroyMethod()==null;
        assert c.getInAttributes().size()==0;
        assert c.getUnwrapMethod()==null;
        assert c.getOutAttributes().size()==0;
        assert c.getRemoveMethods().size()==0;
        c = new Component(ManagedPersistenceContext.class, "pc");
        assert c.getName().equals("pc");
        assert c.getBeanClass()==ManagedPersistenceContext.class;
        assert c.getType()==ComponentType.JAVA_BEAN;
        assert c.getScope()==ScopeType.CONVERSATION;
        assert c.hasDestroyMethod();
        assert c.hasCreateMethod();
        assert c.getCreateMethod().getName().equals("create");
        assert c.getDestroyMethod().getName().equals("destroy");
        assert c.getInAttributes().size()==0;
        assert c.getUnwrapMethod().getName().equals("getEntityManager");
        assert c.getOutAttributes().size()==0;
        assert c.getRemoveMethods().size()==0;
  
        c = new Component(ManagedHibernateSession.class, "pc");
        assert c.getName().equals("pc");
        assert c.getBeanClass()==ManagedHibernateSession.class;
        assert c.getType()==ComponentType.JAVA_BEAN;
        assert c.getScope()==ScopeType.CONVERSATION;
        assert c.hasDestroyMethod();
        assert c.hasCreateMethod();
        assert c.getCreateMethod().getName().equals("create");
        assert c.getDestroyMethod().getName().equals("destroy");
        assert c.getInAttributes().size()==0;
        assert c.getUnwrapMethod().getName().equals("getSession");
        assert c.getOutAttributes().size()==0;
        assert c.getRemoveMethods().size()==0;
     }
  }
  
  
  
  1.1      date: 2007/10/08 18:15:47;  author: pmuir;  state: Exp;jboss-seam/src/test/unit/org/jboss/seam/test/unit/LocaleTest.java
  
  Index: LocaleTest.java
  ===================================================================
  package org.jboss.seam.test.unit;
  
  import java.io.IOException;
  import java.util.Locale;
  
  import javax.faces.component.UIOutput;
  import javax.faces.event.ValueChangeEvent;
  
  import org.jboss.deployers.spi.DeploymentException;
  import org.jboss.seam.international.LocaleSelector;
  import org.jboss.seam.mock.SeamTest;
  import org.testng.annotations.Test;
  
  public class LocaleTest extends SeamTest
  {
  
     @Override
     protected void startJbossEmbeddedIfNecessary() throws DeploymentException, IOException {}
     
     @Test
     public void localeTest() throws Exception
     {
        new FacesRequest()
        {
           @Override
           protected void invokeApplication() throws Exception
           {
              assert org.jboss.seam.international.Locale.instance().equals(Locale.getDefault());
              
              LocaleSelector.instance().setLocale(Locale.UK);
              
              assert org.jboss.seam.international.Locale.instance().equals(Locale.UK);
            
              LocaleSelector.instance().setLocaleString(Locale.FRANCE.toString());
              
              LocaleSelector.instance().getLanguage().equals(Locale.FRANCE.getLanguage());
              LocaleSelector.instance().getCountry().equals(Locale.FRANCE.getCountry());
              LocaleSelector.instance().getVariant().equals(Locale.FRANCE.getVariant());
              
              assert org.jboss.seam.international.Locale.instance().equals(Locale.FRANCE);
              assert LocaleSelector.instance().getLocaleString().equals(Locale.FRANCE.toString());
              
              LocaleSelector.instance().select();
              assert org.jboss.seam.international.Locale.instance().equals(Locale.FRANCE);
              
              LocaleSelector.instance().selectLanguage(Locale.JAPANESE.getLanguage());
              assert org.jboss.seam.international.Locale.instance().getLanguage().equals(Locale.JAPANESE.getLanguage());
              
              ValueChangeEvent valueChangeEvent = new ValueChangeEvent(new UIOutput(), Locale.JAPANESE.toString(), Locale.TAIWAN.toString());
              LocaleSelector.instance().select(valueChangeEvent);
              assert org.jboss.seam.international.Locale.instance().equals(Locale.TAIWAN);
              
              Locale uk_posix = new Locale(Locale.UK.getLanguage(), Locale.UK.getCountry(), "POSIX");
              LocaleSelector.instance().setLocale(uk_posix);
              
              assert org.jboss.seam.international.Locale.instance().equals(uk_posix);
              assert LocaleSelector.instance().getLanguage().equals(uk_posix.getLanguage());
              assert LocaleSelector.instance().getCountry().equals(uk_posix.getCountry());
              assert LocaleSelector.instance().getVariant().equals(uk_posix.getVariant());
              
              LocaleSelector.instance().setLanguage(Locale.CHINA.getLanguage());
              LocaleSelector.instance().setCountry(Locale.CHINA.getCountry()); 
              LocaleSelector.instance().setVariant(null);
              
              assert org.jboss.seam.international.Locale.instance().equals(Locale.CHINA);
              
              LocaleSelector.instance().setLanguage(Locale.ITALIAN.getLanguage());
              LocaleSelector.instance().setCountry(null);            
              LocaleSelector.instance().setVariant(null);
              
              assert org.jboss.seam.international.Locale.instance().equals(Locale.ITALIAN);
              
              assert LocaleSelector.instance().getSupportedLocales().size() == 1;
              assert LocaleSelector.instance().getSupportedLocales().get(0).getValue().equals(Locale.ENGLISH.toString());
              assert LocaleSelector.instance().getSupportedLocales().get(0).getLabel().equals(Locale.ENGLISH.getDisplayName());
  
              boolean failed = false;
              try
              {
                 LocaleSelector.instance().setLocale(null);
              }
              catch (NullPointerException e) 
              {
                 failed = true;
              }
              assert failed;
              
              // TODO Test cookie stuff (need to extend Mocks for this)
              
           }
        }.run();
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list