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 46 public class PTPTestCase extends JMSTestCase { 47 48 protected Admin admin; 49 protected InitialContext ctx; 50 private static final String QCF_NAME = "testQCF"; 51 private static final String QUEUE_NAME = "testQueue"; 52 53 56 protected Queue senderQueue; 57 58 61 protected QueueSender sender; 62 63 66 protected QueueConnectionFactory senderQCF; 67 68 71 protected QueueConnection senderConnection; 72 73 76 protected QueueSession senderSession; 77 78 81 protected Queue receiverQueue; 82 83 86 protected QueueReceiver receiver; 87 88 91 protected QueueConnectionFactory receiverQCF; 92 93 96 protected QueueConnection receiverConnection; 97 98 101 protected QueueSession receiverSession; 102 103 108 protected void setUp() { 109 try { 110 admin = AdminFactory.getAdmin(); 113 admin.createQueueConnectionFactory(QCF_NAME); 115 admin.createQueue(QUEUE_NAME); 116 117 ctx = admin.createInitialContext(); 119 120 senderQCF = (QueueConnectionFactory)ctx.lookup(QCF_NAME); 121 senderQueue = (Queue)ctx.lookup(QUEUE_NAME); 122 senderConnection = senderQCF.createQueueConnection(); 123 senderSession = senderConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); 124 sender = senderSession.createSender(senderQueue); 125 126 receiverQCF = (QueueConnectionFactory)ctx.lookup(QCF_NAME); 127 receiverQueue = (Queue)ctx.lookup(QUEUE_NAME); 128 receiverConnection = receiverQCF.createQueueConnection(); 129 receiverSession = receiverConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); 130 receiver = receiverSession.createReceiver(receiverQueue); 131 132 senderConnection.start(); 133 receiverConnection.start(); 134 } catch (Exception e) { 136 e.printStackTrace(); 138 } 139 } 140 141 144 protected void tearDown() { 145 try { 146 senderConnection.close(); 147 receiverConnection.close(); 148 149 admin.deleteQueueConnectionFactory(QCF_NAME); 150 admin.deleteQueue(QUEUE_NAME); 151 152 ctx.close(); 153 } catch (Exception e) { 154 e.printStackTrace(); 156 } finally { 157 senderQueue = null; 158 sender = null; 159 senderQCF = null; 160 senderSession = null; 161 senderConnection = null; 162 163 receiverQueue = null; 164 receiver = null; 165 receiverQCF = null; 166 receiverSession = null; 167 receiverConnection = null; 168 } 169 } 170 171 public PTPTestCase(String name) { 172 super(name); 173 } 174 } 175 | Popular Tags |