X-Git-Url: http://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fde%2Fjuplo%2Fkafka%2Fchat%2Fbackend%2Fapi%2FChatBackendControllerTest.java;h=403c9d52f267187598642daf30901357825f576e;hb=8adc14c2abeacb3605b0638afa95b1e4eea9e087;hp=2f120ae28d2143e5f666fd2cbf6ab355dd2954d2;hpb=aa0efd1151673c5f0f1576c3026f6fdd0dfad691;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 2f120ae2..403c9d52 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 @@ -41,7 +41,7 @@ public class ChatBackendControllerTest // When WebTestClient.ResponseSpec responseSpec = client .get() - .uri("/list/{chatroomId}", chatroomId) + .uri("/{chatroomId}/list", chatroomId) .accept(MediaType.APPLICATION_JSON) .exchange(); @@ -61,7 +61,7 @@ public class ChatBackendControllerTest // When WebTestClient.ResponseSpec responseSpec = client .get() - .uri("/get/{chatroomId}", chatroomId) + .uri("/{chatroomId}", chatroomId) .accept(MediaType.APPLICATION_JSON) .exchange(); @@ -83,7 +83,7 @@ public class ChatBackendControllerTest WebTestClient.ResponseSpec responseSpec = client .put() .uri( - "/put/{chatroomId}/{username}/{messageId}", + "/{chatroomId}/{username}/{messageId}", chatroomId, username, messageId) @@ -109,7 +109,7 @@ public class ChatBackendControllerTest WebTestClient.ResponseSpec responseSpec = client .get() .uri( - "/get/{chatroomId}/{username}/{messageId}", + "/{chatroomId}/{username}/{messageId}", chatroomId, username, messageId) @@ -131,7 +131,7 @@ public class ChatBackendControllerTest // 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(); @@ -185,7 +185,7 @@ public class ChatBackendControllerTest client .put() .uri( - "/put/{chatroomId}/{username}/{messageId}", + "/{chatroomId}/{username}/{messageId}", chatroomId, user, messageId) @@ -204,4 +204,46 @@ public class ChatBackendControllerTest .jsonPath("$.mutatedText").isEqualTo(textMutatedMessage); verify(chatRoomService, never()).persistMessage(eq(key), any(LocalDateTime.class), any(String.class)); } + + @Test + @DisplayName("Assert expected problem-details for invalid username on PUT /put/{chatroomId}/{username}/{messageId}") + void testInvalidUsernameException(@Autowired WebTestClient client) throws Exception + { + // Given + UUID chatroomId = UUID.randomUUID(); + String user = "Foo"; + Long messageId = 66l; + Message.MessageKey key = Message.MessageKey.of(user, messageId); + String textMessage = "Hallo Welt"; + ChatRoom chatRoom = new ChatRoom( + chatroomId, + "Test-ChatRoom", + Clock.systemDefaultZone(), + chatRoomService, 8); + when(chatHomeService.getChatRoom(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)); + + // When + client + .put() + .uri( + "/{chatroomId}/{username}/{messageId}", + chatroomId, + user, + messageId) + .bodyValue(textMessage) + .accept(MediaType.APPLICATION_JSON) + .exchange() + // Then + .expectStatus().is4xxClientError() + .expectBody() + .jsonPath("$.type").isEqualTo("/problem/invalid-username") + .jsonPath("$.username").isEqualTo(user); + verify(chatRoomService, never()).persistMessage(eq(key), any(LocalDateTime.class), any(String.class)); + } }