1 16 package org.springframework.jms.connection; 17 18 import javax.jms.Connection ; 19 import javax.jms.ConnectionFactory ; 20 import javax.jms.JMSException ; 21 import javax.jms.QueueConnection ; 22 import javax.jms.QueueConnectionFactory ; 23 import javax.jms.TopicConnection ; 24 import javax.jms.TopicConnectionFactory ; 25 26 import junit.framework.TestCase; 27 import org.easymock.MockControl; 28 29 33 public class SingleConnectionFactoryTests extends TestCase { 34 35 public void testWithConnection() throws JMSException { 36 MockControl conControl = MockControl.createControl(Connection .class); 37 Connection con = (Connection ) conControl.getMock(); 38 39 con.start(); 40 conControl.setVoidCallable(2); 41 con.close(); 42 conControl.setVoidCallable(1); 43 44 conControl.replay(); 45 46 SingleConnectionFactory scf = new SingleConnectionFactory(con); 47 Connection con1 = scf.createConnection(); 48 con1.start(); 49 con1.close(); Connection con2 = scf.createConnection(); 51 con2.start(); 52 con2.close(); scf.destroy(); 55 conControl.verify(); 56 } 57 58 public void testWithQueueConnection() throws JMSException { 59 MockControl conControl = MockControl.createControl(QueueConnection .class); 60 Connection con = (QueueConnection ) conControl.getMock(); 61 62 con.start(); 63 conControl.setVoidCallable(2); 64 con.close(); 65 conControl.setVoidCallable(1); 66 67 conControl.replay(); 68 69 SingleConnectionFactory scf = new SingleConnectionFactory(con); 70 QueueConnection con1 = scf.createQueueConnection(); 71 con1.start(); 72 con1.close(); QueueConnection con2 = scf.createQueueConnection(); 74 con2.start(); 75 con2.close(); scf.destroy(); 78 conControl.verify(); 79 } 80 81 public void testWithTopicConnection() throws JMSException { 82 MockControl conControl = MockControl.createControl(TopicConnection .class); 83 Connection con = (TopicConnection ) conControl.getMock(); 84 85 con.start(); 86 conControl.setVoidCallable(2); 87 con.close(); 88 conControl.setVoidCallable(1); 89 90 conControl.replay(); 91 92 SingleConnectionFactory scf = new SingleConnectionFactory(con); 93 TopicConnection con1 = scf.createTopicConnection(); 94 con1.start(); 95 con1.close(); TopicConnection con2 = scf.createTopicConnection(); 97 con2.start(); 98 con2.close(); scf.destroy(); 101 conControl.verify(); 102 } 103 104 public void testWithConnectionFactory() throws JMSException { 105 MockControl cfControl = MockControl.createControl(ConnectionFactory .class); 106 ConnectionFactory cf = (ConnectionFactory ) cfControl.getMock(); 107 MockControl conControl = MockControl.createControl(Connection .class); 108 Connection con = (Connection ) conControl.getMock(); 109 110 cf.createConnection(); 111 cfControl.setReturnValue(con, 1); 112 con.start(); 113 conControl.setVoidCallable(2); 114 con.close(); 115 conControl.setVoidCallable(1); 116 117 cfControl.replay(); 118 conControl.replay(); 119 120 SingleConnectionFactory scf = new SingleConnectionFactory(cf); 121 Connection con1 = scf.createConnection(); 122 con1.start(); 123 con1.close(); Connection con2 = scf.createConnection(); 125 con2.start(); 126 con2.close(); scf.destroy(); 129 cfControl.verify(); 130 conControl.verify(); 131 } 132 133 public void testConnectionFactory102WithQueue() throws JMSException { 134 MockControl cfControl = MockControl.createControl(QueueConnectionFactory .class); 135 QueueConnectionFactory cf = (QueueConnectionFactory ) cfControl.getMock(); 136 MockControl conControl = MockControl.createControl(QueueConnection .class); 137 QueueConnection con = (QueueConnection ) conControl.getMock(); 138 139 cf.createQueueConnection(); 140 cfControl.setReturnValue(con, 1); 141 con.start(); 142 conControl.setVoidCallable(2); 143 con.close(); 144 conControl.setVoidCallable(1); 145 146 cfControl.replay(); 147 conControl.replay(); 148 149 SingleConnectionFactory scf = new SingleConnectionFactory102(cf, false); 150 QueueConnection con1 = scf.createQueueConnection(); 151 con1.start(); 152 con1.close(); QueueConnection con2 = scf.createQueueConnection(); 154 con2.start(); 155 con2.close(); scf.destroy(); 158 cfControl.verify(); 159 conControl.verify(); 160 } 161 162 public void testConnectionFactory102WithTopic() throws JMSException { 163 MockControl cfControl = MockControl.createControl(TopicConnectionFactory .class); 164 TopicConnectionFactory cf = (TopicConnectionFactory ) cfControl.getMock(); 165 MockControl conControl = MockControl.createControl(TopicConnection .class); 166 TopicConnection con = (TopicConnection ) conControl.getMock(); 167 168 cf.createTopicConnection(); 169 cfControl.setReturnValue(con, 1); 170 con.start(); 171 conControl.setVoidCallable(2); 172 con.close(); 173 conControl.setVoidCallable(1); 174 175 cfControl.replay(); 176 conControl.replay(); 177 178 SingleConnectionFactory scf = new SingleConnectionFactory102(cf, true); 179 TopicConnection con1 = scf.createTopicConnection(); 180 con1.start(); 181 con1.close(); TopicConnection con2 = scf.createTopicConnection(); 183 con2.start(); 184 con2.close(); scf.destroy(); 187 cfControl.verify(); 188 conControl.verify(); 189 } 190 191 } 192 | Popular Tags |