|
26 | 26 |
|
27 | 27 | import com.rabbitmq.client.AMQP;
|
28 | 28 | import com.rabbitmq.client.Channel;
|
29 |
| -import com.rabbitmq.client.Command; |
30 | 29 | import com.rabbitmq.client.Connection;
|
31 | 30 | import com.rabbitmq.client.ConnectionFactory;
|
32 | 31 | import com.rabbitmq.client.QueueingConsumer;
|
33 |
| -import com.rabbitmq.client.ShutdownSignalException; |
34 | 32 | import com.rabbitmq.client.impl.AMQChannel;
|
35 | 33 | import com.rabbitmq.client.impl.AMQImpl;
|
36 | 34 | import com.rabbitmq.tools.Host;
|
@@ -238,73 +236,68 @@ public void testNoAccess()
|
238 | 236 | Host.rabbitmqctl("set_permissions -p /test test \"\" \"\" \"\"");
|
239 | 237 | Thread.sleep(2000);
|
240 | 238 |
|
241 |
| - expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() { |
242 |
| - public void with(String _) throws IOException { |
243 |
| - channel.queueDeclare(); |
244 |
| - }} |
| 239 | + assertAccessRefused(new WithName() { |
| 240 | + public void with(String _) throws IOException { |
| 241 | + channel.queueDeclare(); |
| 242 | + } |
| 243 | + } |
245 | 244 | );
|
246 | 245 |
|
247 |
| - expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() { |
248 |
| - public void with(String _) throws IOException { |
249 |
| - channel.queueDeclare("justaqueue", false, false, true, null); |
250 |
| - }} |
251 |
| - ); |
252 |
| - expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() { |
253 |
| - public void with(String _) throws IOException { |
254 |
| - channel.queueDelete("configure"); |
255 |
| - }} |
| 246 | + assertAccessRefused(new WithName() { |
| 247 | + public void with(String _) throws IOException { |
| 248 | + channel.queueDeclare("justaqueue", false, false, true, null); |
| 249 | + } |
| 250 | + } |
256 | 251 | );
|
257 |
| - expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() { |
258 |
| - public void with(String _) throws IOException { |
259 |
| - channel.queueBind("write", "write", "write"); |
260 |
| - }} |
| 252 | + assertAccessRefused(new WithName() { |
| 253 | + public void with(String _) throws IOException { |
| 254 | + channel.queueDelete("configure"); |
| 255 | + } |
| 256 | + } |
261 | 257 | );
|
262 |
| - expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() { |
263 |
| - public void with(String _) throws IOException { |
264 |
| - channel.queuePurge("read"); |
265 |
| - }} |
| 258 | + assertAccessRefused(new WithName() { |
| 259 | + public void with(String _) throws IOException { |
| 260 | + channel.queueBind("write", "write", "write"); |
| 261 | + } |
| 262 | + } |
266 | 263 | );
|
267 |
| - expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() { |
268 |
| - public void with(String _) throws IOException { |
269 |
| - channel.exchangeDeclare("justanexchange", "direct"); |
270 |
| - }} |
| 264 | + assertAccessRefused(new WithName() { |
| 265 | + public void with(String _) throws IOException { |
| 266 | + channel.queuePurge("read"); |
| 267 | + } |
| 268 | + } |
271 | 269 | );
|
272 |
| - expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() { |
273 |
| - public void with(String _) throws IOException { |
274 |
| - channel.exchangeDeclare("configure", "direct"); |
275 |
| - }} |
| 270 | + assertAccessRefused(new WithName() { |
| 271 | + public void with(String _) throws IOException { |
| 272 | + channel.exchangeDeclare("justanexchange", "direct"); |
| 273 | + } |
| 274 | + } |
276 | 275 | );
|
277 |
| - expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() { |
278 |
| - public void with(String _) throws IOException { |
279 |
| - channel.basicPublish("write", "", null, "foo".getBytes()); |
280 |
| - channel.basicQos(0); |
281 |
| - }} |
| 276 | + assertAccessRefused(new WithName() { |
| 277 | + public void with(String _) throws IOException { |
| 278 | + channel.exchangeDeclare("configure", "direct"); |
| 279 | + } |
| 280 | + } |
282 | 281 | );
|
283 |
| - expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() { |
284 |
| - public void with(String _) throws IOException { |
285 |
| - channel.basicGet("read", false); |
286 |
| - }} |
| 282 | + assertAccessRefused(new WithName() { |
| 283 | + public void with(String _) throws IOException { |
| 284 | + channel.basicPublish("write", "", null, "foo".getBytes()); |
| 285 | + channel.basicQos(0); |
| 286 | + } |
| 287 | + } |
287 | 288 | );
|
288 |
| - expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() { |
289 |
| - public void with(String _) throws IOException { |
290 |
| - channel.basicConsume("read", null); |
291 |
| - }} |
| 289 | + assertAccessRefused(new WithName() { |
| 290 | + public void with(String _) throws IOException { |
| 291 | + channel.basicGet("read", false); |
| 292 | + } |
| 293 | + } |
292 | 294 | );
|
293 |
| - } |
294 |
| - |
295 |
| - protected void expectExceptionRun(int exceptionCode, WithName action) |
296 |
| - throws IOException |
297 |
| - { |
298 |
| - try { |
299 |
| - action.with(""); |
300 |
| - fail(); |
301 |
| - } catch (IOException e) { |
302 |
| - checkShutdownSignal(exceptionCode, e); |
303 |
| - openChannel(); |
304 |
| - } catch (AlreadyClosedException e) { |
305 |
| - checkShutdownSignal(exceptionCode, e); |
306 |
| - openChannel(); |
| 295 | + assertAccessRefused(new WithName() { |
| 296 | + public void with(String _) throws IOException { |
| 297 | + channel.basicConsume("read", null); |
| 298 | + } |
307 | 299 | }
|
| 300 | + ); |
308 | 301 | }
|
309 | 302 |
|
310 | 303 | protected WithName createAltExchConfigTest(final String exchange)
|
@@ -336,6 +329,10 @@ protected void runTest(boolean expC, boolean expW, boolean expR,
|
336 | 329 | runTest(expR, "read", test);
|
337 | 330 | }
|
338 | 331 |
|
| 332 | + protected void assertAccessRefused(WithName test) throws IOException { |
| 333 | + runTest(false, "", test); |
| 334 | + } |
| 335 | + |
339 | 336 | protected void runTest(boolean exp, String name, WithName test)
|
340 | 337 | throws IOException
|
341 | 338 | {
|
|
0 commit comments