Search in sources :

Example 6 with AuditEntryEntity

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

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

the class DefaultRestApiAuditAccessorTest method findMatchingAuditIdTest.

@Test
public void findMatchingAuditIdTest() {
    AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
    Mockito.when(auditEntryRepository.findMatchingAudit(Mockito.anyLong(), Mockito.any(UUID.class))).thenReturn(Optional.empty());
    DefaultRestApiAuditAccessor auditUtility = new DefaultRestApiAuditAccessor(auditEntryRepository, null, null, null, null, null);
    Optional<Long> nullValue = auditUtility.findMatchingAuditId(1L, UUID.randomUUID());
    assertFalse(nullValue.isPresent());
    AuditEntryEntity auditEntryEntity = new AuditEntryEntity(null, null, null, null, null, null);
    Long expectedLong = 2L;
    auditEntryEntity.setId(expectedLong);
    Mockito.when(auditEntryRepository.findMatchingAudit(Mockito.anyLong(), Mockito.any(UUID.class))).thenReturn(Optional.of(auditEntryEntity));
    Optional<Long> actualValue = auditUtility.findMatchingAuditId(expectedLong, UUID.randomUUID());
    assertTrue(actualValue.isPresent());
    assertEquals(expectedLong, actualValue.get());
}
Also used : AuditEntryRepository(com.synopsys.integration.alert.database.audit.AuditEntryRepository) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 8 with AuditEntryEntity

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

the class DefaultProcessingAuditAccessor method fromView.

private AuditEntryEntity fromView(AuditEntryNotificationView view) {
    AuditEntryEntity auditEntry = new AuditEntryEntity(view.getJobId(), view.getTimeCreated(), view.getTimeLastSent(), view.getStatus(), view.getErrorMessage(), view.getErrorStackTrace());
    auditEntry.setId(view.getId());
    return auditEntry;
}
Also used : AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity)

Example 9 with AuditEntryEntity

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

the class DefaultProcessingAuditAccessor method updateAuditEntries.

private void updateAuditEntries(UUID jobId, Set<Long> notificationIds, Consumer<AuditEntryEntity> auditFieldSetter) {
    if (notificationIds.isEmpty()) {
        return;
    }
    List<AuditEntryNotificationView> auditEntryNotificationViews = auditEntryRepository.findByJobIdAndNotificationIds(jobId, notificationIds);
    List<AuditEntryEntity> updatedAuditEntries = new ArrayList<>(auditEntryNotificationViews.size());
    for (AuditEntryNotificationView view : auditEntryNotificationViews) {
        AuditEntryEntity auditEntryToSave = fromView(view);
        auditEntryToSave.setTimeLastSent(DateUtils.createCurrentDateTimestamp());
        auditFieldSetter.accept(auditEntryToSave);
        updatedAuditEntries.add(auditEntryToSave);
        logger.trace("Updated audit entry: {}.", auditEntryToSave.getId());
    }
    auditEntryRepository.saveAll(updatedAuditEntries);
}
Also used : ArrayList(java.util.ArrayList) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) AuditEntryNotificationView(com.synopsys.integration.alert.database.audit.AuditEntryNotificationView)

Example 10 with AuditEntryEntity

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

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