1+ /*
2+ * Copyright (c) 2018-2019 Pivotal Software Inc, All Rights Reserved.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ package reactor .rabbitmq ;
18+
19+ import org .junit .jupiter .api .Assertions ;
20+ import org .junit .jupiter .api .Nested ;
21+ import org .junit .jupiter .api .Test ;
22+
23+ class QueueSpecificationTest {
24+
25+ @ Nested
26+ class NullName {
27+ @ Test
28+ void nullNameShouldReturnANonDurableQueue () {
29+ Assertions .assertFalse (
30+ QueueSpecification .queue ().isDurable ());
31+ }
32+
33+ @ Test
34+ void passingNullNameShouldReturnANonDurableQueue () {
35+ Assertions .assertFalse (
36+ QueueSpecification .queue (null ).isDurable ());
37+ }
38+
39+ @ Test
40+ void nullNameShouldNotAbleToConfigureDurableToTrue () {
41+ Assertions .assertThrows (
42+ IllegalArgumentException .class ,
43+ () -> QueueSpecification .queue ().durable (true ),
44+ "once a queue has null name, durable is always false" );
45+ }
46+
47+ @ Test
48+ void nullNameShouldKeepDurableWhenConfigureDurableToFalse () {
49+ Assertions .assertFalse (
50+ QueueSpecification .queue ().durable (false ).isDurable ());
51+ }
52+
53+ @ Test
54+ void passingNullNameShouldReturnAExclusiveQueue () {
55+ Assertions .assertTrue (
56+ QueueSpecification .queue ().isExclusive ());
57+ }
58+
59+ @ Test
60+ void nullNameShouldNotAbleToConfigureExclusiveToFalse () {
61+ Assertions .assertThrows (
62+ IllegalArgumentException .class ,
63+ () -> QueueSpecification .queue ().exclusive (false ),
64+ "once a queue has null name, exclusive is always true" );
65+ }
66+
67+ @ Test
68+ void nullNameShouldKeepDurableWhenConfigureExclusiveToTrue () {
69+ Assertions .assertTrue (
70+ QueueSpecification .queue ().exclusive (true ).isExclusive ());
71+ }
72+
73+ @ Test
74+ void passingNullNameShouldReturnAnAutoDeleteQueue () {
75+ Assertions .assertTrue (
76+ QueueSpecification .queue ().isAutoDelete ());
77+ }
78+
79+ @ Test
80+ void nullNameShouldNotAbleToConfigureAutoDeleteToFalse () {
81+ Assertions .assertThrows (
82+ IllegalArgumentException .class ,
83+ () -> QueueSpecification .queue ().autoDelete (false ),
84+ "once a queue has null name, autoDelete is always true" );
85+ }
86+
87+ @ Test
88+ void nullNameShouldKeepAutoDeleteWhenConfigureAutoDeleteToTrue () {
89+ Assertions .assertTrue (
90+ QueueSpecification .queue ().autoDelete (true ).isAutoDelete ());
91+ }
92+
93+ @ Test
94+ void passingANonNullNameAfterShouldReturnAConfigurableQueueSpecification () {
95+ QueueSpecification queueSpecification = QueueSpecification .queue ()
96+ .name ("not-null-anymore" )
97+ .durable (true )
98+ .exclusive (false )
99+ .autoDelete (false );
100+
101+ Assertions .assertEquals (queueSpecification .getName (), "not-null-anymore" );
102+ Assertions .assertTrue (queueSpecification .isDurable ());
103+ Assertions .assertFalse (queueSpecification .isAutoDelete ());
104+ Assertions .assertFalse (queueSpecification .isExclusive ());
105+ }
106+ }
107+
108+ @ Nested
109+ class NotNullName {
110+ @ Test
111+ void queueSpecificationShouldReturnCorrespondingProperties () {
112+ QueueSpecification queueSpecification = QueueSpecification .queue ("my-queue" )
113+ .durable (false )
114+ .autoDelete (false )
115+ .exclusive (false );
116+
117+ Assertions .assertEquals (queueSpecification .getName (), "my-queue" );
118+ Assertions .assertFalse (queueSpecification .isDurable ());
119+ Assertions .assertFalse (queueSpecification .isAutoDelete ());
120+ Assertions .assertFalse (queueSpecification .isExclusive ());
121+ Assertions .assertNull (queueSpecification .getArguments ());
122+ }
123+
124+ @ Test
125+ void queueSpecificationShouldReturnCorrespondingPropertiesWhenEmptyName () {
126+ QueueSpecification queueSpecification = QueueSpecification .queue ("" )
127+ .durable (false )
128+ .autoDelete (false )
129+ .exclusive (false );
130+
131+ Assertions .assertEquals (queueSpecification .getName (), "" );
132+ Assertions .assertFalse (queueSpecification .isDurable ());
133+ Assertions .assertFalse (queueSpecification .isAutoDelete ());
134+ Assertions .assertFalse (queueSpecification .isExclusive ());
135+ Assertions .assertNull (queueSpecification .getArguments ());
136+ }
137+ }
138+ }
0 commit comments