Search in sources :

Example 16 with AlertNotificationModel

use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.

the class NotificationAccessorTestIT method findByCreatedAtBefore.

@Test
public void findByCreatedAtBefore() {
    OffsetDateTime time = DateUtils.createCurrentDateTimestamp();
    OffsetDateTime searchDate = time.plusHours(1);
    OffsetDateTime createdAt = time.minusHours(5);
    AlertNotificationModel entity = createNotificationModel(createdAt);
    notificationManager.saveAllNotifications(List.of(entity));
    OffsetDateTime createdAtLaterThanSearch = time.plusHours(3);
    entity = createNotificationModel(createdAtLaterThanSearch);
    notificationManager.saveAllNotifications(List.of(entity));
    List<AlertNotificationModel> foundList = notificationManager.findByCreatedAtBefore(searchDate);
    assertEquals(1, foundList.size());
    searchDate = time.minusHours(6);
    foundList = notificationManager.findByCreatedAtBefore(searchDate);
    assertTrue(foundList.isEmpty());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) OffsetDateTime(java.time.OffsetDateTime) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 17 with AlertNotificationModel

use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.

the class NotificationAccessorTestIT method testFindAll.

@Test
public void testFindAll() {
    NotificationEntity notificationContent = createNotificationContent();
    notificationContent = notificationContentRepository.save(notificationContent);
    PageRequest pageRequest = PageRequest.of(0, 10);
    Page<AlertNotificationModel> all = notificationManager.findAll(pageRequest, false);
    assertFalse(all.isEmpty());
    all = notificationManager.findAll(pageRequest, true);
    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.findAll(pageRequest, true);
    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)

Example 18 with AlertNotificationModel

use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.

the class NotificationAccessorTestIT method testFindByIdsInvalidIds.

@Test
public void testFindByIdsInvalidIds() {
    AlertNotificationModel model = createNotificationModel();
    model = notificationManager.saveAllNotifications(List.of(model)).get(0);
    List<Long> notificationIds = Arrays.asList(model.getId() + 10, model.getId() + 20, model.getId() + 30);
    List<AlertNotificationModel> notificationModelList = notificationManager.findByIds(notificationIds);
    assertTrue(notificationModelList.isEmpty());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 19 with AlertNotificationModel

use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.

the class NotificationAccessorTestIT method findByCreatedAtBetween.

@Test
public void findByCreatedAtBetween() {
    OffsetDateTime time = DateUtils.createCurrentDateTimestamp();
    OffsetDateTime startDate = time.minusHours(1);
    OffsetDateTime endDate = time.plusHours(1);
    OffsetDateTime createdAt = time.minusHours(3);
    AlertNotificationModel entity = createNotificationModel(createdAt);
    notificationManager.saveAllNotifications(List.of(entity));
    createdAt = time.plusMinutes(1);
    AlertNotificationModel entityToFind1 = createNotificationModel(createdAt);
    createdAt = time.plusMinutes(5);
    AlertNotificationModel entityToFind2 = createNotificationModel(createdAt);
    createdAt = time.plusHours(3);
    entity = createNotificationModel(createdAt);
    notificationManager.saveAllNotifications(List.of(entity));
    notificationManager.saveAllNotifications(List.of(entityToFind1));
    notificationManager.saveAllNotifications(List.of(entityToFind2));
    List<AlertNotificationModel> foundList = notificationManager.findByCreatedAtBetween(startDate, endDate, AlertPagedModel.DEFAULT_PAGE_NUMBER, AlertPagedModel.DEFAULT_PAGE_SIZE).getModels();
    assertEquals(2, foundList.size());
    assertNotificationModel(entityToFind1, foundList.get(0));
    assertNotificationModel(entityToFind2, foundList.get(1));
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) OffsetDateTime(java.time.OffsetDateTime) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 20 with AlertNotificationModel

use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.

the class NotificationAccessorTestIT method testFindByIds.

@Test
public void testFindByIds() {
    AlertNotificationModel notification = createNotificationModel();
    List<AlertNotificationModel> savedModels = notificationManager.saveAllNotifications(List.of(notification));
    List<Long> notificationIds = savedModels.stream().map(AlertNotificationModel::getId).collect(Collectors.toList());
    List<AlertNotificationModel> notificationList = notificationManager.findByIds(notificationIds);
    assertEquals(1, notificationList.size());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)94 Test (org.junit.jupiter.api.Test)62 DetailedNotificationContent (com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent)21 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)20 NotificationEntity (com.synopsys.integration.alert.database.notification.NotificationEntity)16 PageRequest (org.springframework.data.domain.PageRequest)16 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)14 NotificationContentRepository (com.synopsys.integration.alert.database.notification.NotificationContentRepository)14 OffsetDateTime (java.time.OffsetDateTime)13 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)11 ArrayList (java.util.ArrayList)10 NotificationProcessor (com.synopsys.integration.alert.processor.api.NotificationProcessor)9 NotificationReceivedEvent (com.synopsys.integration.alert.api.event.NotificationReceivedEvent)7 FilteredDistributionJobResponseModel (com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel)7 DefaultNotificationAccessor (com.synopsys.integration.alert.database.api.DefaultNotificationAccessor)6 NotificationDetailExtractionDelegator (com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator)6 NotificationContentComponent (com.synopsys.integration.blackduck.api.manual.component.NotificationContentComponent)5 PageImpl (org.springframework.data.domain.PageImpl)5 TaskManager (com.synopsys.integration.alert.api.task.TaskManager)4 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)4