MBeanService { @PreAuthorize(SecurityConstants.MANAGE_ACTIVEMQ) public List<QueueMBean> getQueueStatistics() { try { List<QueueMBean> queues = new ArrayList<>(); for (ObjectName name : mBeanServer.getQueues()) { String destination = name.getKeyProperty(mBeanServer.getDestinationProperty()); QueueViewMBean queueView = mBeanServer.getQueueViewMBean(name); QueueMBean queue = new QueueMBean(destination); queue.setEnqueueCount(queueView.getEnqueueCount()); queue.setDequeueCount(queueView.getDequeueCount()); queue.setExpiredCount(queueView.getExpiredCount()); queue.setConsumerCount(queueView.getConsumerCount()); queue.setQueueSize(queueView.getQueueSize()); queues.add(queue); } return queues; } catch (IOException ex) { throw new MotechException("Could not access MBeans ", ex); } }  @PreAuthorize(SecurityConstants.MANAGE_ACTIVEMQ) List<TopicMBean> getTopicStatistics(); @PreAuthorize(SecurityConstants.MANAGE_ACTIVEMQ) List<QueueMBean> getQueueStatistics(); @PreAuthorize(SecurityConstants.MANAGE_ACTIVEMQ) List<QueueMessage> getQueueMessages(String queueName); static final String JMS_MESSAGE_ID; static final String JMS_REDELIVERED; static final String JMS_TIMESTAMP; }
@Test public void shouldReturnQueues() throws IOException { ObjectName fooQueue = mock(ObjectName.class); ObjectName[] queues = {fooQueue}; QueueViewMBean queueViewMBean = mock(QueueViewMBean.class); given(mBeanServer.getQueueViewMBean(any(ObjectName.class))).willReturn(queueViewMBean); given(mBeanServer.getQueues()).willReturn(queues); given(fooQueue.getKeyProperty(mBeanServer.getDestinationProperty())).willReturn("foo_queue"); List<QueueMBean> queueStatistics = mBeanService.getQueueStatistics(); assertThat(queueStatistics.size(), Is.is(1)); assertThat(queueStatistics.get(0).getDestination(), Is.is("foo_queue")); }