|
2 | 2 |
|
3 | 3 | package com.rabbitmq.amqp1_0.tests.jms;
|
4 | 4 |
|
5 |
| -import java.util.*; |
6 |
| - |
7 |
| -import junit.framework.Test; |
8 |
| -import junit.framework.TestCase; |
9 |
| -import junit.framework.TestSuite; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 6 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
10 | 7 |
|
11 |
| -import javax.jms.Connection; |
12 |
| -import javax.jms.ConnectionFactory; |
13 |
| -import javax.jms.DeliveryMode; |
14 |
| -import javax.jms.Destination; |
15 |
| -import javax.jms.ExceptionListener; |
16 |
| -import javax.jms.JMSException; |
17 |
| -import javax.jms.Message; |
18 |
| -import javax.jms.MessageConsumer; |
19 |
| -import javax.jms.MessageProducer; |
20 |
| -import javax.jms.Session; |
21 |
| -import javax.jms.TextMessage; |
| 8 | +import java.util.*; |
| 9 | +//import javax.jms.Connection; |
| 10 | +//import javax.jms.ConnectionFactory; |
| 11 | +//import javax.jms.DeliveryMode; |
| 12 | +//import javax.jms.Destination; |
| 13 | +//import javax.jms.Message; |
| 14 | +//import javax.jms.MessageConsumer; |
| 15 | +//import javax.jms.MessageProducer; |
| 16 | +//import javax.jms.Session; |
| 17 | +//import javax.jms.TextMessage; |
22 | 18 | import javax.naming.Context;
|
23 |
| -import javax.naming.InitialContext; |
24 |
| - |
25 |
| -/** |
26 |
| - * Unit test for simple App. |
27 |
| - */ |
28 |
| -public class RoundTripTest |
29 |
| - extends TestCase |
30 |
| -{ |
31 |
| - public static final String ADDRESS = "/jms-roundtrip-q"; |
32 |
| - public static final String PAYLOAD = "Payload"; |
33 |
| - |
34 |
| - /** |
35 |
| - * Create the test case |
36 |
| - * |
37 |
| - * @param testName name of the test case |
38 |
| - */ |
39 |
| - public RoundTripTest(String testName) |
40 |
| - { |
41 |
| - super(testName); |
42 |
| - } |
43 |
| - |
44 |
| - /** |
45 |
| - * @return the suite of tests being tested |
46 |
| - */ |
47 |
| - public static Test suite() |
48 |
| - { |
49 |
| - return new TestSuite(RoundTripTest.class); |
50 |
| - } |
51 |
| - |
52 |
| - public void test_roundtrip () throws Exception |
53 |
| - { |
54 |
| - String uri = System.getProperty("rmq_broker_uri"); |
55 |
| - String address = uri + ADDRESS; |
56 |
| - Hashtable<Object, Object> env = new Hashtable<Object, Object>(); |
57 |
| - env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.qpid.jms.jndi.JmsInitialContextFactory"); |
58 |
| - env.put("connectionfactory.myFactoryLookup", uri); |
59 |
| - env.put("queue.myQueueLookup", "my-queue"); |
60 |
| - env.put("jms.sendTimeout", 5); |
61 |
| - env.put("jms.requestTimeout", 5); |
62 |
| - javax.naming.Context context = new javax.naming.InitialContext(env); |
63 |
| - |
64 |
| - assertNotNull(uri); |
65 |
| - |
66 |
| - ConnectionFactory factory = (ConnectionFactory) context.lookup("myFactoryLookup"); |
67 |
| - Destination queue = (Destination) context.lookup("myQueueLookup"); |
68 |
| - |
69 |
| - Connection connection = factory.createConnection("guest", "guest"); |
70 |
| - connection.start(); |
71 |
| - |
72 |
| - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); |
73 |
| - |
74 |
| - MessageProducer messageProducer = session.createProducer(queue); |
75 |
| - MessageConsumer messageConsumer = session.createConsumer(queue); |
76 |
| - |
77 |
| - TextMessage message = session.createTextMessage("Hello world!"); |
78 |
| - messageProducer.send(message, DeliveryMode.NON_PERSISTENT, |
79 |
| - Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE); |
80 |
| - TextMessage receivedMessage = (TextMessage) messageConsumer.receive(2000L); |
81 |
| - |
82 |
| - assertEquals(message.getText(), receivedMessage.getText()); |
83 |
| - } |
| 19 | +import jakarta.jms.*; |
| 20 | +import org.junit.jupiter.api.Test; |
| 21 | + |
| 22 | +/** Unit test for simple App. */ |
| 23 | +public class RoundTripTest { |
| 24 | + |
| 25 | + @Test |
| 26 | + public void test_roundtrip() throws Exception { |
| 27 | + String uri = System.getProperty("rmq_broker_uri", "amqp://localhost:5672"); |
| 28 | + Hashtable<Object, Object> env = new Hashtable<>(); |
| 29 | + env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.qpid.jms.jndi.JmsInitialContextFactory"); |
| 30 | + env.put("connectionfactory.myFactoryLookup", uri); |
| 31 | + env.put("queue.myQueueLookup", "my-queue"); |
| 32 | + env.put("jms.sendTimeout", 5); |
| 33 | + env.put("jms.requestTimeout", 5); |
| 34 | + javax.naming.Context context = new javax.naming.InitialContext(env); |
| 35 | + |
| 36 | + assertNotNull(uri); |
| 37 | + |
| 38 | + ConnectionFactory factory = (ConnectionFactory) context.lookup("myFactoryLookup"); |
| 39 | + Destination queue = (Destination) context.lookup("myQueueLookup"); |
| 40 | + |
| 41 | + Connection connection = factory.createConnection("guest", "guest"); |
| 42 | + connection.start(); |
| 43 | + |
| 44 | + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); |
| 45 | + |
| 46 | + MessageProducer messageProducer = session.createProducer(queue); |
| 47 | + MessageConsumer messageConsumer = session.createConsumer(queue); |
| 48 | + |
| 49 | + TextMessage message = session.createTextMessage("Hello world!"); |
| 50 | + messageProducer.send( |
| 51 | + message, |
| 52 | + DeliveryMode.NON_PERSISTENT, |
| 53 | + Message.DEFAULT_PRIORITY, |
| 54 | + Message.DEFAULT_TIME_TO_LIVE); |
| 55 | + TextMessage receivedMessage = (TextMessage) messageConsumer.receive(2000L); |
| 56 | + |
| 57 | + assertEquals(message.getText(), receivedMessage.getText()); |
| 58 | + } |
84 | 59 | }
|
0 commit comments