@@ -33,74 +33,65 @@ public class CcRoutes extends BrokerTestCase {
3333 protected String exDirect = "direct_cc_exchange" ;
3434 protected String exTopic = "topic_cc_exchange" ;
3535 protected BasicProperties props ;
36- protected Map headers ;
37- protected List ccList ;
38- protected List bccList ;
36+ protected Map < String , Object > headers ;
37+ protected List < String > ccList ;
38+ protected List < String > bccList ;
3939
4040 @ Override protected void setUp () throws IOException {
4141 super .setUp ();
4242 props = new BasicProperties ();
43- headers = new HashMap ();
44- ccList = new ArrayList ();
45- bccList = new ArrayList ();
43+ headers = new HashMap < String , Object > ();
44+ ccList = new ArrayList < String > ();
45+ bccList = new ArrayList < String > ();
4646 }
4747
4848 @ Override protected void createResources () throws IOException {
4949 super .createResources ();
5050 for (String q : queues ) {
51- channel .queueDeclare (q , false , false , false , null );
51+ channel .queueDeclare (q , false , true , true , null );
5252 }
53- channel .exchangeDeclare (exDirect , "direct" );
54- channel .exchangeDeclare (exTopic , "topic" );
55- }
56-
57- @ Override protected void releaseResources () throws IOException {
58- for (String q : queues ) {
59- channel .queueDelete (q );
60- }
61- channel .exchangeDelete (exDirect );
62- channel .exchangeDelete (exTopic );
63- super .releaseResources ();
53+ channel .exchangeDeclare (exDirect , "direct" , false , true , null );
54+ channel .exchangeDeclare (exTopic , "topic" , false , true , null );
6455 }
6556
6657 public void testCcList () throws IOException {
6758 ccList .add ("queue2" );
6859 ccList .add ("queue3" );
6960 headerPublish ("" , "queue1" , ccList , null );
70- expect (new String []{"queue1" , "queue2" , "queue3" });
61+ expect (new String []{"queue1" , "queue2" , "queue3" }, true );
7162 }
7263
7364 public void testCcIgnoreEmptyAndInvalidRoutes () throws IOException {
7465 bccList .add ("frob" );
7566 headerPublish ("" , "queue1" , ccList , bccList );
76- expect (new String []{"queue1" });
67+ expect (new String []{"queue1" }, true );
7768 }
7869
7970 public void testBcc () throws IOException {
8071 bccList .add ("queue2" );
8172 headerPublish ("" , "queue1" , null , bccList );
82- expect (new String []{"queue1" , "queue2" });
73+ expect (new String []{"queue1" , "queue2" }, false );
8374 }
8475
8576 public void testNoDuplicates () throws IOException {
8677 ccList .add ("queue1" );
8778 ccList .add ("queue1" );
8879 bccList .add ("queue1" );
89- headerPublish ("" , "queue1" , null , bccList );
90- expect (new String [] {"queue1" });
80+ headerPublish ("" , "queue1" , ccList , bccList );
81+ expect (new String [] {"queue1" }, true );
9182 }
9283
9384 public void testDirectExchangeWithoutBindings () throws IOException {
9485 ccList .add ("queue1" );
9586 headerPublish (exDirect , "queue2" , ccList , null );
96- expect (new String [] {});
87+ expect (new String [] {}, true );
9788 }
9889
9990 public void testTopicExchange () throws IOException {
10091 ccList .add ("routing_key" );
10192 channel .queueBind ("queue2" , exTopic , "routing_key" );
10293 headerPublish (exTopic , "" , ccList , null );
103- expect (new String [] {"queue2" });
94+ expect (new String [] {"queue2" }, true );
10495 }
10596
10697 public void testBoundExchanges () throws IOException {
@@ -109,10 +100,10 @@ public void testBoundExchanges() throws IOException {
109100 channel .exchangeBind (exTopic , exDirect , "routing_key1" );
110101 channel .queueBind ("queue2" , exTopic , "routing_key2" );
111102 headerPublish (exDirect , "" , ccList , bccList );
112- expect (new String [] {"queue2" });
103+ expect (new String [] {"queue2" }, true );
113104 }
114105
115- private void headerPublish (String ex , String to , List cc , List bcc ) throws IOException {
106+ private void headerPublish (String ex , String to , List < String > cc , List < String > bcc ) throws IOException {
116107 if (cc != null ) {
117108 headers .put ("CC" , ccList );
118109 }
@@ -123,17 +114,19 @@ private void headerPublish(String ex, String to, List cc, List bcc) throws IOExc
123114 channel .basicPublish (ex , to , props , new byte [0 ]);
124115 }
125116
126- private void expect (String [] expectedQueues ) throws IOException {
117+ private void expect (String [] expectedQueues , boolean usedCc ) throws IOException {
127118 GetResponse getResponse ;
128- List expectedList = Arrays .asList (expectedQueues );
119+ List < String > expectedList = Arrays .asList (expectedQueues );
129120 for (String q : queues ) {
130121 getResponse = basicGet (q );
131122 if (expectedList .contains (q )) {
132123 assertNotNull (getResponse );
133124 assertEquals (0 , getResponse .getMessageCount ());
134125 Map headers = getResponse .getProps ().getHeaders ();
135- if (headers != null )
126+ if (headers != null ){
127+ assertEquals (usedCc , headers .containsKey ("CC" ));
136128 assertFalse (headers .containsKey ("BCC" ));
129+ }
137130 } else {
138131 assertNull (getResponse );
139132 }
0 commit comments