KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > jms > JMSSessionTest


1 /*
2  * Copyright (c) 2004 Your Corporation. All Rights Reserved.
3  */

4 package org.jfox.jms;
5
6 import javax.jms.Connection JavaDoc;
7 import javax.jms.MessageConsumer JavaDoc;
8 import javax.jms.MessageProducer JavaDoc;
9 import javax.jms.Session JavaDoc;
10 import javax.jms.TextMessage JavaDoc;
11 import javax.naming.InitialContext JavaDoc;
12
13 import junit.framework.TestCase;
14
15 /**
16  * @author <a HREF="mailto:yy.young@gmail.com">Young Yang</a>
17  */

18
19 public class JMSSessionTest extends TestCase {
20
21     JMSConnectionFactory jmsConnectionFactory;
22     Connection JavaDoc conn;
23     Session JavaDoc session;
24
25     public void setUp() throws Exception JavaDoc {
26         super.setUp();
27         InitialContext JavaDoc ctx = new InitialContext JavaDoc();
28         Object JavaDoc 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 JavaDoc {
36         super.tearDown();
37     }
38
39     public void testCreateTextMessage() {
40         String JavaDoc s = "Hello,JMS!";
41         try{
42             TextMessage JavaDoc tm = session.createTextMessage(s);
43             assertEquals(s,tm.getText());
44         }
45         catch(Exception JavaDoc e){
46             e.printStackTrace();
47             fail(e.getMessage());
48         }
49     }
50
51     public void testCreateConsumer(){
52         try{
53             MessageConsumer JavaDoc consumer = session.createConsumer(new JMSQueue("test"));
54             
55         }
56         catch(Exception JavaDoc e){
57             e.printStackTrace();
58             fail(e.getMessage());
59         }
60     }
61
62     public void testCreateProducer(){
63         try{
64             MessageProducer JavaDoc producer = session.createProducer(new JMSQueue("test"));
65         }
66         catch(Exception JavaDoc e){
67             e.printStackTrace();
68             fail(e.getMessage());
69         }
70     }
71
72 }
73
74
Popular Tags