Skip to content

Commit c09d083

Browse files
author
Matthias Radestock
committed
add test for table field types
1 parent fede582 commit c09d083

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

test/src/com/rabbitmq/client/test/functional/FunctionalTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
public class FunctionalTests extends TestCase {
3838
public static TestSuite suite() {
3939
TestSuite suite = new TestSuite("functional");
40+
suite.addTestSuite(Tables.class);
4041
suite.addTestSuite(Routing.class);
4142
suite.addTestSuite(BindingLifecycle.class);
4243
suite.addTestSuite(Transactions.class);
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// The contents of this file are subject to the Mozilla Public License
2+
// Version 1.1 (the "License"); you may not use this file except in
3+
// compliance with the License. You may obtain a copy of the License at
4+
// http://www.mozilla.org/MPL/
5+
//
6+
// Software distributed under the License is distributed on an "AS IS"
7+
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
8+
// License for the specific language governing rights and limitations
9+
// under the License.
10+
//
11+
// The Original Code is RabbitMQ.
12+
//
13+
// The Initial Developers of the Original Code are LShift Ltd,
14+
// Cohesive Financial Technologies LLC, and Rabbit Technologies Ltd.
15+
//
16+
// Portions created before 22-Nov-2008 00:00:00 GMT by LShift Ltd,
17+
// Cohesive Financial Technologies LLC, or Rabbit Technologies Ltd
18+
// are Copyright (C) 2007-2008 LShift Ltd, Cohesive Financial
19+
// Technologies LLC, and Rabbit Technologies Ltd.
20+
//
21+
// Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift
22+
// Ltd. Portions created by Cohesive Financial Technologies LLC are
23+
// Copyright (C) 2007-2009 Cohesive Financial Technologies
24+
// LLC. Portions created by Rabbit Technologies Ltd are Copyright
25+
// (C) 2007-2009 Rabbit Technologies Ltd.
26+
//
27+
// All Rights Reserved.
28+
//
29+
// Contributor(s): ______________________________________.
30+
//
31+
32+
package com.rabbitmq.client.test.functional;
33+
34+
import com.rabbitmq.client.AMQP;
35+
import com.rabbitmq.client.impl.LongStringHelper;
36+
import com.rabbitmq.client.AMQP.BasicProperties;
37+
38+
import java.io.IOException;
39+
import java.util.Arrays;
40+
import java.util.Map;
41+
import java.util.Set;
42+
import java.util.HashMap;
43+
import java.math.BigDecimal;
44+
45+
public class Tables extends BrokerTestCase
46+
{
47+
48+
public void testTypes() throws IOException {
49+
50+
AMQP.Queue.DeclareOk ok = channel.queueDeclare();
51+
String q = ok.getQueue();
52+
53+
Map<String, Object> headers = new HashMap<String, Object>();
54+
Map<String, Object> subTable = new HashMap<String, Object>();
55+
subTable.put("key", 1);
56+
headers.put("S", LongStringHelper.asLongString("string"));
57+
headers.put("I", new Integer(1));
58+
headers.put("D", new BigDecimal("1.1"));
59+
headers.put("T", new java.util.Date(1000000));
60+
headers.put("F", subTable);
61+
headers.put("b", (byte)1);
62+
headers.put("d", 1.1d);
63+
headers.put("f", 1.1f);
64+
headers.put("l", 1L);
65+
headers.put("s", (short)1);
66+
headers.put("t", true);
67+
headers.put("x", "byte".getBytes());
68+
headers.put("V", null);
69+
BasicProperties props = new BasicProperties(null, null, headers, null,
70+
null, null, null, null,
71+
null, null, null, null,
72+
null, null);
73+
74+
channel.basicPublish("", q, props, "".getBytes());
75+
BasicProperties rProps = channel.basicGet(q, true).getProps();
76+
assertMapsEqual(props.headers, rProps.headers);
77+
// assertEquals(props.headers, rProps.headers);
78+
79+
}
80+
81+
private static void assertMapsEqual(Map<String, Object> a,
82+
Map<String, Object> b) {
83+
84+
assertEquals(a.keySet(), b.keySet());
85+
Set<String> keys = a.keySet();
86+
for (String k : keys) {
87+
Object va = a.get(k);
88+
Object vb = b.get(k);
89+
if (va instanceof byte[] && vb instanceof byte[]) {
90+
assertTrue("unequal entry for key " + k,
91+
Arrays.equals((byte[])va, (byte[])vb));
92+
} else {
93+
assertEquals("unequal entry for key " + k, va, vb);
94+
}
95+
}
96+
}
97+
98+
}

0 commit comments

Comments
 (0)