X-Git-Url: http://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fde%2Fjuplo%2Fkafka%2Fchat%2Fbackend%2Fapi%2FChatBackendControllerTest.java;h=1b25a11eb7874581a0501a0aaaead48c98eb4804;hb=2095f4c6a102a52f2a15360d1b6355e4990f8f43;hp=eeaf5ee84ca028e1c6f194602a6ad7f6a5d4d17b;hpb=f5bc2f9d05c472ad1b8f55fe193727ea3a84dc4d;p=demos%2Fkafka%2Fchat diff --git a/src/test/java/de/juplo/kafka/chat/backend/api/ChatBackendControllerTest.java b/src/test/java/de/juplo/kafka/chat/backend/api/ChatBackendControllerTest.java index eeaf5ee8..1b25a11e 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/api/ChatBackendControllerTest.java +++ b/src/test/java/de/juplo/kafka/chat/backend/api/ChatBackendControllerTest.java @@ -1,6 +1,7 @@ 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; @@ -20,13 +21,15 @@ import static org.mockito.ArgumentMatchers.any; 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; @@ -36,12 +39,12 @@ public class ChatBackendControllerTest { // 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(); @@ -56,12 +59,12 @@ public class ChatBackendControllerTest { // 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(); @@ -77,13 +80,13 @@ public class ChatBackendControllerTest 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) @@ -103,13 +106,13 @@ public class ChatBackendControllerTest 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) @@ -126,12 +129,12 @@ public class ChatBackendControllerTest { // 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(); @@ -167,9 +170,10 @@ public class ChatBackendControllerTest 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, @@ -185,7 +189,7 @@ public class ChatBackendControllerTest client .put() .uri( - "/put/{chatroomId}/{username}/{messageId}", + "/{chatroomId}/{username}/{messageId}", chatroomId, user, messageId) @@ -218,9 +222,10 @@ public class ChatBackendControllerTest 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()); @@ -232,7 +237,7 @@ public class ChatBackendControllerTest client .put() .uri( - "/put/{chatroomId}/{username}/{messageId}", + "/{chatroomId}/{username}/{messageId}", chatroomId, user, messageId)