Skip to content

Commit ea23cc6

Browse files
author
Emile Joubert
committed
Test sender-specified destinations
1 parent 24d0764 commit ea23cc6

File tree

2 files changed

+152
-0
lines changed

2 files changed

+152
-0
lines changed
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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-2010 LShift
22+
// Ltd. Portions created by Cohesive Financial Technologies LLC are
23+
// Copyright (C) 2007-2010 Cohesive Financial Technologies
24+
// LLC. Portions created by Rabbit Technologies Ltd are Copyright
25+
// (C) 2007-2010 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.BasicProperties;
35+
import com.rabbitmq.client.GetResponse;
36+
import com.rabbitmq.client.test.BrokerTestCase;
37+
38+
import java.io.IOException;
39+
import java.util.ArrayList;
40+
import java.util.HashMap;
41+
import java.util.Arrays;
42+
import java.util.List;
43+
import java.util.Map;
44+
45+
public class CcRoutes extends BrokerTestCase {
46+
47+
static private String[] queues = new String[]{"queue1", "queue2", "queue3"};
48+
protected String exDirect = "direct_cc_exchange";
49+
protected String exFanout = "fanout_cc_exchange";
50+
protected BasicProperties props;
51+
protected Map headers;
52+
protected List ccList;
53+
protected List bccList;
54+
55+
@Override protected void setUp() throws IOException {
56+
super.setUp();
57+
props = new BasicProperties();
58+
headers = new HashMap();
59+
ccList = new ArrayList();
60+
bccList = new ArrayList();
61+
}
62+
63+
@Override protected void createResources() throws IOException {
64+
super.createResources();
65+
for (String q : queues) {
66+
channel.queueDeclare(q, false, false, false, null);
67+
}
68+
channel.exchangeDeclare(exDirect, "direct");
69+
channel.exchangeDeclare(exFanout, "fanout");
70+
}
71+
72+
@Override protected void releaseResources() throws IOException {
73+
for (String q : queues) {
74+
channel.queueDelete(q);
75+
}
76+
channel.exchangeDelete(exDirect);
77+
channel.exchangeDelete(exFanout);
78+
super.releaseResources();
79+
}
80+
81+
public void testCcSingleton() throws IOException {
82+
headers.put("CC", "queue2");
83+
props.setHeaders(headers);
84+
channel.basicPublish("", "queue1", props, new byte[0]);
85+
expect(new String []{"queue1", "queue2"});
86+
}
87+
88+
public void testCcList() throws IOException {
89+
ccList.add("queue2");
90+
headerPublish("", "queue1", ccList, null);
91+
expect(new String []{"queue1", "queue2"});
92+
}
93+
94+
public void testCcIgnoreEmptyAndInvalidRoutes() throws IOException {
95+
bccList.add("frob");
96+
headerPublish("", "queue1", ccList, bccList);
97+
expect(new String []{"queue1"});
98+
}
99+
100+
public void testBcc() throws IOException {
101+
bccList.add("queue2");
102+
headerPublish("", "queue1", null, bccList);
103+
expect(new String []{"queue1", "queue2"});
104+
}
105+
106+
public void testNoDuplicates() throws IOException {
107+
ccList.add("queue1");
108+
ccList.add("queue1");
109+
bccList.add("queue1");
110+
headerPublish("", "queue1", null, bccList);
111+
expect(new String[] {"queue1"});
112+
}
113+
114+
public void testDirectExchangeWithoutBindings() throws IOException {
115+
ccList.add("queue1");
116+
headerPublish(exDirect, "unbound", ccList, null);
117+
expect(new String[] {"queue1"});
118+
}
119+
120+
public void testFanoutExchange() throws IOException {
121+
ccList.add("queue2");
122+
headerPublish(exFanout, "queue1", ccList, null);
123+
expect(new String[] {"queue2"});
124+
}
125+
126+
private void headerPublish(String ex, String to, List cc, List bcc) throws IOException {
127+
if (cc != null) {
128+
headers.put("CC", ccList);
129+
}
130+
if (bcc != null) {
131+
headers.put("BCC", bccList);
132+
}
133+
props.setHeaders(headers);
134+
channel.basicPublish(ex, to, props, new byte[0]);
135+
}
136+
137+
private void expect(String[] expectedQueues) throws IOException {
138+
GetResponse getResponse;
139+
List expectedList = Arrays.asList(expectedQueues);
140+
for (String q : queues) {
141+
getResponse = basicGet(q);
142+
if (expectedList.contains(q)) {
143+
assertNotNull(getResponse);
144+
assertEquals(0, getResponse.getMessageCount());
145+
assertFalse(getResponse.getProps().getHeaders().containsKey("BCC"));
146+
} else {
147+
assertNull(getResponse);
148+
}
149+
}
150+
}
151+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public static TestSuite suite() {
7373
suite.addTestSuite(SaslMechanisms.class);
7474
suite.addTestSuite(UserIDHeader.class);
7575
suite.addTestSuite(InternalExchange.class);
76+
suite.addTestSuite(CcRoutes.class);
7677
return suite;
7778
}
7879
}

0 commit comments

Comments
 (0)