1 24 25 package org.objectweb.jtests.jms.conform.queue; 26 27 import org.objectweb.jtests.jms.framework.*; 28 import junit.framework.*; 29 30 import javax.jms.*; 31 import java.util.Enumeration ; 32 33 39 public class QueueBrowserTest extends PTPTestCase { 40 41 44 protected QueueBrowser receiverBrowser; 45 46 49 protected QueueBrowser senderBrowser ; 50 51 54 public void testSenderBrowser() { 55 try { 56 TextMessage message_1 = senderSession.createTextMessage(); 57 message_1.setText("testBrowser:message_1"); 58 TextMessage message_2 = senderSession.createTextMessage(); 59 message_2.setText("testBrowser:message_2"); 60 61 sender.send(message_1); 63 sender.send(message_2); 64 65 Enumeration enumeration = senderBrowser.getEnumeration(); 67 int count = 0; 68 while (enumeration.hasMoreElements()) { 69 count ++; 71 Object obj = enumeration.nextElement(); 73 assertTrue(obj instanceof TextMessage); 74 TextMessage msg = (TextMessage)obj; 75 assertTrue(msg.getText().startsWith("testBrowser:message_")); 76 } 77 assertEquals(2, count); 79 80 Message m = receiver.receive(TestConfig.TIMEOUT); 82 assertTrue (m instanceof TextMessage); 84 TextMessage msg = (TextMessage)m; 85 assertEquals("testBrowser:message_1", msg.getText()); 86 87 m = receiver.receive(TestConfig.TIMEOUT); 89 assertTrue (m instanceof TextMessage); 91 msg = (TextMessage)m; 92 assertEquals("testBrowser:message_2", msg.getText()); 93 94 enumeration = receiverBrowser.getEnumeration(); 96 assertTrue(!enumeration.hasMoreElements()); 100 } catch (JMSException e) { 101 fail(e); 102 } 103 } 104 105 109 public void testBrowserWithMessageSelector() { 110 try { 111 senderBrowser = senderSession.createBrowser(senderQueue, "pi = 3.14159"); 112 113 TextMessage message_1 = senderSession.createTextMessage(); 114 message_1.setText("testBrowserWithMessageSelector:message_1"); 115 TextMessage message_2 = senderSession.createTextMessage(); 116 message_2.setDoubleProperty("pi", 3.14159); 117 message_2.setText("testBrowserWithMessageSelector:message_2"); 118 119 sender.send(message_1); 120 sender.send(message_2); 121 122 Enumeration enumeration = senderBrowser.getEnumeration(); 123 int count = 0; 124 while (enumeration.hasMoreElements()) { 125 count ++; 126 Object obj = enumeration.nextElement(); 127 assertTrue(obj instanceof TextMessage); 128 TextMessage msg = (TextMessage)obj; 129 assertEquals("testBrowserWithMessageSelector:message_2", msg.getText()); 130 } 131 assertEquals(1, count); 132 } catch (JMSException e) { 133 fail(e); 134 } 135 } 136 137 public void setUp() { 138 try { 139 super.setUp(); 140 receiverBrowser = receiverSession.createBrowser(receiverQueue); 141 senderBrowser = senderSession.createBrowser(senderQueue); 142 } catch (JMSException e) { 143 e.printStackTrace(); 144 } 145 } 146 147 public void tearDown() { 148 try { 149 receiverBrowser.close(); 150 senderBrowser.close(); 151 super.tearDown(); 152 } catch (JMSException e) { 153 e.printStackTrace(); 154 } finally { 155 receiverBrowser = null; 156 senderBrowser = null; 157 } 158 } 159 160 163 public static Test suite() { 164 return new TestSuite(QueueBrowserTest.class); 165 } 166 167 public QueueBrowserTest(String name) { 168 super(name); 169 } 170 } 171 | Popular Tags |