1 22 package org.jboss.test.jbossmessaging.ra; 23 24 import javax.jms.Connection ; 25 import javax.jms.Message ; 26 27 import javax.jms.QueueConnection ; 28 import javax.jms.QueueConnectionFactory ; 29 import javax.jms.QueueSender ; 30 import javax.jms.QueueSession ; 31 import javax.jms.Session ; 32 import javax.jms.TextMessage ; 33 import javax.jms.Queue ; 34 import javax.naming.Context ; 35 36 import javax.management.ObjectName ; 37 38 import javax.naming.InitialContext ; 39 import junit.framework.Assert; 40 41 import junit.framework.Test; 42 43 import org.jboss.test.jbossmessaging.JMSTestCase; 44 import org.jboss.test.JBossTestSetup; 45 46 import org.jboss.test.jmsra.bean.*; 47 48 58 59 public class RaSyncRecUnitTestCase extends JMSTestCase { 60 61 private final static String BEAN_JNDI = "QueueRec"; 62 private final static String QUEUE_FACTORY = "ConnectionFactory"; 63 private final static String QUEUE = "queue/A"; 64 private final static int MESSAGE_NR = 10; 65 66 69 protected QueueConnection connection; 70 73 protected QueueSession session; 74 77 protected QueueSender sender; 78 79 82 protected QueueRec rec; 83 84 91 public RaSyncRecUnitTestCase(String name) { 92 super(name); 93 } 94 95 100 protected void setUp() throws Exception 101 { 102 super.setUp() ; 104 105 Context context = getInitialContext(); 107 try 108 { 109 QueueRecHome home = (QueueRecHome)context.lookup(BEAN_JNDI); 110 rec = home.create(); 111 112 init(context); 113 } 114 finally 115 { 116 context.close(); 117 } 118 119 connection.start(); 121 122 } 123 124 130 protected void init(final Context context) throws Exception 131 { 132 QueueConnectionFactory factory = 133 (QueueConnectionFactory )context.lookup(QUEUE_FACTORY); 134 135 connection = factory.createQueueConnection(); 136 137 session = ((QueueConnection )connection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE); 138 139 Queue queue = (Queue )context.lookup(QUEUE); 140 141 sender = ((QueueSession )session).createSender(queue); 142 } 143 144 149 protected void tearDown() throws Exception 150 { 151 if (sender != null) 152 { 153 sender.close(); 154 } 155 if (session != null) { 156 session.close(); 157 } 158 if (connection != null) 159 { 160 connection.close(); 161 } 162 163 super.tearDown() ; 165 } 166 167 170 public void testSyncRec() throws Exception { 171 TextMessage message = session.createTextMessage(); 173 message.setText(String.valueOf(MESSAGE_NR)); 174 message.setIntProperty(Publisher.JMS_MESSAGE_NR, MESSAGE_NR); 175 sender.send(message); 176 getLog().debug("sent message with nr = " + MESSAGE_NR); 177 178 int res = rec.getMessage(); 180 Assert.assertEquals(MESSAGE_NR, res); 181 getLog().debug("testSyncRec() OK"); 182 } 183 184 public static Test suite() throws Exception 185 { 186 return new JBossTestSetup(getDeploySetup(RaSyncRecUnitTestCase.class, "jmsra.jar")) 187 { 188 protected void setUp() throws Exception 189 { 190 super.setUp(); 191 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 192 String resourceName = getJMSResourceRelativePathname("test-destinations-full-service.xml") ; 193 deploy (loader.getResource(resourceName).toString()); 194 } 195 196 protected void tearDown() throws Exception 197 { 198 super.tearDown(); 199 200 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 210 String resourceName = getJMSResourceRelativePathname("test-destinations-full-service.xml") ; 211 undeploy (loader.getResource(resourceName).toString()); 212 } 213 }; 214 } 215 } 217 218 219 220 221 | Popular Tags |