KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jbossmq > test > ConnectionConsumerUnitTestCase


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.Connection JavaDoc;
25 import javax.jms.ConnectionFactory JavaDoc;
26 import javax.jms.JMSException JavaDoc;
27 import javax.jms.Queue JavaDoc;
28 import javax.jms.QueueConnection JavaDoc;
29 import javax.jms.QueueConnectionFactory JavaDoc;
30 import javax.jms.QueueSession JavaDoc;
31 import javax.jms.Session JavaDoc;
32 import javax.jms.Topic JavaDoc;
33 import javax.jms.TopicConnection JavaDoc;
34 import javax.jms.TopicConnectionFactory JavaDoc;
35 import javax.jms.TopicSession JavaDoc;
36 import javax.naming.InitialContext JavaDoc;
37
38 import org.jboss.test.JBossTestCase;
39 import org.jboss.test.jbossmq.MockServerSessionPool;
40
41 /**
42  * ConnectionConsumerUnitTestCase.
43  *
44  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
45  * @version $Revision: 39152 $
46  */

47 public class ConnectionConsumerUnitTestCase extends JBossTestCase
48 {
49    /**
50     * Create a new ConnectionConsumerUnitTestCase.
51     *
52     * @param name the test name
53     */

54    public ConnectionConsumerUnitTestCase(String JavaDoc name)
55    {
56       super(name);
57    }
58    
59    public void testConnectionConsumerWrongTemporaryDestination() throws Exception JavaDoc
60    {
61       InitialContext JavaDoc ctx = getInitialContext();
62       ConnectionFactory JavaDoc factory = (ConnectionFactory JavaDoc) ctx.lookup("ConnectionFactory");
63       Queue JavaDoc queue = null;
64       Connection JavaDoc connection = factory.createConnection();
65       try
66       {
67          Session JavaDoc s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
68          queue = s.createTemporaryQueue();
69          Connection JavaDoc 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 JavaDoc 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 JavaDoc
91    {
92       InitialContext JavaDoc ctx = getInitialContext();
93       QueueConnectionFactory JavaDoc factory = (QueueConnectionFactory JavaDoc) ctx.lookup("ConnectionFactory");
94       Queue JavaDoc queue = null;
95       QueueConnection JavaDoc connection = factory.createQueueConnection();
96       try
97       {
98          QueueSession JavaDoc s = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
99          queue = s.createTemporaryQueue();
100          QueueConnection JavaDoc 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 JavaDoc 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 JavaDoc
122    {
123       InitialContext JavaDoc ctx = getInitialContext();
124       TopicConnectionFactory JavaDoc factory = (TopicConnectionFactory JavaDoc) ctx.lookup("ConnectionFactory");
125       Topic JavaDoc topic = null;
126       TopicConnection JavaDoc connection = factory.createTopicConnection();
127       try
128       {
129          TopicSession JavaDoc s = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
130          topic = s.createTemporaryTopic();
131          TopicConnection JavaDoc 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 JavaDoc 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