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 java .util .Map ;
35+ import java .util .HashMap ;
36+ import java .io .IOException ;
37+
38+ import com .rabbitmq .client .Channel ;
39+
40+ import com .rabbitmq .client .test .BrokerTestCase ;
41+
42+ public class ExchangeDeclare extends BrokerTestCase {
43+
44+ static final String TYPE = "direct" ;
45+
46+ static final String NAME = "exchange_test" ;
47+
48+ public void releaseResources () throws IOException {
49+ channel .exchangeDelete (NAME );
50+ }
51+
52+ public static void verifyEquivalent (Channel channel , String name , String type , boolean durable , boolean autoDelete , Map <String , Object > args )
53+ throws IOException {
54+ channel .exchangeDeclarePassive (name );
55+ channel .exchangeDeclare (name , type , durable , autoDelete , args );
56+ }
57+
58+ // Note: this will close the channel
59+ public static void verifyNotEquivalent (Channel channel , String name , String type , boolean durable , boolean autoDelete , Map <String , Object > args )
60+ throws IOException {
61+ channel .exchangeDeclarePassive (name );
62+ try {
63+ channel .exchangeDeclare (name , type , durable , autoDelete , args );
64+ fail ("Exchange was supposed to be not equivalent" );
65+ }
66+ catch (IOException ioe ) {
67+ return ;
68+ }
69+ }
70+
71+ public void testExchangeNoArgsEquivalence () throws IOException {
72+ channel .exchangeDeclare (NAME , TYPE , false , false , null );
73+ verifyEquivalent (channel , NAME , TYPE , false , false , null );
74+ }
75+
76+ public void testExchangeNonsenseArgsEquivalent () throws IOException {
77+ channel .exchangeDeclare (NAME , TYPE , false , false , null );
78+ Map <String , Object > args = new HashMap <String , Object >();
79+ args .put ("nonsensical-argument-surely-not-in-use" , "foo" );
80+ verifyEquivalent (channel , NAME , TYPE , false , false , args );
81+ }
82+
83+ public void testExchangeDurableNotEquivalent () throws IOException {
84+ channel .exchangeDeclare (NAME , TYPE , false , false , null );
85+ verifyNotEquivalent (channel , NAME , TYPE , true , false , null );
86+ }
87+
88+ public void testExchangeTypeNotEquivalent () throws IOException {
89+ channel .exchangeDeclare (NAME , "direct" , false , false , null );
90+ verifyNotEquivalent (channel , NAME , "fanout" , false , false , null );
91+ }
92+
93+ public void testExchangeAutoDeleteNotEquivalent () throws IOException {
94+ channel .exchangeDeclare (NAME , "direct" , false , false , null );
95+ verifyNotEquivalent (channel , NAME , "direct" , false , true , null );
96+ }
97+ }
0 commit comments