KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jtests > jms > framework > PTPTestCase


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2002 INRIA
4  * Contact: joram-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer(s): Jeff Mesnil (jmesnil@inrialpes.fr)
22  * Contributor(s): ______________________________________.
23  */

24
25 package org.objectweb.jtests.jms.framework;
26
27 import org.objectweb.jtests.jms.admin.*;
28
29 import junit.framework.*;
30 import javax.naming.*;
31 import javax.jms.*;
32
33 /**
34  * Creates convenient Point to Point JMS objects which can be needed for tests.
35  * <br />
36  * This class defines the setUp and tearDown methods so
37  * that JMS administrated objects and other "ready to use" PTP objects (that is to say queues,
38  * sessions, senders and receviers) are available conveniently for the test cases.
39  * <br />
40  * Classes which want that convenience should extend <code>PTPTestCase</code> instead of
41  * <code>JMSTestCase</code>.
42  *
43  * @author Jeff Mesnil (jmesnil@inrialpes.fr)
44  * @version $Id: PTPTestCase.java,v 1.3 2002/06/20 11:06:50 jmesnil Exp $
45  */

46 public class PTPTestCase extends JMSTestCase {
47
48     protected Admin admin;
49     protected InitialContext ctx;
50     private static final String JavaDoc QCF_NAME = "testQCF";
51     private static final String JavaDoc QUEUE_NAME = "testQueue";
52
53     /**
54      * Queue used by a sender
55      */

56     protected Queue senderQueue;
57     
58     /**
59      * Sender on queue
60      */

61     protected QueueSender sender;
62     
63     /**
64      * QueueConnectionFactory of the sender
65      */

66     protected QueueConnectionFactory senderQCF;
67     
68     /**
69      * QueueConnection of the sender
70      */

71     protected QueueConnection senderConnection;
72     
73     /**
74      * QueueSession of the sender (non transacted, AUTO_ACKNOWLEDGE)
75      */

76     protected QueueSession senderSession;
77     
78     /**
79      * Queue used by a receiver
80      */

81     protected Queue receiverQueue;
82     
83     /**
84      * Receiver on queue
85      */

86     protected QueueReceiver receiver;
87     
88     /**
89      * QueueConnectionFactory of the receiver
90      */

91     protected QueueConnectionFactory receiverQCF;
92     
93     /**
94      * QueueConnection of the receiver
95      */

96     protected QueueConnection receiverConnection;
97     
98     /**
99      * QueueSession of the receiver (non transacted, AUTO_ACKNOWLEDGE)
100      */

101     protected QueueSession receiverSession;
102     
103     /**
104      * Create all administrated objects connections and sessions ready to use for tests.
105      * <br />
106      * Start connections.
107      */

108     protected void setUp() {
109     try {
110         // Admin step
111
// gets the provider administration wrapper...
112
admin = AdminFactory.getAdmin();
113         // ...and creates administrated objects and binds them
114
admin.createQueueConnectionFactory(QCF_NAME);
115         admin.createQueue(QUEUE_NAME);
116
117         // end of admin step, start of JMS client step
118
ctx = admin.createInitialContext();
119
120         senderQCF = (QueueConnectionFactory)ctx.lookup(QCF_NAME);
121         senderQueue = (Queue)ctx.lookup(QUEUE_NAME);
122         senderConnection = senderQCF.createQueueConnection();
123         senderSession = senderConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
124         sender = senderSession.createSender(senderQueue);
125
126         receiverQCF = (QueueConnectionFactory)ctx.lookup(QCF_NAME);
127         receiverQueue = (Queue)ctx.lookup(QUEUE_NAME);
128         receiverConnection = receiverQCF.createQueueConnection();
129         receiverSession = receiverConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
130         receiver = receiverSession.createReceiver(receiverQueue);
131
132         senderConnection.start();
133         receiverConnection.start();
134         //end of client step
135
} catch (Exception JavaDoc e) {
136         //XXX
137
e.printStackTrace();
138     }
139     }
140     
141     /**
142      * Close connections and delete administrated objects
143      */

144     protected void tearDown() {
145     try {
146         senderConnection.close();
147         receiverConnection.close();
148
149         admin.deleteQueueConnectionFactory(QCF_NAME);
150         admin.deleteQueue(QUEUE_NAME);
151             
152         ctx.close();
153     } catch (Exception JavaDoc e) {
154         //XXX
155
e.printStackTrace();
156     } finally {
157         senderQueue = null;
158         sender = null;
159         senderQCF = null;
160         senderSession = null;
161         senderConnection = null;
162
163         receiverQueue = null;
164         receiver = null;
165         receiverQCF = null;
166         receiverSession = null;
167         receiverConnection = null;
168     }
169     }
170     
171     public PTPTestCase(String JavaDoc name) {
172     super(name);
173     }
174 }
175
Popular Tags