Search in sources :

Example 6 with AuditEntryRepository

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

the class AuditEntryActionsTest method testGetNull.

@Test
public void testGetNull() {
    AuthorizationManager authorizationManager = Mockito.mock(AuthorizationManager.class);
    Mockito.when(authorizationManager.hasReadPermission(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class))).thenReturn(Boolean.TRUE);
    AuditDescriptorKey auditDescriptorKey = new AuditDescriptorKey();
    AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
    Mockito.when(auditEntryRepository.findFirstByCommonConfigIdOrderByTimeLastSentDesc(Mockito.any())).thenReturn(Optional.empty());
    DefaultNotificationAccessor notificationAccessor = Mockito.mock(DefaultNotificationAccessor.class);
    Mockito.when(notificationAccessor.findById(Mockito.anyLong())).thenReturn(Optional.empty());
    DefaultRestApiAuditAccessor auditEntryUtility = new DefaultRestApiAuditAccessor(auditEntryRepository, null, null, null, notificationAccessor, null);
    AuditEntryActions auditEntryActions = new AuditEntryActions(authorizationManager, auditDescriptorKey, auditEntryUtility, notificationAccessor, null, null, null);
    ActionResponse<AuditEntryModel> auditEntryModel = auditEntryActions.get(1L);
    assertTrue(auditEntryModel.isError());
    assertFalse(auditEntryModel.hasContent());
}
Also used : AuditEntryRepository(com.synopsys.integration.alert.database.audit.AuditEntryRepository) DefaultRestApiAuditAccessor(com.synopsys.integration.alert.database.api.DefaultRestApiAuditAccessor) DefaultNotificationAccessor(com.synopsys.integration.alert.database.api.DefaultNotificationAccessor) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuditDescriptorKey(com.synopsys.integration.alert.component.audit.AuditDescriptorKey) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) AuditDescriptorKey(com.synopsys.integration.alert.component.audit.AuditDescriptorKey) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) AuditEntryModel(com.synopsys.integration.alert.common.persistence.model.AuditEntryModel) Test(org.junit.jupiter.api.Test)

Example 7 with AuditEntryRepository

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

the class DefaultProcessingAuditAccessorTest method setAuditEntryStatusTest.

private AuditEntryEntity setAuditEntryStatusTest(AuditEntryStatus expectedStatus, AuditAccessorStatusSetter statusSetter) {
    UUID testJobId = UUID.randomUUID();
    Long testNotificationId = 99L;
    Set<Long> testNotificationIds = Set.of(testNotificationId);
    AuditEntryNotificationView testView = new AuditEntryNotificationView(0L, testJobId, testNotificationId, null, null, null, null, null);
    AtomicReference<AuditEntryEntity> savedEntry = new AtomicReference<>();
    AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
    Mockito.when(auditEntryRepository.findByJobIdAndNotificationIds(testJobId, testNotificationIds)).thenReturn(List.of(testView));
    Mockito.when(auditEntryRepository.saveAll(Mockito.anyList())).then(invocation -> {
        List<AuditEntryEntity> savedEntries = invocation.getArgument(0);
        if (!savedEntries.isEmpty()) {
            savedEntry.set(savedEntries.get(0));
        }
        return List.of();
    });
    DefaultProcessingAuditAccessor processingAuditAccessor = new DefaultProcessingAuditAccessor(auditEntryRepository, null);
    statusSetter.setStatus(processingAuditAccessor, testJobId, testNotificationIds);
    AuditEntryEntity auditEntryEntity = savedEntry.get();
    assertNotNull(auditEntryEntity, "Expected an audit entry to have been saved");
    assertEquals(testView.getId(), auditEntryEntity.getId());
    assertEquals(testView.getJobId(), auditEntryEntity.getCommonConfigId());
    assertEquals(expectedStatus.name(), auditEntryEntity.getStatus());
    assertNotNull(auditEntryEntity.getTimeLastSent(), "Expected time last sent to be set");
    return auditEntryEntity;
}
Also used : AuditEntryRepository(com.synopsys.integration.alert.database.audit.AuditEntryRepository) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) AtomicReference(java.util.concurrent.atomic.AtomicReference) UUID(java.util.UUID) AuditEntryNotificationView(com.synopsys.integration.alert.database.audit.AuditEntryNotificationView)

Example 8 with AuditEntryRepository

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

the class DefaultRestApiAuditAccessorTest method findFirstByJobIdNotNullTest.

@Test
public void findFirstByJobIdNotNullTest() {
    OffsetDateTime timeLastSent = DateUtils.createCurrentDateTimestamp();
    OffsetDateTime timeCreated = timeLastSent.minusMinutes(10L);
    AuditEntryStatus status = AuditEntryStatus.PENDING;
    UUID testUUID = UUID.randomUUID();
    AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
    AuditEntryEntity auditEntryEntity = new AuditEntryEntity(testUUID, timeCreated, timeLastSent, status.name(), null, null);
    Mockito.when(auditEntryRepository.findFirstByCommonConfigIdOrderByTimeLastSentDesc(Mockito.any(UUID.class))).thenReturn(Optional.of(auditEntryEntity));
    DefaultRestApiAuditAccessor auditUtility = new DefaultRestApiAuditAccessor(auditEntryRepository, null, null, null, null, null);
    AuditJobStatusModel auditJobStatusModel = auditUtility.findFirstByJobId(testUUID).get();
    String testTimeAuditCreated = auditJobStatusModel.getTimeAuditCreated();
    String testTimeLastSent = auditJobStatusModel.getTimeLastSent();
    String testStatus = auditJobStatusModel.getStatus();
    assertTrue(auditUtility.findFirstByJobId(testUUID).isPresent());
    assertEquals(DateUtils.formatDate(timeCreated, DateUtils.AUDIT_DATE_FORMAT), testTimeAuditCreated);
    assertEquals(DateUtils.formatDate(timeLastSent, DateUtils.AUDIT_DATE_FORMAT), testTimeLastSent);
    assertEquals(status.getDisplayName(), testStatus);
}
Also used : AuditEntryRepository(com.synopsys.integration.alert.database.audit.AuditEntryRepository) OffsetDateTime(java.time.OffsetDateTime) AuditJobStatusModel(com.synopsys.integration.alert.common.persistence.model.AuditJobStatusModel) AuditEntryStatus(com.synopsys.integration.alert.common.enumeration.AuditEntryStatus) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 9 with AuditEntryRepository

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

the class DefaultRestApiAuditAccessorTest method findFirstByJobIdNullTest.

@Test
public void findFirstByJobIdNullTest() {
    AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
    ContentConverter contentConverter = Mockito.mock(ContentConverter.class);
    AuditEntryEntity auditEntryEntity = new AuditEntryEntity(null, null, null, null, null, null);
    Mockito.when(auditEntryRepository.findFirstByCommonConfigIdOrderByTimeLastSentDesc(Mockito.any(UUID.class))).thenReturn(Optional.of(auditEntryEntity));
    DefaultRestApiAuditAccessor auditUtility = new DefaultRestApiAuditAccessor(auditEntryRepository, null, null, null, null, contentConverter);
    UUID testUUID = UUID.randomUUID();
    AuditJobStatusModel auditJobStatusModel = auditUtility.findFirstByJobId(testUUID).get();
    String timeAuditCreated = auditJobStatusModel.getTimeAuditCreated();
    String timeLastSent = auditJobStatusModel.getTimeLastSent();
    String status = auditJobStatusModel.getStatus();
    assertTrue(auditUtility.findFirstByJobId(testUUID).isPresent());
    assertNull(timeAuditCreated);
    assertNull(timeLastSent);
    assertNull(status);
}
Also used : ContentConverter(com.synopsys.integration.alert.common.ContentConverter) AuditEntryRepository(com.synopsys.integration.alert.database.audit.AuditEntryRepository) AuditJobStatusModel(com.synopsys.integration.alert.common.persistence.model.AuditJobStatusModel) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 10 with AuditEntryRepository

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

the class DefaultRestApiAuditAccessorTest method findFirstByJobIdEmptyTest.

@Test
public void findFirstByJobIdEmptyTest() {
    AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
    ContentConverter contentConverter = Mockito.mock(ContentConverter.class);
    Mockito.when(auditEntryRepository.findFirstByCommonConfigIdOrderByTimeLastSentDesc(Mockito.any(UUID.class))).thenReturn(Optional.empty());
    DefaultRestApiAuditAccessor auditUtility = new DefaultRestApiAuditAccessor(auditEntryRepository, null, null, null, null, contentConverter);
    assertFalse(auditUtility.findFirstByJobId(UUID.randomUUID()).isPresent());
}
Also used : ContentConverter(com.synopsys.integration.alert.common.ContentConverter) AuditEntryRepository(com.synopsys.integration.alert.database.audit.AuditEntryRepository) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Aggregations

AuditEntryRepository (com.synopsys.integration.alert.database.audit.AuditEntryRepository)14 Test (org.junit.jupiter.api.Test)13 AuditNotificationRepository (com.synopsys.integration.alert.database.audit.AuditNotificationRepository)7 UUID (java.util.UUID)7 AuditEntryEntity (com.synopsys.integration.alert.database.audit.AuditEntryEntity)6 ContentConverter (com.synopsys.integration.alert.common.ContentConverter)5 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)5 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)5 AuditDescriptorKey (com.synopsys.integration.alert.component.audit.AuditDescriptorKey)5 DefaultRestApiAuditAccessor (com.synopsys.integration.alert.database.api.DefaultRestApiAuditAccessor)5 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)5 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)4 JobAccessor (com.synopsys.integration.alert.common.persistence.accessor.JobAccessor)4 AuditEntryModel (com.synopsys.integration.alert.common.persistence.model.AuditEntryModel)4 AuditEntryPageModel (com.synopsys.integration.alert.common.persistence.model.AuditEntryPageModel)4 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)4 DefaultNotificationAccessor (com.synopsys.integration.alert.database.api.DefaultNotificationAccessor)4 NotificationContentRepository (com.synopsys.integration.alert.database.notification.NotificationContentRepository)4 PageRequest (org.springframework.data.domain.PageRequest)4 AuditJobStatusModel (com.synopsys.integration.alert.common.persistence.model.AuditJobStatusModel)3