Search in sources :

Example 1 with AuditNotificationRelation

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

the class NotificationContentRepositoryIT method initializeNotificationRepo.

private Long initializeNotificationRepo(String searchTerm, int numberToCreate) throws ParseException {
    List<NotificationEntity> notifications = new ArrayList<>(numberToCreate);
    long searchableCount = 0;
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(RestConstants.JSON_DATE_FORMAT);
    for (int i = 0; i < numberToCreate; i++) {
        Date newDate = new Date();
        String dateString = simpleDateFormat.format(newDate);
        NotificationEntity entity;
        if (i % 31 == 0) {
            entity = createEntity(dateString, searchTerm);
            searchableCount++;
        } else {
            entity = createEntity(dateString);
        }
        notifications.add(entity);
    }
    List<NotificationEntity> savedNotifications = notificationContentRepository.saveAll(notifications);
    DistributionJobRequestModel jobRequestModel = createJobRequestModel();
    DistributionJobModel jobModel = jobAccessor.createJob(jobRequestModel);
    UUID jobId = jobModel.getJobId();
    // more investigation is needed
    for (NotificationEntity savedNotification : savedNotifications) {
        AuditEntryEntity newEntry = new AuditEntryEntity(jobId, OffsetDateTime.now(), null, AuditEntryStatus.PENDING.name(), null, null);
        AuditEntryEntity savedEntry = auditEntryRepository.save(newEntry);
        AuditNotificationRelation notifAudit = new AuditNotificationRelation(savedEntry.getId(), savedNotification.getId());
        auditNotificationRepository.save(notifAudit);
    }
    auditEntryRepository.flush();
    return searchableCount;
}
Also used : ArrayList(java.util.ArrayList) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) Date(java.util.Date) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) AuditNotificationRelation(com.synopsys.integration.alert.database.audit.AuditNotificationRelation) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) UUID(java.util.UUID) NotificationEntity(com.synopsys.integration.alert.database.notification.NotificationEntity) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with AuditNotificationRelation

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

the class DefaultRestApiAuditAccessorTest method convertToAuditEntryModelFromNotificationTest.

@Test
public void convertToAuditEntryModelFromNotificationTest() throws Exception {
    Long id = 1L;
    Long providerConfigId = 2L;
    String provider = "provider-test";
    String providerConfigName = "providerConfigName-test";
    String notificationType = "notificationType-test";
    String content = "content-test";
    OffsetDateTime timeLastSent = DateUtils.createCurrentDateTimestamp();
    OffsetDateTime timeCreated = timeLastSent.minusSeconds(10);
    Long auditEntryId = 3L;
    String channelName = "test-channel.common.name-value";
    String eventType = "test-channel.common.channel.name-value";
    AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
    AuditNotificationRepository auditNotificationRepository = Mockito.mock(AuditNotificationRepository.class);
    JobAccessor jobAccessor = Mockito.mock(JobAccessor.class);
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    ContentConverter contentConverter = new ContentConverter(new DefaultConversionService());
    AlertNotificationModel alertNotificationModel = new AlertNotificationModel(id, providerConfigId, provider, providerConfigName, notificationType, content, DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp(), false);
    AuditNotificationRelation auditNotificationRelation = new AuditNotificationRelation(auditEntryId, alertNotificationModel.getId());
    AuditEntryEntity auditEntryEntity = new AuditEntryEntity(UUID.randomUUID(), timeCreated, timeLastSent, AuditEntryStatus.SUCCESS.name(), null, null);
    Mockito.when(auditNotificationRepository.findByNotificationId(Mockito.any())).thenReturn(List.of(auditNotificationRelation));
    Mockito.when(auditEntryRepository.findAllById(Mockito.any())).thenReturn(List.of(auditEntryEntity));
    DistributionJobModel distributionJob = DistributionJobModel.builder().jobId(UUID.randomUUID()).enabled(true).blackDuckGlobalConfigId(2L).channelDescriptorName("test-channel.common.channel.name-value").name("test-channel.common.name-value").distributionFrequency(FrequencyType.REAL_TIME).filterByProject(false).notificationTypes(List.of(NotificationType.LICENSE_LIMIT.name())).processingType(ProcessingType.DEFAULT).createdAt(DateUtils.createCurrentDateTimestamp()).build();
    Mockito.when(jobAccessor.getJobById(Mockito.any())).thenReturn(Optional.of(distributionJob));
    DefaultRestApiAuditAccessor auditUtility = new DefaultRestApiAuditAccessor(auditEntryRepository, auditNotificationRepository, jobAccessor, configurationModelConfigurationAccessor, null, contentConverter);
    AuditEntryModel testAuditEntryModel = auditUtility.convertToAuditEntryModelFromNotification(alertNotificationModel);
    assertEquals(id, Long.valueOf(testAuditEntryModel.getId()));
    assertNotNull(testAuditEntryModel.getNotification());
    assertFalse(testAuditEntryModel.getJobs().isEmpty());
    assertEquals(1, testAuditEntryModel.getJobs().size());
    JobAuditModel testJob = testAuditEntryModel.getJobs().get(0);
    assertEquals(channelName, testJob.getName());
    assertEquals(eventType, testJob.getEventType());
    assertEquals(AuditEntryStatus.SUCCESS.getDisplayName(), testAuditEntryModel.getOverallStatus());
    assertEquals(DateUtils.formatDate(timeLastSent, DateUtils.AUDIT_DATE_FORMAT), testAuditEntryModel.getLastSent());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) JobAuditModel(com.synopsys.integration.alert.common.rest.model.JobAuditModel) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) ContentConverter(com.synopsys.integration.alert.common.ContentConverter) AuditEntryRepository(com.synopsys.integration.alert.database.audit.AuditEntryRepository) JobAccessor(com.synopsys.integration.alert.common.persistence.accessor.JobAccessor) OffsetDateTime(java.time.OffsetDateTime) AuditNotificationRepository(com.synopsys.integration.alert.database.audit.AuditNotificationRepository) AuditNotificationRelation(com.synopsys.integration.alert.database.audit.AuditNotificationRelation) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) AuditEntryModel(com.synopsys.integration.alert.common.persistence.model.AuditEntryModel) Test(org.junit.jupiter.api.Test)

Example 3 with AuditNotificationRelation

use of com.synopsys.integration.alert.database.audit.AuditNotificationRelation 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 4 with AuditNotificationRelation

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

the class AuditEntryControllerTestIT method testResendNotification.

@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testResendNotification() throws Exception {
    DistributionJobRequestModel jobRequestModel = createJobRequestModel();
    DistributionJobModel job = jobAccessor.createJob(jobRequestModel);
    NotificationEntity notificationEntity = mockNotificationContent.createEntity();
    notificationEntity = notificationRepository.save(notificationEntity);
    mockAuditEntryEntity.setCommonConfigId(job.getJobId());
    AuditEntryEntity auditEntity = mockAuditEntryEntity.createEntity();
    auditEntity = auditEntryRepository.save(auditEntity);
    auditNotificationRepository.save(new AuditNotificationRelation(auditEntity.getId(), notificationEntity.getId()));
    String resendUrl = auditUrl + "/resend/" + notificationEntity.getId() + "/";
    MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(resendUrl).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) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) NotificationEntity(com.synopsys.integration.alert.database.notification.NotificationEntity) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 5 with AuditNotificationRelation

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

the class AuditEntryControllerTestIT method testResendJobConfig.

@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testResendJobConfig() throws Exception {
    List<ConfigurationFieldModel> slackFields = new ArrayList<>(MockConfigurationModelFactory.createSlackDistributionFields());
    ConfigurationFieldModel providerConfigName = providerConfigModel.getField(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME).orElse(null);
    slackFields.add(providerConfigName);
    DistributionJobRequestModel jobRequestModel = createJobRequestModel();
    DistributionJobModel jobModel = jobAccessor.createJob(jobRequestModel);
    NotificationEntity notificationEntity = mockNotificationContent.createEntity();
    notificationEntity = notificationRepository.save(notificationEntity);
    mockAuditEntryEntity.setCommonConfigId(jobModel.getJobId());
    AuditEntryEntity auditEntity = mockAuditEntryEntity.createEntity();
    auditEntity = auditEntryRepository.save(auditEntity);
    auditNotificationRepository.save(new AuditNotificationRelation(auditEntity.getId(), notificationEntity.getId()));
    String resendUrl = auditUrl + "/resend/" + notificationEntity.getId() + "/job/" + auditEntity.getCommonConfigId();
    MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(resendUrl).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf());
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
Also used : ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) ArrayList(java.util.ArrayList) 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) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) NotificationEntity(com.synopsys.integration.alert.database.notification.NotificationEntity) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

AuditEntryEntity (com.synopsys.integration.alert.database.audit.AuditEntryEntity)12 AuditNotificationRelation (com.synopsys.integration.alert.database.audit.AuditNotificationRelation)12 NotificationEntity (com.synopsys.integration.alert.database.notification.NotificationEntity)9 Test (org.junit.jupiter.api.Test)9 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)8 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)7 DistributionJobRequestModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel)5 OffsetDateTime (java.time.OffsetDateTime)5 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)4 AuditEntryModel (com.synopsys.integration.alert.common.persistence.model.AuditEntryModel)3 MockAuditEntryEntity (com.synopsys.integration.alert.component.audit.mock.MockAuditEntryEntity)3 ArrayList (java.util.ArrayList)3 PageRequest (org.springframework.data.domain.PageRequest)3 WithMockUser (org.springframework.security.test.context.support.WithMockUser)3 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)3 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)2 JobAuditModel (com.synopsys.integration.alert.common.rest.model.JobAuditModel)2 NotificationConfig (com.synopsys.integration.alert.common.rest.model.NotificationConfig)2 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)2 MockNotificationContent (com.synopsys.integration.alert.mock.entity.MockNotificationContent)2