]> review.fuel-infra Code Review - packages/trusty/rabbitmq-server.git/blob
d056bc3f922123dda93fde12d197ff7012e370a8
[packages/trusty/rabbitmq-server.git] /
1 // vim:sw=4:et:
2
3 package com.rabbitmq.amqp1_0.tests.proton;
4
5 import junit.framework.Test;
6 import junit.framework.TestCase;
7 import junit.framework.TestSuite;
8
9 import org.apache.qpid.proton.message.Message;
10 import org.apache.qpid.proton.message.impl.MessageImpl;
11 import org.apache.qpid.proton.messenger.Messenger;
12 import org.apache.qpid.proton.messenger.impl.MessengerImpl;
13 import org.apache.qpid.proton.amqp.messaging.AmqpValue;
14 import org.apache.qpid.proton.amqp.messaging.MessageAnnotations;
15 import org.apache.qpid.proton.amqp.Symbol;
16
17 import java.util.Map;
18 import java.util.HashMap;
19
20 /**
21  * Unit test for simple App.
22  */
23 public class MessageAnnotationsTest
24     extends TestCase
25 {
26     public static final String ADDRESS = "/message_annotations-q";
27     public static final String PAYLOAD = "Payload";
28
29     /**
30      * Create the test case
31      *
32      * @param testName name of the test case
33      */
34     public MessageAnnotationsTest(String testName)
35     {
36         super(testName);
37     }
38
39     /**
40      * @return the suite of tests being tested
41      */
42     public static Test suite()
43     {
44         return new TestSuite(MessageAnnotationsTest.class);
45     }
46
47     public void test_message_annotations()
48     {
49         String uri = System.getProperty("rmq_broker_uri");
50         assertNotNull(uri);
51         String address = uri + ADDRESS;
52
53         Messenger mng = new MessengerImpl();
54         Message sent_msg, received_msg;
55
56         mng.setTimeout(1000);
57         try {
58             mng.start();
59         } catch (Exception e) {
60             fail();
61         }
62
63         sent_msg = new MessageImpl();
64         sent_msg.setAddress(address);
65         sent_msg.setBody(new AmqpValue(PAYLOAD));
66
67         Map<Symbol, Object> map = new HashMap<Symbol, Object>();
68         map.put(Symbol.valueOf("key1"), "value1");
69         map.put(Symbol.valueOf("key2"), "value2");
70         MessageAnnotations annotations = new MessageAnnotations(map);
71         sent_msg.setMessageAnnotations(annotations);
72
73         mng.put(sent_msg);
74         mng.send();
75
76         mng.subscribe(address);
77         mng.recv();
78         received_msg = mng.get();
79
80         assertEquals(sent_msg.getSubject(),
81           received_msg.getSubject());
82         assertEquals(sent_msg.getContentType(),
83           received_msg.getContentType());
84         assertEquals(sent_msg.getBody().toString(),
85           received_msg.getBody().toString());
86         assertEquals(sent_msg.getMessageAnnotations().toString(),
87           received_msg.getMessageAnnotations().toString());
88
89         mng.stop();
90     }
91 }