You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You're now sure that beyond the technical conformance, the `Order Service` also behaves as expected regarding business
246
302
constraints.
247
303
304
+
### Bonus step - Verify the business conformance of Order Service API in pure Java
305
+
306
+
Even if the Postman Collection runner is a great way to validate business conformance, you may want to do it in pure Java.
307
+
This is possible by retrieving the messages exchanged during the test and checking their content. Let's review the `testOpenAPIContractAndBusinessConformance()`
308
+
test in class `OrderControllerContractTests` under `src/test/java/org/acme/order/api`:
Copy file name to clipboardExpand all lines: step-5-write-async-tests.md
+44-1Lines changed: 44 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -86,7 +86,7 @@ Things are a bit more complex here, but we'll walk through step-by-step:
86
86
87
87
The sequence diagram below details the test sequence. You'll see 2 parallel blocks being executed:
88
88
* One that corresponds to Microcks test - where it connects and listen for Kafka messages,
89
-
* One that corresponds to the `OrderService`invokation that is expected to trigger a message on Kafka.
89
+
* One that corresponds to the `OrderService`invocation that is expected to trigger a message on Kafka.
90
90
91
91
```mermaid
92
92
sequenceDiagram
@@ -113,6 +113,49 @@ Because the test is a success, it means that Microcks has received an `OrderEven
113
113
conformance with the AsyncAPI contract or this event-driven architecture. So you're sure that all your Spring Boot configuration, Kafka JSON serializer
114
114
configuration and network communication are actually correct!
115
115
116
+
### Bonus step - Verify the event content
117
+
118
+
So you're now sure that an event has been sent to Kafka and that it's valid regarding the AsyncAPI contract. But what about the content
119
+
of this event? If you want to go further and check the content of the event, you can do it by asking Microcks the events read during the
120
+
test execution and actually check their content. This can be done adding a few lines of code:
121
+
122
+
```java
123
+
@Test
124
+
void testEventIsPublishedWhenOrderIsCreated() {
125
+
// [...] Unchanged comparing previous step.
126
+
127
+
try {
128
+
// [...] Unchanged comparing previous step.
129
+
130
+
// Get the Microcks test result.
131
+
TestResult testResult = testRequestFuture.get();
132
+
133
+
// [...] Unchanged comparing previous step.
134
+
135
+
// Check the content of the emitted event, read from Kafka topic.
0 commit comments