1 24 25 package org.objectweb.jtests.jms.conform.connection; 26 27 import org.objectweb.jtests.jms.framework.PTPTestCase; 28 import org.objectweb.jtests.jms.framework.TestConfig; 29 import javax.jms.*; 30 import junit.framework.*; 31 32 40 public class ConnectionTest extends PTPTestCase { 41 42 46 public void testAcknowledge() { 47 try { 48 receiverConnection.stop(); 49 receiverSession = receiverConnection.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE); 50 receiver = receiverSession.createReceiver(receiverQueue); 51 receiverConnection.start(); 52 53 Message message = senderSession.createMessage(); 54 sender.send(message); 55 56 Message m = receiver.receive(TestConfig.TIMEOUT); 57 receiverConnection.close(); 58 m.acknowledge(); 59 fail("§4.3.5 Invoking the acknowledge method of a received message from a closed "+ 60 "connection's session must throw a [javax.jms.]IllegalStateException.\n"); 61 } catch (javax.jms.IllegalStateException e) { 62 } catch (JMSException e) { 63 fail("§4.3.5 Invoking the acknowledge method of a received message from a closed "+ 64 "connection's session must throw a [javax.jms.]IllegalStateException, not a "+ e); 65 } catch (java.lang.IllegalStateException e) { 66 fail("§4.3.5 Invoking the acknowledge method of a received message from a closed "+ 67 "connection's session must throw an [javax.jms.]IllegalStateException "+ 68 "[not a java.lang.IllegalStateException]"); 69 } 70 } 71 72 76 public void testUseClosedConnection() { 77 try { 78 senderConnection.close(); 79 senderConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); 80 fail("Should raise a javax.jms.IllegalStateException"); 81 } catch (javax.jms.IllegalStateException e) { 82 } catch (JMSException e) { 83 fail("Should raise a javax.jms.IllegalStateException, not a "+ e); 84 } catch (java.lang.IllegalStateException e) { 85 fail("Should raise a javax.jms.IllegalStateException, not a java.lang.IllegalStateException"); 86 } 87 } 88 89 93 public void testMessageSentWhenConnectionClosed() { 94 try { 95 senderConnection.stop(); 96 Message message = senderSession.createTextMessage(); 97 sender.send(message); 98 99 Message m = receiver.receive(TestConfig.TIMEOUT); 100 } catch (JMSException e) { 101 fail(e); 102 } 103 } 104 105 106 109 public void testCloseClosedConnection() { 110 try { 111 senderConnection.close(); 114 senderConnection.close(); 116 } catch (Exception e) { 117 fail("§4.3.5 Closing a closed connection must not throw an exception.\n"); 118 } 119 } 120 121 124 public void testStartStartedConnection() { 125 try { 126 senderConnection.start(); 129 } catch (JMSException e) { 130 fail(e); 131 } 132 } 133 134 137 public void testStopStoppedConnection() { 138 try { 139 senderConnection.stop(); 142 senderConnection.stop(); 144 } catch (JMSException e) { 145 fail(e); 146 } 147 } 148 149 152 public void testStopConsumerConnection() { 153 try { 154 receiverConnection.stop(); 155 156 receiver.setMessageListener(new MessageListener() { 157 public void onMessage(Message m) { 158 try { 159 fail("The message must not be received, the consumer connection is stopped"); 160 assertEquals("test", ((TextMessage)m).getText()); 161 } catch (JMSException e) { 162 fail(e); 163 } 164 } 165 }); 166 167 TextMessage message = senderSession.createTextMessage(); 168 message.setText("test"); 169 sender.send(message); 170 synchronized(this) { 171 try { 172 wait(1000); 173 } catch (Exception e) { 174 fail (e); 175 } 176 } 177 } catch (JMSException e) { 178 fail(e); 179 } 180 } 181 182 185 public static Test suite() { 186 return new TestSuite(ConnectionTest.class); 187 } 188 189 public ConnectionTest(String name) { 190 super(name); 191 } 192 } 193 | Popular Tags |