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 ,
53+ String type , boolean durable , boolean autoDelete ,
54+ Map <String , Object > args ) throws IOException {
55+ channel .exchangeDeclarePassive (name );
56+ channel .exchangeDeclare (name , type , durable , autoDelete , args );
57+ }
58+
59+ // Note: this will close the channel
60+ public static void verifyNotEquivalent (Channel channel , String name ,
61+ String type , boolean durable , boolean autoDelete ,
62+ Map <String , Object > args ) throws IOException {
63+ channel .exchangeDeclarePassive (name );
64+ try {
65+ channel .exchangeDeclare (name , type , durable , autoDelete , args );
66+ fail ("Exchange was supposed to be not equivalent" );
67+ } catch (IOException ioe ) {
68+ return ;
69+ }
70+ }
71+
72+ public void testExchangeNoArgsEquivalence () throws IOException {
73+ channel .exchangeDeclare (NAME , TYPE , false , false , null );
74+ verifyEquivalent (channel , NAME , TYPE , false , false , null );
75+ }
76+
77+ public void testExchangeNonsenseArgsEquivalent () throws IOException {
78+ channel .exchangeDeclare (NAME , TYPE , false , false , null );
79+ Map <String , Object > args = new HashMap <String , Object >();
80+ args .put ("nonsensical-argument-surely-not-in-use" , "foo" );
81+ verifyEquivalent (channel , NAME , TYPE , false , false , args );
82+ }
83+
84+ public void testExchangeDurableNotEquivalent () throws IOException {
85+ channel .exchangeDeclare (NAME , TYPE , false , false , null );
86+ verifyNotEquivalent (channel , NAME , TYPE , true , false , null );
87+ }
88+
89+ public void testExchangeTypeNotEquivalent () throws IOException {
90+ channel .exchangeDeclare (NAME , "direct" , false , false , null );
91+ verifyNotEquivalent (channel , NAME , "fanout" , false , false , null );
92+ }
93+
94+ public void testExchangeAutoDeleteNotEquivalent () throws IOException {
95+ channel .exchangeDeclare (NAME , "direct" , false , false , null );
96+ verifyNotEquivalent (channel , NAME , "direct" , false , true , null );
97+ }
98+ }
0 commit comments