KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jbossmq > 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.jbossmq.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.JBossTestCase;
31
32 /**
33  * Duplciate client id tests
34  *
35  * @author <a HREF="mailto:adrian@jboss.org>Adrian Brock</a>
36  * @version <tt>$Revision: 37406 $</tt>
37  */

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