Skip to content

Commit

Permalink
✅ (callable) fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias-Pe committed Aug 8, 2024
1 parent 003c164 commit 0cb37a0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,36 +60,42 @@ 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<String> categories = categoryController.getCategories(0).call().getContent();
Assertions.assertThat(categories).hasSize(3);
}

@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
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);
}
}

0 comments on commit 0cb37a0

Please sign in to comment.