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 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 47 public class UIL2ConnectionUnitTestCase extends JBossTestCase 48 { 49 50 public UIL2ConnectionUnitTestCase(String name) 51 { 52 super(name); 53 } 54 55 protected void setUp() throws Exception 56 { 57 } 58 59 public void testMultipleUIL2ConnectViaJNDI() throws Exception 60 { 61 62 getLog().debug("Starting testMultipleUIL2ConnectViaJNDI"); 63 64 InitialContext ctx = new InitialContext (); 65 66 QueueConnectionFactory cf = (QueueConnectionFactory ) ctx.lookup("UIL2ConnectionFactory"); 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 testMultipleUIL2ConnectViaJNDI"); 83 } 84 85 public void testUIL2ConnectViaJNDI() throws Exception 86 { 87 InitialContext ctx = new InitialContext (); 88 89 QueueConnectionFactory cf = (QueueConnectionFactory ) ctx.lookup("UIL2ConnectionFactory"); 90 QueueConnection c = cf.createQueueConnection(); 91 c.close(); 92 93 XAQueueConnectionFactory xacf = (XAQueueConnectionFactory ) ctx.lookup("UIL2XAConnectionFactory"); 94 XAQueueConnection xac = xacf.createXAQueueConnection(); 95 xac.close(); 96 } 97 98 public void testUIL2ConnectNoJNDI() throws Exception 99 { 100 101 Properties props = new Properties (); 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 cf = new SpyConnectionFactory(props); 112 QueueConnection c = cf.createQueueConnection(); 113 c.close(); 114 115 XAQueueConnectionFactory xacf = new SpyXAConnectionFactory(props); 116 XAQueueConnection xac = xacf.createXAQueueConnection(); 117 xac.close(); 118 } 119 public void testOverriddenUIL2ConnectViaJNDI() throws Exception 120 { 121 InitialContext ctx = new InitialContext (); 122 123 SpyConnectionFactory cf = (SpyConnectionFactory) ctx.lookup("OverriddenUIL2ConnectionFactory"); 124 Properties props = cf.getProperties(); 125 String 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 139 { 140 return getDeploySetup(UIL2ConnectionUnitTestCase.class, "overridden-uil2-service.xml"); 141 } 142 143 public static void main(java.lang.String [] args) 144 { 145 TestRunner.run(UIL2ConnectionUnitTestCase.class); 146 } 147 } 148 | Popular Tags |