1 22 package org.jboss.ejb3.test.mdbtopic.unit; 23 24 import javax.jms.MessageProducer ; 25 import javax.jms.QueueSession ; 26 import javax.jms.TextMessage ; 27 import javax.jms.Topic ; 28 import javax.jms.TopicConnection ; 29 import javax.jms.TopicConnectionFactory ; 30 import javax.jms.TopicSession ; 31 import javax.naming.NamingException ; 32 33 import junit.framework.Test; 34 35 import org.jboss.ejb3.test.mdbtopic.TestStatus; 36 import org.jboss.logging.Logger; 38 import org.jboss.test.JBossTestCase; 39 40 46 public class TopicMDBUnitTestCase extends JBossTestCase 47 { 48 @SuppressWarnings ("unused") 49 private static final Logger log = Logger.getLogger(TopicMDBUnitTestCase.class); 50 51 static boolean deployed = false; 52 53 static int test = 0; 54 55 public TopicMDBUnitTestCase(String name) 56 { 57 super(name); 58 } 59 60 public void testTopic() throws Exception 61 { 62 TestStatus status = (TestStatus) getInitialContext().lookup("TestStatusBean/remote"); 63 clear(status); 64 TopicConnection cnn = null; 65 MessageProducer sender = null; 66 TopicSession session = null; 67 68 Topic topic = (Topic ) getInitialContext().lookup("topic/mdbtest"); 69 TopicConnectionFactory factory = getTopicConnectionFactory(); 70 cnn = factory.createTopicConnection(); 71 session = cnn.createTopicSession(false, QueueSession.AUTO_ACKNOWLEDGE); 72 73 TextMessage msg = session.createTextMessage("Hello World"); 74 75 sender = session.createProducer(topic); 76 sender.send(msg); 77 session.close(); 78 cnn.close(); 79 80 Thread.sleep(2000); 81 assertEquals(1, status.topicFired()); 82 assertTrue(status.interceptedTopic()); 83 assertFalse(status.postConstruct()); 84 assertFalse(status.preDestroy()); 85 } 86 87 private TopicConnectionFactory getTopicConnectionFactory() 88 throws Exception 89 { 90 try 91 { 92 return (TopicConnectionFactory ) getInitialContext().lookup("ConnectionFactory"); 93 } 94 catch (NamingException e) 95 { 96 return (TopicConnectionFactory ) getInitialContext().lookup("java:/ConnectionFactory"); 97 } 98 } 99 100 private void clear(TestStatus status) 101 { 102 status.clear(); 103 assertEquals(0, status.bmtQueueRan()); 104 assertEquals(0, status.defaultedQueueFired()); 105 assertEquals(0, status.messageCount()); 106 assertEquals(0, status.nondurableQueueFired()); 107 assertEquals(0, status.overrideDefaultedQueueFired()); 108 assertEquals(0, status.overrideQueueFired()); 109 assertEquals(0, status.queueFired()); 110 assertEquals(0, status.topicFired()); 111 assertFalse(status.interceptedQueue()); 112 assertFalse(status.interceptedTopic()); 113 assertFalse(status.postConstruct()); 114 assertFalse(status.preDestroy()); 115 } 116 117 public static Test suite() throws Exception 123 { 124 return getDeploySetup(TopicMDBUnitTestCase.class, "mdbtopic-test.jar"); 125 } 126 127 } | Popular Tags |