@Test void sendImmediatelyReportTest() { EmailNotification emailNotification = EmailNotification.IMMEDIATELY; Category category = ModelUtils.getCategory(); User user = ModelUtils.getUser(); user.setEmailNotification(emailNotification); Place place = ModelUtils.getPlace(); place.setCategory(category); when(userRepo.findAllByEmailNotification(emailNotification)) .thenReturn(Collections.singletonList(user)); when(modelMapper.map(user, PlaceAuthorDto.class)) .thenReturn(new PlaceAuthorDto(1L, "dto", "email")); when(modelMapper.map(place.getCategory(), CategoryDto.class)) .thenReturn(new CategoryDto("category")); when(modelMapper.map(place, PlaceNotificationDto.class)) .thenReturn(new PlaceNotificationDto("name", new CategoryDto("category"))); notificationService.sendImmediatelyReport(place); verify(rabbitTemplate, Mockito.times(1)) .convertAndSend(any(), anyString(), any(SendReportEmailMessage.class)); }
@Override public void sendImmediatelyReport(Place newPlace) { log.info(LogMessage.IN_SEND_IMMEDIATELY_REPORT, newPlace.getName()); EmailNotification emailNotification = EmailNotification.IMMEDIATELY; List<PlaceAuthorDto> subscribers = getSubscribers(emailNotification); Map<CategoryDto, List<PlaceNotificationDto>> categoriesDtoWithPlacesDtoMap = new HashMap<>(); CategoryDto map = modelMapper.map(newPlace.getCategory(), CategoryDto.class); List<PlaceNotificationDto> placeDtoList = Collections.singletonList(modelMapper.map(newPlace, PlaceNotificationDto.class)); categoriesDtoWithPlacesDtoMap.put(map, placeDtoList); List<PlaceAuthorDto> placeAuthorDto = subscribers.stream() .map(o -> modelMapper.map(o, PlaceAuthorDto.class)) .collect(Collectors.toList()); rabbitTemplate.convertAndSend(sendEmailTopic, SEND_REPORT_ROUTING_KEY, new SendReportEmailMessage(placeAuthorDto, categoriesDtoWithPlacesDtoMap, emailNotification.toString())); }
NotificationServiceImpl implements NotificationService { @Override public void sendImmediatelyReport(Place newPlace) { log.info(LogMessage.IN_SEND_IMMEDIATELY_REPORT, newPlace.getName()); EmailNotification emailNotification = EmailNotification.IMMEDIATELY; List<PlaceAuthorDto> subscribers = getSubscribers(emailNotification); Map<CategoryDto, List<PlaceNotificationDto>> categoriesDtoWithPlacesDtoMap = new HashMap<>(); CategoryDto map = modelMapper.map(newPlace.getCategory(), CategoryDto.class); List<PlaceNotificationDto> placeDtoList = Collections.singletonList(modelMapper.map(newPlace, PlaceNotificationDto.class)); categoriesDtoWithPlacesDtoMap.put(map, placeDtoList); List<PlaceAuthorDto> placeAuthorDto = subscribers.stream() .map(o -> modelMapper.map(o, PlaceAuthorDto.class)) .collect(Collectors.toList()); rabbitTemplate.convertAndSend(sendEmailTopic, SEND_REPORT_ROUTING_KEY, new SendReportEmailMessage(placeAuthorDto, categoriesDtoWithPlacesDtoMap, emailNotification.toString())); } }
NotificationServiceImpl implements NotificationService { @Override public void sendImmediatelyReport(Place newPlace) { log.info(LogMessage.IN_SEND_IMMEDIATELY_REPORT, newPlace.getName()); EmailNotification emailNotification = EmailNotification.IMMEDIATELY; List<PlaceAuthorDto> subscribers = getSubscribers(emailNotification); Map<CategoryDto, List<PlaceNotificationDto>> categoriesDtoWithPlacesDtoMap = new HashMap<>(); CategoryDto map = modelMapper.map(newPlace.getCategory(), CategoryDto.class); List<PlaceNotificationDto> placeDtoList = Collections.singletonList(modelMapper.map(newPlace, PlaceNotificationDto.class)); categoriesDtoWithPlacesDtoMap.put(map, placeDtoList); List<PlaceAuthorDto> placeAuthorDto = subscribers.stream() .map(o -> modelMapper.map(o, PlaceAuthorDto.class)) .collect(Collectors.toList()); rabbitTemplate.convertAndSend(sendEmailTopic, SEND_REPORT_ROUTING_KEY, new SendReportEmailMessage(placeAuthorDto, categoriesDtoWithPlacesDtoMap, emailNotification.toString())); } @Autowired  NotificationServiceImpl(UserRepo userRepo, PlaceRepo placeRepo,
                                   RabbitTemplate rabbitTemplate,
                                   ModelMapper modelMapper); }
NotificationServiceImpl implements NotificationService { @Override public void sendImmediatelyReport(Place newPlace) { log.info(LogMessage.IN_SEND_IMMEDIATELY_REPORT, newPlace.getName()); EmailNotification emailNotification = EmailNotification.IMMEDIATELY; List<PlaceAuthorDto> subscribers = getSubscribers(emailNotification); Map<CategoryDto, List<PlaceNotificationDto>> categoriesDtoWithPlacesDtoMap = new HashMap<>(); CategoryDto map = modelMapper.map(newPlace.getCategory(), CategoryDto.class); List<PlaceNotificationDto> placeDtoList = Collections.singletonList(modelMapper.map(newPlace, PlaceNotificationDto.class)); categoriesDtoWithPlacesDtoMap.put(map, placeDtoList); List<PlaceAuthorDto> placeAuthorDto = subscribers.stream() .map(o -> modelMapper.map(o, PlaceAuthorDto.class)) .collect(Collectors.toList()); rabbitTemplate.convertAndSend(sendEmailTopic, SEND_REPORT_ROUTING_KEY, new SendReportEmailMessage(placeAuthorDto, categoriesDtoWithPlacesDtoMap, emailNotification.toString())); } @Autowired  NotificationServiceImpl(UserRepo userRepo, PlaceRepo placeRepo,
                                   RabbitTemplate rabbitTemplate,
                                   ModelMapper modelMapper); @Override void sendImmediatelyReport(Place newPlace); @Scheduled(cron = "0 0 12 ? * *", zone = AppConstant.UKRAINE_TIMEZONE) @Override void sendDailyReport(); @Scheduled(cron = "0 0 12 ? * MON", zone = AppConstant.UKRAINE_TIMEZONE) @Override void sendWeeklyReport(); @Scheduled(cron = "0 0 12 1 * ?", zone = AppConstant.UKRAINE_TIMEZONE) @Override void sendMonthlyReport(); }
NotificationServiceImpl implements NotificationService { @Override public void sendImmediatelyReport(Place newPlace) { log.info(LogMessage.IN_SEND_IMMEDIATELY_REPORT, newPlace.getName()); EmailNotification emailNotification = EmailNotification.IMMEDIATELY; List<PlaceAuthorDto> subscribers = getSubscribers(emailNotification); Map<CategoryDto, List<PlaceNotificationDto>> categoriesDtoWithPlacesDtoMap = new HashMap<>(); CategoryDto map = modelMapper.map(newPlace.getCategory(), CategoryDto.class); List<PlaceNotificationDto> placeDtoList = Collections.singletonList(modelMapper.map(newPlace, PlaceNotificationDto.class)); categoriesDtoWithPlacesDtoMap.put(map, placeDtoList); List<PlaceAuthorDto> placeAuthorDto = subscribers.stream() .map(o -> modelMapper.map(o, PlaceAuthorDto.class)) .collect(Collectors.toList()); rabbitTemplate.convertAndSend(sendEmailTopic, SEND_REPORT_ROUTING_KEY, new SendReportEmailMessage(placeAuthorDto, categoriesDtoWithPlacesDtoMap, emailNotification.toString())); } @Autowired  NotificationServiceImpl(UserRepo userRepo, PlaceRepo placeRepo,
                                   RabbitTemplate rabbitTemplate,
                                   ModelMapper modelMapper); @Override void sendImmediatelyReport(Place newPlace); @Scheduled(cron = "0 0 12 ? * *", zone = AppConstant.UKRAINE_TIMEZONE) @Override void sendDailyReport(); @Scheduled(cron = "0 0 12 ? * MON", zone = AppConstant.UKRAINE_TIMEZONE) @Override void sendWeeklyReport(); @Scheduled(cron = "0 0 12 1 * ?", zone = AppConstant.UKRAINE_TIMEZONE) @Override void sendMonthlyReport();  }