KickJava   Java API By Example, From Geeks To Geeks.

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


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 import javax.security.auth.login.LoginContext JavaDoc;
32
33 import org.jboss.mq.SpyConnectionFactory;
34 import org.jboss.mq.SpyXAConnectionFactory;
35 import org.jboss.mq.il.http.HTTPServerILFactory;
36 import org.jboss.test.JBossTestCase;
37 import org.jboss.test.util.AppCallbackHandler;
38
39 /**
40  * Test all the verious ways that a connection can be
41  * established with JBossMQ
42  *
43  * @author hiram.chirino@jboss.org
44  * @author Scott.Stark@jboss.org
45  * @version $Revision: 37406 $
46  */

47 public class HTTPConnectionUnitTestCase extends JBossTestCase
48 {
49
50    public HTTPConnectionUnitTestCase(String JavaDoc name)
51    {
52       super(name);
53    }
54
55    protected void setUp() throws Exception JavaDoc
56    {
57    }
58
59    public void testMultipleHTTPConnectViaJNDI() throws Exception JavaDoc
60    {
61
62       getLog().debug("Starting testMultipleHTTPConnectViaJNDI");
63
64       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
65
66       QueueConnectionFactory JavaDoc cf = (QueueConnectionFactory JavaDoc) ctx.lookup("HTTPConnectionFactory");
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 testMultipleHTTPConnectViaJNDI");
83    }
84
85    public void testHTTPConnectViaJNDI() throws Exception JavaDoc
86    {
87       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
88
89       QueueConnectionFactory JavaDoc cf = (QueueConnectionFactory JavaDoc) ctx.lookup("HTTPConnectionFactory");
90       QueueConnection JavaDoc c = cf.createQueueConnection();
91       c.close();
92
93       XAQueueConnectionFactory JavaDoc xacf = (XAQueueConnectionFactory JavaDoc) ctx.lookup("HTTPXAConnectionFactory");
94       XAQueueConnection JavaDoc xac = xacf.createXAQueueConnection();
95       xac.close();
96    }
97
98    public void testHTTPConnectNoJNDI() throws Exception JavaDoc
99    {
100
101       Properties JavaDoc props = new Properties JavaDoc();
102       props.setProperty(HTTPServerILFactory.SERVER_IL_FACTORY_KEY, HTTPServerILFactory.SERVER_IL_FACTORY);
103       props.setProperty(HTTPServerILFactory.CLIENT_IL_SERVICE_KEY, HTTPServerILFactory.CLIENT_IL_SERVICE);
104       props.setProperty(HTTPServerILFactory.SERVER_URL_KEY, "http://localhost:8080/jbossmq-httpil/HTTPServerILServlet");
105       props.setProperty(HTTPServerILFactory.PING_PERIOD_KEY, "0");
106       props.setProperty(HTTPServerILFactory.TIMEOUT_KEY, "60");
107       props.setProperty(HTTPServerILFactory.REST_INTERVAL_KEY, "1");
108
109       QueueConnectionFactory JavaDoc cf = new SpyConnectionFactory(props);
110       QueueConnection JavaDoc c = cf.createQueueConnection();
111       c.close();
112
113       XAQueueConnectionFactory JavaDoc xacf = new SpyXAConnectionFactory(props);
114       XAQueueConnection JavaDoc xac = xacf.createXAQueueConnection();
115       xac.close();
116    }
117
118    public void testHTTPConnectNoJNDIWithBasicAuthentication() throws Exception JavaDoc
119    {
120
121       ////////////////////THIS IS HOW YOU HANDLE SECURITY ////////////////////
122
String JavaDoc authConf = super.getResourceURL("security/auth.conf");
123       System.setProperty("java.security.auth.login.config", authConf);
124       AppCallbackHandler handler = new AppCallbackHandler("guest", "guest".toCharArray());
125       LoginContext JavaDoc lc = new LoginContext JavaDoc("other", handler);
126       lc.login();
127       ////////////////////////////////////////////////////////////////////////
128

129       Properties JavaDoc props = new Properties JavaDoc();
130       props.setProperty(HTTPServerILFactory.SERVER_IL_FACTORY_KEY, HTTPServerILFactory.SERVER_IL_FACTORY);
131       props.setProperty(HTTPServerILFactory.CLIENT_IL_SERVICE_KEY, HTTPServerILFactory.CLIENT_IL_SERVICE);
132       props.setProperty(HTTPServerILFactory.SERVER_URL_KEY, "http://localhost:8080/jbossmq-httpil/restricted/HTTPServerILServlet");
133       props.setProperty(HTTPServerILFactory.PING_PERIOD_KEY, "0");
134       props.setProperty(HTTPServerILFactory.TIMEOUT_KEY, "60");
135       props.setProperty(HTTPServerILFactory.REST_INTERVAL_KEY, "1");
136
137       QueueConnectionFactory JavaDoc cf = new SpyConnectionFactory(props);
138       QueueConnection JavaDoc c = cf.createQueueConnection();
139       c.close();
140
141       XAQueueConnectionFactory JavaDoc xacf = new SpyXAConnectionFactory(props);
142       XAQueueConnection JavaDoc xac = xacf.createXAQueueConnection();
143       xac.close();
144       lc.logout(); // Log out.
145
}
146
147    public static void main(java.lang.String JavaDoc[] args)
148    {
149       junit.textui.TestRunner.run(HTTPConnectionUnitTestCase.class);
150    }
151 }
152
Popular Tags