Search in sources :

Example 26 with AuditEntryEntity

use of com.synopsys.integration.alert.database.audit.AuditEntryEntity in project hub-alert by blackducksoftware.

the class NotificationAccessorTestIT method testFindAllWithSearch.

@Test
public void testFindAllWithSearch() {
    NotificationEntity notificationContent = createNotificationContent();
    notificationContent = notificationContentRepository.save(notificationContent);
    PageRequest pageRequest = PageRequest.of(0, 10);
    Page<AlertNotificationModel> all = notificationManager.findAllWithSearch(ChannelKeys.EMAIL.getUniversalKey(), pageRequest, false);
    // Search term should not match anything in the saved notifications
    assertTrue(all.isEmpty());
    all = notificationManager.findAllWithSearch(NOTIFICATION_TYPE, pageRequest, false);
    // Search term should match the notification type of the saved notification
    assertFalse(all.isEmpty());
    all = notificationManager.findAllWithSearch(NOTIFICATION_TYPE, pageRequest, true);
    // Search term should match the notification type but it was never sent so no match
    assertTrue(all.isEmpty());
    OffsetDateTime now = DateUtils.createCurrentDateTimestamp();
    AuditEntryEntity auditEntryEntity = new AuditEntryEntity(UUID.randomUUID(), now, now, AuditEntryStatus.PENDING.name(), null, null);
    AuditEntryEntity saveAuditEntry = auditEntryRepository.save(auditEntryEntity);
    AuditNotificationRelation auditNotificationRelation = new AuditNotificationRelation(saveAuditEntry.getId(), notificationContent.getId());
    auditNotificationRepository.save(auditNotificationRelation);
    all = notificationManager.findAllWithSearch(NOTIFICATION_TYPE, pageRequest, true);
    // Search term should match the notification type and the notification was sent so we get a match
    assertFalse(all.isEmpty());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) PageRequest(org.springframework.data.domain.PageRequest) OffsetDateTime(java.time.OffsetDateTime) AuditNotificationRelation(com.synopsys.integration.alert.database.audit.AuditNotificationRelation) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) NotificationEntity(com.synopsys.integration.alert.database.notification.NotificationEntity) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

AuditEntryEntity (com.synopsys.integration.alert.database.audit.AuditEntryEntity)26 Test (org.junit.jupiter.api.Test)18 AuditNotificationRelation (com.synopsys.integration.alert.database.audit.AuditNotificationRelation)12 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)12 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)10 NotificationEntity (com.synopsys.integration.alert.database.notification.NotificationEntity)9 UUID (java.util.UUID)9 DistributionJobRequestModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel)8 OffsetDateTime (java.time.OffsetDateTime)8 AuditEntryRepository (com.synopsys.integration.alert.database.audit.AuditEntryRepository)7 AuditJobStatusModel (com.synopsys.integration.alert.common.persistence.model.AuditJobStatusModel)4 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)4 MockAuditEntryEntity (com.synopsys.integration.alert.component.audit.mock.MockAuditEntryEntity)4 ArrayList (java.util.ArrayList)4 WithMockUser (org.springframework.security.test.context.support.WithMockUser)4 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)4 Transactional (org.springframework.transaction.annotation.Transactional)4 AuditEntryStatus (com.synopsys.integration.alert.common.enumeration.AuditEntryStatus)3 AuditEntryModel (com.synopsys.integration.alert.common.persistence.model.AuditEntryModel)3 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)3