+ // Given
+ UUID chatroomId = UUID.randomUUID();
+ int shard = 666;
+ when(chatHome.getChatRoomData(eq(chatroomId))).thenThrow(new ShardNotOwnedException(shard));
+
+ // When
+ WebTestClient.ResponseSpec responseSpec = client
+ .get()
+ .uri("/{chatroomId}/list", chatroomId)
+ .accept(MediaType.APPLICATION_JSON)
+ .exchange();
+
+ // Then
+ assertProblemDetailsForShardNotOwnedException(responseSpec, shard);
+ }
+
+ @Test
+ @DisplayName("Assert expected problem-details for not owned shard on PUT /put/{chatroomId}/{username}/{messageId}")
+ void testShardNotOwnedExceptionForPutMessage(@Autowired WebTestClient client)
+ {
+ // Given
+ UUID chatroomId = UUID.randomUUID();
+ String username = "foo";
+ Long messageId = 66l;
+ int shard = 666;
+ when(chatHome.getChatRoomData(eq(chatroomId))).thenThrow(new ShardNotOwnedException(shard));
+
+ // When
+ WebTestClient.ResponseSpec responseSpec = client
+ .put()
+ .uri(
+ "/{chatroomId}/{username}/{messageId}",
+ chatroomId,
+ username,
+ messageId)
+ .bodyValue("bar")
+ .accept(MediaType.APPLICATION_JSON)
+ .exchange();
+
+ // Then
+ assertProblemDetailsForShardNotOwnedException(responseSpec, shard);
+ }
+
+ @Test
+ @DisplayName("Assert expected problem-details for not owned shard on GET /get/{chatroomId}/{username}/{messageId}")
+ void testShardNotOwnedExceptionForGetMessage(@Autowired WebTestClient client)
+ {
+ // Given
+ UUID chatroomId = UUID.randomUUID();
+ String username = "foo";
+ Long messageId = 66l;
+ int shard = 666;
+ when(chatHome.getChatRoomData(eq(chatroomId))).thenThrow(new ShardNotOwnedException(shard));
+
+ // When
+ WebTestClient.ResponseSpec responseSpec = client
+ .get()
+ .uri(
+ "/{chatroomId}/{username}/{messageId}",
+ chatroomId,
+ username,
+ messageId)
+ .accept(MediaType.APPLICATION_JSON)
+ .exchange();
+
+ // Then
+ assertProblemDetailsForShardNotOwnedException(responseSpec, shard);
+ }
+
+ @Test
+ @DisplayName("Assert expected problem-details for not owned shard on GET /listen/{chatroomId}")
+ void testShardNotOwnedExceptionForListenChatroom(@Autowired WebTestClient client)
+ {
+ // Given
+ UUID chatroomId = UUID.randomUUID();
+ int shard = 666;
+ when(chatHome.getChatRoomData(eq(chatroomId))).thenThrow(new ShardNotOwnedException(shard));
+
+ // When
+ WebTestClient.ResponseSpec responseSpec = client
+ .get()
+ .uri("/{chatroomId}/listen", chatroomId)
+ // .accept(MediaType.TEXT_EVENT_STREAM, MediaType.APPLICATION_JSON) << TODO: Does not work!
+ .exchange();
+
+ // Then
+ assertProblemDetailsForShardNotOwnedException(responseSpec, shard);
+ }
+
+ private void assertProblemDetailsForShardNotOwnedException(
+ WebTestClient.ResponseSpec responseSpec,
+ int shard)
+ {
+ responseSpec
+ .expectStatus().isNotFound()
+ .expectBody()
+ .jsonPath("$.type").isEqualTo("/problem/shard-not-owned")
+ .jsonPath("$.shard").isEqualTo(shard);