package de.juplo.kafka.chat.backend.api;
import de.juplo.kafka.chat.backend.domain.*;
+import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatHomeService;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.mockito.Mockito.*;
-@SpringBootTest(properties = "spring.main.allow-bean-definition-overriding=true")
+@SpringBootTest(properties = {
+ "spring.main.allow-bean-definition-overriding=true",
+ "chat.backend.inmemory.sharding-strategy=none" })
@AutoConfigureWebTestClient
@Slf4j
public class ChatBackendControllerTest
{
@MockBean
- ChatHomeService chatHomeService;
+ InMemoryChatHomeService chatHomeService;
@MockBean
ChatRoomService chatRoomService;
{
// Given
UUID chatroomId = UUID.randomUUID();
- when(chatHomeService.getChatRoom(any(UUID.class))).thenReturn(Mono.empty());
+ when(chatHomeService.getChatRoom(anyInt(), any(UUID.class))).thenReturn(Mono.empty());
// When
WebTestClient.ResponseSpec responseSpec = client
.get()
- .uri("/list/{chatroomId}", chatroomId)
+ .uri("/{chatroomId}/list", chatroomId)
.accept(MediaType.APPLICATION_JSON)
.exchange();
{
// Given
UUID chatroomId = UUID.randomUUID();
- when(chatHomeService.getChatRoom(any(UUID.class))).thenReturn(Mono.empty());
+ when(chatHomeService.getChatRoom(anyInt(), any(UUID.class))).thenReturn(Mono.empty());
// When
WebTestClient.ResponseSpec responseSpec = client
.get()
- .uri("/get/{chatroomId}", chatroomId)
+ .uri("/{chatroomId}", chatroomId)
.accept(MediaType.APPLICATION_JSON)
.exchange();
UUID chatroomId = UUID.randomUUID();
String username = "foo";
Long messageId = 66l;
- when(chatHomeService.getChatRoom(any(UUID.class))).thenReturn(Mono.empty());
+ when(chatHomeService.getChatRoom(anyInt(), any(UUID.class))).thenReturn(Mono.empty());
// When
WebTestClient.ResponseSpec responseSpec = client
.put()
.uri(
- "/put/{chatroomId}/{username}/{messageId}",
+ "/{chatroomId}/{username}/{messageId}",
chatroomId,
username,
messageId)
UUID chatroomId = UUID.randomUUID();
String username = "foo";
Long messageId = 66l;
- when(chatHomeService.getChatRoom(any(UUID.class))).thenReturn(Mono.empty());
+ when(chatHomeService.getChatRoom(anyInt(), any(UUID.class))).thenReturn(Mono.empty());
// When
WebTestClient.ResponseSpec responseSpec = client
.get()
.uri(
- "/get/{chatroomId}/{username}/{messageId}",
+ "/{chatroomId}/{username}/{messageId}",
chatroomId,
username,
messageId)
{
// Given
UUID chatroomId = UUID.randomUUID();
- when(chatHomeService.getChatRoom(any(UUID.class))).thenReturn(Mono.empty());
+ when(chatHomeService.getChatRoom(anyInt(), any(UUID.class))).thenReturn(Mono.empty());
// When
WebTestClient.ResponseSpec responseSpec = client
.get()
- .uri("/listen/{chatroomId}", chatroomId)
+ .uri("/{chatroomId}/listen", chatroomId)
// .accept(MediaType.TEXT_EVENT_STREAM, MediaType.APPLICATION_JSON) << TODO: Does not work!
.exchange();
ChatRoom chatRoom = new ChatRoom(
chatroomId,
"Test-ChatRoom",
+ 0,
Clock.systemDefaultZone(),
chatRoomService, 8);
- when(chatHomeService.getChatRoom(any(UUID.class))).thenReturn(Mono.just(chatRoom));
+ when(chatHomeService.getChatRoom(anyInt(), any(UUID.class))).thenReturn(Mono.just(chatRoom));
Message existingMessage = new Message(
key,
serialNumberExistingMessage,
.thenReturn(Mono.just(existingMessage));
// Needed for readable error-reports, in case of a bug that leads to according unwanted call
when(chatRoomService.persistMessage(any(Message.MessageKey.class), any(LocalDateTime.class), any(String.class)))
- .thenReturn(mock(Message.class));
+ .thenReturn(Mono.just(mock(Message.class)));
// When
client
.put()
.uri(
- "/put/{chatroomId}/{username}/{messageId}",
+ "/{chatroomId}/{username}/{messageId}",
chatroomId,
user,
messageId)
ChatRoom chatRoom = new ChatRoom(
chatroomId,
"Test-ChatRoom",
+ 0,
Clock.systemDefaultZone(),
chatRoomService, 8);
- when(chatHomeService.getChatRoom(any(UUID.class)))
+ when(chatHomeService.getChatRoom(anyInt(), any(UUID.class)))
.thenReturn(Mono.just(chatRoom));
when(chatRoomService.getMessage(any(Message.MessageKey.class)))
.thenReturn(Mono.empty());
// Needed for readable error-reports, in case of a bug that leads to according unwanted call
when(chatRoomService.persistMessage(any(Message.MessageKey.class), any(LocalDateTime.class), any(String.class)))
- .thenReturn(mock(Message.class));
+ .thenReturn(Mono.just(mock(Message.class)));
// When
client
.put()
.uri(
- "/put/{chatroomId}/{username}/{messageId}",
+ "/{chatroomId}/{username}/{messageId}",
chatroomId,
user,
messageId)