1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package dev.aherscu.qa.testing.example.scenarios.tutorial7;
18
19 import static dev.aherscu.qa.testing.utils.StreamMatchersExtensions.*;
20 import static java.nio.charset.StandardCharsets.*;
21 import static java.util.Arrays.*;
22
23 import org.testng.annotations.*;
24
25 import dev.aherscu.qa.jgiven.rabbitmq.*;
26 import dev.aherscu.qa.jgiven.rabbitmq.model.*;
27 import dev.aherscu.qa.jgiven.rabbitmq.utils.*;
28 import dev.aherscu.qa.testing.utils.config.*;
29 import lombok.*;
30
31
32
33 public class RabbitMqTest
34 extends AbstractRabbitMqTest<Integer, String> {
35
36
37
38
39
40 protected RabbitMqTest() {
41 super(TestConfiguration.class);
42 }
43
44 @Test
45 @SneakyThrows
46 public void shouldRetrieve() {
47 given()
48 .a_queue(queueHandler);
49
50 when()
51 .publishing(asList(
52 Message.<String> builder()
53 .content("hello")
54 .build(),
55 Message.<String> builder()
56 .content("world")
57 .build()))
58 .and().consuming();
59
60 then()
61 .the_retrieved_messages(adaptedStream(message -> message.content,
62 hasSpecificItems("world", "hello")));
63 }
64
65 @BeforeMethod
66 @Override
67 @SneakyThrows
68 protected void beforeMethodInitiateQueueHandler() {
69 @SuppressWarnings("resource")
70
71 val testingChannel = connection.createChannel();
72 queueHandler = QueueHandler.<Integer, String> builder()
73 .channel(testingChannel)
74 .queue(testingChannel.queueDeclare().getQueue())
75 .indexingBy(message -> message.content.hashCode())
76 .consumingBy(bytes -> new String(bytes, UTF_8))
77 .publishingBy(String::getBytes)
78 .build();
79 }
80 }