From bba008882440187844decfcbce7b70bc5d013811 Mon Sep 17 00:00:00 2001 From: IliaWithHat Date: Mon, 30 Sep 2024 12:22:40 +0300 Subject: [PATCH 1/6] Made changes for change place status. --- .../java/greencity/client/RestClient.java | 10 +++--- ...Message.java => ChangePlaceStatusDto.java} | 15 ++++---- .../java/greencity/message/EmailMessage.java | 2 +- .../src/test/java/greencity/ModelUtils.java | 35 +++---------------- .../java/greencity/client/RestClientTest.java | 6 ++-- .../greencity/service/PlaceServiceImpl.java | 18 +++++----- 6 files changed, 30 insertions(+), 56 deletions(-) rename service-api/src/main/java/greencity/message/{SendChangePlaceStatusEmailMessage.java => ChangePlaceStatusDto.java} (54%) diff --git a/service-api/src/main/java/greencity/client/RestClient.java b/service-api/src/main/java/greencity/client/RestClient.java index da04301bb0..71cc5d52d0 100644 --- a/service-api/src/main/java/greencity/client/RestClient.java +++ b/service-api/src/main/java/greencity/client/RestClient.java @@ -9,6 +9,7 @@ import greencity.dto.user.UserRoleDto; import greencity.dto.user.UserVO; import greencity.enums.Role; +import greencity.message.ChangePlaceStatusDto; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -16,7 +17,6 @@ import greencity.message.GeneralEmailMessage; import greencity.message.HabitAssignNotificationMessage; import greencity.message.ScheduledEmailMessage; -import greencity.message.SendChangePlaceStatusEmailMessage; import greencity.message.SendHabitNotification; import greencity.message.SendReportEmailMessage; import greencity.message.UserTaggedInCommentMessage; @@ -474,18 +474,16 @@ public void scheduleDeleteDeactivatedUsers() { } /** - * send SendChangePlaceStatusEmailMessage to GreenCityUser. + * Send ChangePlaceStatusDto to GreenCityUser. * * @param changePlaceStatusEmailMessage with information for sending email * during status update for {@link PlaceVO} * when PlaceStatus.PROPOSED. - * @author Taras Kavkalo */ - public void changePlaceStatus(SendChangePlaceStatusEmailMessage changePlaceStatusEmailMessage) { + public void changePlaceStatus(ChangePlaceStatusDto changePlaceStatusEmailMessage) { HttpHeaders headers = setHeader(); headers.setContentType(MediaType.APPLICATION_JSON); - HttpEntity entity = - new HttpEntity<>(changePlaceStatusEmailMessage, headers); + HttpEntity entity = new HttpEntity<>(changePlaceStatusEmailMessage, headers); restTemplate.exchange(greenCityUserServerAddress + RestTemplateLinks.CHANGE_PLACE_STATUS, HttpMethod.POST, entity, Object.class); } diff --git a/service-api/src/main/java/greencity/message/SendChangePlaceStatusEmailMessage.java b/service-api/src/main/java/greencity/message/ChangePlaceStatusDto.java similarity index 54% rename from service-api/src/main/java/greencity/message/SendChangePlaceStatusEmailMessage.java rename to service-api/src/main/java/greencity/message/ChangePlaceStatusDto.java index eb75975708..68d48b3e98 100644 --- a/service-api/src/main/java/greencity/message/SendChangePlaceStatusEmailMessage.java +++ b/service-api/src/main/java/greencity/message/ChangePlaceStatusDto.java @@ -1,19 +1,20 @@ package greencity.message; -import java.io.Serializable; +import greencity.enums.PlaceStatus; import lombok.AllArgsConstructor; import lombok.Builder; -import lombok.Getter; -import lombok.ToString; +import lombok.Data; +import lombok.NoArgsConstructor; -@Getter -@ToString +@Data @AllArgsConstructor +@NoArgsConstructor @Builder -public final class SendChangePlaceStatusEmailMessage implements Serializable, EmailMessage { +public final class ChangePlaceStatusDto implements EmailMessage { private String authorFirstName; + private String authorLanguage; private String placeName; - private String placeStatus; + private PlaceStatus placeStatus; private String authorEmail; @Override diff --git a/service-api/src/main/java/greencity/message/EmailMessage.java b/service-api/src/main/java/greencity/message/EmailMessage.java index 599c7420db..5752b9fd7c 100644 --- a/service-api/src/main/java/greencity/message/EmailMessage.java +++ b/service-api/src/main/java/greencity/message/EmailMessage.java @@ -1,5 +1,5 @@ package greencity.message; public interface EmailMessage { - public String getEmail(); + String getEmail(); } diff --git a/service-api/src/test/java/greencity/ModelUtils.java b/service-api/src/test/java/greencity/ModelUtils.java index 98b6b5050d..bfce3447e4 100644 --- a/service-api/src/test/java/greencity/ModelUtils.java +++ b/service-api/src/test/java/greencity/ModelUtils.java @@ -20,16 +20,15 @@ import greencity.dto.user.UserShoppingListItemResponseDto; import greencity.dto.user.UserVO; import greencity.dto.verifyemail.VerifyEmailVO; +import greencity.enums.PlaceStatus; import greencity.enums.Role; import greencity.enums.ShoppingListItemStatus; +import greencity.message.ChangePlaceStatusDto; import greencity.message.GeneralEmailMessage; import greencity.message.ScheduledEmailMessage; -import greencity.message.SendChangePlaceStatusEmailMessage; import greencity.message.SendReportEmailMessage; import greencity.message.SendHabitNotification; import greencity.message.HabitAssignNotificationMessage; -import greencity.message.UserReceivedCommentMessage; -import greencity.message.UserReceivedCommentReplyMessage; import greencity.message.UserTaggedInCommentMessage; import java.util.UUID; import org.springframework.http.HttpHeaders; @@ -71,9 +70,9 @@ private static PlaceAuthorDto getPlaceAuthorDto() { .build(); } - public static SendChangePlaceStatusEmailMessage getSendChangePlaceStatusEmailMessage() { - return SendChangePlaceStatusEmailMessage.builder() - .placeStatus("status") + public static ChangePlaceStatusDto getSendChangePlaceStatusEmailMessage() { + return ChangePlaceStatusDto.builder() + .placeStatus(PlaceStatus.APPROVED) .authorEmail("test@gmail.com") .placeName("placeName") .authorFirstName("taras") @@ -261,30 +260,6 @@ public static UserTaggedInCommentMessage getUserTaggedInCommentMessage() { .build(); } - public static UserReceivedCommentMessage getUserReceivedCommentMessage() { - return UserReceivedCommentMessage.builder() - .commentText("test") - .baseLink("http://localhost:8060/events/1") - .authorName("Denys") - .receiverName("Ivan") - .language("en") - .receiverEmail("Ivan@gmail.com") - .build(); - } - - public static UserReceivedCommentReplyMessage getUserReceivedCommentReplyMessage() { - return UserReceivedCommentReplyMessage.builder() - .commentText("test") - .baseLink("http://localhost:8060/events/1") - .authorName("Denys") - .receiverName("Ivan") - .language("en") - .receiverEmail("Ivan@gmail.com") - .parentCommentText("parent comment") - .parentCommentAuthorName("Dmytro") - .build(); - } - public static ScheduledEmailMessage getScheduledEmailMessage() { return ScheduledEmailMessage.builder() .username("test") diff --git a/service-api/src/test/java/greencity/client/RestClientTest.java b/service-api/src/test/java/greencity/client/RestClientTest.java index 412aa333d9..1d897520c6 100644 --- a/service-api/src/test/java/greencity/client/RestClientTest.java +++ b/service-api/src/test/java/greencity/client/RestClientTest.java @@ -17,9 +17,9 @@ import greencity.dto.eventcomment.EventCommentForSendEmailDto; import greencity.enums.EmailNotification; import greencity.enums.Role; +import greencity.message.ChangePlaceStatusDto; import greencity.message.GeneralEmailMessage; import greencity.message.ScheduledEmailMessage; -import greencity.message.SendChangePlaceStatusEmailMessage; import greencity.message.SendHabitNotification; import greencity.message.SendReportEmailMessage; import greencity.message.HabitAssignNotificationMessage; @@ -436,11 +436,11 @@ void sendReport() { @Test void changePlaceStatus() { - SendChangePlaceStatusEmailMessage message = ModelUtils.getSendChangePlaceStatusEmailMessage(); + ChangePlaceStatusDto message = ModelUtils.getSendChangePlaceStatusEmailMessage(); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.APPLICATION_JSON); httpHeaders.set(AUTHORIZATION, ACCESS_TOKEN); - HttpEntity entity = new HttpEntity<>(message, httpHeaders); + HttpEntity entity = new HttpEntity<>(message, httpHeaders); when(jwtTool.createAccessToken(anyString(), any(Role.class))).thenReturn(TOKEN); when(restTemplate.exchange(GREEN_CITY_USER_ADDRESS diff --git a/service/src/main/java/greencity/service/PlaceServiceImpl.java b/service/src/main/java/greencity/service/PlaceServiceImpl.java index f1662d473b..df3c89b665 100644 --- a/service/src/main/java/greencity/service/PlaceServiceImpl.java +++ b/service/src/main/java/greencity/service/PlaceServiceImpl.java @@ -62,7 +62,7 @@ import greencity.exception.exceptions.NotFoundException; import greencity.exception.exceptions.PlaceStatusException; import greencity.exception.exceptions.UserBlockedException; -import greencity.message.SendChangePlaceStatusEmailMessage; +import greencity.message.ChangePlaceStatusDto; import greencity.repository.CategoryRepo; import greencity.repository.PlaceRepo; import greencity.repository.UserRepo; @@ -313,8 +313,6 @@ public PageableDto findAll(Pageable pageable, Principal principal /** * {@inheritDoc} - * - * @author Nazar Vladyka */ @Override public UpdatePlaceStatusDto updateStatus(Long id, PlaceStatus status) { @@ -328,8 +326,11 @@ public UpdatePlaceStatusDto updateStatus(Long id, PlaceStatus status) { notificationService.sendImmediatelyReport(modelMapper.map(updatable, PlaceVO.class)); } if (oldStatus.equals(PlaceStatus.PROPOSED)) { - restClient.changePlaceStatus(new SendChangePlaceStatusEmailMessage(updatable.getAuthor().getName(), - updatable.getName(), updatable.getStatus().toString().toLowerCase(), + restClient.changePlaceStatus(new ChangePlaceStatusDto( + updatable.getAuthor().getName(), + updatable.getAuthor().getLanguage().getCode(), + updatable.getName(), + updatable.getStatus(), updatable.getAuthor().getEmail())); } return modelMapper.map(placeRepo.save(updatable), UpdatePlaceStatusDto.class); @@ -608,10 +609,9 @@ public PlaceResponse addPlaceFromUi(AddPlaceDto dto, String email, MultipartFile private void mapMultipartFilesToPhotos(MultipartFile[] images, Place place, User user) { if (images != null && images.length > 0 && images[0] != null) { List placePhotos = new ArrayList<>(); - for (int i = 0; i < images.length; i++) { - if (images[i] != null) { - placePhotos - .add(Photo.builder().place(place).name(fileService.upload(images[i])).user(user).build()); + for (MultipartFile image : images) { + if (image != null) { + placePhotos.add(Photo.builder().place(place).name(fileService.upload(image)).user(user).build()); } } place.setPhotos(placePhotos); From a0c09d485982dea1319bc06880ee0fc3f0674f63 Mon Sep 17 00:00:00 2001 From: IliaWithHat Date: Mon, 30 Sep 2024 17:21:40 +0300 Subject: [PATCH 2/6] Made changes for habit assign notification. --- .../src/main/java/greencity/constant/RestTemplateLinks.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service-api/src/main/java/greencity/constant/RestTemplateLinks.java b/service-api/src/main/java/greencity/constant/RestTemplateLinks.java index 35b24e6796..0a51254dc3 100644 --- a/service-api/src/main/java/greencity/constant/RestTemplateLinks.java +++ b/service-api/src/main/java/greencity/constant/RestTemplateLinks.java @@ -38,7 +38,7 @@ public class RestTemplateLinks { public static final String FIND_ALL_USERS_CITIES = "/user/findAllUsersCities"; public static final String ADD_EVENT_COMMENT = "/email/addEventComment"; public static final String SEND_GENERAL_EMAIL_NOTIFICATION = "/email/general/notification"; - public static final String SEND_HABIT_ASSIGN_NOTIFICATION = "/email/habitAssign/notification"; + public static final String SEND_HABIT_ASSIGN_NOTIFICATION = "/email/sendHabitAssignNotification"; public static final String SEND_USERS_MENTION_IN_COMMENT_NOTIFICATION = "/email/taggedUserInComment/notification"; public static final String SEND_SCHEDULED_NOTIFICATION = "/email/scheduled/notification"; } From cbb98f0a8921f19cb74885eb7e4b05b89c693072 Mon Sep 17 00:00:00 2001 From: IliaWithHat Date: Wed, 2 Oct 2024 14:18:10 +0300 Subject: [PATCH 3/6] Made changes for send report. --- .../message/SendReportEmailMessage.java | 18 ++++++------- .../service/NotificationServiceImpl.java | 25 ++++++++----------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/service-api/src/main/java/greencity/message/SendReportEmailMessage.java b/service-api/src/main/java/greencity/message/SendReportEmailMessage.java index a07771a75e..b68387aac9 100644 --- a/service-api/src/main/java/greencity/message/SendReportEmailMessage.java +++ b/service-api/src/main/java/greencity/message/SendReportEmailMessage.java @@ -2,21 +2,21 @@ import greencity.dto.category.CategoryDto; import greencity.dto.place.PlaceNotificationDto; -import greencity.dto.user.PlaceAuthorDto; -import java.io.Serializable; +import greencity.dto.user.SubscriberDto; +import greencity.enums.EmailNotification; import java.util.List; import java.util.Map; import lombok.AllArgsConstructor; import lombok.Builder; -import lombok.Getter; -import lombok.ToString; +import lombok.Data; +import lombok.NoArgsConstructor; -@Getter -@ToString +@Data @AllArgsConstructor +@NoArgsConstructor @Builder -public class SendReportEmailMessage implements Serializable { - private List subscribers; +public class SendReportEmailMessage { + private List subscribers; private Map> categoriesDtoWithPlacesDtoMap; - private String emailNotification; + private EmailNotification emailNotification; } diff --git a/service/src/main/java/greencity/service/NotificationServiceImpl.java b/service/src/main/java/greencity/service/NotificationServiceImpl.java index d6d755f138..45b6e5a6f2 100644 --- a/service/src/main/java/greencity/service/NotificationServiceImpl.java +++ b/service/src/main/java/greencity/service/NotificationServiceImpl.java @@ -7,7 +7,7 @@ import greencity.dto.category.CategoryDto; import greencity.dto.place.PlaceNotificationDto; import greencity.dto.place.PlaceVO; -import greencity.dto.user.PlaceAuthorDto; +import greencity.dto.user.SubscriberDto; import greencity.entity.Notification; import greencity.entity.Place; import greencity.entity.User; @@ -35,7 +35,6 @@ import java.time.LocalDateTime; import java.time.ZoneId; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -44,7 +43,6 @@ import java.util.Set; import java.util.concurrent.Executors; import java.util.concurrent.ThreadPoolExecutor; -import java.util.stream.Collectors; @Slf4j @Service @@ -66,16 +64,15 @@ public class NotificationServiceImpl implements NotificationService { public void sendImmediatelyReport(PlaceVO newPlace) { log.info(LogMessage.IN_SEND_IMMEDIATELY_REPORT, newPlace.getName()); EmailNotification emailNotification = EmailNotification.IMMEDIATELY; - List subscribers = getSubscribers(emailNotification); + List subscribers = getSubscribers(emailNotification); Map> categoriesDtoWithPlacesDtoMap = new HashMap<>(); CategoryDto map = modelMapper.map(newPlace.getCategory(), CategoryDto.class); - List placeDtoList = - Collections.singletonList(modelMapper.map(newPlace, PlaceNotificationDto.class)); + List placeDtoList = List.of(modelMapper.map(newPlace, PlaceNotificationDto.class)); categoriesDtoWithPlacesDtoMap.put(map, placeDtoList); - restClient.sendReport(new SendReportEmailMessage(subscribers, - categoriesDtoWithPlacesDtoMap, emailNotification.toString())); + restClient.sendReport(new SendReportEmailMessage(subscribers, categoriesDtoWithPlacesDtoMap, + emailNotification)); } /** @@ -310,7 +307,7 @@ public void sendUsersTaggedInCommentEmailNotification(UserTaggedInCommentMessage private void sendReport(EmailNotification emailNotification, LocalDateTime startDate) { log.info(LogMessage.IN_SEND_REPORT, emailNotification); - List subscribers = getSubscribers(emailNotification); + List subscribers = getSubscribers(emailNotification); Map> categoriesDtoWithPlacesDtoMap = new HashMap<>(); LocalDateTime endDate = LocalDateTime.now(ZONE_ID); if (!subscribers.isEmpty()) { @@ -319,16 +316,16 @@ private void sendReport(EmailNotification emailNotification, LocalDateTime start categoriesDtoWithPlacesDtoMap = getCategoriesDtoWithPlacesDtoMap(places); } if (!categoriesDtoWithPlacesDtoMap.isEmpty()) { - restClient.sendReport( - new SendReportEmailMessage(subscribers, categoriesDtoWithPlacesDtoMap, emailNotification.toString())); + restClient.sendReport(new SendReportEmailMessage(subscribers, categoriesDtoWithPlacesDtoMap, + emailNotification)); } } - private List getSubscribers(EmailNotification emailNotification) { + private List getSubscribers(EmailNotification emailNotification) { log.info(LogMessage.IN_GET_SUBSCRIBERS, emailNotification); return restClient.findAllByEmailNotification(emailNotification).stream() - .map(o -> modelMapper.map(o, PlaceAuthorDto.class)) - .collect(Collectors.toList()); + .map(o -> modelMapper.map(o, SubscriberDto.class)) + .toList(); } private Map> getCategoriesDtoWithPlacesDtoMap(List places) { From da9b2aaf1916c0bd7466bc28b039aaa00dca7faa Mon Sep 17 00:00:00 2001 From: IliaWithHat Date: Thu, 3 Oct 2024 09:28:45 +0300 Subject: [PATCH 4/6] Fix. --- .../src/test/java/greencity/ModelUtils.java | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/service-api/src/test/java/greencity/ModelUtils.java b/service-api/src/test/java/greencity/ModelUtils.java index bfce3447e4..96530cea8b 100644 --- a/service-api/src/test/java/greencity/ModelUtils.java +++ b/service-api/src/test/java/greencity/ModelUtils.java @@ -15,11 +15,11 @@ import greencity.dto.shoppinglistitem.CustomShoppingListItemResponseDto; import greencity.dto.tag.TagUaEnDto; import greencity.dto.user.EcoNewsAuthorDto; -import greencity.dto.user.PlaceAuthorDto; import greencity.dto.user.SubscriberDto; import greencity.dto.user.UserShoppingListItemResponseDto; import greencity.dto.user.UserVO; import greencity.dto.verifyemail.VerifyEmailVO; +import greencity.enums.EmailNotification; import greencity.enums.PlaceStatus; import greencity.enums.Role; import greencity.enums.ShoppingListItemStatus; @@ -62,14 +62,6 @@ public static PlaceNotificationDto getPlaceNotificationDto() { .build(); } - private static PlaceAuthorDto getPlaceAuthorDto() { - return PlaceAuthorDto.builder() - .id(1L) - .email("test@gmail.com") - .name("taras") - .build(); - } - public static ChangePlaceStatusDto getSendChangePlaceStatusEmailMessage() { return ChangePlaceStatusDto.builder() .placeStatus(PlaceStatus.APPROVED) @@ -102,10 +94,10 @@ public static CategoryDto getCategoryDto() { public static SendReportEmailMessage getSendReportEmailMessage() { return SendReportEmailMessage.builder() - .emailNotification("notification") + .emailNotification(EmailNotification.WEEKLY) .categoriesDtoWithPlacesDtoMap(Collections.singletonMap( getCategoryDto(), Collections.singletonList(getPlaceNotificationDto()))) - .subscribers(Collections.singletonList(getPlaceAuthorDto())) + .subscribers(getSubscribers()) .build(); } From 85bbb41f23232da333cd6650c8799ac49719be15 Mon Sep 17 00:00:00 2001 From: IliaWithHat Date: Thu, 3 Oct 2024 09:55:36 +0300 Subject: [PATCH 5/6] Fix. --- service/src/test/java/greencity/ModelUtils.java | 4 ++++ .../java/greencity/service/PlaceServiceImplTest.java | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/service/src/test/java/greencity/ModelUtils.java b/service/src/test/java/greencity/ModelUtils.java index 86448d5897..015fefe234 100644 --- a/service/src/test/java/greencity/ModelUtils.java +++ b/service/src/test/java/greencity/ModelUtils.java @@ -419,6 +419,7 @@ public static User getUser() { .dateOfRegistration(localDateTime) .subscribedEvents(new HashSet<>()) .favoriteEvents(new HashSet<>()) + .language(getLanguage()) .build(); } @@ -508,6 +509,7 @@ public static UserVO getAuthorVO() { .lastActivityTime(localDateTime) .verifyEmail(new VerifyEmailVO()) .dateOfRegistration(localDateTime) + .languageVO(getLanguageVO()) .build(); } @@ -1073,6 +1075,7 @@ public static Place getPlace() { place.setAuthor(getUser()); place.setModifiedDate(ZonedDateTime.now()); place.setStatus(PlaceStatus.PROPOSED); + place.setAuthor(getUser()); return place; } @@ -1090,6 +1093,7 @@ public static PlaceVO getPlaceVO() { CategoryVO categoryVO = new CategoryVO(); categoryVO.setName("category"); placeVO.setCategory(categoryVO); + placeVO.setAuthor(getAuthorVO()); return placeVO; } diff --git a/service/src/test/java/greencity/service/PlaceServiceImplTest.java b/service/src/test/java/greencity/service/PlaceServiceImplTest.java index 618bd68fcc..3ccc8f3916 100644 --- a/service/src/test/java/greencity/service/PlaceServiceImplTest.java +++ b/service/src/test/java/greencity/service/PlaceServiceImplTest.java @@ -11,6 +11,7 @@ import greencity.dto.discount.DiscountValueVO; import greencity.dto.filter.FilterDistanceDto; import greencity.dto.filter.FilterPlaceDto; +import greencity.dto.language.LanguageVO; import greencity.dto.location.LocationAddressAndGeoDto; import greencity.dto.location.LocationAddressAndGeoForUpdateDto; import greencity.dto.location.LocationVO; @@ -87,6 +88,14 @@ class PlaceServiceImplTest { .name("test") .build(); + private final Language language = Language.builder() + .id(2L) + .code("en") + .build(); + private final LanguageVO languageVO = LanguageVO.builder() + .id(2L) + .code("en") + .build(); private final User user = User.builder() .id(1L) @@ -95,6 +104,7 @@ class PlaceServiceImplTest { .role(Role.ROLE_USER) .lastActivityTime(LocalDateTime.now()) .dateOfRegistration(LocalDateTime.now()) + .language(language) .build(); private final UserVO userVO = UserVO.builder() @@ -104,6 +114,7 @@ class PlaceServiceImplTest { .role(Role.ROLE_USER) .lastActivityTime(LocalDateTime.now()) .dateOfRegistration(LocalDateTime.now()) + .languageVO(languageVO) .build(); private final Place genericEntity1 = Place.builder() .id(1L) From 572fc6b6ff5952d9029d089ae68d61066c2afea3 Mon Sep 17 00:00:00 2001 From: IliaWithHat Date: Thu, 3 Oct 2024 10:02:51 +0300 Subject: [PATCH 6/6] Fix. --- .../src/test/java/greencity/ModelUtils.java | 56 ------------------- .../service/PlaceServiceImplTest.java | 51 +++-------------- 2 files changed, 9 insertions(+), 98 deletions(-) diff --git a/service/src/test/java/greencity/ModelUtils.java b/service/src/test/java/greencity/ModelUtils.java index 015fefe234..c624955950 100644 --- a/service/src/test/java/greencity/ModelUtils.java +++ b/service/src/test/java/greencity/ModelUtils.java @@ -20,7 +20,6 @@ import greencity.dto.category.CategoryVO; import greencity.dto.comment.AddCommentDtoRequest; import greencity.dto.comment.AddCommentDtoResponse; -import greencity.dto.comment.AmountCommentLikesDto; import greencity.dto.comment.CommentAuthorDto; import greencity.dto.comment.CommentDto; import greencity.dto.comment.CommentVO; @@ -642,14 +641,6 @@ public static EcoNews getEcoNews() { .build(); } - public static Comment getEcoNewsComment(CommentStatus commentStatus) { - return Comment.builder() - .status(commentStatus) - .text("sdfs") - .articleType(ArticleType.ECO_NEWS) - .build(); - } - public static EcoNews getEcoNewsForMethodConvertTest() { Tag tag = new Tag(); tag.setTagTranslations( @@ -1254,18 +1245,6 @@ public static List getListSocialNetworkVO() { return socialNetworkVO; } - public static Comment getEcoNewsComment() { - return Comment.builder() - .id(1L) - .status(CommentStatus.ORIGINAL) - .text("text") - .createdDate(LocalDateTime.now()) - .modifiedDate(LocalDateTime.now()) - .user(getUser()) - .articleType(ArticleType.ECO_NEWS) - .build(); - } - public static PlaceByBoundsDto getPlaceByBoundsDtoForFindAllTest() { return PlaceByBoundsDto.builder() .id(1L) @@ -1427,10 +1406,6 @@ public static AchievementManagementDto getAchievementManagementDto() { 1); } - public static UserAchievementVO getUserAchievementVO() { - return new UserAchievementVO(1L, getUserVO(), getAchievementVO(), true); - } - public static UserAchievement getUserAchievement() { return new UserAchievement(1L, getUser(), getAchievement(), false, getHabit()); } @@ -1748,14 +1723,6 @@ public static MultipartFile[] getMultipartFiles() { new MockMultipartFile("secondFile.tmp", "Hello World".getBytes())}; } - public static MultipartFile getMultipartImageFile() { - return new MockMultipartFile( - "images", - "image.jpg", - "image/jpeg", - "image data".getBytes()); - } - public static MultipartFile[] getMultipartImageFiles() { return new MockMultipartFile[] { new MockMultipartFile( @@ -1812,22 +1779,6 @@ public static AddressDto getAddressDtoCorrect() { .build(); } - public static AddressDto getSecondAddressDtoCorrect() { - return AddressDto.builder() - .latitude(46.4567236) - .longitude(28.2354469) - .streetUa("Вулиця") - .streetEn("Street") - .houseNumber("1B") - .cityUa("Одеса") - .cityEn("Odessa") - .regionUa("Область") - .regionEn("Oblast") - .countryUa("Країна") - .countryEn("Country") - .build(); - } - public static AddressDto getAddressDtoWithoutData() { return AddressDto.builder().build(); } @@ -2674,13 +2625,6 @@ public static SearchEventsDto getSearchEvents() { return SearchEventsDto.builder().id(1L).title("Title").tags(new ArrayList<>()).build(); } - public static AmountCommentLikesDto getAmountCommentLikesDto() { - return AmountCommentLikesDto.builder() - .id(1L) - .amountLikes(2) - .build(); - } - public static User getTagUser() { return User.builder() .id(1L) diff --git a/service/src/test/java/greencity/service/PlaceServiceImplTest.java b/service/src/test/java/greencity/service/PlaceServiceImplTest.java index 3ccc8f3916..fb78289580 100644 --- a/service/src/test/java/greencity/service/PlaceServiceImplTest.java +++ b/service/src/test/java/greencity/service/PlaceServiceImplTest.java @@ -7,17 +7,11 @@ import greencity.dto.PageableDto; import greencity.dto.category.CategoryDto; import greencity.dto.category.CategoryDtoResponse; -import greencity.dto.discount.DiscountValueDto; -import greencity.dto.discount.DiscountValueVO; import greencity.dto.filter.FilterDistanceDto; import greencity.dto.filter.FilterPlaceDto; import greencity.dto.language.LanguageVO; -import greencity.dto.location.LocationAddressAndGeoDto; import greencity.dto.location.LocationAddressAndGeoForUpdateDto; import greencity.dto.location.LocationVO; -import greencity.dto.openhours.OpeningHoursDto; -import greencity.dto.openhours.OpeningHoursVO; -import greencity.dto.photo.PhotoAddDto; import greencity.dto.place.AddPlaceDto; import greencity.dto.place.AdminPlaceDto; import greencity.dto.place.BulkUpdatePlaceStatusDto; @@ -53,7 +47,6 @@ import java.util.HashSet; import java.util.List; import java.util.Optional; -import java.util.Set; import java.util.stream.Collectors; import jakarta.persistence.criteria.CriteriaBuilder; @@ -62,13 +55,15 @@ import jakarta.persistence.criteria.Path; import jakarta.persistence.criteria.Predicate; import jakarta.persistence.criteria.Root; -import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; import org.mockito.Spy; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; import org.modelmapper.ModelMapper; import org.modelmapper.TypeToken; import org.springframework.data.domain.Page; @@ -78,7 +73,8 @@ import org.springframework.data.jpa.domain.Specification; import org.springframework.web.multipart.MultipartFile; -@Slf4j +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.LENIENT) class PlaceServiceImplTest { private final Category category = Category.builder() .id(1L) @@ -130,39 +126,12 @@ class PlaceServiceImplTest { .status(PlaceStatus.PROPOSED) .modifiedDate(ZonedDateTime.now()) .build(); - private final LocationAddressAndGeoDto locationDto = LocationAddressAndGeoDto.builder() - .address("test") - .lat(45.456) - .lng(46.456) - .build(); - private final Location location = Location.builder() - .id(1L) - .address("test") - .lat(45.456) - .lng(46.456) - .build(); private final LocationVO locationVO = LocationVO.builder() .id(1L) .address("test") .lat(45.456) .lng(46.456) .build(); - private Set openingHoursList = new HashSet<>(); - private Set openingHoursListEntity = new HashSet<>(); - private Set openingHoursListEntityVO = new HashSet<>(); - private Set discountValues = new HashSet<>(); - private Set discountValuesDto = new HashSet<>(); - private Set discountValuesVO = new HashSet<>(); - private List photoDtos = new ArrayList<>(); - private List photos = new ArrayList<>(); - private PlaceAddDto placeAddDto = PlaceAddDto.builder() - .name("Test") - .category(categoryDto) - .location(locationDto) - .openingHoursList(openingHoursList) - .discountValues(discountValuesDto) - .photos(photoDtos) - .build(); @Mock private PlaceRepo placeRepo; @Mock @@ -186,7 +155,7 @@ class PlaceServiceImplTest { @Mock private CategoryRepo categoryRepo; - private ZoneId zoneId = ZoneId.of("Europe/Kiev"); + private final ZoneId zoneId = ZoneId.of("Europe/Kiev"); private PlaceService placeService; @Mock private GoogleApiService googleApiService; @@ -199,7 +168,6 @@ class PlaceServiceImplTest { @BeforeEach void init() { - MockitoAnnotations.initMocks(this); placeService = new PlaceServiceImpl(placeRepo, modelMapper, categoryService, locationService, specificationService, restClient, openingHoursService, discountService, notificationService, zoneId, proposePlaceMapper, categoryRepo, googleApiService, userRepo, favoritePlaceRepo, fileService); @@ -509,10 +477,9 @@ void findAllWithPrincipalTest() { void updateTest() { PlaceUpdateDto placeUpdateDto = new PlaceUpdateDto(); Place place = ModelUtils.getPlace(); - PlaceVO placeVO = ModelUtils.getPlaceVO(); placeUpdateDto.setId(1L); - placeUpdateDto.setOpeningHoursList(openingHoursList); - placeUpdateDto.setDiscountValues(discountValuesDto); + placeUpdateDto.setOpeningHoursList(new HashSet<>()); + placeUpdateDto.setDiscountValues(new HashSet<>()); placeUpdateDto.setName("new Name"); placeUpdateDto.setCategory(categoryDto); placeUpdateDto.setLocation(new LocationAddressAndGeoForUpdateDto());