import de.juplo.kafka.chat.backend.domain.*;
import lombok.extern.slf4j.Slf4j;
-import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.web.reactive.server.WebTestClient;
+import reactor.core.publisher.Mono;
import java.time.LocalDateTime;
-import java.util.Optional;
import java.util.UUID;
import static org.mockito.ArgumentMatchers.any;
@MockBean
ChatHome chatHome;
- @Disabled
@Test
@DisplayName("Assert expected problem-details for unknown chatroom on GET /list/{chatroomId}")
void testUnknownChatroomExceptionForListChatroom(@Autowired WebTestClient client)
{
// Given
UUID chatroomId = UUID.randomUUID();
- when(chatHome.getChatroom(any(UUID.class))).thenReturn(Optional.empty());
+ when(chatHome.getChatroom(any(UUID.class)))
+ .thenReturn(Mono.error(() -> new UnknownChatroomException(chatroomId)));
// When
WebTestClient.ResponseSpec responseSpec = client
}
- @Disabled
@Test
@DisplayName("Assert expected problem-details for unknown chatroom on GET /get/{chatroomId}")
void testUnknownChatroomExceptionForGetChatroom(@Autowired WebTestClient client)
{
// Given
UUID chatroomId = UUID.randomUUID();
- when(chatHome.getChatroom(any(UUID.class))).thenReturn(Optional.empty());
+ when(chatHome.getChatroom(any(UUID.class)))
+ .thenReturn(Mono.error(() -> new UnknownChatroomException(chatroomId)));
// When
WebTestClient.ResponseSpec responseSpec = client
UUID chatroomId = UUID.randomUUID();
String username = "foo";
Long messageId = 66l;
- when(chatHome.getChatroom(any(UUID.class))).thenReturn(Optional.empty());
+ when(chatHome.getChatroom(any(UUID.class)))
+ .thenReturn(Mono.error(() -> new UnknownChatroomException(chatroomId)));
// When
WebTestClient.ResponseSpec responseSpec = client
UUID chatroomId = UUID.randomUUID();
String username = "foo";
Long messageId = 66l;
- when(chatHome.getChatroom(any(UUID.class))).thenReturn(Optional.empty());
+ when(chatHome.getChatroom(any(UUID.class)))
+ .thenReturn(Mono.error(() -> new UnknownChatroomException(chatroomId)));
// When
WebTestClient.ResponseSpec responseSpec = client
{
// Given
UUID chatroomId = UUID.randomUUID();
- when(chatHome.getChatroom(any(UUID.class))).thenReturn(Optional.empty());
+ when(chatHome.getChatroom(any(UUID.class)))
+ .thenReturn(Mono.error(() -> new UnknownChatroomException(chatroomId)));
// When
WebTestClient.ResponseSpec responseSpec = client
.get()
.uri("/listen/{chatroomId}", chatroomId)
- .accept(MediaType.TEXT_EVENT_STREAM, MediaType.APPLICATION_JSON)
+ // .accept(MediaType.TEXT_EVENT_STREAM, MediaType.APPLICATION_JSON) << TODO: Does not work!
.exchange();
// Then
Long messageId = 66l;
ChatRoom chatRoom = mock(ChatRoom.class);
when(chatHome.getChatroom(any(UUID.class)))
- .thenReturn(Optional.of(chatRoom));
+ .thenReturn(Mono.just(chatRoom));
Message.MessageKey key = Message.MessageKey.of("foo", 1l);
LocalDateTime timestamp = LocalDateTime.now();
- Message mutated = new Message(key, 0l, timestamp, "Mutated!");
Message existing = new Message(key, 0l, timestamp, "Existing");
when(chatRoom.addMessage(any(Long.class), any(String.class), any(String.class)))
- .thenThrow(new MessageMutationException(mutated, existing));
+ .thenReturn(Mono.error(() -> new MessageMutationException(existing, "Mutated!")));
// When
client
.expectStatus().is4xxClientError()
.expectBody()
.jsonPath("$.type").isEqualTo("/problem/message-mutation")
- .jsonPath("$.mutatedMessage.text").isEqualTo("Mutated!")
- .jsonPath("$.existingMessage.text").isEqualTo("Existing");
+ .jsonPath("$.existingMessage.text").isEqualTo("Existing")
+ .jsonPath("$.mutatedText").isEqualTo("Mutated!");
}
}