KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jtests > jms > conform > connection > TopicConnectionTest


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): Andreas Mueller <am@iit.de>
23  */

24
25 package org.objectweb.jtests.jms.conform.connection;
26
27 import org.objectweb.jtests.jms.framework.*;
28 import javax.jms.*;
29 import junit.framework.*;
30
31 /**
32  * Test topic-specific connection features.
33  *
34  * Test setting of client ID which is relevant only for Durable Subscribtion
35  */

36
37 public class TopicConnectionTest extends PubSubTestCase {
38     
39     /**
40      * Test that a call to <code>setClientID</code> will throw an
41      * <code>IllegalStateException</code> if a client ID has already been set
42      * see JMS javadoc
43      * http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/jms/Connection.html#setClientID(java.lang.String)
44      */

45     public void testSetClientID_1() {
46     try {
47         // we start from a clean state for the connection
48
subscriberConnection.close();
49         subscriberConnection = null;
50         
51         subscriberConnection = subscriberTCF.createTopicConnection();
52         // if the JMS provider does not set a client ID, we do.
53
if (subscriberConnection.getClientID() == null) {
54         subscriberConnection.setClientID("testSetClientID_1");
55         assertEquals("testSetClientID_1", subscriberConnection.getClientID());
56         }
57         // now the connection has a client ID (either "testSetClientID_1" or one set by the provider
58
assertTrue(subscriberConnection.getClientID() != null);
59         
60         // a attempt to set a client ID should now throw an IllegalStateException
61
subscriberConnection.setClientID("another client ID");
62         fail("Should raise a javax.jms.IllegalStateException");
63     } catch (javax.jms.IllegalStateException JavaDoc e) {
64     } catch (JMSException e) {
65         fail("Should raise a javax.jms.IllegalStateException, not a "+ e);
66     } catch (java.lang.IllegalStateException JavaDoc e) {
67         fail("Should raise a javax.jms.IllegalStateException, not a java.lang.IllegalStateException");
68     }
69     }
70
71     /**
72      * Test that a call to <code>setClientID</code> can occur only after connection creation
73      * and before any other action on the connection.
74      * <em>This test is relevant only if the ID is set by the JMS client</em>
75      * see JMS javadoc
76      * http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/jms/Connection.html#setClientID(java.lang.String)
77      */

78     public void testSetClientID_2() {
79     try {
80         // we start from a clean state for the first connection
81
subscriberConnection.close();
82         subscriberConnection = null;
83
84         subscriberConnection = subscriberTCF.createTopicConnection();
85         // if the JMS provider has set a client ID, this test is not relevant
86
if (subscriberConnection.getClientID() != null) {
87         return;
88         }
89
90         //we start the connection
91
subscriberConnection.start();
92         
93         // an attempt to set the client ID now should throw a IllegalStateException
94
subscriberConnection.setClientID("testSetClientID_2");
95         fail("Should throw a javax.jms.IllegalStateException");
96     } catch (javax.jms.IllegalStateException JavaDoc e) {
97     } catch (JMSException e) {
98         fail("Should raise a javax.jms.IllegalStateException, not a "+ e);
99     } catch (java.lang.IllegalStateException JavaDoc e) {
100         fail("Should raise a javax.jms.IllegalStateException, not a java.lang.IllegalStateException");
101     }
102     }
103
104     /**
105      * Method to use this class in a Test suite
106      */

107     public static Test suite() {
108     return new TestSuite(TopicConnectionTest.class);
109     }
110   
111     public TopicConnectionTest(String JavaDoc name) {
112     super(name);
113     }
114 }
115
116
117
118
Popular Tags