@Test public void getPageOfAuditEntriesTest() { Integer pageNumber = 0; int pageSize = 2; String searchTerm = null; String sortField = "lastSent"; String sortOrder = "ASC"; Boolean onlyShowSentNotifications = Boolean.TRUE; String overallStatus = "overallStatusString"; String lastSent = DateUtils.createCurrentDateString(DateUtils.AUDIT_DATE_FORMAT); AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class); DefaultNotificationAccessor notificationManager = Mockito.mock(DefaultNotificationAccessor.class); AuditNotificationRepository auditNotificationRepository = Mockito.mock(AuditNotificationRepository.class); PageRequest pageRequest = PageRequest.of(0, 10); Mockito.when(auditEntryRepository.findMatchingAudit(Mockito.anyLong(), Mockito.any(UUID.class))).thenReturn(Optional.empty()); Mockito.when(notificationManager.getPageRequestForNotifications(pageNumber, pageSize, sortField, sortOrder)).thenReturn(pageRequest); AlertNotificationModel alertNotificationModel = new AlertNotificationModel(1L, 1L, "provider-test", "providerConfigName-test", "notificationType-test", "{content: \"content is here...\"}", DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp()); AlertNotificationModel alertNotificationModel2 = new AlertNotificationModel(2L, 2L, "provider-test2", "providerConfigName-test2", "notificationType-test2", "{content: \"content is here2..\"}", DateUtils.createCurrentDateTimestamp().minusSeconds(15), DateUtils.createCurrentDateTimestamp().minusSeconds(10)); Pageable auditPageable = Mockito.mock(Pageable.class); Mockito.when(auditPageable.getOffset()).thenReturn(pageNumber.longValue()); Mockito.when(auditPageable.getPageSize()).thenReturn(pageSize); Page<AlertNotificationModel> auditPage = new PageImpl<>(List.of(alertNotificationModel, alertNotificationModel2), auditPageable, 1); Mockito.when(notificationManager.findAll(pageRequest, onlyShowSentNotifications)).thenReturn(auditPage); NotificationConfig notificationConfig = new NotificationConfig("3", "createdAtString", "providerString", 2L, "providerConfigNameString", "providerCreationTimeString", "notificationTypeString", "content-test"); AuditEntryModel auditEntryModel = new AuditEntryModel("2", notificationConfig, List.of(), overallStatus, lastSent); Function<AlertNotificationModel, AuditEntryModel> notificationToAuditEntryConverter = (AlertNotificationModel notificationModel) -> auditEntryModel; DefaultAuditAccessor auditUtility = new DefaultAuditAccessor(auditEntryRepository, auditNotificationRepository, null, notificationManager, null); AlertPagedModel<AuditEntryModel> alertPagedModel = auditUtility.getPageOfAuditEntries(pageNumber, pageSize, searchTerm, sortField, sortOrder, onlyShowSentNotifications, notificationToAuditEntryConverter); assertEquals(1, alertPagedModel.getTotalPages()); assertEquals(pageNumber.intValue(), alertPagedModel.getCurrentPage()); assertEquals(pageSize, alertPagedModel.getPageSize()); assertEquals(2, alertPagedModel.getContent().size()); assertEquals(lastSent, alertPagedModel.getContent().get(0).getLastSent()); assertEquals(lastSent, alertPagedModel.getContent().get(1).getLastSent()); AuditEntryModel auditContentTest = alertPagedModel.getContent().stream().findFirst().orElse(null); assertEquals(auditEntryModel.getId(), auditContentTest.getId()); assertEquals(notificationConfig, auditContentTest.getNotification()); assertEquals(0, auditContentTest.getJobs().size()); assertEquals(overallStatus, auditContentTest.getOverallStatus()); assertEquals(lastSent, auditContentTest.getLastSent()); }
@Override @Transactional public AuditEntryPageModel getPageOfAuditEntries(Integer pageNumber, Integer pageSize, String searchTerm, String sortField, String sortOrder, boolean onlyShowSentNotifications, Function<AlertNotificationModel, AuditEntryModel> notificationToAuditEntryConverter) { Page<AlertNotificationModel> auditPage = getPageOfNotifications(sortField, sortOrder, searchTerm, pageNumber, pageSize, onlyShowSentNotifications); List<AuditEntryModel> auditEntries = convertToAuditEntryModelFromNotificationsSorted(auditPage.getContent(), notificationToAuditEntryConverter, sortField, sortOrder); return new AuditEntryPageModel(auditPage.getTotalPages(), auditPage.getNumber(), auditEntries.size(), auditEntries); }
DefaultAuditAccessor implements AuditAccessor { @Override @Transactional public AuditEntryPageModel getPageOfAuditEntries(Integer pageNumber, Integer pageSize, String searchTerm, String sortField, String sortOrder, boolean onlyShowSentNotifications, Function<AlertNotificationModel, AuditEntryModel> notificationToAuditEntryConverter) { Page<AlertNotificationModel> auditPage = getPageOfNotifications(sortField, sortOrder, searchTerm, pageNumber, pageSize, onlyShowSentNotifications); List<AuditEntryModel> auditEntries = convertToAuditEntryModelFromNotificationsSorted(auditPage.getContent(), notificationToAuditEntryConverter, sortField, sortOrder); return new AuditEntryPageModel(auditPage.getTotalPages(), auditPage.getNumber(), auditEntries.size(), auditEntries); } }
DefaultAuditAccessor implements AuditAccessor { @Override @Transactional public AuditEntryPageModel getPageOfAuditEntries(Integer pageNumber, Integer pageSize, String searchTerm, String sortField, String sortOrder, boolean onlyShowSentNotifications, Function<AlertNotificationModel, AuditEntryModel> notificationToAuditEntryConverter) { Page<AlertNotificationModel> auditPage = getPageOfNotifications(sortField, sortOrder, searchTerm, pageNumber, pageSize, onlyShowSentNotifications); List<AuditEntryModel> auditEntries = convertToAuditEntryModelFromNotificationsSorted(auditPage.getContent(), notificationToAuditEntryConverter, sortField, sortOrder); return new AuditEntryPageModel(auditPage.getTotalPages(), auditPage.getNumber(), auditEntries.size(), auditEntries); } @Autowired  DefaultAuditAccessor(AuditEntryRepository auditEntryRepository, AuditNotificationRepository auditNotificationRepository, ConfigurationAccessor configurationAccessor,
        DefaultNotificationAccessor notificationAccessor, ContentConverter contentConverter); }
DefaultAuditAccessor implements AuditAccessor { @Override @Transactional public AuditEntryPageModel getPageOfAuditEntries(Integer pageNumber, Integer pageSize, String searchTerm, String sortField, String sortOrder, boolean onlyShowSentNotifications, Function<AlertNotificationModel, AuditEntryModel> notificationToAuditEntryConverter) { Page<AlertNotificationModel> auditPage = getPageOfNotifications(sortField, sortOrder, searchTerm, pageNumber, pageSize, onlyShowSentNotifications); List<AuditEntryModel> auditEntries = convertToAuditEntryModelFromNotificationsSorted(auditPage.getContent(), notificationToAuditEntryConverter, sortField, sortOrder); return new AuditEntryPageModel(auditPage.getTotalPages(), auditPage.getNumber(), auditEntries.size(), auditEntries); } @Autowired  DefaultAuditAccessor(AuditEntryRepository auditEntryRepository, AuditNotificationRepository auditNotificationRepository, ConfigurationAccessor configurationAccessor,
        DefaultNotificationAccessor notificationAccessor, ContentConverter contentConverter); @Override Optional<Long> findMatchingAuditId(Long notificationId, UUID commonDistributionId); @Override @Transactional Optional<AuditJobStatusModel> findFirstByJobId(UUID jobId); @Override @Transactional AuditEntryPageModel getPageOfAuditEntries(Integer pageNumber, Integer pageSize, String searchTerm, String sortField, String sortOrder, boolean onlyShowSentNotifications,
        Function<AlertNotificationModel, AuditEntryModel> notificationToAuditEntryConverter); @Override @Transactional Map<Long, Long> createAuditEntry(Map<Long, Long> existingNotificationIdToAuditId, UUID jobId, MessageContentGroup contentGroup); @Override @Transactional void setAuditEntrySuccess(Collection<Long> auditEntryIds); @Override @Transactional void setAuditEntryFailure(Collection<Long> auditEntryIds, String errorMessage, Throwable t); @Override @Transactional AuditEntryModel convertToAuditEntryModelFromNotification(AlertNotificationModel notificationContentEntry); }
DefaultAuditAccessor implements AuditAccessor { @Override @Transactional public AuditEntryPageModel getPageOfAuditEntries(Integer pageNumber, Integer pageSize, String searchTerm, String sortField, String sortOrder, boolean onlyShowSentNotifications, Function<AlertNotificationModel, AuditEntryModel> notificationToAuditEntryConverter) { Page<AlertNotificationModel> auditPage = getPageOfNotifications(sortField, sortOrder, searchTerm, pageNumber, pageSize, onlyShowSentNotifications); List<AuditEntryModel> auditEntries = convertToAuditEntryModelFromNotificationsSorted(auditPage.getContent(), notificationToAuditEntryConverter, sortField, sortOrder); return new AuditEntryPageModel(auditPage.getTotalPages(), auditPage.getNumber(), auditEntries.size(), auditEntries); } @Autowired  DefaultAuditAccessor(AuditEntryRepository auditEntryRepository, AuditNotificationRepository auditNotificationRepository, ConfigurationAccessor configurationAccessor,
        DefaultNotificationAccessor notificationAccessor, ContentConverter contentConverter); @Override Optional<Long> findMatchingAuditId(Long notificationId, UUID commonDistributionId); @Override @Transactional Optional<AuditJobStatusModel> findFirstByJobId(UUID jobId); @Override @Transactional AuditEntryPageModel getPageOfAuditEntries(Integer pageNumber, Integer pageSize, String searchTerm, String sortField, String sortOrder, boolean onlyShowSentNotifications,
        Function<AlertNotificationModel, AuditEntryModel> notificationToAuditEntryConverter); @Override @Transactional Map<Long, Long> createAuditEntry(Map<Long, Long> existingNotificationIdToAuditId, UUID jobId, MessageContentGroup contentGroup); @Override @Transactional void setAuditEntrySuccess(Collection<Long> auditEntryIds); @Override @Transactional void setAuditEntryFailure(Collection<Long> auditEntryIds, String errorMessage, Throwable t); @Override @Transactional AuditEntryModel convertToAuditEntryModelFromNotification(AlertNotificationModel notificationContentEntry);  }