1 24 25 package org.objectweb.jtests.jms.framework; 26 27 import org.objectweb.jtests.jms.admin.*; 28 29 import junit.framework.*; 30 import javax.naming.*; 31 import javax.jms.*; 32 33 47 public class UnifiedTestCase extends JMSTestCase { 48 49 protected Admin admin; 50 protected InitialContext ctx; 51 private static final String CF_NAME = "testCF"; 52 private static final String TCF_NAME = "testTCF"; 53 private static final String QCF_NAME = "testQCF"; 54 private static final String DESTINATION_NAME = "testDestination"; 55 private static final String QUEUE_NAME = "testQueue"; 56 private static final String TOPIC_NAME = "testTopic"; 57 58 62 65 protected Destination producerDestination; 66 67 70 protected MessageProducer producer; 71 72 75 protected ConnectionFactory producerCF; 76 77 80 protected Connection producerConnection; 81 82 85 protected Session producerSession; 86 87 90 protected Destination consumerDestination; 91 92 95 protected MessageConsumer consumer; 96 97 100 protected ConnectionFactory consumerCF; 101 102 105 protected Connection consumerConnection; 106 107 110 protected Session consumerSession; 111 112 116 119 protected QueueConnectionFactory queueConnectionFactory; 120 121 124 protected Queue queue; 125 126 130 133 protected TopicConnectionFactory topicConnectionFactory; 134 135 138 protected Topic topic; 139 140 145 protected void setUp() { 146 try { 147 admin = AdminFactory.getAdmin(); 150 admin.createConnectionFactory(CF_NAME); 152 admin.createQueueConnectionFactory(QCF_NAME); 153 admin.createTopicConnectionFactory(TCF_NAME); 154 admin.createQueue(DESTINATION_NAME); 156 admin.createQueue(QUEUE_NAME); 157 admin.createTopic(TOPIC_NAME); 158 159 ctx = admin.createInitialContext(); 161 162 producerCF = (ConnectionFactory)ctx.lookup(CF_NAME); 163 producerDestination = (Destination)ctx.lookup(DESTINATION_NAME); 166 producerConnection = producerCF.createConnection(); 167 producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); 168 producer = producerSession.createProducer(producerDestination); 169 170 consumerCF = (ConnectionFactory)ctx.lookup(CF_NAME); 171 consumerDestination = (Destination)ctx.lookup(DESTINATION_NAME); 174 consumerConnection = consumerCF.createConnection(); 175 consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); 176 consumer = consumerSession.createConsumer(consumerDestination); 177 178 queueConnectionFactory = (QueueConnectionFactory)ctx.lookup(QCF_NAME); 179 queue = (Queue)ctx.lookup(QUEUE_NAME); 180 181 topicConnectionFactory = (TopicConnectionFactory)ctx.lookup(TCF_NAME); 182 topic = (Topic)ctx.lookup(TOPIC_NAME); 183 184 producerConnection.start(); 185 consumerConnection.start(); 186 } catch (Exception e) { 188 e.printStackTrace(); 190 } 191 } 192 193 196 protected void tearDown() { 197 try { 198 consumerConnection.close(); 199 producerConnection.close(); 200 201 admin.deleteConnectionFactory(CF_NAME); 202 admin.deleteQueueConnectionFactory(QCF_NAME); 203 admin.deleteTopicConnectionFactory(TCF_NAME); 204 admin.deleteQueue(DESTINATION_NAME); 205 admin.deleteQueue(QUEUE_NAME); 206 admin.deleteTopic(TOPIC_NAME); 207 208 ctx.close(); 209 } catch (Exception e) { 210 e.printStackTrace(); 212 } finally { 213 producerDestination = null; 214 producer = null; 215 producerCF = null; 216 producerSession = null; 217 producerConnection = null; 218 219 consumerDestination = null; 220 consumer = null; 221 consumerCF = null; 222 consumerSession = null; 223 consumerConnection = null; 224 225 queueConnectionFactory = null; 226 queue = null; 227 228 topicConnectionFactory = null; 229 topic = null; 230 } 231 } 232 233 public UnifiedTestCase(String name) { 234 super(name); 235 } 236 } 237 | Popular Tags |