KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jbossmessaging > test > DuplicateClientIDUnitTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.jbossmessaging.test;
23
24 import javax.jms.InvalidClientIDException JavaDoc;
25 import javax.jms.JMSException JavaDoc;
26 import javax.jms.TopicConnection JavaDoc;
27 import javax.jms.TopicConnectionFactory JavaDoc;
28 import javax.naming.Context JavaDoc;
29
30 import org.jboss.test.jbossmessaging.JMSTestCase;
31
32 /**
33  * Duplciate client id tests
34  *
35  * @author <a HREF="mailto:richard.achmatowicz@jboss.org>Richard Achmatowicz</a>
36  * @author <a HREF="mailto:adrian@jboss.org>Adrian Brock</a>
37  * @version <tt>$Revision: 37406 $</tt>
38  */

39 public class DuplicateClientIDUnitTestCase extends JMSTestCase
40 {
41    static String JavaDoc TOPIC_FACTORY = "ConnectionFactory";
42    
43    public DuplicateClientIDUnitTestCase(String JavaDoc name) throws Exception JavaDoc
44    {
45       super(name);
46    }
47
48    public void testDuplicateClientID() throws Exception JavaDoc
49    {
50       TopicConnection JavaDoc c1 = getTopicConnectionFactory().createTopicConnection();
51       try
52       {
53          c1.setClientID("testClientID");
54          TopicConnection JavaDoc c2 = getTopicConnectionFactory().createTopicConnection();
55          try
56          {
57             c2.setClientID("testClientID");
58             fail("Should not be here - duplicate client id");
59          }
60          catch (InvalidClientIDException JavaDoc expected)
61          {
62          }
63          finally
64          {
65             c2.close();
66          }
67       }
68       finally
69       {
70          c1.close();
71       }
72    }
73
74    public void testPreconfiguredDuplicateClientID() throws Exception JavaDoc
75    {
76       TopicConnection JavaDoc c1 = getTopicConnectionFactory().createTopicConnection("john", "needle");
77       try
78       {
79          try
80          {
81             TopicConnection JavaDoc c2 = getTopicConnectionFactory().createTopicConnection("john", "needle");
82             c2.close();
83             fail("Should not be here - duplicate client id");
84          }
85          catch (JMSException JavaDoc expected)
86          {
87          }
88       }
89       finally
90       {
91          c1.close();
92       }
93    }
94
95    public void testNotDuplicateClientID() throws Exception JavaDoc
96    {
97       TopicConnection JavaDoc c1 = getTopicConnectionFactory().createTopicConnection();
98       try
99       {
100          TopicConnection JavaDoc c2 = getTopicConnectionFactory().createTopicConnection();
101          c2.close();
102       }
103       finally
104       {
105          c1.close();
106       }
107    }
108
109    protected TopicConnectionFactory JavaDoc getTopicConnectionFactory() throws Exception JavaDoc
110    {
111       Context JavaDoc context = getInitialContext();
112       return (TopicConnectionFactory JavaDoc) context.lookup(TOPIC_FACTORY);
113    }
114 }
115
116
Popular Tags