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 SessionTest extends PTPTestCase { 41 42 47 public void testRecoverTransactedSession() { 48 try { 49 assertEquals(false, senderSession.getTransacted()); 51 senderSession = senderConnection.createQueueSession(true, 0); 53 assertEquals(true, senderSession.getTransacted()); 54 senderSession.recover(); 55 fail("Should raise an IllegalStateException, the session is not transacted.\n"); 56 } catch (javax.jms.IllegalStateException e) { 57 } catch (java.lang.IllegalStateException e) { 58 fail ("Should raise a javax.jms.IllegalStateException, not a java.lang.IllegalStateException.\n"); 59 } catch (Exception e) { 60 fail("Should raise a javax.jms.IllegalStateException, not a "+ e); 61 } 62 } 63 64 69 public void testRollbackTransactedSession() { 70 try { 71 senderSession = senderConnection.createQueueSession(true, 0); 73 sender = senderSession.createSender(senderQueue); 74 assertEquals(true, senderSession.getTransacted()); 75 76 TextMessage message = senderSession.createTextMessage(); 77 message.setText("testRollbackTransactedSession"); 78 sender.send (message); 80 81 senderSession.rollback(); 83 84 TextMessage m = (TextMessage) receiver.receiveNoWait(); 85 assertEquals(null, m); 87 } catch (Exception e) { 88 fail(e); 89 } 90 } 91 92 97 public void testCommitTransactedSession() { 98 try { 99 senderSession = senderConnection.createQueueSession(true, 0); 101 sender = senderSession.createSender(senderQueue); 102 assertEquals(true, senderSession.getTransacted()); 103 104 TextMessage message = senderSession.createTextMessage(); 105 message.setText("testCommitTransactedSession"); 106 sender.send (message); 108 109 TextMessage m = (TextMessage) receiver.receiveNoWait(); 110 assertEquals(null,m); 112 113 senderSession.commit(); 115 116 m = (TextMessage) receiver.receive(TestConfig.TIMEOUT); 117 assertTrue(m != null); 118 assertEquals("testCommitTransactedSession", m.getText()); 119 } catch (Exception e) { 120 fail(e); 121 } 122 } 123 124 129 public void testRollbackNonTransactedSession() { 130 try { 131 assertEquals(false, senderSession.getTransacted()); 133 senderSession.rollback(); 134 fail("Should raise an IllegalStateException, the session is not transacted.\n"); 135 } catch (javax.jms.IllegalStateException e) { 136 } catch (java.lang.IllegalStateException e) { 137 fail ("Should raise a javax.jms.IllegalStateException, not a java.lang.IllegalStateException.\n"); 138 } catch (Exception e) { 139 fail("Should raise a javax.jms.IllegalStateException, not a "+ e); 140 } 141 } 142 143 148 public void testCommitNonTransactedSession() { 149 try { 150 assertEquals(false, senderSession.getTransacted()); 152 senderSession.commit(); 153 fail("Should raise an IllegalStateException, the session is not transacted.\n"); 154 } catch (javax.jms.IllegalStateException e) { 155 } catch (java.lang.IllegalStateException e) { 156 fail ("Should raise a javax.jms.IllegalStateException, not a java.lang.IllegalStateException.\n"); 157 } catch (Exception e) { 158 fail("Should raise a javax.jms.IllegalStateException, not a "+ e); 159 } 160 } 161 162 166 public void testGetTransacted() { 167 try { 168 assertEquals(false, senderSession.getTransacted()); 170 senderSession = senderConnection.createQueueSession(true, Session.AUTO_ACKNOWLEDGE); 172 assertEquals(true, senderSession.getTransacted()); 173 } catch (Exception e) { 174 fail(e); 175 } 176 } 177 178 179 183 public void testAcknowledge() { 184 try { 185 receiverSession = receiverConnection.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE); 186 receiver = receiverSession.createReceiver(receiverQueue); 187 188 Message message = senderSession.createMessage(); 189 sender.send(message); 190 191 Message m = receiver.receive(TestConfig.TIMEOUT); 192 receiverSession.close(); 193 m.acknowledge(); 194 fail("§4.4.1 Invoking the acknowledge method of a received message from a closed "+ 195 " session must throw an [javax.jms.]IllegalStateException.\n"); 196 } catch (javax.jms.IllegalStateException e) { 197 } catch (JMSException e) { 198 fail("Should raise a javax.jms.IllegalStateException, not a "+ e); 199 } catch (java.lang.IllegalStateException e) { 200 fail("§4.4.1 Invoking the acknowledge method of a received message from a closed "+ 201 "session must throw an [javax.jms.]IllegalStateException, "+ 202 "[not a java.lang.IllegalStateException]"); 203 } 204 } 205 206 210 public void testUseMessage() { 211 try { 212 TextMessage message = senderSession.createTextMessage(); 213 message.setText("testUseMessage"); 214 sender.send(message); 215 216 TextMessage m = (TextMessage)receiver.receive(TestConfig.TIMEOUT); 217 receiverSession.close(); 218 assertEquals("testUseMessage", m.getText()); 219 } catch (Exception e) { 220 fail("§4.4.1 It is valid to continue to use message objects created or received via "+ 221 "the [closed] session.\n"); 222 } 223 } 224 225 229 public void testUsedClosedSession() { 230 try { 231 senderSession.close(); 232 senderSession.createMessage(); 233 fail ("§4.4.1 An attempt to use [a closed session] must throw a [javax.jms.]IllegalStateException.\n"); 234 } catch (javax.jms.IllegalStateException e) { 235 } catch (JMSException e) { 236 fail("Should raise a javax.jms.IllegalStateException, not a "+ e); 237 } catch (java.lang.IllegalStateException e) { 238 fail("Should raise a javax.jms.IllegalStateException, not a java.lang.IllegalStateException"); 239 } 240 } 241 242 246 public void testCloseClosedSession() { 247 try { 248 senderSession.close(); 251 senderSession.close(); 253 } catch (Exception e) { 254 fail("§4.4.1 Closing a closed session must NOT throw an exception.\n"); 255 } 256 } 257 258 261 public static Test suite() { 262 return new TestSuite(SessionTest.class); 263 } 264 265 public SessionTest(String name) { 266 super(name); 267 } 268 } 269 | Popular Tags |