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

Norman Richards norman.richards at jboss.com
Thu Oct 18 17:26:29 EDT 2007


  User: nrichards
  Date: 07/10/18 17:26:29

  Modified:    src/test/integration/src/org/jboss/seam/test/integration  
                        testng.xml
  Added:       src/test/integration/src/org/jboss/seam/test/integration  
                        MessagingTest.java
  Log:
  jms integration tests
  
  Revision  Changes    Path
  1.7       +48 -41    jboss-seam/src/test/integration/src/org/jboss/seam/test/integration/testng.xml
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: testng.xml
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/test/integration/src/org/jboss/seam/test/integration/testng.xml,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -b -r1.6 -r1.7
  --- testng.xml	15 Oct 2007 22:08:08 -0000	1.6
  +++ testng.xml	18 Oct 2007 21:26:29 -0000	1.7
  @@ -1,6 +1,7 @@
   <!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
   
   <suite name="Seam Core Tests" verbose="2" parallel="false">
  +
      <test name="Seam Core - Integration: Contexts">
        <classes>
          <class name="org.jboss.seam.test.integration.PageContextTest"/>
  @@ -49,4 +50,10 @@
      		<class name="org.jboss.seam.test.integration.BusinessProcessTest" />
      	</classes>
      </test>
  +
  +    <test name="Seam Core - Integration: JMS">
  +   	    <classes>
  +   		    <class name="org.jboss.seam.test.integration.MessagingTest" />
  +        </classes>
  +    </test>
   </suite>
  
  
  
  1.1      date: 2007/10/18 21:26:29;  author: nrichards;  state: Exp;jboss-seam/src/test/integration/src/org/jboss/seam/test/integration/MessagingTest.java
  
  Index: MessagingTest.java
  ===================================================================
  package org.jboss.seam.test.integration;
  
  import javax.ejb.ActivationConfigProperty;
  import javax.ejb.MessageDriven;
  import javax.jms.JMSException;
  import javax.jms.Message;
  import javax.jms.MessageListener;
  import javax.jms.QueueSender;
  import javax.jms.QueueSession;
  import javax.jms.TextMessage;
  import javax.jms.TopicPublisher;
  import javax.jms.TopicSession;
  
  import org.jboss.seam.annotations.In;
  import org.jboss.seam.annotations.Name;
  import org.jboss.seam.contexts.Contexts;
  import org.jboss.seam.mock.SeamTest;
  import org.testng.annotations.Test;
  
  public class MessagingTest
      extends SeamTest
  {
      @Test
      public void delayForStartup() 
          throws InterruptedException 
      {
          // need to delay a bit to make sure the messaging system is running
          // really only needed when running this test in isolation
          Thread.sleep(3000);
      }
      
      @Test(dependsOnMethods={"delayForStartup"})
      public void publishToTopic()
          throws Exception
      {
          final SimpleReference<String> messageText = new SimpleReference<String>();
          
          new FacesRequest() {
              @Override
              protected void invokeApplication()
                  throws Exception 
              {
                  Contexts.getApplicationContext().set("testMessage", messageText);
                  invokeAction("#{testTopic.publish}");
              }
          }.run();      
  
          // need to delay a bit to make sure the message is delivered
          // might need 
          Thread.sleep(2000);
          
          assert messageText.getValue().equals("message for topic");
      }
      
      @Test(dependsOnMethods={"delayForStartup"})
      public void sendToQueue()
          throws Exception
      {
          final SimpleReference<String> messageText = new SimpleReference<String>();
          
          new FacesRequest() {
              @Override
              protected void invokeApplication()
                  throws Exception 
              {
                  Contexts.getApplicationContext().set("testMessage", messageText);
                  invokeAction("#{testQueue.send}");
              }
          }.run();      
  
          // need to delay a bit to make sure the message is delivered
          // might need 
          Thread.sleep(2000);
          
          assert messageText.getValue().equals("message for queue");
      }
  
  
      @Name("testTopic")
      public static class TopicBean {
          @In 
          private TopicPublisher testPublisher; 
          
          @In 
          private TopicSession topicSession; 
          
          public void publish() 
              throws JMSException 
          { 
              testPublisher.publish(topicSession.createTextMessage("message for topic")); 
          } 
      }
      
      @Name("testQueue")
      public static class QueueBean {
          @In 
          private QueueSender testSender;
          
          @In 
          private QueueSession queueSession;
          
          public void send() throws JMSException { 
              testSender.send(queueSession.createTextMessage("message for queue")); 
          } 
      }
      
      @MessageDriven(activationConfig={
          @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Topic"),
          @ActivationConfigProperty(propertyName="destination",     propertyValue="topic/testTopic")
      })
      @Name("testTopicListener")
      static public class TestTopicListener 
          implements MessageListener
      {
          @In
          private SimpleReference<String> testMessage;
  
          public void onMessage(Message msg)
          {
              try {
                  testMessage.setValue(((TextMessage) msg).getText());
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      }
      
      @MessageDriven(activationConfig={
          @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
          @ActivationConfigProperty(propertyName="destination",     propertyValue="queue/testQueue")
      })
      @Name("testQueueListener")
      static public class TestQueueListener 
          implements MessageListener
      {
          @In
          private SimpleReference<String> testMessage;
  
          public void onMessage(Message msg)
          {
              try {
                  testMessage.setValue(((TextMessage) msg).getText());
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      }
      
      
      static class SimpleReference<T> {
          T value;
          public SimpleReference() {            
          }
          public SimpleReference(T value) {
              setValue(value);
          }
          public T getValue() { 
              return value; 
          }
          public void setValue(T value) {
              this.value = value;
          }
      }
  }
  
  
  



More information about the jboss-cvs-commits mailing list