From 0cb37a01364eada023c330c2a0cfbd4c9a029e2d Mon Sep 17 00:00:00 2001 From: Tobias Peslalz Date: Thu, 8 Aug 2024 19:31:53 +0200 Subject: [PATCH] :white_check_mark: (callable) fix failing tests --- .../NotificationserviceApplicationTests.java | 8 ++++---- .../PostserviceApplicationTests.java | 20 ++++++++++++------- .../UserserviceApplicationTests.java | 8 ++++---- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/notificationservice/src/test/java/edu/hm/peslalz/thesis/notificationservice/NotificationserviceApplicationTests.java b/notificationservice/src/test/java/edu/hm/peslalz/thesis/notificationservice/NotificationserviceApplicationTests.java index 5692be4..1194aa6 100644 --- a/notificationservice/src/test/java/edu/hm/peslalz/thesis/notificationservice/NotificationserviceApplicationTests.java +++ b/notificationservice/src/test/java/edu/hm/peslalz/thesis/notificationservice/NotificationserviceApplicationTests.java @@ -72,10 +72,10 @@ void controllerTests() throws Exception { notification.setPostingUsersId(4); notificationService.createNotification(notification); Assertions.assertThat(notificationController.getUsersNotifications(3).call()).contains(notification); - Assertions.assertThat(notificationController.getNotificationCount(3, null)).isEqualTo(1); - Assertions.assertThat(notificationController.getNotificationCount(3, false)).isEqualTo(1); - notificationController.setReadStatus(3, true); - Assertions.assertThat(notificationController.getNotificationCount(3, true)).isEqualTo(1); + Assertions.assertThat(notificationController.getNotificationCount(3, null).call()).isEqualTo(1); + Assertions.assertThat(notificationController.getNotificationCount(3, false).call()).isEqualTo(1); + notificationController.setReadStatus(3, true).call(); + Assertions.assertThat(notificationController.getNotificationCount(3, true).call()).isEqualTo(1); } @AfterAll diff --git a/postservice/src/test/java/edu/hm/peslalz/thesis/postservice/PostserviceApplicationTests.java b/postservice/src/test/java/edu/hm/peslalz/thesis/postservice/PostserviceApplicationTests.java index b2a9736..de50f56 100644 --- a/postservice/src/test/java/edu/hm/peslalz/thesis/postservice/PostserviceApplicationTests.java +++ b/postservice/src/test/java/edu/hm/peslalz/thesis/postservice/PostserviceApplicationTests.java @@ -60,20 +60,20 @@ void scenario() throws Exception { verify(rabbitTemplate, times(1)).convertAndSend(eq("postservice.direct"), eq("post"),any(String.class)); Assertions.assertThat(postFirst.getCategories()).hasSize(2); Assertions.assertThat(Objects.requireNonNull(postController.getPostImage(postFirst.getId()).call().getBody()).getContentAsByteArray()).isEqualTo(imageBytes); - postController.likePost(postFirst.getId(), 1); - postController.commentPost(postFirst.getId(), new CommentRequest(2, "What a first post! Wow :)")); + postController.likePost(postFirst.getId(), 1).call(); + postController.commentPost(postFirst.getId(), new CommentRequest(2, "What a first post! Wow :)")).call(); postFirst = postController.getPost(postFirst.getId()).call(); Assertions.assertThat(postFirst).isNotNull(); Assertions.assertThat(postFirst.getComments()).hasSize(1); Assertions.assertThat(postFirst.getLikes()).isEqualTo(1); - assertThrows(ResponseStatusException.class, () -> commentController.likeComment(12345)); - assertThrows(ResponseStatusException.class, () -> postController.getPost(12345)); + assertThrows(ResponseStatusException.class, () -> commentController.likeComment(12345).call()); + assertThrows(ResponseStatusException.class, () -> postController.getPost(12345).call()); Assertions.assertThat(postController.getPosts("blog", null, 0, 50).call()).hasSize(1); Assertions.assertThat(postController.getPosts(null, 1, 0, 50).call()).hasSize(1); Comment comment = commentController.likeComment(postFirst.getComments().stream().findFirst().get().getId()).call(); Assertions.assertThat(comment.getLikes()).isEqualTo(1); - postController.createPost(1, "NewzFromMyLaif", Set.of("life", "blog"), null); + postController.createPost(1, "NewzFromMyLaif", Set.of("life", "blog"), null).call(); List categories = categoryController.getCategories(0).call().getContent(); Assertions.assertThat(categories).hasSize(3); } @@ -81,7 +81,7 @@ void scenario() throws Exception { @Test void scenarioUserNotFound() { Mockito.when(userClient.getUserAccount(ArgumentMatchers.anyInt())).thenThrow(FeignException.class); - assertThrows(ResponseStatusException.class, () -> postController.createPost(1, null, null, null)); + assertThrows(ResponseStatusException.class, () -> postController.createPost(1, null, null, null).call()); } @Test @@ -89,7 +89,13 @@ void parallelLikes() throws Exception { Post postFirst = postController.createPost(1, "MyFirstPost", Set.of("beginnings", "blog"), null).call(); Assertions.assertThat(postFirst.getCategories()).hasSize(2); Post finalPostFirst = postFirst; - IntStream.range(0, 20).parallel().forEach(i -> postController.likePost(finalPostFirst.getId(),1)); + IntStream.range(0, 20).parallel().forEach(i -> { + try { + postController.likePost(finalPostFirst.getId(),1).call(); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); postFirst = postController.getPost(postFirst.getId()).call(); Assertions.assertThat(postFirst.getLikes()).isEqualTo(20); } diff --git a/userservice/src/test/java/edu/hm/peslalz/thesis/userservice/UserserviceApplicationTests.java b/userservice/src/test/java/edu/hm/peslalz/thesis/userservice/UserserviceApplicationTests.java index eb71c28..3e66863 100644 --- a/userservice/src/test/java/edu/hm/peslalz/thesis/userservice/UserserviceApplicationTests.java +++ b/userservice/src/test/java/edu/hm/peslalz/thesis/userservice/UserserviceApplicationTests.java @@ -38,7 +38,7 @@ void scenario() throws Exception { private UserAccount createUser() throws Exception { UserAccount testiasTestlalz = userAccountController.createUserAccount(new UserAccountRequest("Testias Testlaz")).call(); assertThat(testiasTestlalz.getId()).isNotNull(); - assertThat(userAccountController.getUserAccount(testiasTestlalz.getId())).isEqualTo(userAccountController.searchUser("Testias Testlaz", 0).call().stream().iterator().next()); + assertThat(userAccountController.getUserAccount(testiasTestlalz.getId()).call()).isEqualTo(userAccountController.searchUser("Testias Testlaz", 0).call().stream().iterator().next()); return testiasTestlalz; } @@ -57,9 +57,9 @@ private UserAccount createNewUserAndFollow(UserAccount testiasTestlalz) throws E private void countFollowers(UserAccount contentCreator) throws Exception { UserAccount contentCreatorLover = userAccountController.createUserAccount(new UserAccountRequest("ContentCreatorLover")).call(); - userAccountController.followUser(contentCreator.getUsername(), contentCreatorLover.getId()); - userAccountController.followUser(contentCreator.getUsername(), contentCreatorLover.getId()); - userAccountController.followUser(contentCreator.getUsername(), contentCreatorLover.getId()); + userAccountController.followUser(contentCreator.getUsername(), contentCreatorLover.getId()).call(); + userAccountController.followUser(contentCreator.getUsername(), contentCreatorLover.getId()).call(); + userAccountController.followUser(contentCreator.getUsername(), contentCreatorLover.getId()).call(); assertThat(userAccountController.getFollowers(contentCreator.getId()).call()).hasSize(2); } }