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

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


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

  Added:       src/test/integration/src/org/jboss/seam/test/integration     
                        MiscTests.java BeanB.java testng.xml
                        PageContextTest.java BeanA.java
  Log:
  JBSEAM-2028
  
  Revision  Changes    Path
  1.1      date: 2007/10/08 18:15:48;  author: pmuir;  state: Exp;jboss-seam/src/test/integration/src/org/jboss/seam/test/integration/MiscTests.java
  
  Index: MiscTests.java
  ===================================================================
  package org.jboss.seam.test.integration;
  
  import org.jboss.seam.Component;
  import org.jboss.seam.core.Events;
  import org.jboss.seam.mock.SeamTest;
  import org.testng.annotations.Test;
  
  public class MiscTests extends SeamTest {
  
      @Test
      public void eventChain() throws Exception {
  
          new FacesRequest("/index.xhtml") {
  
              @Override
              protected void invokeApplication() throws Exception {
                  BeanA beanA = (BeanA) Component.getInstance("beanA");
                  BeanB beanB = (BeanB) Component.getInstance("beanB");
                  
                  System.out.println("beanA: " + beanA.hashCode());
                  System.out.println("beanB: " + beanB.hashCode());
  
                  assert "Foo".equals(beanA.getMyValue());
                  assert beanB.getMyValue() == null;
  
                  Events.instance().raiseEvent("BeanA.refreshMyValue");
  
                  beanA = (BeanA) Component.getInstance("beanA");
                  
                  assert "Bar".equals(beanA.getMyValue());        
              }
              
              @Override
              protected void renderResponse() throws Exception
              {
                 BeanB beanB = (BeanB) Component.getInstance("beanB");
                 assert "Bar".equals(beanB.getMyValue());
              }
          }.run();
      }
  
  }
  
  
  
  
  
  1.1      date: 2007/10/08 18:15:48;  author: pmuir;  state: Exp;jboss-seam/src/test/integration/src/org/jboss/seam/test/integration/BeanB.java
  
  Index: BeanB.java
  ===================================================================
  package org.jboss.seam.test.integration;
  
  import java.io.Serializable;
  
  import org.jboss.seam.Component;
  import org.jboss.seam.ScopeType;
  import org.jboss.seam.annotations.AutoCreate;
  import org.jboss.seam.annotations.Name;
  import org.jboss.seam.annotations.Observer;
  import org.jboss.seam.annotations.Scope;
  
  @Name("beanB")
  @Scope(ScopeType.PAGE)
  @AutoCreate
  public class BeanB implements Serializable {
  
      private String myValue;
  
      public String getMyValue() {
          return myValue;
      }
  
      public void setMyValue(String myValue) {
          this.myValue = myValue;
      }
  
      @Observer(value = "BeanA.valueModified")
      public void takeValueFromBeanA() {
          BeanA beanA = (BeanA) Component.getInstance("beanA");
          myValue = beanA.getMyValue();
      }
  
  }
  
  
  1.1      date: 2007/10/08 18:15:48;  author: pmuir;  state: Exp;jboss-seam/src/test/integration/src/org/jboss/seam/test/integration/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="Integration">
       <classes>
         <class name="org.jboss.seam.test.integration.PageContextTest"/>
         <class name="org.jboss.seam.test.integration.MiscTests"/>
       </classes>
     </test>
  	
  </suite>
  
  
  1.1      date: 2007/10/08 18:15:48;  author: pmuir;  state: Exp;jboss-seam/src/test/integration/src/org/jboss/seam/test/integration/PageContextTest.java
  
  Index: PageContextTest.java
  ===================================================================
  package org.jboss.seam.test.integration;
  
  import org.jboss.seam.contexts.Contexts;
  import org.jboss.seam.mock.SeamTest;
  import org.testng.annotations.Test;
  
  public class PageContextTest extends SeamTest
  {
  
     @Test
     public void pageContextTest() throws Exception {
  
        new FacesRequest("/index.xhtml") {
            
           @Override
           protected void invokeApplication() throws Exception
           {
              Contexts.getPageContext().set("foo", "bar");
              assert Contexts.getPageContext().get("foo") == null;
           }
           
           @Override
           protected void renderResponse() throws Exception
           {
               assert Contexts.getPageContext().get("foo") != null;
               assert "bar".equals(Contexts.getPageContext().get("foo"));
           }
        }.run();
        
    } 
     
  }
  
  
  
  1.1      date: 2007/10/08 18:15:48;  author: pmuir;  state: Exp;jboss-seam/src/test/integration/src/org/jboss/seam/test/integration/BeanA.java
  
  Index: BeanA.java
  ===================================================================
  package org.jboss.seam.test.integration;
  
  import org.jboss.seam.ScopeType;
  import org.jboss.seam.annotations.AutoCreate;
  import org.jboss.seam.annotations.Create;
  import org.jboss.seam.annotations.Name;
  import org.jboss.seam.annotations.Observer;
  import org.jboss.seam.annotations.Scope;
  import org.jboss.seam.core.Events;
  
  @Name("beanA")
  @Scope(ScopeType.CONVERSATION)
  @AutoCreate
  public class BeanA {
  
      private String myValue;
  
      public String getMyValue() {
          return myValue;
      }
  
      public void setMyValue(String myValue) {
          this.myValue = myValue;
      }
  
      @Create
      public void create() {
          myValue = "Foo";
      }
  
      @Observer(value = "BeanA.refreshMyValue")
      public void refreshMyValue() {
          myValue = "Bar";
          Events.instance().raiseEvent("BeanA.valueModified");
      }
  
  }
  
  



More information about the jboss-cvs-commits mailing list