]> git.somenet.org - pub/jan/dst18.git/blob - ass3-messaging/src/test/java/dst/ass3/messaging/RabbitResource.java
[3.2-java] der meh part. like srsly docker-java? -.-
[pub/jan/dst18.git] / ass3-messaging / src / test / java / dst / ass3 / messaging / RabbitResource.java
1 package dst.ass3.messaging;
2
3 import org.junit.rules.ExternalResource;
4 import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
5 import org.springframework.amqp.rabbit.core.RabbitAdmin;
6 import org.springframework.amqp.rabbit.core.RabbitManagementTemplate;
7 import org.springframework.amqp.rabbit.core.RabbitTemplate;
8
9 public class RabbitResource extends ExternalResource {
10
11     private RabbitAdmin admin;
12     private RabbitManagementTemplate manager;
13     private CachingConnectionFactory connectionFactory;
14     private RabbitTemplate client;
15
16     @Override
17     protected void before() throws Throwable {
18         manager = new RabbitManagementTemplate(Constants.RMQ_API_URL, Constants.RMQ_USER, Constants.RMQ_PASSWORD);
19
20         connectionFactory = new CachingConnectionFactory(Constants.RMQ_HOST);
21         connectionFactory.setUsername(Constants.RMQ_USER);
22         connectionFactory.setPassword(Constants.RMQ_PASSWORD);
23
24         client = new RabbitTemplate(connectionFactory);
25         admin = new RabbitAdmin(connectionFactory);
26     }
27
28     @Override
29     protected void after() {
30         connectionFactory.destroy();
31     }
32
33     public RabbitManagementTemplate getManager() {
34         return manager;
35     }
36
37     public RabbitTemplate getClient() {
38         return client;
39     }
40
41     public RabbitAdmin getAdmin() {
42         return admin;
43     }
44
45     public CachingConnectionFactory getConnectionFactory() {
46         return connectionFactory;
47     }
48 }