1 4 package org.jfox.jms; 5 6 import javax.jms.Connection ; 7 import javax.jms.MessageConsumer ; 8 import javax.jms.MessageProducer ; 9 import javax.jms.Session ; 10 import javax.jms.TextMessage ; 11 import javax.naming.InitialContext ; 12 13 import junit.framework.TestCase; 14 15 18 19 public class JMSSessionTest extends TestCase { 20 21 JMSConnectionFactory jmsConnectionFactory; 22 Connection conn; 23 Session session; 24 25 public void setUp() throws Exception { 26 super.setUp(); 27 InitialContext ctx = new InitialContext (); 28 Object cf = ctx.lookup("jms/defaultcf"); 29 jmsConnectionFactory = (JMSConnectionFactory) javax.rmi.PortableRemoteObject.narrow(cf, JMSConnectionFactory.class); 30 conn = jmsConnectionFactory.createConnection(); 31 conn.start(); 32 session = conn.createSession(false,Session.AUTO_ACKNOWLEDGE); 33 } 34 35 public void tearDown() throws Exception { 36 super.tearDown(); 37 } 38 39 public void testCreateTextMessage() { 40 String s = "Hello,JMS!"; 41 try{ 42 TextMessage tm = session.createTextMessage(s); 43 assertEquals(s,tm.getText()); 44 } 45 catch(Exception e){ 46 e.printStackTrace(); 47 fail(e.getMessage()); 48 } 49 } 50 51 public void testCreateConsumer(){ 52 try{ 53 MessageConsumer consumer = session.createConsumer(new JMSQueue("test")); 54 55 } 56 catch(Exception e){ 57 e.printStackTrace(); 58 fail(e.getMessage()); 59 } 60 } 61 62 public void testCreateProducer(){ 63 try{ 64 MessageProducer producer = session.createProducer(new JMSQueue("test")); 65 } 66 catch(Exception e){ 67 e.printStackTrace(); 68 fail(e.getMessage()); 69 } 70 } 71 72 } 73 74 | Popular Tags |