Source code: org/objectweb/jtests/jms/conform/topic/TemporaryTopicTest.java
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.conform.topic;
26
27 import org.objectweb.jtests.jms.framework.*;
28 import junit.framework.*;
29
30 import javax.jms.*;
31
32
33 /**
34 * Test the <code>javax.jms.TemporaryTopic</code> features.
35 *
36 * @author Jeff Mesnil (jmesnil@inrialpes.fr)
37 * @version $Id: TemporaryTopicTest.java,v 1.1 2002/04/21 21:15:19 chirino Exp $
38 */
39 public class TemporaryTopicTest extends PubSubTestCase {
40
41 private TemporaryTopic tempTopic;
42 private TopicSubscriber tempSubscriber;
43
44 /**
45 * Test a TemporaryTopic
46 */
47 public void testTemporaryTopic() {
48 try {
49 // we stop both publisher and subscriber connections
50 publisherConnection.stop();
51 subscriberConnection.stop();
52 // we create a temporary topic to receive messages
53 tempTopic = subscriberSession.createTemporaryTopic();
54 // we recreate the sender because it has been
55 // already created with another Destination as parameter
56 publisher = publisherSession.createPublisher(tempTopic);
57 // we create a temporary subscriber on the temporary topic
58 tempSubscriber = subscriberSession.createSubscriber(tempTopic);
59 subscriberConnection.start();
60 publisherConnection.start();
61
62 TextMessage message = publisherSession.createTextMessage();
63 message.setText("testTemporaryTopic");
64 publisher.publish(message);
65
66 Message m = tempSubscriber.receive();
67 assertTrue(m instanceof TextMessage);
68 TextMessage msg = (TextMessage)m;
69 assertEquals("testTemporaryTopic", msg.getText());
70 } catch (JMSException e) {
71 fail(e);
72 }
73 }
74
75 /**
76 * Method to use this class in a Test suite
77 */
78 public static Test suite() {
79 return new TestSuite(TemporaryTopicTest.class);
80 }
81
82 public TemporaryTopicTest(String name) {
83 super(name);
84 }
85 }