1 package dst.ass3.messaging.impl;
3 import static dst.ass3.messaging.Constants.RMQ_VHOST;
4 import static dst.ass3.messaging.Constants.TOPIC_EXCHANGE;
5 import static dst.ass3.messaging.Constants.WORK_QUEUES;
6 import static org.hamcrest.CoreMatchers.*;
7 import static org.junit.Assert.assertThat;
9 import java.io.IOException;
10 import java.util.Arrays;
11 import java.util.List;
12 import java.util.concurrent.TimeUnit;
13 import java.util.stream.Collectors;
15 import org.junit.After;
16 import org.junit.Before;
17 import org.junit.Rule;
18 import org.junit.Test;
19 import org.junit.rules.Timeout;
20 import org.springframework.amqp.core.Exchange;
21 import org.springframework.amqp.core.Queue;
23 import dst.ass3.messaging.IMessagingFactory;
24 import dst.ass3.messaging.IQueueManager;
25 import dst.ass3.messaging.RabbitResource;
27 public class QueueManagerTest {
30 public RabbitResource rabbit = new RabbitResource();
33 public Timeout timeout = new Timeout(10, TimeUnit.SECONDS);
35 private IMessagingFactory factory = new MessagingFactory();
36 private IQueueManager queueManager;
39 public void setUp() throws Exception {
40 factory = new MessagingFactory();
41 queueManager = factory.createQueueManager();
45 public void tearDown() throws Exception {
48 } catch (IOException e) {
54 public void setUp_createsQueues() throws Exception {
58 List<Queue> queues = rabbit.getManager().getQueues();
59 assertThat(queues.size(), not(0));
61 // make sure all work queues exist
62 List<String> queueNames = queues.stream().map(Queue::getName).collect(Collectors.toList());
63 Arrays.stream(WORK_QUEUES)
64 .forEach(wq -> assertThat(queueNames, hasItem(wq)));
66 queueManager.tearDown();
71 public void setUp_createsExchange() throws Exception {
74 Exchange exchange = rabbit.getManager().getExchange(RMQ_VHOST, TOPIC_EXCHANGE);
75 assertThat(exchange, notNullValue());
77 queueManager.tearDown();
82 public void tearDown_removesQueues() throws Exception {
84 queueManager.tearDown();
85 List<Queue> queues = rabbit.getManager().getQueues();
86 List<String> queueNames = queues.stream().map(Queue::getName).collect(Collectors.toList());
87 Arrays.stream(WORK_QUEUES)
88 .forEach(wq -> assertThat(queueNames, not(hasItem(wq))));
92 public void tearDown_removesExchange() throws Exception {
94 queueManager.tearDown();
95 Exchange exchange = rabbit.getManager().getExchange(RMQ_VHOST, TOPIC_EXCHANGE);
96 assertThat(exchange, nullValue());