2525import java .io .IOException ;
2626import java .util .concurrent .Callable ;
2727import java .util .concurrent .TimeoutException ;
28+ import org .slf4j .Logger ;
29+ import org .slf4j .LoggerFactory ;
2830
2931import static org .junit .Assert .fail ;
3032
3133public class TopicPermissions extends BrokerTestCase {
3234
35+ private static final Logger LOGGER = LoggerFactory .getLogger (TopicPermissions .class );
36+
3337 String protectedTopic = "protected.topic" ;
3438 String notProtectedTopic = "not.protected.topic" ;
3539 String noneTopicExchange = "not.a.topic" ;
3640
3741 @ Override
3842 protected boolean shouldRun () throws IOException {
43+ LOGGER .debug ("Checking if test should run" );
3944 return Host .isRabbitMqCtlCommandAvailable ("set_topic_permissions" );
4045 }
4146
4247 @ Override
4348 protected void createResources () throws IOException , TimeoutException {
49+ LOGGER .debug ("Creating AMQP resources" );
4450 channel .exchangeDeclare (protectedTopic , BuiltinExchangeType .TOPIC );
4551 channel .exchangeDeclare (notProtectedTopic , BuiltinExchangeType .TOPIC );
4652 channel .exchangeDeclare (noneTopicExchange , BuiltinExchangeType .DIRECT );
4753
54+ LOGGER .debug ("Setting permissions" );
4855 Host .rabbitmqctl ("set_topic_permissions -p / guest " + protectedTopic + " \" ^{username}\" \" ^{username}\" " );
4956 Host .rabbitmqctl ("set_topic_permissions -p / guest " + noneTopicExchange + " \" ^{username}\" \" ^{username}\" " );
5057 }
5158
5259 @ Override
5360 protected void releaseResources () throws IOException {
61+ LOGGER .debug ("Deleting AMQP resources" );
5462 channel .exchangeDelete (protectedTopic );
5563 channel .exchangeDelete (notProtectedTopic );
5664 channel .exchangeDelete (noneTopicExchange );
5765
66+ LOGGER .debug ("Clearing permissions" );
5867 Host .rabbitmqctl ("clear_topic_permissions -p / guest" );
5968 }
6069
@@ -107,14 +116,18 @@ public void topicPermissions() throws IOException {
107116 }
108117
109118 void assertAccessOk (String description , Callable <Void > action ) {
119+ LOGGER .debug ("Running '" + description + "'" );
110120 try {
111121 action .call ();
112122 } catch (Exception e ) {
113123 fail (description + " (" + e .getMessage ()+")" );
124+ } finally {
125+ LOGGER .debug ("'" + description + "' done" );
114126 }
115127 }
116128
117129 void assertAccessRefused (String description , Callable <Void > action ) throws IOException {
130+ LOGGER .debug ("Running '" + description + "'" );
118131 try {
119132 action .call ();
120133 fail (description );
@@ -126,6 +139,8 @@ void assertAccessRefused(String description, Callable<Void> action) throws IOExc
126139 openChannel ();
127140 } catch (Exception e ) {
128141 fail ("Unexpected exception: " + e .getMessage ());
142+ } finally {
143+ LOGGER .debug ("'" + description + "' done" );
129144 }
130145 }
131146}
0 commit comments