Search in sources :

Example 26 with NotificationEntity

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

the class AuditEntryControllerTestIT method testGetConfigWithId.

@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testGetConfigWithId() throws Exception {
    AuditEntryEntity entity = mockAuditEntryEntity.createEntity();
    entity = auditEntryRepository.save(entity);
    NotificationEntity notificationContent = mockNotificationContent.createEntity();
    notificationContent = notificationRepository.save(notificationContent);
    auditNotificationRepository.save(new AuditNotificationRelation(entity.getId(), notificationContent.getId()));
    String getUrl = auditUrl + "/" + notificationContent.getId();
    MockHttpServletRequestBuilder request = MockMvcRequestBuilders.get(getUrl).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf());
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) AuditNotificationRelation(com.synopsys.integration.alert.database.audit.AuditNotificationRelation) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) MockAuditEntryEntity(com.synopsys.integration.alert.component.audit.mock.MockAuditEntryEntity) NotificationEntity(com.synopsys.integration.alert.database.notification.NotificationEntity) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 27 with NotificationEntity

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

the class NotificationAccessorTestIT method testFindAllWithSearchByFieldValue.

@Test
public void testFindAllWithSearchByFieldValue() {
    NotificationEntity notificationContent = createNotificationContent();
    notificationContent = notificationContentRepository.save(notificationContent);
    OffsetDateTime currentTime = DateUtils.createCurrentDateTimestamp();
    DistributionJobEntity distributionJobEntity = new DistributionJobEntity(null, "job_name", true, FrequencyType.REAL_TIME.name(), ProcessingType.DEFAULT.name(), ChannelKeys.EMAIL.getUniversalKey(), UUID.randomUUID(), currentTime, null);
    DistributionJobEntity savedJob = distributionJobRepository.save(distributionJobEntity);
    final String auditStatus = "audit status thing";
    AuditEntryEntity auditEntryEntity = new AuditEntryEntity(savedJob.getJobId(), DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp(), auditStatus, "", "");
    auditEntryEntity = auditEntryRepository.save(auditEntryEntity);
    AuditNotificationRelation auditNotificationRelation = new AuditNotificationRelation(auditEntryEntity.getId(), notificationContent.getId());
    auditNotificationRepository.save(auditNotificationRelation);
    PageRequest pageRequest = PageRequest.of(0, 10);
    Page<AlertNotificationModel> all = notificationManager.findAllWithSearch(ChannelKeys.EMAIL.getUniversalKey(), pageRequest, false);
    // Search term should match the channel name
    assertFalse(all.isEmpty());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) PageRequest(org.springframework.data.domain.PageRequest) DistributionJobEntity(com.synopsys.integration.alert.database.job.DistributionJobEntity) 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 28 with NotificationEntity

use of com.synopsys.integration.alert.database.notification.NotificationEntity 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)

Example 29 with NotificationEntity

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

the class MockNotificationContent method createEntity.

@Override
public NotificationEntity createEntity() {
    NotificationEntity notificationContent = new NotificationEntity(createdAt, provider, providerConfigId, providerCreationTime, notificationType, content, false);
    notificationContent.setId(id);
    return notificationContent;
}
Also used : NotificationEntity(com.synopsys.integration.alert.database.notification.NotificationEntity)

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