1 24 25 package org.objectweb.jtests.jms.conform.session; 26 27 import org.objectweb.jtests.jms.framework.*; 28 import junit.framework.*; 29 30 import javax.jms.*; 31 32 40 public class QueueSessionTest extends PTPTestCase { 41 42 46 public void testRollbackRececeivedMessage() { 47 try { 48 senderConnection.stop(); 49 senderSession = senderConnection.createQueueSession(true, 0); 52 assertEquals(true, senderSession.getTransacted()); 53 sender = senderSession.createSender(senderQueue); 55 senderConnection.start(); 56 57 receiverConnection.stop(); 58 receiverSession = receiverConnection.createQueueSession(true,0); 61 assertEquals(true, receiverSession.getTransacted()); 62 receiver = receiverSession.createReceiver(receiverQueue); 64 receiverConnection.start(); 65 66 TextMessage message = senderSession.createTextMessage(); 68 message.setText("testRollbackRececeivedMessage"); 69 sender.send(message); 70 senderSession.commit(); 72 73 Message m = receiver.receive(TestConfig.TIMEOUT); 75 assertTrue(m != null); 76 assertTrue(m instanceof TextMessage); 77 TextMessage msg = (TextMessage)m; 78 assertEquals("testRollbackRececeivedMessage", msg.getText()); 80 assertEquals(false, msg.getJMSRedelivered()); 82 83 receiverSession.rollback(); 85 86 m = receiver.receive(TestConfig.TIMEOUT); 88 assertTrue(m != null); 89 assertTrue(m instanceof TextMessage); 90 msg = (TextMessage)m; 91 assertEquals("testRollbackRececeivedMessage", msg.getText()); 93 assertEquals(true, msg.getJMSRedelivered()); 95 96 } catch (Exception e) { 97 fail(e); 98 } 99 } 100 101 105 public void testCreateBrowser_2() { 106 try { 107 QueueBrowser browser = senderSession.createBrowser(senderQueue, 108 "definitely not a message selector!"); 109 fail("Should throw a javax.jms.InvalidSelectorException.\n"); 110 } catch (InvalidSelectorException e) { 111 } catch (JMSException e) { 112 fail("Should throw a javax.jms.InvalidSelectorException, not a "+ e); 113 } 114 } 115 116 120 public void testCreateBrowser_1() { 121 try { 122 QueueBrowser browser = senderSession.createBrowser((Queue)null); 123 fail("Should throw a javax.jms.InvalidDestinationException.\n"); 124 } catch (InvalidDestinationException e) { 125 } catch (JMSException e) { 126 fail("Should throw a javax.jms.InvalidDestinationException, not a "+ e); 127 } 128 } 129 130 134 public void testCreateReceiver_2() { 135 try { 136 receiver = senderSession.createReceiver(senderQueue, 137 "definitely not a message selector!"); 138 fail("Should throw a javax.jms.InvalidSelectorException.\n"); 139 } catch (InvalidSelectorException e) { 140 } catch (JMSException e) { 141 fail("Should throw a javax.jms.InvalidSelectorException, not a "+ e); 142 } 143 } 144 145 149 public void testCreateReceiver_1() { 150 try { 151 receiver = senderSession.createReceiver((Queue)null); 152 fail("Should throw a javax.jms.InvalidDestinationException.\n"); 153 } catch (InvalidDestinationException e) { 154 } catch (JMSException e) { 155 fail("Should throw a javax.jms.InvalidDestinationException, not a "+ e); 156 } 157 } 158 159 162 public static Test suite() { 163 return new TestSuite(QueueSessionTest.class); 164 } 165 166 public QueueSessionTest(String name) { 167 super(name); 168 } 169 } 170 | Popular Tags |