1 22 package org.jboss.test.jbossmq.test; 23 24 import java.util.Properties ; 25 26 import javax.jms.QueueConnection ; 27 import javax.jms.QueueConnectionFactory ; 28 import javax.jms.XAQueueConnection ; 29 import javax.jms.XAQueueConnectionFactory ; 30 import javax.naming.InitialContext ; 31 import javax.security.auth.login.LoginContext ; 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 47 public class HTTPConnectionUnitTestCase extends JBossTestCase 48 { 49 50 public HTTPConnectionUnitTestCase(String name) 51 { 52 super(name); 53 } 54 55 protected void setUp() throws Exception 56 { 57 } 58 59 public void testMultipleHTTPConnectViaJNDI() throws Exception 60 { 61 62 getLog().debug("Starting testMultipleHTTPConnectViaJNDI"); 63 64 InitialContext ctx = new InitialContext (); 65 66 QueueConnectionFactory cf = (QueueConnectionFactory ) ctx.lookup("HTTPConnectionFactory"); 67 68 QueueConnection connections[] = new QueueConnection [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 86 { 87 InitialContext ctx = new InitialContext (); 88 89 QueueConnectionFactory cf = (QueueConnectionFactory ) ctx.lookup("HTTPConnectionFactory"); 90 QueueConnection c = cf.createQueueConnection(); 91 c.close(); 92 93 XAQueueConnectionFactory xacf = (XAQueueConnectionFactory ) ctx.lookup("HTTPXAConnectionFactory"); 94 XAQueueConnection xac = xacf.createXAQueueConnection(); 95 xac.close(); 96 } 97 98 public void testHTTPConnectNoJNDI() throws Exception 99 { 100 101 Properties props = new Properties (); 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 cf = new SpyConnectionFactory(props); 110 QueueConnection c = cf.createQueueConnection(); 111 c.close(); 112 113 XAQueueConnectionFactory xacf = new SpyXAConnectionFactory(props); 114 XAQueueConnection xac = xacf.createXAQueueConnection(); 115 xac.close(); 116 } 117 118 public void testHTTPConnectNoJNDIWithBasicAuthentication() throws Exception 119 { 120 121 String 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 lc = new LoginContext ("other", handler); 126 lc.login(); 127 129 Properties props = new Properties (); 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 cf = new SpyConnectionFactory(props); 138 QueueConnection c = cf.createQueueConnection(); 139 c.close(); 140 141 XAQueueConnectionFactory xacf = new SpyXAConnectionFactory(props); 142 XAQueueConnection xac = xacf.createXAQueueConnection(); 143 xac.close(); 144 lc.logout(); } 146 147 public static void main(java.lang.String [] args) 148 { 149 junit.textui.TestRunner.run(HTTPConnectionUnitTestCase.class); 150 } 151 } 152 | Popular Tags |