1 package de.juplo.kafka.chat.backend;
3 import de.juplo.kafka.chat.backend.api.ChatRoomInfoTo;
4 import lombok.extern.slf4j.Slf4j;
5 import org.junit.jupiter.api.BeforeEach;
6 import org.junit.jupiter.api.Test;
7 import org.springframework.core.ParameterizedTypeReference;
8 import org.springframework.http.HttpStatus;
9 import org.springframework.http.MediaType;
10 import org.springframework.http.codec.ServerSentEvent;
11 import org.springframework.web.reactive.function.client.WebClient;
12 import org.testcontainers.junit.jupiter.Testcontainers;
13 import reactor.core.publisher.Flux;
14 import reactor.core.publisher.Mono;
19 public abstract class AbstractHandoverIT
21 static final ParameterizedTypeReference<ServerSentEvent<String>> SSE_TYPE = new ParameterizedTypeReference<>() {};
24 private final AbstractHandoverITContainers containers;
27 AbstractHandoverIT(AbstractHandoverITContainers containers)
29 this.containers = containers;
34 void test() throws InterruptedException
36 ChatRoomInfoTo chatRoom = createChatRoom("bar").block();
37 TestClient testClient = new TestClient(
38 containers.haproxy.getMappedPort(8400),
43 receiveMessages(chatRoom)
45 .doOnNext(message -> log.info("message: {}", message))
50 Mono<ChatRoomInfoTo> createChatRoom(String name)
55 .contentType(MediaType.TEXT_PLAIN)
57 .accept(MediaType.APPLICATION_JSON)
58 .exchangeToMono(response ->
60 if (response.statusCode().equals(HttpStatus.OK))
62 return response.bodyToMono(ChatRoomInfoTo.class);
66 return response.createError();
71 Flux<ServerSentEvent<String>> receiveMessages(ChatRoomInfoTo chatRoom)
76 "/{chatRoomId}/listen",
78 .accept(MediaType.TEXT_EVENT_STREAM)
80 .bodyToFlux(SSE_TYPE);
87 void setUp() throws Exception
91 Integer port = containers.haproxy.getMappedPort(8400);
92 webClient = WebClient.create("http://localhost:" + port);