Search in sources :

Example 16 with NotificationEntity

use of com.synopsys.integration.alert.database.notification.NotificationEntity in project hub-alert by blackducksoftware.

the class AuditEntryHandlerTestIT method getTestIT.

@Test
public void getTestIT() {
    NotificationEntity savedNotificationEntity = notificationContentRepository.save(mockNotification.createEntity());
    notificationContentRepository.save(new MockNotificationContent(DateUtils.createCurrentDateTimestamp(), "provider", DateUtils.createCurrentDateTimestamp(), "notificationType", "{}", 234L, providerConfigModel.getConfigurationId()).createEntity());
    DistributionJobRequestModel jobRequestModel = createJobRequestModel();
    DistributionJobModel jobModel = jobAccessor.createJob(jobRequestModel);
    AuditEntryEntity savedAuditEntryEntity = auditEntryRepository.save(new AuditEntryEntity(jobModel.getJobId(), DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp(), AuditEntryStatus.SUCCESS.toString(), null, null));
    auditNotificationRepository.save(new AuditNotificationRelation(savedAuditEntryEntity.getId(), savedNotificationEntity.getId()));
    AuthorizationManager authorizationManager = Mockito.mock(AuthorizationManager.class);
    Mockito.when(authorizationManager.hasReadPermission(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class))).thenReturn(Boolean.TRUE);
    AuditEntryActions auditEntryActions = createAuditActions(authorizationManager);
    AuditEntryPageModel auditEntries = auditEntryActions.get(null, null, null, null, null, true).getContent().orElse(null);
    assertEquals(1, auditEntries.getContent().size());
    AuditEntryModel auditEntryResponse = auditEntryActions.get(savedNotificationEntity.getId()).getContent().orElse(null);
    assertNotNull(auditEntryResponse);
    AuditEntryModel auditEntry = auditEntries.getContent().get(0);
    assertEquals(savedNotificationEntity.getId().toString(), auditEntry.getId());
    assertFalse(auditEntry.getJobs().isEmpty());
    assertEquals(1, auditEntry.getJobs().size());
    NotificationConfig notification = auditEntry.getNotification();
    String createdAtStringValue = DateUtils.formatDate(savedNotificationEntity.getCreatedAt(), DateUtils.AUDIT_DATE_FORMAT);
    assertEquals(createdAtStringValue, notification.getCreatedAt());
    assertEquals(savedNotificationEntity.getNotificationType(), notification.getNotificationType());
    assertNotNull(notification.getContent());
    auditEntries = auditEntryActions.get(null, null, null, null, null, false).getContent().orElse(null);
    assertEquals(2, auditEntries.getContent().size());
}
Also used : MockNotificationContent(com.synopsys.integration.alert.mock.entity.MockNotificationContent) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuditDescriptorKey(com.synopsys.integration.alert.component.audit.AuditDescriptorKey) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) AuditEntryPageModel(com.synopsys.integration.alert.common.persistence.model.AuditEntryPageModel) AuditNotificationRelation(com.synopsys.integration.alert.database.audit.AuditNotificationRelation) NotificationConfig(com.synopsys.integration.alert.common.rest.model.NotificationConfig) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) NotificationEntity(com.synopsys.integration.alert.database.notification.NotificationEntity) AuditEntryModel(com.synopsys.integration.alert.common.persistence.model.AuditEntryModel) Test(org.junit.jupiter.api.Test) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest)

Example 17 with NotificationEntity

use of com.synopsys.integration.alert.database.notification.NotificationEntity in project hub-alert by blackducksoftware.

the class NotificationAccessorTestIT method deleteNotificationsCreatedBeforeTest.

@Test
public void deleteNotificationsCreatedBeforeTest() {
    OffsetDateTime currentTime = DateUtils.createCurrentDateTimestamp();
    OffsetDateTime oneHourAgo = currentTime.minusHours(1);
    OffsetDateTime oneAndAHalfHoursAgo = oneHourAgo.minusMinutes(30);
    OffsetDateTime twoHoursAgo = currentTime.minusHours(2);
    OffsetDateTime threeHoursAgo = currentTime.minusHours(3);
    OffsetDateTime oneDayAgo = currentTime.minusDays(1);
    NotificationEntity notification1 = createNotificationContent(oneHourAgo);
    // These notifications should be deleted
    NotificationEntity notification2 = createNotificationContent(twoHoursAgo);
    NotificationEntity notification3 = createNotificationContent(threeHoursAgo);
    NotificationEntity notification4 = createNotificationContent(oneDayAgo);
    notificationContentRepository.saveAll(List.of(notification1, notification2, notification3, notification4));
    int deletedCount = notificationManager.deleteNotificationsCreatedBefore(oneAndAHalfHoursAgo);
    assertEquals(3, deletedCount);
    List<NotificationEntity> remainingNotifications = notificationContentRepository.findAll();
    assertEquals(1, remainingNotifications.size());
    NotificationEntity remainingNotification = remainingNotifications.get(0);
    assertEquals(notification1.getCreatedAt(), remainingNotification.getCreatedAt());
}
Also used : OffsetDateTime(java.time.OffsetDateTime) NotificationEntity(com.synopsys.integration.alert.database.notification.NotificationEntity) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 18 with NotificationEntity

use of com.synopsys.integration.alert.database.notification.NotificationEntity in project hub-alert by blackducksoftware.

the class NotificationReceivedEventHandlerTestIT method createAlertNotificationModel.

private AlertNotificationModel createAlertNotificationModel(boolean processed) {
    String bomEditContent = "{" + "\"type\":\"" + NotificationType.BOM_EDIT.name() + "\"," + "\"content\": {" + "\"projectVersion\": \"" + properties.getBlackDuckURL() + "/api/projects\"," + "\"bomComponent\": \"" + properties.getBlackDuckURL() + "\"," + "\"componentName\": \"test\"," + "\"componentVersionName\": \"test\"" + "}" + "}";
    MockNotificationContent notificationMocker = new MockNotificationContent(DateUtils.createCurrentDateTimestamp(), blackDuckProviderKey.getUniversalKey(), DateUtils.createCurrentDateTimestamp(), NotificationType.BOM_EDIT.name(), bomEditContent, null, blackDuckGlobalConfigId);
    NotificationEntity entity = notificationMocker.createEntity();
    return new AlertNotificationModel(null, entity.getProviderConfigId(), entity.getProvider(), "providerConfigName", entity.getNotificationType(), entity.getContent(), entity.getCreatedAt(), entity.getProviderCreationTime(), processed);
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) MockNotificationContent(com.synopsys.integration.alert.mock.entity.MockNotificationContent) NotificationEntity(com.synopsys.integration.alert.database.notification.NotificationEntity)

Example 19 with NotificationEntity

use of com.synopsys.integration.alert.database.notification.NotificationEntity in project hub-alert by blackducksoftware.

the class DefaultNotificationAccessorTest method saveAllNotificationsTest.

@Test
void saveAllNotificationsTest() {
    OffsetDateTime createdAt = DateUtils.createCurrentDateTimestamp();
    OffsetDateTime providerCreationTime = createdAt.minusSeconds(10);
    AlertNotificationModel alertNotificationModel = new AlertNotificationModel(null, providerConfigId, provider, providerConfigName, notificationType, content, createdAt, providerCreationTime, false);
    NotificationEntity notificationEntity = new NotificationEntity(id, createdAt, provider, providerConfigId, providerCreationTime, notificationType, content, false);
    ConfigurationModel configurationModel = createConfigurationModel();
    NotificationContentRepository notificationContentRepository = Mockito.mock(NotificationContentRepository.class);
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    Mockito.when(notificationContentRepository.saveAll(Mockito.any())).thenReturn(List.of(notificationEntity));
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationById(Mockito.any())).thenReturn(Optional.of(configurationModel));
    DefaultNotificationAccessor notificationManager = new DefaultNotificationAccessor(notificationContentRepository, null, configurationModelConfigurationAccessor);
    List<AlertNotificationModel> alertNotificationModelList = notificationManager.saveAllNotifications(List.of(alertNotificationModel));
    assertEquals(1, alertNotificationModelList.size());
    AlertNotificationModel testAlertNotificationModel = alertNotificationModelList.get(0);
    testExpectedAlertNotificationModel(expectedAlertNotificationModel, testAlertNotificationModel);
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) OffsetDateTime(java.time.OffsetDateTime) NotificationContentRepository(com.synopsys.integration.alert.database.notification.NotificationContentRepository) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) NotificationEntity(com.synopsys.integration.alert.database.notification.NotificationEntity) Test(org.junit.jupiter.api.Test)

Example 20 with NotificationEntity

use of com.synopsys.integration.alert.database.notification.NotificationEntity in project hub-alert by blackducksoftware.

the class DefaultNotificationAccessorTest method findByCreatedAtBetweenTest.

@Test
void findByCreatedAtBetweenTest() {
    NotificationEntity notificationEntity = new NotificationEntity(id, DateUtils.createCurrentDateTimestamp(), provider, providerConfigId, DateUtils.createCurrentDateTimestamp(), notificationType, content, false);
    ConfigurationModel configurationModel = createConfigurationModel();
    NotificationContentRepository notificationContentRepository = Mockito.mock(NotificationContentRepository.class);
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    Mockito.when(notificationContentRepository.findByCreatedAtBetween(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(new PageImpl<>(List.of(notificationEntity)));
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationById(Mockito.any())).thenReturn(Optional.of(configurationModel));
    DefaultNotificationAccessor notificationManager = new DefaultNotificationAccessor(notificationContentRepository, null, configurationModelConfigurationAccessor);
    List<AlertNotificationModel> alertNotificationModelList = notificationManager.findByCreatedAtBetween(DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp(), AlertPagedModel.DEFAULT_PAGE_NUMBER, AlertPagedModel.DEFAULT_PAGE_SIZE).getModels();
    assertEquals(1, alertNotificationModelList.size());
    AlertNotificationModel alertNotificationModel = alertNotificationModelList.get(0);
    testExpectedAlertNotificationModel(expectedAlertNotificationModel, alertNotificationModel);
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) NotificationContentRepository(com.synopsys.integration.alert.database.notification.NotificationContentRepository) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) NotificationEntity(com.synopsys.integration.alert.database.notification.NotificationEntity) Test(org.junit.jupiter.api.Test)

Aggregations

NotificationEntity (com.synopsys.integration.alert.database.notification.NotificationEntity)29 Test (org.junit.jupiter.api.Test)24 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)16 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)13 NotificationContentRepository (com.synopsys.integration.alert.database.notification.NotificationContentRepository)13 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)11 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)11 AuditEntryEntity (com.synopsys.integration.alert.database.audit.AuditEntryEntity)9 AuditNotificationRelation (com.synopsys.integration.alert.database.audit.AuditNotificationRelation)9 PageRequest (org.springframework.data.domain.PageRequest)9 OffsetDateTime (java.time.OffsetDateTime)8 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)7 MockNotificationContent (com.synopsys.integration.alert.mock.entity.MockNotificationContent)6 DistributionJobRequestModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel)5 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)4 PageImpl (org.springframework.data.domain.PageImpl)4 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)3 AuditEntryPageModel (com.synopsys.integration.alert.common.persistence.model.AuditEntryPageModel)3 AuditDescriptorKey (com.synopsys.integration.alert.component.audit.AuditDescriptorKey)3 MockAuditEntryEntity (com.synopsys.integration.alert.component.audit.mock.MockAuditEntryEntity)3