FIX
[demos/kafka/chat] / src / test / java / de / juplo / kafka / chat / backend / AbstractConfigurationWithShardingIT.java
1 package de.juplo.kafka.chat.backend;
2
3 import org.junit.jupiter.api.DisplayName;
4 import org.junit.jupiter.api.Test;
5 import org.springframework.http.MediaType;
6 import org.testcontainers.shaded.org.awaitility.Awaitility;
7
8 import java.time.Duration;
9
10 import static org.hamcrest.Matchers.endsWith;
11
12
13 public abstract class AbstractConfigurationWithShardingIT extends AbstractConfigurationIT
14 {
15   @Test
16   @DisplayName("A PUT-message for a not owned shard yields 404 - NOT FOUND")
17   void testNotFoundForPutMessageToAChatRoomInNotOwnedShard()
18   {
19     String otherChatRoomId = "4e7246a6-29ae-43ea-b56f-669c3481ac19";
20     int shard = 0;
21
22     Awaitility
23         .await()
24         .atMost(Duration.ofSeconds(15))
25         .untilAsserted(() ->
26           webTestClient
27               .put()
28               .uri(
29                   "http://localhost:{port}/{chatRoomId}/otto/66",
30                   port,
31                   otherChatRoomId)
32               .contentType(MediaType.TEXT_PLAIN)
33               .accept(MediaType.APPLICATION_JSON)
34               .bodyValue("The devil rules route 66")
35               .exchange()
36               .expectStatus().isNotFound()
37               .expectBody()
38               .jsonPath("$.type").value(endsWith("/problem/shard-not-owned"))
39               .jsonPath("$.shard").isEqualTo(shard));
40   }
41 }