KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Properties JavaDoc;
25
26 import javax.jms.QueueConnection JavaDoc;
27 import javax.jms.QueueConnectionFactory JavaDoc;
28 import javax.jms.XAQueueConnection JavaDoc;
29 import javax.jms.XAQueueConnectionFactory JavaDoc;
30 import javax.naming.InitialContext JavaDoc;
31
32 import junit.framework.Test;
33 import junit.textui.TestRunner;
34
35 import org.jboss.mq.SpyConnectionFactory;
36 import org.jboss.mq.SpyXAConnectionFactory;
37 import org.jboss.mq.il.uil2.UILServerILFactory;
38 import org.jboss.test.JBossTestCase;
39
40 /**
41  * Test all the verious ways that a connection can be
42  * established with JBossMQ
43  *
44  * @author hiram.chirino@jboss.org
45  * @version $Revision: 37406 $
46  */

47 public class UIL2ConnectionUnitTestCase extends JBossTestCase
48 {
49
50    public UIL2ConnectionUnitTestCase(String JavaDoc name)
51    {
52       super(name);
53    }
54
55    protected void setUp() throws Exception JavaDoc
56    {
57    }
58
59    public void testMultipleUIL2ConnectViaJNDI() throws Exception JavaDoc
60    {
61
62       getLog().debug("Starting testMultipleUIL2ConnectViaJNDI");
63
64       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
65
66       QueueConnectionFactory JavaDoc cf = (QueueConnectionFactory JavaDoc) ctx.lookup("UIL2ConnectionFactory");
67
68       QueueConnection JavaDoc connections[] = new QueueConnection JavaDoc[10];
69
70       getLog().debug("Creating " + connections.length + " connections.");
71       for (int i = 0; i < connections.length; i++)
72       {
73          connections[i] = cf.createQueueConnection();
74       }
75
76       getLog().debug("Closing the connections.");
77       for (int i = 0; i < connections.length; i++)
78       {
79          connections[i].close();
80       }
81
82       getLog().debug("Finished testMultipleUIL2ConnectViaJNDI");
83    }
84
85    public void testUIL2ConnectViaJNDI() throws Exception JavaDoc
86    {
87       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
88
89       QueueConnectionFactory JavaDoc cf = (QueueConnectionFactory JavaDoc) ctx.lookup("UIL2ConnectionFactory");
90       QueueConnection JavaDoc c = cf.createQueueConnection();
91       c.close();
92
93       XAQueueConnectionFactory JavaDoc xacf = (XAQueueConnectionFactory JavaDoc) ctx.lookup("UIL2XAConnectionFactory");
94       XAQueueConnection JavaDoc xac = xacf.createXAQueueConnection();
95       xac.close();
96    }
97
98    public void testUIL2ConnectNoJNDI() throws Exception JavaDoc
99    {
100
101       Properties JavaDoc props = new Properties JavaDoc();
102       props.setProperty(org.jboss.mq.il.uil2.UILServerILFactory.SERVER_IL_FACTORY_KEY,
103             org.jboss.mq.il.uil2.UILServerILFactory.SERVER_IL_FACTORY);
104       props.setProperty(org.jboss.mq.il.uil2.UILServerILFactory.CLIENT_IL_SERVICE_KEY,
105             org.jboss.mq.il.uil2.UILServerILFactory.CLIENT_IL_SERVICE);
106       props.setProperty(org.jboss.mq.il.uil2.UILServerILFactory.PING_PERIOD_KEY, "1000");
107       props.setProperty(org.jboss.mq.il.uil2.UILServerILFactory.UIL_ADDRESS_KEY, getServerHost());
108       props.setProperty(org.jboss.mq.il.uil2.UILServerILFactory.UIL_PORT_KEY, "8093");
109       props.setProperty(org.jboss.mq.il.uil2.UILServerILFactory.UIL_RECEIVE_REPLIES_KEY, "no");
110
111       QueueConnectionFactory JavaDoc cf = new SpyConnectionFactory(props);
112       QueueConnection JavaDoc c = cf.createQueueConnection();
113       c.close();
114
115       XAQueueConnectionFactory JavaDoc xacf = new SpyXAConnectionFactory(props);
116       XAQueueConnection JavaDoc xac = xacf.createXAQueueConnection();
117       xac.close();
118    }
119    public void testOverriddenUIL2ConnectViaJNDI() throws Exception JavaDoc
120    {
121       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
122
123       SpyConnectionFactory cf = (SpyConnectionFactory) ctx.lookup("OverriddenUIL2ConnectionFactory");
124       Properties JavaDoc props = cf.getProperties();
125       String JavaDoc value = props.getProperty(UILServerILFactory.UIL_CONNECTADDRESS_KEY);
126       assertEquals("Overridden Address", value);
127       value = props.getProperty(UILServerILFactory.UIL_CONNECTPORT_KEY);
128       assertEquals("-1000", value);
129       
130       cf = (SpyConnectionFactory) ctx.lookup("OverriddenUIL2XAConnectionFactory");
131       props = cf.getProperties();
132       value = props.getProperty(UILServerILFactory.UIL_CONNECTADDRESS_KEY);
133       assertEquals("Overridden Address", value);
134       value = props.getProperty(UILServerILFactory.UIL_CONNECTPORT_KEY);
135       assertEquals("-1000", value);
136    }
137
138    public static Test suite() throws Exception JavaDoc
139    {
140       return getDeploySetup(UIL2ConnectionUnitTestCase.class, "overridden-uil2-service.xml");
141    }
142
143    public static void main(java.lang.String JavaDoc[] args)
144    {
145       TestRunner.run(UIL2ConnectionUnitTestCase.class);
146    }
147 }
148
Popular Tags