-
Notifications
You must be signed in to change notification settings - Fork 0
/
RabbitTests.java
49 lines (42 loc) · 1.67 KB
/
RabbitTests.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.example.junitstuff;
import com.example.junitstuff.model.Thing;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.test.RabbitListenerTestHarness;
import org.springframework.amqp.rabbit.test.TestRabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.TimeZone;
import java.util.UUID;
import static com.example.junitstuff.RabbitConfiguration.*;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
/**
* This is supposed to verify that the listener got the message and also verify that the special header is present and
* contains a certain value.
*/
@Slf4j
@SpringBootTest(classes = {TestConfig.class, ApplicationConfig.class})
class RabbitTests {
private final TenantContext tenantContext = new TenantContext();
@Autowired
private RabbitListenerTestHarness harness;
@Autowired
private TestRabbitTemplate template;
@Test
void test() {
Thing t = new Thing(UUID.randomUUID(), "Arc Reactor", ZonedDateTime.now(ZoneId.of("UTC")));
final String tenant = "STARK";
log.info("Sending message, Exchange:{}, Routing Key:{}, Object:{}", EXCHANGE_NAME, ROUTING_KEY, t);
try {
tenantContext.setTenantId(tenant);
template.convertAndSend(EXCHANGE_NAME, QUEUE_NAME, t);
} finally {
tenantContext.clear();
}
ThingListener thingListener = harness.getSpy(LISTENER_ID);
verify(thingListener).receiveWidget(tenant, t);
}
}