import java.util.List;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.random.RandomGenerator;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.endsWith;
-import static pl.rzrz.assertj.reactor.Assertions.assertThat;
@Slf4j
}
@Test
- @DisplayName("Restored messages can be seen, when listening to restored chat-room")
- void testListenToRestoredChatRoomYieldsRestoredMessages()
- {
- Awaitility
- .await()
- .atMost(Duration.ofSeconds(15))
- .untilAsserted(() ->
- {
- Flux<MessageTo> result = webTestClient
- .get()
- .uri(
- "http://localhost:{port}/{chatRoomId}/listen",
- port,
- EXISTING_CHATROOM)
- .accept(MediaType.TEXT_EVENT_STREAM)
- .exchange()
- .expectStatus().isOk()
- .returnResult(MessageTo.class)
- .getResponseBody();
-
- List<MessageTo> messages = result
- .take(expectedExistingMessages.length)
- .collectList()
- .block();
- assertThat(messages).containsExactly(expectedExistingMessages);
- });
- }
-
- @Test
- @DisplayName("Newly send messages can be seen, when listening to restored chat-room")
- void testListenToRestoredChatRoomYieldsAddedMessages()
+ @DisplayName("Only newly send messages can be seen, when listening to restored chat-room")
+ void testListenToRestoredChatRoomYieldsOnlyNewlyAddedMessages()
{
MessageTo sentMessage = webTestClient
.put()
.uri(
- "http://localhost:{port}/{chatRoomId}/nerd/7",
+ "http://localhost:{port}/{chatRoomId}/nerd/{messageId}",
port,
- EXISTING_CHATROOM)
+ EXISTING_CHATROOM,
+ RandomGenerator.getDefault().nextInt())
.contentType(MediaType.TEXT_PLAIN)
.accept(MediaType.APPLICATION_JSON)
.bodyValue("Hello world!")