1 22 package org.jboss.test.jbossmq.test; 23 24 import javax.jms.InvalidClientIDException ; 25 import javax.jms.JMSException ; 26 import javax.jms.TopicConnection ; 27 import javax.jms.TopicConnectionFactory ; 28 import javax.naming.Context ; 29 30 import org.jboss.test.JBossTestCase; 31 32 38 public class DuplicateClientIDUnitTestCase extends JBossTestCase 39 { 40 static String TOPIC_FACTORY = "ConnectionFactory"; 41 42 public DuplicateClientIDUnitTestCase(String name) throws Exception 43 { 44 super(name); 45 } 46 47 public void testDuplicateClientID() throws Exception 48 { 49 TopicConnection c1 = getTopicConnectionFactory().createTopicConnection(); 50 try 51 { 52 c1.setClientID("testClientID"); 53 TopicConnection c2 = getTopicConnectionFactory().createTopicConnection(); 54 try 55 { 56 c2.setClientID("testClientID"); 57 fail("Should not be here - duplicate client id"); 58 } 59 catch (InvalidClientIDException 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 74 { 75 TopicConnection c1 = getTopicConnectionFactory().createTopicConnection("john", "needle"); 76 try 77 { 78 try 79 { 80 TopicConnection c2 = getTopicConnectionFactory().createTopicConnection("john", "needle"); 81 c2.close(); 82 fail("Should not be here - duplicate client id"); 83 } 84 catch (JMSException expected) 85 { 86 } 87 } 88 finally 89 { 90 c1.close(); 91 } 92 } 93 94 public void testNotDuplicateClientID() throws Exception 95 { 96 TopicConnection c1 = getTopicConnectionFactory().createTopicConnection(); 97 try 98 { 99 TopicConnection c2 = getTopicConnectionFactory().createTopicConnection(); 100 c2.close(); 101 } 102 finally 103 { 104 c1.close(); 105 } 106 } 107 108 protected TopicConnectionFactory getTopicConnectionFactory() throws Exception 109 { 110 Context context = getInitialContext(); 111 return (TopicConnectionFactory ) context.lookup(TOPIC_FACTORY); 112 } 113 } 114 115 | Popular Tags |