projects
/
demos
/
kafka
/
chat
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
refactor: Removed `ChatHomeFactory`
[demos/kafka/chat]
/
src
/
test
/
java
/
de
/
juplo
/
kafka
/
chat
/
backend
/
api
/
ChatBackendControllerTest.java
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
403c9d5
..
5ebd08d
100644
(file)
--- 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,32
+1,39
@@
package de.juplo.kafka.chat.backend.api;
package de.juplo.kafka.chat.backend.api;
+import de.juplo.kafka.chat.backend.ChatBackendProperties;
import de.juplo.kafka.chat.backend.domain.*;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.boot.test.context.SpringBootTest;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.context.annotation.Bean;
import org.springframework.http.MediaType;
import org.springframework.test.web.reactive.server.WebTestClient;
import reactor.core.publisher.Mono;
import java.time.Clock;
import java.time.LocalDateTime;
import org.springframework.http.MediaType;
import org.springframework.test.web.reactive.server.WebTestClient;
import reactor.core.publisher.Mono;
import java.time.Clock;
import java.time.LocalDateTime;
+import java.util.Arrays;
import java.util.UUID;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import java.util.UUID;
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.owned-shards=0,1,2,3,4,5,6,7,8,9" })
@AutoConfigureWebTestClient
@Slf4j
public class ChatBackendControllerTest
{
@MockBean
@AutoConfigureWebTestClient
@Slf4j
public class ChatBackendControllerTest
{
@MockBean
- ChatHomeService chatHomeService;
+
InMemory
ChatHomeService chatHomeService;
@MockBean
ChatRoomService chatRoomService;
@MockBean
ChatRoomService chatRoomService;
@@
-36,7
+43,7
@@
public class ChatBackendControllerTest
{
// Given
UUID chatroomId = UUID.randomUUID();
{
// Given
UUID chatroomId = UUID.randomUUID();
- when(chatHomeService.getChatRoom(any(UUID.class))).thenReturn(Mono.empty());
+ when(chatHomeService.getChatRoom(any
Int(), any
(UUID.class))).thenReturn(Mono.empty());
// When
WebTestClient.ResponseSpec responseSpec = client
// When
WebTestClient.ResponseSpec responseSpec = client
@@
-56,7
+63,7
@@
public class ChatBackendControllerTest
{
// Given
UUID chatroomId = UUID.randomUUID();
{
// Given
UUID chatroomId = UUID.randomUUID();
- when(chatHomeService.getChatRoom(any(UUID.class))).thenReturn(Mono.empty());
+ when(chatHomeService.getChatRoom(any
Int(), any
(UUID.class))).thenReturn(Mono.empty());
// When
WebTestClient.ResponseSpec responseSpec = client
// When
WebTestClient.ResponseSpec responseSpec = client
@@
-77,7
+84,7
@@
public class ChatBackendControllerTest
UUID chatroomId = UUID.randomUUID();
String username = "foo";
Long messageId = 66l;
UUID chatroomId = UUID.randomUUID();
String username = "foo";
Long messageId = 66l;
- when(chatHomeService.getChatRoom(any(UUID.class))).thenReturn(Mono.empty());
+ when(chatHomeService.getChatRoom(any
Int(), any
(UUID.class))).thenReturn(Mono.empty());
// When
WebTestClient.ResponseSpec responseSpec = client
// When
WebTestClient.ResponseSpec responseSpec = client
@@
-103,7
+110,7
@@
public class ChatBackendControllerTest
UUID chatroomId = UUID.randomUUID();
String username = "foo";
Long messageId = 66l;
UUID chatroomId = UUID.randomUUID();
String username = "foo";
Long messageId = 66l;
- when(chatHomeService.getChatRoom(any(UUID.class))).thenReturn(Mono.empty());
+ when(chatHomeService.getChatRoom(any
Int(), any
(UUID.class))).thenReturn(Mono.empty());
// When
WebTestClient.ResponseSpec responseSpec = client
// When
WebTestClient.ResponseSpec responseSpec = client
@@
-126,7
+133,7
@@
public class ChatBackendControllerTest
{
// Given
UUID chatroomId = UUID.randomUUID();
{
// Given
UUID chatroomId = UUID.randomUUID();
- when(chatHomeService.getChatRoom(any(UUID.class))).thenReturn(Mono.empty());
+ when(chatHomeService.getChatRoom(any
Int(), any
(UUID.class))).thenReturn(Mono.empty());
// When
WebTestClient.ResponseSpec responseSpec = client
// When
WebTestClient.ResponseSpec responseSpec = client
@@
-167,9
+174,10
@@
public class ChatBackendControllerTest
ChatRoom chatRoom = new ChatRoom(
chatroomId,
"Test-ChatRoom",
ChatRoom chatRoom = new ChatRoom(
chatroomId,
"Test-ChatRoom",
+ 0,
Clock.systemDefaultZone(),
chatRoomService, 8);
Clock.systemDefaultZone(),
chatRoomService, 8);
- when(chatHomeService.getChatRoom(any(UUID.class))).thenReturn(Mono.just(chatRoom));
+ when(chatHomeService.getChatRoom(any
Int(), any
(UUID.class))).thenReturn(Mono.just(chatRoom));
Message existingMessage = new Message(
key,
serialNumberExistingMessage,
Message existingMessage = new Message(
key,
serialNumberExistingMessage,
@@
-218,9
+226,10
@@
public class ChatBackendControllerTest
ChatRoom chatRoom = new ChatRoom(
chatroomId,
"Test-ChatRoom",
ChatRoom chatRoom = new ChatRoom(
chatroomId,
"Test-ChatRoom",
+ 0,
Clock.systemDefaultZone(),
chatRoomService, 8);
Clock.systemDefaultZone(),
chatRoomService, 8);
- when(chatHomeService.getChatRoom(any(UUID.class)))
+ when(chatHomeService.getChatRoom(any
Int(), any
(UUID.class)))
.thenReturn(Mono.just(chatRoom));
when(chatRoomService.getMessage(any(Message.MessageKey.class)))
.thenReturn(Mono.empty());
.thenReturn(Mono.just(chatRoom));
when(chatRoomService.getMessage(any(Message.MessageKey.class)))
.thenReturn(Mono.empty());
@@
-246,4
+255,20
@@
public class ChatBackendControllerTest
.jsonPath("$.username").isEqualTo(user);
verify(chatRoomService, never()).persistMessage(eq(key), any(LocalDateTime.class), any(String.class));
}
.jsonPath("$.username").isEqualTo(user);
verify(chatRoomService, never()).persistMessage(eq(key), any(LocalDateTime.class), any(String.class));
}
+
+ @TestConfiguration
+ static class Config
+ {
+ @Bean
+ ChatHome[] chatHomes(
+ ChatBackendProperties properties,
+ InMemoryChatHomeService service)
+ {
+ ChatHome[] chatHomes = new ChatHome[properties.getInmemory().getNumShards()];
+ Arrays
+ .stream(properties.getInmemory().getOwnedShards())
+ .forEach(i -> chatHomes[i] = new ChatHome(service, i));
+ return chatHomes;
+ }
+ }
}
}