Skip to content

Commit 17d5985

Browse files
author
Simon MacMullen
committed
Further reduce duplication.
1 parent 6081714 commit 17d5985

File tree

1 file changed

+55
-58
lines changed

1 file changed

+55
-58
lines changed

test/src/com/rabbitmq/client/test/server/Permissions.java

Lines changed: 55 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@
2626

2727
import com.rabbitmq.client.AMQP;
2828
import com.rabbitmq.client.Channel;
29-
import com.rabbitmq.client.Command;
3029
import com.rabbitmq.client.Connection;
3130
import com.rabbitmq.client.ConnectionFactory;
3231
import com.rabbitmq.client.QueueingConsumer;
33-
import com.rabbitmq.client.ShutdownSignalException;
3432
import com.rabbitmq.client.impl.AMQChannel;
3533
import com.rabbitmq.client.impl.AMQImpl;
3634
import com.rabbitmq.tools.Host;
@@ -238,73 +236,68 @@ public void testNoAccess()
238236
Host.rabbitmqctl("set_permissions -p /test test \"\" \"\" \"\"");
239237
Thread.sleep(2000);
240238

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+
}
245244
);
246245

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+
}
256251
);
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+
}
261257
);
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+
}
266263
);
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+
}
271269
);
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+
}
276275
);
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+
}
282281
);
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+
}
287288
);
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+
}
292294
);
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+
}
307299
}
300+
);
308301
}
309302

310303
protected WithName createAltExchConfigTest(final String exchange)
@@ -336,6 +329,10 @@ protected void runTest(boolean expC, boolean expW, boolean expR,
336329
runTest(expR, "read", test);
337330
}
338331

332+
protected void assertAccessRefused(WithName test) throws IOException {
333+
runTest(false, "", test);
334+
}
335+
339336
protected void runTest(boolean exp, String name, WithName test)
340337
throws IOException
341338
{

0 commit comments

Comments
 (0)