From b83405fb7038b383baf7a9304dab43b4e7f34661 Mon Sep 17 00:00:00 2001 From: denniskp <122602355+denniskp@users.noreply.github.com> Date: Wed, 29 May 2024 20:23:20 +0200 Subject: [PATCH] Restore deleted source code This reverts commit 309abec963b6f0ad67b70e831a348afb69c1b24d, reversing changes made to 92142a10e46e5049ff24754341acc26b51398c49. --- .../dhbwhub/controller/AuthController.java | 5 +- .../dhbwhub/controller/CourseController.java | 3 +- .../dhbwhub/controller/EventController.java | 5 ++ .../tinf22b6/dhbwhub/mapper/EventMapper.java | 19 +++-- .../dhbwhub/mapper/FriendshipMapper.java | 2 +- .../dhbwhub/mapper/NotificationMapper.java | 11 ++- .../tinf22b6/dhbwhub/mapper/UserMapper.java | 1 + .../de/tinf22b6/dhbwhub/model/EventPost.java | 10 +++ .../java/de/tinf22b6/dhbwhub/model/User.java | 2 + .../dhbwhub/proposal/UserProposal.java | 2 + .../dhbwhub/service/EventServiceImpl.java | 73 ++++++++++++++++++- .../service/interfaces/EventService.java | 1 + .../dhbwhub/AbstractApplicationTest.java | 44 +++++++++-- .../controller/EventControllerTests.java | 20 +++++ .../controller/UserControllerTests.java | 3 + .../service/EventServiceImplTests.java | 6 ++ 16 files changed, 188 insertions(+), 19 deletions(-) diff --git a/src/main/java/de/tinf22b6/dhbwhub/controller/AuthController.java b/src/main/java/de/tinf22b6/dhbwhub/controller/AuthController.java index 5c22ec94..dae23a7b 100644 --- a/src/main/java/de/tinf22b6/dhbwhub/controller/AuthController.java +++ b/src/main/java/de/tinf22b6/dhbwhub/controller/AuthController.java @@ -77,7 +77,7 @@ public ResponseEntity signup(@Valid @RequestBody SignupRequest signupRequest) signupRequest.getEmail(), passwordEncoder.encode(signupRequest.getPassword()), null,true); - User newUser = new User("new User", null, newAccount); + User newUser = new User(null, "new User", null, newAccount); accountRepository.save(newAccount); @@ -121,4 +121,5 @@ public ResponseEntity tokenValidation (@Valid @RequestBody TokenValidationReq } } -} \ No newline at end of file + +} diff --git a/src/main/java/de/tinf22b6/dhbwhub/controller/CourseController.java b/src/main/java/de/tinf22b6/dhbwhub/controller/CourseController.java index bb19ef88..739ea2b7 100644 --- a/src/main/java/de/tinf22b6/dhbwhub/controller/CourseController.java +++ b/src/main/java/de/tinf22b6/dhbwhub/controller/CourseController.java @@ -44,5 +44,4 @@ public Course update(@PathVariable Long id, @RequestBody CourseProposal proposal public void delete(@PathVariable Long id) { service.delete(id); } - -} \ No newline at end of file +} diff --git a/src/main/java/de/tinf22b6/dhbwhub/controller/EventController.java b/src/main/java/de/tinf22b6/dhbwhub/controller/EventController.java index a50f1109..197c6aed 100644 --- a/src/main/java/de/tinf22b6/dhbwhub/controller/EventController.java +++ b/src/main/java/de/tinf22b6/dhbwhub/controller/EventController.java @@ -48,6 +48,11 @@ public EventThreadViewProposal create(@RequestBody CreateEventPostProposal propo return service.create(proposal); } + @PutMapping("/update-event/{id}") + public EventThreadViewProposal update(@PathVariable Long id, @RequestBody UpdateEventPostProposal proposal) { + return service.update(id, proposal); + } + @PostMapping("/create-comment") public EventCommentThreadViewProposal create(@RequestBody CreateEventCommentProposal proposal) { return service.create(proposal); diff --git a/src/main/java/de/tinf22b6/dhbwhub/mapper/EventMapper.java b/src/main/java/de/tinf22b6/dhbwhub/mapper/EventMapper.java index 249e902e..fc93f4b7 100644 --- a/src/main/java/de/tinf22b6/dhbwhub/mapper/EventMapper.java +++ b/src/main/java/de/tinf22b6/dhbwhub/mapper/EventMapper.java @@ -4,29 +4,35 @@ import de.tinf22b6.dhbwhub.proposal.simplified_models.*; public class EventMapper { - public static EventPost mapToModel(CreateEventPostProposal proposal){ + public static EventPost mapToModel(CreateEventPostProposal proposal, User user, Picture picture){ return new EventPost( proposal.getTitle(), proposal.getDescription(), proposal.getLocation().getLocation(), proposal.getLocation().getLatitude(), proposal.getLocation().getLongitude(), + proposal.getTimestamp(), proposal.getStartdate(), proposal.getEnddate(), - 0 + 0, + picture, + user ); } - public static EventPost mapToModel(UpdateEventPostProposal proposal, EventPost post){ + public static EventPost mapToModel(UpdateEventPostProposal proposal, EventPost post, Picture picture){ return new EventPost( proposal.getTitle(), proposal.getDescription(), proposal.getLocation().getLocation(), proposal.getLocation().getLatitude(), proposal.getLocation().getLongitude(), + post.getTimestamp(), proposal.getStartdate(), proposal.getEnddate(), - post.getLikes() + post.getLikes(), + picture, + post.getUser() ); } @@ -37,9 +43,12 @@ public static EventPost mapToModel(EventPost post, int likes) { post.getLocation(), post.getLatitude(), post.getLongitude(), + post.getTimestamp(), post.getStartdate(), post.getEnddate(), - likes + likes, + post.getPicture(), + post.getUser() ); } diff --git a/src/main/java/de/tinf22b6/dhbwhub/mapper/FriendshipMapper.java b/src/main/java/de/tinf22b6/dhbwhub/mapper/FriendshipMapper.java index 043fe25e..686cadce 100644 --- a/src/main/java/de/tinf22b6/dhbwhub/mapper/FriendshipMapper.java +++ b/src/main/java/de/tinf22b6/dhbwhub/mapper/FriendshipMapper.java @@ -17,4 +17,4 @@ public static Friendship mapToFriendship(User requester, User receiver){ requester, receiver); } -} \ No newline at end of file +} diff --git a/src/main/java/de/tinf22b6/dhbwhub/mapper/NotificationMapper.java b/src/main/java/de/tinf22b6/dhbwhub/mapper/NotificationMapper.java index e0d621b5..fb2a72e6 100644 --- a/src/main/java/de/tinf22b6/dhbwhub/mapper/NotificationMapper.java +++ b/src/main/java/de/tinf22b6/dhbwhub/mapper/NotificationMapper.java @@ -139,4 +139,13 @@ public static CommentLikeNotification mapToCommentLikeNotification(Comment comme false ); } -} \ No newline at end of file + + public static EventCommentLikeNotification mapToEventCommentLikeNotification(EventComment eventComment, User user) { + return new EventCommentLikeNotification( + eventComment.getEventPost().getUser(), + eventComment.getEventPost(), + user, + false + ); + } +} diff --git a/src/main/java/de/tinf22b6/dhbwhub/mapper/UserMapper.java b/src/main/java/de/tinf22b6/dhbwhub/mapper/UserMapper.java index 0cde5f4b..a95c41ef 100644 --- a/src/main/java/de/tinf22b6/dhbwhub/mapper/UserMapper.java +++ b/src/main/java/de/tinf22b6/dhbwhub/mapper/UserMapper.java @@ -6,6 +6,7 @@ public class UserMapper { public static User mapToModel(UserProposal proposal) { return new User( + proposal.getAge(), proposal.getDescription(), proposal.getCourse() != null ? CourseMapper.mapToModel(proposal.getCourse()) : null, proposal.getAccount() != null ? AccountMapper.mapToModel(proposal.getAccount()) : null diff --git a/src/main/java/de/tinf22b6/dhbwhub/model/EventPost.java b/src/main/java/de/tinf22b6/dhbwhub/model/EventPost.java index 25cb3474..9c1c6a2f 100644 --- a/src/main/java/de/tinf22b6/dhbwhub/model/EventPost.java +++ b/src/main/java/de/tinf22b6/dhbwhub/model/EventPost.java @@ -27,10 +27,20 @@ public class EventPost { private final Double longitude; + private final Date timestamp; + private final Date startdate; private final Date enddate; private final int likes; + @JoinColumn(name = "picture_id") + @ManyToOne(cascade = CascadeType.PERSIST) + private final Picture picture; + + @JoinColumn(name = "user_id") + @ManyToOne(cascade = CascadeType.PERSIST) + private final User user; + } diff --git a/src/main/java/de/tinf22b6/dhbwhub/model/User.java b/src/main/java/de/tinf22b6/dhbwhub/model/User.java index c7836704..c90ee0e3 100644 --- a/src/main/java/de/tinf22b6/dhbwhub/model/User.java +++ b/src/main/java/de/tinf22b6/dhbwhub/model/User.java @@ -19,6 +19,8 @@ public class User { @Column(name = "user_id") private Long id; + private final Integer age; + private final String description; @JoinColumn(name = "course_id") diff --git a/src/main/java/de/tinf22b6/dhbwhub/proposal/UserProposal.java b/src/main/java/de/tinf22b6/dhbwhub/proposal/UserProposal.java index ad89b5d7..e9d5e03e 100644 --- a/src/main/java/de/tinf22b6/dhbwhub/proposal/UserProposal.java +++ b/src/main/java/de/tinf22b6/dhbwhub/proposal/UserProposal.java @@ -10,6 +10,8 @@ @AllArgsConstructor @NoArgsConstructor public class UserProposal { + private Integer age; + private String description; private CourseProposal course; diff --git a/src/main/java/de/tinf22b6/dhbwhub/service/EventServiceImpl.java b/src/main/java/de/tinf22b6/dhbwhub/service/EventServiceImpl.java index 96bac15c..ebfbd7c7 100644 --- a/src/main/java/de/tinf22b6/dhbwhub/service/EventServiceImpl.java +++ b/src/main/java/de/tinf22b6/dhbwhub/service/EventServiceImpl.java @@ -2,9 +2,13 @@ import de.tinf22b6.dhbwhub.exception.NoSuchEntryException; import de.tinf22b6.dhbwhub.mapper.EventMapper; +import de.tinf22b6.dhbwhub.mapper.EventTagMapper; +import de.tinf22b6.dhbwhub.mapper.NotificationMapper; +import de.tinf22b6.dhbwhub.mapper.PictureMapper; import de.tinf22b6.dhbwhub.model.*; import de.tinf22b6.dhbwhub.model.log_tables.LikeLogtableEventComment; import de.tinf22b6.dhbwhub.model.log_tables.LikeLogtableEventPost; +import de.tinf22b6.dhbwhub.model.notification_tables.EventCommentLikeNotification; import de.tinf22b6.dhbwhub.proposal.simplified_models.*; import de.tinf22b6.dhbwhub.repository.*; import de.tinf22b6.dhbwhub.service.interfaces.EventService; @@ -12,21 +16,29 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Objects; @Service public class EventServiceImpl implements EventService { private final EventRepository repository; private final UserRepository userRepository; + private final PictureRepository pictureRepository; private final LogtableRepository logtableRepository; + private final NotificationRepository notificationRepository; public EventServiceImpl(@Autowired EventRepository repository, @Autowired UserRepository userRepository, - @Autowired LogtableRepository logtableRepository) { + @Autowired PictureRepository pictureRepository, + @Autowired LogtableRepository logtableRepository, + @Autowired NotificationRepository notificationRepository) { this.repository = repository; this.userRepository = userRepository; + this.pictureRepository = pictureRepository; this.logtableRepository = logtableRepository; + this.notificationRepository = notificationRepository; } @Override @@ -65,7 +77,12 @@ public List getHomepageEvents() { @Override public EventThreadViewProposal create(CreateEventPostProposal proposal) { - EventPost post = repository.save(EventMapper.mapToModel(proposal)); + // Creating the Post itself + User user = userRepository.findByAccountId(proposal.getAccountId()); + Picture picture = proposal.getPostImage().length != 0 ? + pictureRepository.save(PictureMapper.mapToModelPost(proposal.getPostImage())): null; + + EventPost post = repository.save(EventMapper.mapToModel(proposal,user,picture)); // Creating Tags after the Post is created Arrays.stream(proposal.getTags()).forEach(t -> { @@ -92,6 +109,52 @@ public int getAmountOfComments(Long id) { return repository.getAmountOfComments(id); } + @Override + public EventThreadViewProposal update(Long id, UpdateEventPostProposal proposal) { + EventPost initialPost = getEventPost(id); + Picture picture; + + byte[] proposalImageData = proposal.getPostImage() != null? proposal.getPostImage() : new byte[0]; + byte[] initialImageData = initialPost.getPicture() != null? initialPost.getPicture().getImageData() : new byte[0]; + // Check if Picture has changed + if (proposalImageData.length == 0 && initialImageData.length != 0) { + pictureRepository.delete(initialPost.getPicture().getId()); + picture = null; + } + else if (!Arrays.equals(initialImageData, proposalImageData)) { + pictureRepository.delete(initialPost.getPicture().getId()); + picture = pictureRepository.save(PictureMapper.mapToModelPost(proposalImageData)); + } else { + picture = initialPost.getPicture(); + } + + // Update post + EventPost updatedPost = EventMapper.mapToModel(proposal, initialPost, picture); + updatedPost.setId(id); + + EventPost post = repository.save(updatedPost); + + /* Check if Tags changed + formerTags = Tags in the database + proposedTags = Tags proposed + * */ + List formerTags = repository.findTagsByPostId(id); + List proposedTags = new ArrayList<>(Arrays.stream(proposal.getTags()).toList()); + + for (EventTag eventTag : formerTags) { + if (proposedTags.contains(eventTag.getTag())) { + proposedTags.remove(eventTag.getTag()); + } else { + repository.deleteEventTag(eventTag.getId()); + } + } + proposedTags.forEach(t -> { + if( t != null) repository.save(EventTagMapper.mapToModel(post, t)); + }); + + return getEventThreadView(updatedPost.getId()); + } + @Override public void deletePost(Long id) { getEventPost(id); @@ -172,6 +235,12 @@ public int adjustCommentLikes(LikeEventCommentProposal likeEventCommentProposal, throw new EntityExistsException("Entity already exists!"); } logtableRepository.saveEventComment(likeLogtableEventComment); + + if (!Objects.equals(eventComment.getUser().getId(), user.getId())) { + EventCommentLikeNotification notification = NotificationMapper.mapToEventCommentLikeNotification(eventComment, user); + notification.setAccumulatedId(null); + notificationRepository.saveEventCommentLikeNotification(notification); + } } else { likes = eventComment.getLikes() == 0 ? 0 : eventComment.getLikes() - 1; LikeLogtableEventComment likeLogtableEventComment = logtableRepository.findEventComment(likeEventCommentProposal.getEventCommentId(),likeEventCommentProposal.getUserId()); diff --git a/src/main/java/de/tinf22b6/dhbwhub/service/interfaces/EventService.java b/src/main/java/de/tinf22b6/dhbwhub/service/interfaces/EventService.java index 6ccf83ad..adf76a91 100644 --- a/src/main/java/de/tinf22b6/dhbwhub/service/interfaces/EventService.java +++ b/src/main/java/de/tinf22b6/dhbwhub/service/interfaces/EventService.java @@ -14,6 +14,7 @@ public interface EventService { List getHomepageEvents(); EventThreadViewProposal create(CreateEventPostProposal proposal); EventThreadViewProposal getEventThreadView(Long id); + EventThreadViewProposal update(Long id, UpdateEventPostProposal proposal); void deletePost(Long id); void deleteComment(Long id); void deleteTag(Long id); diff --git a/src/test/java/de/tinf22b6/dhbwhub/AbstractApplicationTest.java b/src/test/java/de/tinf22b6/dhbwhub/AbstractApplicationTest.java index fa828390..e8c64ee3 100644 --- a/src/test/java/de/tinf22b6/dhbwhub/AbstractApplicationTest.java +++ b/src/test/java/de/tinf22b6/dhbwhub/AbstractApplicationTest.java @@ -55,11 +55,11 @@ protected Course createDefaultCourse2() { } protected User createDefaultUser() { - return new User("Ich studiere Informatik", createDefaultCourse(), createDefaultAccount()); + return new User(19, "Ich studiere Informatik", createDefaultCourse(), createDefaultAccount()); } protected User createDefaultUser2() { - return new User("Ich studiere Jura", createDefaultCourse2(), createDefaultAccount2()); + return new User(21, "Ich studiere Jura", createDefaultCourse2(), createDefaultAccount2()); } protected Friendship createDefaultFriendship() { @@ -132,7 +132,11 @@ protected CourseProposal createDefaultCourseProposal() { } protected UserProposal createDefaultUserProposal() { - return new UserProposal("Ich studiere Informatik", createDefaultCourseProposal(), createDefaultAccountProposal()); + return new UserProposal(19, "Ich studiere Informatik", createDefaultCourseProposal(), createDefaultAccountProposal()); + } + + protected FriendshipProposal createDefaultFriendshipProposal() { + return new FriendshipProposal(createDefaultAccountProposal(), createDefaultAccountProposal(), false); } protected PostProposal createDefaultPostProposal() { @@ -180,15 +184,15 @@ protected UpdatePostProposal createDefaultUpdatePostProposal() { } protected EventPost createDefaultEventPost() { - return new EventPost("Titel 1", "Beschreibung 1", "Location 1", 1.0, 2.0, new Date(1478979208L), new Date(1478979209L), 1); + return new EventPost("Titel 1", "Beschreibung 1", "Location 1", 1.0, 2.0, new Date(1478979207L), new Date(1478979208L), new Date(1478979209L), 1, createDefaultPicture(), createDefaultUser()); } protected EventPost createUpdatedDefaultEventPost() { - return new EventPost("Titel 1", "Beschreibung 1", "Location 1", 1.0, 2.0, new Date(1478979208L), new Date(1478979209L), 2); + return new EventPost("Titel 1", "Beschreibung 1", "Location 1", 1.0, 2.0, new Date(1478979207L), new Date(1478979208L), new Date(1478979209L), 2, createDefaultPicture(), createDefaultUser()); } protected EventPost createUpdatedDefaultEventPost2() { - return new EventPost("Titel 1", "Beschreibung 1", "Location 1", 1.0, 2.0, new Date(1478979208L), new Date(1478979209L), 0); + return new EventPost("Titel 1", "Beschreibung 1", "Location 1", 1.0, 2.0, new Date(1478979207L), new Date(1478979208L), new Date(1478979209L), 0, createDefaultPicture(), createDefaultUser()); } protected EventComment createDefaultEventComment() { @@ -214,6 +218,10 @@ protected CreateEventPostProposal createDefaultCreateEventPostProposal() { return new CreateEventPostProposal("Titel 1", "Beschreibung 1", createDefaultLocationProposal(), new Date(1478979207L), new Date(1478979208L), new Date(1478979209L), new String[]{"Tag 1", "Tag 2"}, createDefaultPicture().getImageData(), 1L); } + protected UpdateEventPostProposal createDefaultUpdateEventPostProposal() { + return new UpdateEventPostProposal("Titel 1", "Beschreibung 1", createDefaultLocationProposal(), new Date(1478979207L), new Date(1478979208L), new String[]{"Tag 1", "Tag 2"}, createDefaultPicture().getImageData()); + } + protected EventThreadViewProposal createDefaultEventThreadViewProposal() { return new EventThreadViewProposal(1L, "Titel 1", "Beschreibung 1", List.of("Tag 1", "Tag 2"), createDefaultLocationProposal(), 0, 0, new Date(1478979208L), new Date(1478979209L), List.of(createDefaultEventCommentThreadViewProposal(),createDefaultEventCommentThreadViewProposal())); } @@ -230,6 +238,14 @@ protected EventCommentThreadViewProposal createDefaultEventCommentThreadViewProp return new EventCommentThreadViewProposal(1L, 1L, "Beschreibung 1", "Maxim", 1L, createDefaultPicture().getImageData(), new Date(1478979207L), 0); } + protected CreateEventCommentProposal createDefaultCreateEventCommentProposal() { + return new CreateEventCommentProposal(1L, 1L, "Beschreibung 1", new Date(1478979207L)); + } + + protected UpdateEventCommentProposal createDefaultUpdateEventCommentProposal() { + return new UpdateEventCommentProposal("Beschreibung 1"); + } + protected FollowUserProposal createDefaultFollowUserProposal() { return new FollowUserProposal(0L, 1L); } @@ -278,6 +294,22 @@ protected DeleteNotificationProposal createDeleteNotificationProposal() { return new DeleteNotificationProposal(1L, null, "Type-Post-Like"); } + protected DeleteNotificationProposal createDeleteNotificationProposal2() { + return new DeleteNotificationProposal(1L, null, "Type-Post-Comment"); + } + + protected DeleteNotificationProposal createDeleteNotificationProposal3() { + return new DeleteNotificationProposal(1L, null, "Type-Comment-Like"); + } + + protected DeleteNotificationProposal createDeleteNotificationProposal4() { + return new DeleteNotificationProposal(1L, null, "Type-Event-Comment-Like"); + } + + protected DeleteNotificationProposal createDeleteNotificationProposal5() { + return new DeleteNotificationProposal(1L, null, "Type-Follow"); + } + protected UserLikes createDefaultUserLikes() { return new UserLikes(1L, List.of(1L, 2L), List.of(2L, 4L), List.of(1L, 3L), List.of(2L)); } diff --git a/src/test/java/de/tinf22b6/dhbwhub/controller/EventControllerTests.java b/src/test/java/de/tinf22b6/dhbwhub/controller/EventControllerTests.java index c4ed5c0a..fcfd67e8 100644 --- a/src/test/java/de/tinf22b6/dhbwhub/controller/EventControllerTests.java +++ b/src/test/java/de/tinf22b6/dhbwhub/controller/EventControllerTests.java @@ -119,8 +119,25 @@ void CreateEvent_StatusIsOk() throws Exception { .andExpect(jsonPath("$.description", is(eventPostProposal.getDescription()))); } + @Test + void UpdateEvent_StatusIsOk() throws Exception { + UpdateEventPostProposal eventPostProposal = createDefaultUpdateEventPostProposal(); + EventThreadViewProposal eventThreadViewProposal = createDefaultEventThreadViewProposal(); + + when(eventService.update(any(Long.class), any(UpdateEventPostProposal.class))).thenReturn(eventThreadViewProposal); + + ResultActions response = mockMvc.perform(put("/event/update-event/1") + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(eventPostProposal))); + + response.andExpect(status().isOk()) + .andExpect(jsonPath("$.title", is(eventPostProposal.getTitle()))) + .andExpect(jsonPath("$.description", is(eventPostProposal.getDescription()))); + } + @Test void IncreaseLikesPost_StatusIsOk() throws Exception { + Integer likes = 1; LikeEventPostProposal likeEventPostProposal = createDefaultLikeEventPostProposal(); when(eventService.adjustPostLikes(any(LikeEventPostProposal.class),any(Integer.class))).thenReturn(2); @@ -134,6 +151,7 @@ void IncreaseLikesPost_StatusIsOk() throws Exception { @Test void DecreaseLikesPost_StatusIsOk() throws Exception { + Integer likes = 0; LikeEventPostProposal likeEventPostProposal = createDefaultLikeEventPostProposal(); when(eventService.adjustPostLikes(any(LikeEventPostProposal.class),any(Integer.class))).thenReturn(0); @@ -146,6 +164,7 @@ void DecreaseLikesPost_StatusIsOk() throws Exception { @Test void IncreaseLikesComment_StatusIsOk() throws Exception { + Integer likes = 1; LikeEventCommentProposal likeEventCommentProposal = createDefaultLikeEventCommentProposal(); when(eventService.adjustCommentLikes(any(LikeEventCommentProposal.class),any(Integer.class))).thenReturn(2); @@ -159,6 +178,7 @@ void IncreaseLikesComment_StatusIsOk() throws Exception { @Test void DecreaseLikesComment_StatusIsOk() throws Exception { + Integer likes = 0; LikeEventCommentProposal likeEventCommentProposal = createDefaultLikeEventCommentProposal(); when(eventService.adjustCommentLikes(any(LikeEventCommentProposal.class),any(Integer.class))).thenReturn(0); diff --git a/src/test/java/de/tinf22b6/dhbwhub/controller/UserControllerTests.java b/src/test/java/de/tinf22b6/dhbwhub/controller/UserControllerTests.java index 53f9bdaf..8119cd76 100644 --- a/src/test/java/de/tinf22b6/dhbwhub/controller/UserControllerTests.java +++ b/src/test/java/de/tinf22b6/dhbwhub/controller/UserControllerTests.java @@ -66,6 +66,7 @@ void Get_StatusIsOk() throws Exception { .contentType(MediaType.APPLICATION_JSON)); response.andExpect(status().isOk()) + .andExpect(jsonPath("$.age", is(user.getAge()))) .andExpect(jsonPath("$.description", is(user.getDescription()))); } @@ -79,6 +80,7 @@ void Create_StatusIsOk() throws Exception { .content(objectMapper.writeValueAsString(userProposal))); response.andExpect(status().isOk()) + .andExpect(jsonPath("$.age", is(userProposal.getAge()))) .andExpect(jsonPath("$.description", is(userProposal.getDescription()))); } @@ -92,6 +94,7 @@ void Update_StatusIsOk() throws Exception { .content(objectMapper.writeValueAsString(userProposal))); response.andExpect(status().isOk()) + .andExpect(jsonPath("$.age", is(userProposal.getAge()))) .andExpect(jsonPath("$.description", is(userProposal.getDescription()))); } diff --git a/src/test/java/de/tinf22b6/dhbwhub/service/EventServiceImplTests.java b/src/test/java/de/tinf22b6/dhbwhub/service/EventServiceImplTests.java index 5cc6beaf..3c5ffd5a 100644 --- a/src/test/java/de/tinf22b6/dhbwhub/service/EventServiceImplTests.java +++ b/src/test/java/de/tinf22b6/dhbwhub/service/EventServiceImplTests.java @@ -8,6 +8,7 @@ import de.tinf22b6.dhbwhub.proposal.simplified_models.EventCommentThreadViewProposal; import de.tinf22b6.dhbwhub.repository.EventRepository; import de.tinf22b6.dhbwhub.repository.LogtableRepository; +import de.tinf22b6.dhbwhub.repository.NotificationRepository; import de.tinf22b6.dhbwhub.repository.UserRepository; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -35,6 +36,9 @@ class EventServiceImplTests extends AbstractApplicationTest { @Mock private LogtableRepository logtableRepository; + @Mock + private NotificationRepository notificationRepository; + @InjectMocks private EventServiceImpl eventService; @@ -134,6 +138,7 @@ void GetEventTags_HasSize_Two() { @Test void IncreasePostLikes_ValueIncreased() { EventPost post = createDefaultEventPost(); + post.getUser().setId(0L); EventPost updatedPost = createUpdatedDefaultEventPost(); User user = createDefaultUser(); user.setId(1L); @@ -163,6 +168,7 @@ void IncreaseCommentLikes_ValueIncreased() { @Test void DecreasePostLikes_ValueDecreased() { EventPost post = createDefaultEventPost(); + post.getUser().setId(0L); EventPost updatedPost = createUpdatedDefaultEventPost2(); User user = createDefaultUser(); user.setId(1L);