1 22 package org.jboss.test.jbossmessaging.test; 23 24 import javax.jms.Connection ; 25 import javax.jms.ConnectionFactory ; 26 import javax.jms.JMSException ; 27 import javax.jms.Queue ; 28 import javax.jms.QueueConnection ; 29 import javax.jms.QueueConnectionFactory ; 30 import javax.jms.QueueSession ; 31 import javax.jms.Session ; 32 import javax.jms.Topic ; 33 import javax.jms.TopicConnection ; 34 import javax.jms.TopicConnectionFactory ; 35 import javax.jms.TopicSession ; 36 import javax.naming.InitialContext ; 37 38 import org.jboss.test.jbossmessaging.JMSTestCase; 39 import org.jboss.test.jbossmessaging.MockServerSessionPool; 40 41 47 public class ConnectionConsumerUnitTestCase extends JMSTestCase 48 { 49 54 public ConnectionConsumerUnitTestCase(String name) 55 { 56 super(name); 57 } 58 59 public void testConnectionConsumerWrongTemporaryDestination() throws Exception 60 { 61 InitialContext ctx = getInitialContext(); 62 ConnectionFactory factory = (ConnectionFactory ) ctx.lookup("ConnectionFactory"); 63 Queue queue = null; 64 Connection connection = factory.createConnection(); 65 try 66 { 67 Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 68 queue = s.createTemporaryQueue(); 69 Connection connection2 = factory.createConnection(); 70 try 71 { 72 connection2.createConnectionConsumer(queue, "", MockServerSessionPool.getServerSessionPool(), 1); 73 fail("Expected an error listening to a temporary destination from a different connection"); 74 } 75 catch (JMSException expected) 76 { 77 log.debug("Got the expected jms exception", expected); 78 } 79 finally 80 { 81 connection2.close(); 82 } 83 } 84 finally 85 { 86 connection.close(); 87 } 88 } 89 90 public void testQueueConnectionConsumerWrongTemporaryDestination() throws Exception 91 { 92 InitialContext ctx = getInitialContext(); 93 QueueConnectionFactory factory = (QueueConnectionFactory ) ctx.lookup("ConnectionFactory"); 94 Queue queue = null; 95 QueueConnection connection = factory.createQueueConnection(); 96 try 97 { 98 QueueSession s = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); 99 queue = s.createTemporaryQueue(); 100 QueueConnection connection2 = factory.createQueueConnection(); 101 try 102 { 103 connection2.createConnectionConsumer(queue, "", MockServerSessionPool.getServerSessionPool(), 1); 104 fail("Expected an error listening to a temporary destination from a different connection"); 105 } 106 catch (JMSException expected) 107 { 108 log.debug("Got the expected jms exception", expected); 109 } 110 finally 111 { 112 connection2.close(); 113 } 114 } 115 finally 116 { 117 connection.close(); 118 } 119 } 120 121 public void testTopicConnectionConsumerWrongTemporaryDestination() throws Exception 122 { 123 InitialContext ctx = getInitialContext(); 124 TopicConnectionFactory factory = (TopicConnectionFactory ) ctx.lookup("ConnectionFactory"); 125 Topic topic = null; 126 TopicConnection connection = factory.createTopicConnection(); 127 try 128 { 129 TopicSession s = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); 130 topic = s.createTemporaryTopic(); 131 TopicConnection connection2 = factory.createTopicConnection(); 132 try 133 { 134 connection2.createConnectionConsumer(topic, "", MockServerSessionPool.getServerSessionPool(), 1); 135 fail("Expected an error listening to a temporary destination from a different connection"); 136 } 137 catch (JMSException expected) 138 { 139 log.debug("Got the expected jms exception", expected); 140 } 141 finally 142 { 143 connection2.close(); 144 } 145 } 146 finally 147 { 148 connection.close(); 149 } 150 } 151 } 152 | Popular Tags |